List of usage examples for java.lang Class getDeclaredField
@CallerSensitive public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException
From source file:com.canappi.connector.yp.yhere.HomeView.java
public void viewDidLoad() { Bundle extras = getIntent().getExtras(); if (extras != null) { Set<String> keys = extras.keySet(); for (Iterator<String> iter = keys.iterator(); iter.hasNext();) { String key = iter.next(); Class c = SearchView.class; try { Field f = c.getDeclaredField(key); Object extra = extras.get(key); String value = extra.toString(); f.set(this, extras.getString(value)); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace();/*from ww w.ja v a 2s . c o m*/ } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else { } homeViewIds = new HashMap(); homeViewValues = new HashMap(); isUserDefault = false; String restaurantButtonText = ""; String restaurantButtonPressedText = ""; restaurantButton = (Button) findViewById(R.id.restaurantButton); restaurantButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToRestaurantView(v); } }); String groceryButtonText = ""; String groceryButtonPressedText = ""; groceryButton = (Button) findViewById(R.id.groceryButton); groceryButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToGroceryView(v); } }); String gasButtonText = ""; String gasButtonPressedText = ""; gasButton = (Button) findViewById(R.id.gasButton); gasButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToGasView(v); } }); String teatherButtonText = ""; String teatherButtonPressedText = ""; teatherButton = (Button) findViewById(R.id.teatherButton); teatherButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToTeatherView(v); } }); String couponButtonText = ""; String couponButtonPressedText = ""; couponButton = (Button) findViewById(R.id.couponButton); couponButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToCouponView(v); } }); String lubeButtonText = ""; String lubeButtonPressedText = ""; lubeButton = (Button) findViewById(R.id.lubeButton); lubeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToLubeView(v); } }); String gameButtonText = ""; String gameButtonPressedText = ""; gameButton = (Button) findViewById(R.id.gameButton); gameButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goGameView(v); } }); String bakeryButtonText = ""; String bakeryButtonPressedText = ""; bakeryButton = (Button) findViewById(R.id.bakeryButton); bakeryButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToBakeryView(v); } }); String repairButtonText = ""; String repairButtonPressedText = ""; repairButton = (Button) findViewById(R.id.repairButton); repairButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToRepairView(v); } }); if (isUserDefault) { termEditText.setText(retrieveFromUserDefaultsFor("term"), TextView.BufferType.EDITABLE); } String findButtonText = "Search"; String findButtonPressedText = ""; findButton = (Button) findViewById(R.id.findButton); findButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToSearchView(v); } }); didSelectViewController(); }
From source file:com.att.android.arodatacollector.utils.AROCollectorUtils.java
/** * Retrieves the value of the specified field from an instance of the specified class using * reflection.//from w w w .j a v a 2s .co m * * @param mClass * The name of the class. * @param mInstance * The object containing the value to be retrieved. * @param fieldName * The name of the field to be retrieved. * @return The value of the specified field from the specified class. */ public final String getSpecifiedFieldValues(Class<?> mClass, Object mInstance, String fieldName) { String fieldValue = ""; if (mClass == null || mInstance == null || fieldName == null) return fieldValue; try { final Field field = mClass.getDeclaredField(fieldName); if (field != null) { field.setAccessible(true); fieldValue = field.get(mInstance).toString(); } } catch (NoSuchFieldException exp) { fieldValue = ""; AROLogger.e(TAG, "Exception in getSpecifiedFieldValues NoSuchFieldException" + exp); } catch (IllegalAccessException ile) { fieldValue = ""; AROLogger.e(TAG, "Exception in getSpecifiedFieldValues IllegalAccessException" + ile); } return fieldValue; }
From source file:com.nova.geracao.portfolio.BlogServlet.java
private Object getInstanceFromPropertiesMap(Entity entity, Class<?> klass) { Object result = null;//from w ww .j ava2s .c o m try { Field[] fields = klass.getDeclaredFields(); result = klass.newInstance(); for (int i = 0; i < fields.length; i++) { if (entity.hasProperty(fields[i].getName())) { fields[i].setAccessible(true); Object value = entity.getProperty(fields[i].getName()); if (!ClassUtils.isAssignable(fields[i].getType(), BaseDataClass.class)) { fields[i].set(result, value); } else { Object embedValue = getInstanceFromPropertiesMap((EmbeddedEntity) value, fields[i].getType()); fields[i].set(result, embedValue); } } } Field fieldId = klass.getDeclaredField("id"); fieldId.setAccessible(true); fieldId.set(result, entity.getKey().getId()); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } return result; }
From source file:com.nova.geracao.portfolio.BlogServlet.java
private Object getInstanceFromPropertiesMap(EmbeddedEntity entity, Class<?> klass) { Object result = null;/*from w w w. java 2s . com*/ try { Field[] fields = klass.getDeclaredFields(); result = klass.newInstance(); for (int i = 0; i < fields.length; i++) { if (entity.hasProperty(fields[i].getName())) { fields[i].setAccessible(true); Object value = entity.getProperty(fields[i].getName()); if (!ClassUtils.isAssignable(fields[i].getType(), BaseDataClass.class)) { fields[i].set(result, value); } else { Object embedValue = getInstanceFromPropertiesMap((EmbeddedEntity) value, fields[i].getType()); fields[i].set(result, embedValue); } } } Field fieldId = klass.getDeclaredField("id"); fieldId.setAccessible(true); fieldId.set(result, entity.getKey().getId()); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } return result; }
From source file:gemlite.core.internal.measurement.index.BigComparator.java
private Map<String, String> getValueFields() { if (valueFields == null) { valueFields = new HashMap<>(); try {/*ww w . j a v a 2 s . c om*/ IMapperTool mapperTool = DomainRegistry.getMapperTool(regionName); Class keyClass = mapperTool.getKeyClass(); Collection keyFields = mapperTool.getKeyFieldNames(); if (keyFields.size() == 1) { String fieldName = (String) keyFields.iterator().next(); String type = keyClass.getSimpleName(); valueFields.put(fieldName, type); } else { for (Iterator it = keyFields.iterator(); it.hasNext();) { String fieldName = (String) it.next(); Field field = keyClass.getDeclaredField(fieldName); String type = field.getType().getSimpleName(); valueFields.put(fieldName, type); } } } catch (Exception e) { LogUtil.getCoreLog().error("Get Index Value Info error.", e); } } return valueFields; }
From source file:org.grails.datastore.mapping.model.config.GormMappingConfigurationStrategy.java
/** * Tests whether an class is a persistent entity * * Based on the same method in Grails core within the DomainClassArtefactHandler class * @param clazz The java class//from w w w .j av a 2 s. co m * * @return True if it is a persistent entity */ public boolean isPersistentEntity(Class clazz) { // its not a closure if (clazz == null) return false; if (Closure.class.isAssignableFrom(clazz)) { return false; } if (Enum.class.isAssignableFrom(clazz)) return false; if (clazz.isAnnotationPresent(Entity.class)) { return true; } // this is done so we don't need a statically typed reference to the Grails annotation for (Annotation annotation : clazz.getAnnotations()) { if (annotation.toString().equals("@grails.persistence.Entity()")) return true; } Class testClass = clazz; boolean result = false; while (testClass != null && !testClass.equals(GroovyObject.class) && !testClass.equals(Object.class)) { try { // make sure the identify and version field exist testClass.getDeclaredField(IDENTITY_PROPERTY); testClass.getDeclaredField(VERSION_PROPERTY); // passes all conditions return true result = true; break; } catch (SecurityException e) { // ignore } catch (NoSuchFieldException e) { // ignore } testClass = testClass.getSuperclass(); } return result; }
From source file:com.hortonworks.streamline.webservice.RestIntegrationTest.java
public <T> T filterFields(T object, List<String> fields) throws Exception { if (fields != null && !fields.isEmpty()) { Class<?> clazz = object.getClass(); for (String fieldName : fields) { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true);/* ww w . ja va 2 s .co m*/ field.set(object, null); } } return object; }
From source file:com.opengamma.masterdb.security.SecurityTestCase.java
protected <T extends ManageableSecurity> void assertSecurities(final Class<T> securityClass, final Collection<T> securities) { String securityType = null;//from ww w .j ava 2 s.c om Class<?> c = securityClass; while (c != null) { try { securityType = (String) c.getDeclaredField("SECURITY_TYPE").get(null); } catch (final Throwable t) { // Ignore } c = c.getSuperclass(); } if (securityClass != RawSecurity.class) { assertNotNull(securityType); } for (final T security : securities) { assertSecurity(securityClass, security); } }
From source file:com.legstar.coxb.impl.reflect.CComplexReflectBinding.java
/** * Creates a binding property for each child. * //from w w w . j a v a 2 s. com * @param parentJaxbType the parent JAXB Class with annotations * @param xmlType the JAXB annotations * @throws ReflectBindingException if children bindings fail * */ public void initChildren(final Class<?> parentJaxbType, final XmlType xmlType) throws ReflectBindingException { if (_log.isDebugEnabled()) { _log.debug("Initializing children of: " + parentJaxbType.getSimpleName()); } /* Map of choice elements for redefined elements */ RedefinesMap redefinesMap = new RedefinesMap(); /* Process each property of this complex type in the predefined order */ for (String prop : xmlType.propOrder()) { /* Get a reference to this property field and type */ Field field; Class<?> jaxbType; try { field = parentJaxbType.getDeclaredField(prop); jaxbType = BindingUtil.getJavaClass(field); } catch (SecurityException e) { throw new ReflectBindingException(e); } catch (NoSuchFieldException e) { throw new ReflectBindingException(e); } catch (CobolBindingException e) { throw new ReflectBindingException(e); } ICobolBinding cobolBinding = ReflectBindingFactory.createBinding(jaxbType, field, this, _jaxbObjectFactory); if (_log.isDebugEnabled()) { _log.debug("Java field " + jaxbType.getSimpleName() + " bound to " + cobolBinding); } /* * If this element is a variable size array or list without an * explicit depending on clause, dynamically generate a counter. */ if (cobolBinding.getMaxOccurs() > 1 && cobolBinding.getMinOccurs() < cobolBinding.getMaxOccurs() && (cobolBinding.getDependingOn() == null || cobolBinding.getDependingOn().length() == 0)) { createDynamicCounter(cobolBinding); } /* * If this element is redefined, create a choice which will be * populated as we discover alternatives. The choice becomes the * parent for the redefined element and all alternatives. */ String redefines = cobolBinding.getRedefines(); if (cobolBinding.isRedefined()) { if (_log.isDebugEnabled()) { _log.debug( "Creating Choice binding for redefined Cobol element " + cobolBinding.getCobolName()); } ICobolChoiceBinding choice = ReflectBindingFactory.createChoiceBinding(this, cobolBinding, redefinesMap); getChildrenList().add(choice); } else if (redefines != null && redefines.length() > 0) { if (_log.isDebugEnabled()) { _log.debug("Adding " + cobolBinding.getCobolName() + " to Choice binding for Cobol element " + redefines); } ICobolChoiceBinding choice = redefinesMap.getChoiceElement(redefines); if (choice == null) { throw new ReflectBindingException("Cobol element " + cobolBinding.getCobolName() + " redefining unbound element " + redefines); } /* * Add the redefining item to the alternative list in the choice * element */ choice.addAlternative(cobolBinding); } else { getChildrenList().add(cobolBinding); } } if (_log.isDebugEnabled()) { _log.debug("Children sucessfully initialized for: " + parentJaxbType.getSimpleName()); } }
From source file:com.canappi.connector.yp.yhere.CouponView.java
public void viewDidLoad() { Bundle extras = getIntent().getExtras(); if (extras != null) { Set<String> keys = extras.keySet(); for (Iterator<String> iter = keys.iterator(); iter.hasNext();) { String key = iter.next(); Class c = SearchView.class; try { Field f = c.getDeclaredField(key); Object extra = extras.get(key); String value = extra.toString(); f.set(this, extras.getString(value)); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace();/*www. j av a 2s . c o m*/ } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else { } couponViewIds = new HashMap(); couponViewValues = new HashMap(); isUserDefault = false; resultsListView = (ListView) findViewById(R.id.resultsTable); resultsAdapter = new ResultsEfficientAdapter(this); businessNameArray = new ArrayList<String>(); couponDescriptionArray = new ArrayList<String>(); couponIdArray = new ArrayList<String>(); phoneNumberArray = new ArrayList<String>(); callArray = new ArrayList<String>(); streetArray = new ArrayList<String>(); cityArray = new ArrayList<String>(); resultsListView.setAdapter(resultsAdapter); didSelectViewController(); }