List of usage examples for java.lang Class getFields
@CallerSensitive public Field[] getFields() throws SecurityException
From source file:com.eviware.x.form.support.ADialogBuilder.java
public static XFormDialog buildDialog(Class<? extends Object> formClass, ActionList actions, FormLayout layout) {//from w w w . ja v a 2s. c om AForm formAnnotation = formClass.getAnnotation(AForm.class); if (formAnnotation == null) { throw new RuntimeException("formClass is not annotated correctly.."); } MessageSupport messages = MessageSupport.getMessages(formClass); XFormDialogBuilder builder = XFormFactory.createDialogBuilder(messages.get(formAnnotation.name())); XForm form = createForm(builder, layout); for (Field field : formClass.getFields()) { AField fieldAnnotation = field.getAnnotation(AField.class); if (fieldAnnotation != null) { try { addFormField(form, field, fieldAnnotation, messages); } catch (Exception e) { e.printStackTrace(); } } } ActionList defaultActions = StringUtils.isBlank(formAnnotation.helpUrl()) ? builder.buildOkCancelActions() : builder.buildOkCancelHelpActions(formAnnotation.helpUrl()); if (actions == null) { actions = defaultActions; } else { actions.addActions(defaultActions); } XFormDialog dialog = builder.buildDialog(actions, messages.get(formAnnotation.description()), UISupport.createImageIcon(formAnnotation.icon())); return dialog; }
From source file:jp.co.ctc_g.jfw.core.util.Beans.java
/** * ???/*from w w w . j av a2 s .c om*/ * @param clazz * @return ?? */ public static String[] listPseudoPropertyNames(Class<?> clazz) { List<String> names = new ArrayList<String>(); for (PropertyDescriptor pd : Beans.findPropertyDescriptorsFor(clazz)) { names.add(pd.getName()); } for (Field f : clazz.getFields()) { String n = f.getName(); if (!names.contains(n)) names.add(n); } return names.toArray(new String[0]); }
From source file:kr.debop4j.core.tools.StringTool.java
/** * ?? ?, ? ? . @param obj the obj/* w ww. j a va 2 s . co m*/ * * @param obj the obj * @return the string */ public static String objectToString(final Object obj) { if (obj == null) return NULL_STR; Objects.ToStringHelper helper = Objects.toStringHelper(obj); try { Class objClazz = obj.getClass(); Field[] fields = objClazz.getFields(); for (Field field : fields) helper.add(field.getName(), field.get(obj)); } catch (IllegalAccessException ignored) { log.warn(" ? .", ignored); } return helper.toString(); }
From source file:com.eviware.x.form.support.ADialogBuilder.java
/** * Allow to use custom Ok, Cancel buttons... * <p/>/*from ww w.jav a2s . co m*/ * This means user have to add control for closing dialog. * * @param formClass * @param actions * @param useDefaultOkCancel * @return */ public static XFormDialog buildDialog(Class<? extends Object> formClass, ActionList actions, boolean useDefaultOkCancel) { if (useDefaultOkCancel) { return buildDialog(formClass, actions); } AForm formAnnotation = formClass.getAnnotation(AForm.class); if (formAnnotation == null) { throw new RuntimeException("formClass is not annotated correctly.."); } MessageSupport messages = MessageSupport.getMessages(formClass); XFormDialogBuilder builder = XFormFactory.createDialogBuilder(messages.get(formAnnotation.name())); XForm form = createForm(builder, null); for (Field field : formClass.getFields()) { AField fieldAnnotation = field.getAnnotation(AField.class); if (fieldAnnotation != null) { try { addFormField(form, field, fieldAnnotation, messages); } catch (Exception e) { e.printStackTrace(); } } } ActionList defaultActions = StringUtils.isBlank(formAnnotation.helpUrl()) ? null : builder.buildHelpActions(formAnnotation.helpUrl()); if (actions == null) { actions = defaultActions; } else { // since there is only one action do it like this actions.insertAction(defaultActions.getActionAt(0), 0); } XFormDialog dialog = builder.buildDialog(actions, messages.get(formAnnotation.description()), UISupport.createImageIcon(formAnnotation.icon())); return dialog; }
From source file:net.ostis.sc.memory.SCKeynodesBase.java
protected static void init(SCSession session, Class<? extends SCKeynodesBase> klass) { if (log.isDebugEnabled()) log.debug("Start retrieving keynodes for " + klass); try {/*ww w . j a va2 s. co m*/ // // Search default segment for keynodes // SCSegment defaultSegment = null; { DefaultSegment annotation = klass.getAnnotation(DefaultSegment.class); if (annotation != null) { defaultSegment = session.openSegment(annotation.value()); Validate.notNull(defaultSegment, "Default segment \"{0}\" not found", annotation.value()); klass.getField(annotation.fieldName()).set(null, defaultSegment); } } Field[] fields = klass.getFields(); for (Field field : fields) { int modifiers = field.getModifiers(); if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers)) { Class<?> type = field.getType(); if (type.equals(SCSegment.class)) { // // We have segment field. Load segment by uri. // SegmentURI annotation = field.getAnnotation(SegmentURI.class); if (annotation != null) { String uri = annotation.value(); SCSegment segment = session.openSegment(uri); field.set(null, segment); } else { // May be it already has value? if (log.isWarnEnabled()) { if (field.get(null) == null) log.warn(field + " doesn't have value"); } } } else { if (!(checkKeynode(session, defaultSegment, field) || checkKeynodeURI(session, field) || checkKeynodesNumberPatternURI(session, klass, field))) { if (log.isWarnEnabled()) { if (field.get(null) == null) log.warn(field + " doesn't have annotations and value"); } } } } } } catch (Exception e) { // TODO: handle e.printStackTrace(); } }
From source file:org.apache.openjpa.enhance.Reflection.java
/** * Gets all public field names of the given Class. * //from www.j av a 2s. c o m */ public static Set<String> getPublicFieldNames(Class c) { if (c == null) return Collections.EMPTY_SET; Field[] fields = c.getFields(); if (fields == null || fields.length == 0) return Collections.EMPTY_SET; Set<String> result = new TreeSet<String>(); for (Field f : fields) { if (canReflect(f)) result.add(f.getName()); } return result; }
From source file:org.apache.openjpa.enhance.Reflection.java
/** * Gets values of all field f the given class such that f exactly * match the given modifiers and are of given type (Object implies any type) * unless f is annotated as {@link Reflectable}. * /*from w w w . j a va2 s . c om*/ */ public static <T> Set<T> getFieldValues(Class c, int mods, Class<T> t) { if (c == null) return Collections.EMPTY_SET; Field[] fields = c.getFields(); if (fields == null || fields.length == 0) return Collections.EMPTY_SET; Set<T> result = new TreeSet<T>(); for (Field f : fields) { if (mods == f.getModifiers() && (t == Object.class || t.isAssignableFrom(f.getType())) && canReflect(f)) { try { result.add((T) f.get(null)); } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } } return result; }
From source file:lucee.runtime.reflection.storage.WeakFieldStorage.java
/** * store a class with his methods/*from w w w . j a va2 s. c o m*/ * @param clazz * @return returns stored Struct */ private StructImpl store(Class clazz) { Field[] fieldsArr = clazz.getFields(); StructImpl fieldsMap = new StructImpl(); for (int i = 0; i < fieldsArr.length; i++) { storeField(fieldsArr[i], fieldsMap); } map.put(clazz, fieldsMap); return fieldsMap; }
From source file:com.teradata.tempto.internal.ReflectionInjectorHelper.java
private Object[] readFieldValues(Object instance) { Class<?> instanceClass = instance.getClass(); Field[] fields = instanceClass.getFields(); Object[] values = new Object[fields.length]; for (int i = 0; i < fields.length; i++) { try {/*from w w w. j a v a 2 s . c om*/ values[i] = fields[i].get(instance); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } return values; }
From source file:org.eclipse.wb.internal.core.model.description.rules.PublicFieldPropertiesRule.java
@Override public void begin(String namespace, String name, Attributes attributes) throws Exception { ComponentDescription componentDescription = (ComponentDescription) digester.peek(); Class<?> componentClass = componentDescription.getComponentClass(); for (Field field : componentClass.getFields()) { int modifiers = field.getModifiers(); if (!Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)) { addSingleProperty(componentDescription, field); }// ww w . j a v a2 s .co m } }