List of usage examples for java.lang Class getFields
@CallerSensitive public Field[] getFields() throws SecurityException
From source file:com.yahoo.elide.core.EntityBinding.java
public EntityBinding(Class<?> cls, String type) { // Map id's, attributes, and relationships Collection<AccessibleObject> fieldOrMethodList = CollectionUtils.union(Arrays.asList(cls.getFields()), Arrays.asList(cls.getMethods())); jsonApi = type;/*from ww w . j a v a 2 s .c om*/ // Initialize our maps for this entity. Duplicates are checked above. attrsDeque = new ConcurrentLinkedDeque<>(); relationshipsDeque = new ConcurrentLinkedDeque<>(); relationshipTypes = new ConcurrentHashMap<>(); relationshipToInverse = new ConcurrentHashMap<>(); fieldsToValues = new ConcurrentHashMap<>(); fieldsToTypes = new ConcurrentHashMap<>(); fieldsToTriggers = new MultiValueMap<>(); aliasesToFields = new ConcurrentHashMap<>(); accessibleObject = new ConcurrentHashMap<>(); bindEntityFields(cls, type, fieldOrMethodList); bindAccessibleObjects(cls, fieldOrMethodList); attrs = dequeToList(attrsDeque); relationships = dequeToList(relationshipsDeque); }
From source file:org.hyperic.hq.ui.taglib.ConstantsTag.java
public int doEndTag() throws JspException { try {// w w w. j ava2 s. c o m JspWriter out = pageContext.getOut(); if (className == null) { className = pageContext.getServletContext().getInitParameter(constantsClassNameParam); } if (validate(out)) { // we're misconfigured. getting this far // is a matter of what our failure mode is // if we haven't thrown an Error, carry on log.debug("constants tag misconfigured"); return EVAL_PAGE; } HashMap fieldMap; if (constants.containsKey(className)) { // we cache the result of the constants class // reflection field walk as a map fieldMap = (HashMap) constants.get(className); } else { fieldMap = new HashMap(); Class typeClass = Class.forName(className); //Object con = typeClass.newInstance(); Field[] fields = typeClass.getFields(); for (int i = 0; i < fields.length; i++) { // string comparisons of class names should be cheaper // than reflective Class comparisons, the asumption here // is that most constants are Strings, ints and booleans // but a minimal effort is made to accomadate all types // and represent them as String's for our tag's output //BIG NEW ASSUMPTION: Constants are statics and do not require instantiation of the class if (Modifier.isStatic(fields[i].getModifiers())) { String fieldType = fields[i].getType().getName(); String strVal; if (fieldType.equals("java.lang.String")) { strVal = (String) fields[i].get(null); } else if (fieldType.equals("int")) { strVal = Integer.toString(fields[i].getInt(null)); } else if (fieldType.equals("boolean")) { strVal = Boolean.toString(fields[i].getBoolean(null)); } else if (fieldType.equals("char")) { strVal = Character.toString(fields[i].getChar(null)); } else if (fieldType.equals("double")) { strVal = Double.toString(fields[i].getDouble(null)); } else if (fieldType.equals("float")) { strVal = Float.toString(fields[i].getFloat(null)); } else if (fieldType.equals("long")) { strVal = Long.toString(fields[i].getLong(null)); } else if (fieldType.equals("short")) { strVal = Short.toString(fields[i].getShort(null)); } else if (fieldType.equals("byte")) { strVal = Byte.toString(fields[i].getByte(null)); } else { Object val = (Object) fields[i].get(null); strVal = val.toString(); } fieldMap.put(fields[i].getName(), strVal); } } // cache the result constants.put(className, fieldMap); } if (symbol != null && !fieldMap.containsKey(symbol)) { // tell the developer that he's being a dummy and what // might be done to remedy the situation // TODO: what happens if the constants change? // do we need to throw a JspException, here? String err1 = symbol + " was not found in " + className + "\n"; String err2 = err1 + "use <constants:diag classname=\"" + className + "\"/>\n" + "to figure out what you're looking for"; log.error(err2); die(out, err1); } if (varSpecified) { doSet(fieldMap); } else { doOutput(fieldMap, out); } } catch (JspException e) { throw e; } catch (Exception e) { log.debug("doEndTag() failed: ", e); throw new JspException("Could not access constants tag", e); } return EVAL_PAGE; }
From source file:com.aw.swing.mvp.view.IPView.java
private Object getComponentFullScan(String attributeName, Object source) { List<Field> forms = new ArrayList(); Class cls = source.getClass(); Field[] fields = cls.getFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].getName().equals(attributeName)) { JComponent jComponemt; try { jComponemt = (JComponent) fields[i].get(source); if (jComponemt != null) { jComponemt.putClientProperty("Field", fields[i]); return jComponemt; } else { System.out.println("Null:<" + source.getClass() + ">- <" + fields[i].getName() + ">"); }/*from w w w .j a v a 2s . co m*/ } catch (IllegalAccessException e) { e.printStackTrace(); throw new AWSystemException("Error getting teh value of:<" + fields[i].getName() + ">", e); } } if ((fields[i].getType().getSimpleName().startsWith("Frm"))) { forms.add(fields[i]); } } if (forms.size() > 0) { for (Field field : forms) { try { Object formToBeChecked = field.get(source); if (formToBeChecked != null) { Object cmp = getComponentFullScan(attributeName, formToBeChecked); if (cmp != null) { return cmp; } } else { throw new IllegalStateException("FRM NULL:" + field.getName()); } } catch (IllegalAccessException e) { e.printStackTrace(); throw new AWSystemException("Problems getting value for:<" + field.getName() + ">", e); } } } logger.debug("Searching - Component " + attributeName + " does not exist in:" + source); return null; }
From source file:com.epam.jdi.uitests.mobile.appium.elements.complex.table.EntityTable.java
public EntityTable(Class<E> entityClass) { if (entityClass == null) { throw new IllegalArgumentException("Entity type was not specified"); }//w ww .j a v a 2 s. c om this.entityClass = entityClass; List<String> headers = Arrays.stream(entityClass.getFields()).map(Field::getName) .collect(Collectors.toList()); hasColumnHeaders(headers); }
From source file:edu.internet2.middleware.grouper.changeLog.provisioning.ProvisioningConsumer.java
/** * Convert the ChangeLogEntry to a ChangeEvent * * @param changeLogEntry//from w w w . j ava2s . c o m * @return * @throws IllegalAccessException * @throws ClassNotFoundException */ private ChangeEvent createEventFromLogEntry(ChangeLogEntry changeLogEntry, String consumerName) throws IllegalAccessException, ClassNotFoundException { ChangeEvent event = new ChangeEvent(); event.setSequenceNumber(changeLogEntry.getSequenceNumber()); //if this is a group type add action and category // copy all values from the ChangeLogEntry to the POJO ChangeEvent for (ChangeLogTypeBuiltin logEntryType : ChangeLogTypeBuiltin.values()) { if (changeLogEntry.equalsCategoryAndAction(logEntryType)) { String typeStr = logEntryType.toString(); if (LOG.isDebugEnabled()) LOG.debug("Event is " + logEntryType.toString()); try { event.setEventType(ChangeEvent.ChangeEventType.valueOf(typeStr).name()); //Class labels = (Class)ChangeLogLabels.class.getField(typeStr).get(null); Class labels = Class .forName("edu.internet2.middleware.grouper.changeLog.ChangeLogLabels$" + typeStr); for (Field f : labels.getFields()) { String value = this.getLabelValue(changeLogEntry, (ChangeLogLabel) f.get(null)); String setterName = "set" + Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1); try { Method setter = event.getClass().getMethod(setterName, String.class); setter.invoke(event, value); } catch (Exception e) { LOG.info("Field " + f.getName() + " not supported by class " + event.getClass().getSimpleName()); } } } catch (IllegalArgumentException e) { LOG.info("Unsupported event " + typeStr + ", " + event.getSequenceNumber()); } } } event = addSubjectAttributesIfNecessary(consumerName, event); return event; }
From source file:org.omnaest.utils.reflection.ReflectionUtils.java
/** * Returns the {@link Class#getFields()} for a given {@link Class}. Returns always a {@link List} instance. * // w w w .j a va 2 s .c o m * @param type * @return */ public static List<Field> fieldList(Class<?> type) { // final List<Field> retlist = new ArrayList<Field>(); // if (type != null) { // retlist.addAll(Arrays.asList(type.getFields())); } // return retlist; }
From source file:org.hako.dao.mapper.EntityFactory.java
/** * Filter setters./*from w ww . j a v a 2s . co m*/ * * @param clazz * @return setters */ private List<Setter> filterSetter(Class<?> clazz) { List<Setter> setters = new ArrayList<Setter>(); // filter method setters for (Method m : clazz.getMethods()) { String name = m.getName(); if (name.startsWith("set") && name.length() > 3 && m.getParameterTypes().length == 1) { setters.add(new MethodSetter(m)); } } // filter field setters for (Field f : clazz.getFields()) { setters.add(new FieldSetter(f)); } return setters; }
From source file:org.openqa.selendroid.server.model.internal.execute_native.FindRId.java
@Override public Object executeScript(JSONArray args) { Class rClazz; try {/* w w w. java 2s . com*/ rClazz = serverInstrumentation.getTargetContext().getClassLoader() .loadClass(serverInstrumentation.getTargetContext().getPackageName() + ".R$id"); } catch (ClassNotFoundException e) { e.printStackTrace(); return ""; } String using = null; try { using = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } for (Field field : rClazz.getFields()) { if (field.getName().equalsIgnoreCase(using)) { try { return field.getInt(null); } catch (IllegalAccessException e) { e.printStackTrace(); } } } return ""; }
From source file:be.apsu.extremon.probes.tsp.TSPProbe.java
private void getAllowedSignatureOIDs(String[] names) { oidsAllowed = new HashSet<String>(); oidToName = new HashMap<String, String>(); for (Class<?> clazz : new Class[] { X9ObjectIdentifiers.class, OIWObjectIdentifiers.class, PKCSObjectIdentifiers.class, TeleTrusTObjectIdentifiers.class, X509ObjectIdentifiers.class, CMSSignedDataGenerator.class, CryptoProObjectIdentifiers.class }) { for (Field field : clazz.getFields()) { if (field.getType().equals(ASN1ObjectIdentifier.class) && field.getName().toLowerCase().contains("with")) { try { ASN1ObjectIdentifier identifier = (ASN1ObjectIdentifier) field.get(null); String nameFound = field.getName().toLowerCase().replace("_", ""); oidToName.put(identifier.getId(), nameFound); for (String name : names) { String nameAllowed = name.toLowerCase().replace("_", ""); if (nameAllowed.equals(nameFound)) { oidsAllowed.add(identifier.getId()); }/*from w ww. jav a2s .com*/ } } catch (IllegalArgumentException e) { // if interface changed, simply don't use } catch (IllegalAccessException e) { // if private, simply don't use } } } } }
From source file:com.kelveden.rastajax.core.ResourceClassLoader.java
private List<Parameter> loadClassFields(final Class<?> resourceClass) { final String logPrefix = " |-"; final List<Parameter> fields = new ArrayList<Parameter>(); for (Field field : resourceClass.getFields()) { final Set<Annotation> annotations = JaxRsAnnotationScraper.scrapeJaxRsAnnotationsFrom(field); try {/*from ww w .j a v a2 s . c o m*/ final Parameter parameter = buildParameterFromJaxRsAnnotations(annotations, field.getType()); if (parameter != null) { LOGGER.debug("{} Found {} field '{}' of type '{}'.", logPrefix, parameter.getJaxRsAnnotationType().getSimpleName(), parameter.getName(), parameter.getType().getName()); fields.add(parameter); } } catch (IllegalAccessException e) { throw new ResourceClassLoadingException(String.format("Could not load field '%s' on class '%s'", field.getName(), resourceClass.getName()), e); } catch (InvocationTargetException e) { throw new ResourceClassLoadingException(String.format("Could not load field '%s' on class '%s'", field.getName(), resourceClass.getName()), e); } catch (NoSuchMethodException e) { throw new ResourceClassLoadingException(String.format("Could not load field '%s' on class '%s'", field.getName(), resourceClass.getName()), e); } } return fields; }