List of usage examples for java.lang.reflect Field getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForIsNotEmptyAnnotation(Field field, Object classObject) { boolean contentIsCorrect = false; Annotations.ContentNotEmpty annotation = field.getAnnotation(Annotations.ContentNotEmpty.class); Object[] typeAndContent = getNodesTypeAndContent(field, classObject); Object value = typeAndContent[1]; boolean predicateValue = getPredicateValue(annotation.predicate(), field.getName()); // case of comboBoxes value may contains tab or spaces so we need to trim the value. if (predicateValue && (value == null || value.toString().trim().isEmpty())) { changeNodeTitleLabelVisual((Node) typeAndContent[0], annotation.explain()); } else {/*from w w w . jav a 2 s. c o m*/ changeNodeTitleLabelVisual((Node) typeAndContent[0], ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForContentISOAnnotation(Field field, Object currSceneController) { boolean contentIsCorrect = false; Annotations.ContentISO annotation = field.getAnnotation(Annotations.ContentISO.class); Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController); if (!Pattern.matches(annotation.value(), (String) typeAndContent[1])) { String explainFromBundle = GeneralConfig.getInstance().getTitleFor(annotation.explain()); String explain = explainFromBundle.replaceFirst("#", "" + Annotations.ContentISO.isoLen); changeNodeTitleLabelVisual((Node) typeAndContent[0], explain); } else {/* www . j a v a 2 s. c om*/ changeNodeTitleLabelVisual((Node) typeAndContent[0], ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForContentPatternAnnotation(Field field, Object currSceneController) { boolean contentIsCorrect = false; Annotations.ContentPattern annotation = field.getAnnotation(Annotations.ContentPattern.class); Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController); if (!Pattern.matches(annotation.value(), (String) typeAndContent[1])) { changeNodeTitleLabelVisual((Node) typeAndContent[0], annotation.explain()); } else {// w w w. ja v a 2 s .c om changeNodeTitleLabelVisual((Node) typeAndContent[0], ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForContentMailAnnotation(Field field, Object currSceneController) { boolean contentIsCorrect = false; Annotations.ContentMail annotation = field.getAnnotation(Annotations.ContentMail.class); Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController); boolean validSyntax = Pattern.matches(annotation.valueForSyntax(), (String) typeAndContent[1]); boolean validAlphabet = Pattern.matches(annotation.valueForAlphabet(), (String) typeAndContent[1]); boolean predicateValue = getPredicateValue(annotation.predicate(), field.getName()); if (predicateValue && !validSyntax) { // otherwise email check label may stay a red color changeNodeTitleLabelVisual((Node) typeAndContent[0], annotation.explainForSyntax()); } else if (predicateValue && !validAlphabet) { // otherwise email check label may stay a red color changeNodeTitleLabelVisual((Node) typeAndContent[0], annotation.explainForAlphabet()); } else {/*w w w . j av a 2 s .c o m*/ changeNodeTitleLabelVisual((Node) typeAndContent[0], ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForContentRateAnnotation(Field field, Object currSceneController) { boolean contentIsCorrect = false; Annotations.ContentRate annotation = field.getAnnotation(Annotations.ContentRate.class); Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController); if (!Pattern.matches(annotation.valueForIntegerPart(), (String) typeAndContent[1])) { String explainFromBundle = GeneralConfig.getInstance().getTitleFor(annotation.explainForIntegerPart()); String integerPartExp = explainFromBundle.replaceFirst("#", "" + Annotations.ContentRate.integerPartLen); changeNodeTitleLabelVisual((Node) typeAndContent[0], integerPartExp); } else if (!Pattern.matches(annotation.valueForFractionalPart(), (String) typeAndContent[1])) { String explainFromBundle = GeneralConfig.getInstance() .getTitleFor(annotation.explainForFractionalPart()); String fractionalPartExp = explainFromBundle.replaceFirst("#", "" + Annotations.ContentRate.fractionalPartLen); changeNodeTitleLabelVisual((Node) typeAndContent[0], fractionalPartExp); } else if (!Pattern.matches(annotation.valueForWhole(), (String) typeAndContent[1])) { changeNodeTitleLabelVisual((Node) typeAndContent[0], annotation.explainForWhole()); } else {/* w ww . j a v a2s .c o m*/ changeNodeTitleLabelVisual((Node) typeAndContent[0], ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:com.shenit.commons.utils.GsonUtils.java
/** * ???./* w w w . j a va2s. com*/ * @param clazz * @return */ public static Field<?>[] serializeFields(Class<?> clazz) { if (REGISTERED_FIELDS.containsKey(clazz)) return REGISTERED_FIELDS.get(clazz); java.lang.reflect.Field[] fields = clazz.getDeclaredFields(); List<Field<?>> fs = Lists.newArrayList(); SerializedName serializedName; JsonProperty jsonProp; IgnoreField ignore; for (java.lang.reflect.Field field : fields) { if (field == null) continue; serializedName = field.getAnnotation(SerializedName.class); jsonProp = field.getAnnotation(JsonProperty.class); ignore = field.getAnnotation(IgnoreField.class); if (ignore != null) continue; String name = null; if (serializedName != null) { name = serializedName.value(); } else if (jsonProp != null) { name = jsonProp.value(); } else { name = Modifier.isStatic(field.getModifiers()) ? null : field.getName(); } if (name == null) continue; Default defVal = field.getDeclaredAnnotation(Default.class); fs.add(new Field(name, field.getName(), field.getType(), defVal == null ? null : defVal.value())); } Field<?>[] fsArray = fs.toArray(new Field<?>[0]); REGISTERED_FIELDS.put(clazz, fsArray); return fsArray; }
From source file:edu.usu.sdl.openstorefront.util.ReflectionUtil.java
/** * Finds the PK field of an entity (there should only be one) * * @param <T>/*from w w w . ja va 2 s .c o m*/ * @param entity * @return the PK field or null if not found */ public static <T extends BaseEntity> Field getPKField(T entity) { Objects.requireNonNull(entity, "Entity must not be NULL"); Field pkField = null; List<Field> fields = getAllFields(entity.getClass()); for (Field field : fields) { PK idAnnotation = field.getAnnotation(PK.class); if (idAnnotation != null) { pkField = field; } } return pkField; }
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForContentMapEditorAnnotation(Field field, Object currSceneController) { boolean contentIsCorrect = false; Annotations.ContentMapEditor annotation = field.getAnnotation(Annotations.ContentMapEditor.class); Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController); MapEditor mapEditorComboBox = (MapEditor) typeAndContent[0]; String editorContent = (String) typeAndContent[1]; String keyPart = StringUtils.substringBefore(editorContent, mapEditorComboBox.getDelimiter()).trim(); String valuePart = StringUtils.substringAfter(editorContent, mapEditorComboBox.getDelimiter()).trim(); boolean keyMatch = Pattern.matches(mapEditorComboBox.getKeyPattern(), keyPart); boolean valueMatch = Pattern.matches(mapEditorComboBox.getValuePattern(), valuePart); String explain;/*w ww.j ava 2s .c o m*/ if (!keyMatch || !valueMatch) { explain = (!keyMatch) ? annotation.explainKey() : annotation.explainValue(); changeNodeTitleLabelVisual(mapEditorComboBox, explain); } else if ((keyPart.isEmpty() && !valuePart.isEmpty()) || (!keyPart.isEmpty() && valuePart.isEmpty())) { explain = annotation.explainEmpty(); changeNodeTitleLabelVisual(mapEditorComboBox, explain); } else { changeNodeTitleLabelVisual(mapEditorComboBox, ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForContentAmountAnnotation(Field field, Object currSceneController) { boolean contentIsCorrect = false; Annotations.ContentAmount annotation = field.getAnnotation(Annotations.ContentAmount.class); Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController); String integerPartPattern = annotation.valueForIntegerPart(); int outerIntegerPartMaxLen = annotation.integerPartMaxLen(); if (outerIntegerPartMaxLen > 0) { integerPartPattern = annotation.valueForIntegerPart().replaceFirst( "" + (Annotations.ContentAmount.integerPartMaxLen - 1), "" + annotation.integerPartMaxLen()); }//from w w w . jav a 2 s. com if (!Pattern.matches(integerPartPattern, (String) typeAndContent[1])) { String integerPartExplain = (outerIntegerPartMaxLen > 0) ? "" + outerIntegerPartMaxLen : "" + Annotations.ContentAmount.integerPartMaxLen; String explainFromBundle = GeneralConfig.getInstance().getTitleFor(annotation.explainForIntegerPart()); String integerPartExp = explainFromBundle.replaceFirst("#", integerPartExplain); changeNodeTitleLabelVisual((Node) typeAndContent[0], integerPartExp); } else if (!Pattern.matches(annotation.valueForFractionalPart(), (String) typeAndContent[1])) { String explainFromBundle = GeneralConfig.getInstance() .getTitleFor(annotation.explainForFractionalPart()); String fractionalPartExp = explainFromBundle.replaceFirst("#", "" + Annotations.ContentAmount.fractionalPartMaxLen); changeNodeTitleLabelVisual((Node) typeAndContent[0], fractionalPartExp); } else if (!Pattern.matches(annotation.valueForWhole(), (String) typeAndContent[1])) { changeNodeTitleLabelVisual((Node) typeAndContent[0], annotation.explainForWhole()); } else { changeNodeTitleLabelVisual((Node) typeAndContent[0], ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.java
private static void process(final ClassConfiguration classConfiguration, final String hostClassName, final String expectedBrowserName, final float browserVersionNumeric) { final String simpleClassName = hostClassName.substring(hostClassName.lastIndexOf('.') + 1); CLASS_NAME_MAP_.put(hostClassName, simpleClassName); final Map<String, Method> allGetters = new HashMap<>(); final Map<String, Method> allSetters = new HashMap<>(); for (final Constructor<?> constructor : classConfiguration.getHostClass().getDeclaredConstructors()) { for (final Annotation annotation : constructor.getAnnotations()) { if (annotation instanceof JsxConstructor) { if (isSupported(((JsxConstructor) annotation).value(), expectedBrowserName, browserVersionNumeric)) { classConfiguration.setJSConstructor(constructor); }/*from w w w. ja v a 2 s.c o m*/ } } } for (final Method method : classConfiguration.getHostClass().getDeclaredMethods()) { for (final Annotation annotation : method.getAnnotations()) { if (annotation instanceof JsxGetter) { final JsxGetter jsxGetter = (JsxGetter) annotation; if (isSupported(jsxGetter.value(), expectedBrowserName, browserVersionNumeric)) { String property; if (jsxGetter.propertyName().isEmpty()) { final int prefix = method.getName().startsWith("is") ? 2 : 3; property = method.getName().substring(prefix); property = Character.toLowerCase(property.charAt(0)) + property.substring(1); } else { property = jsxGetter.propertyName(); } allGetters.put(property, method); } } else if (annotation instanceof JsxSetter) { final JsxSetter jsxSetter = (JsxSetter) annotation; if (isSupported(jsxSetter.value(), expectedBrowserName, browserVersionNumeric)) { String property; if (jsxSetter.propertyName().isEmpty()) { property = method.getName().substring(3); property = Character.toLowerCase(property.charAt(0)) + property.substring(1); } else { property = jsxSetter.propertyName(); } allSetters.put(property, method); } } else if (annotation instanceof JsxFunction) { if (isSupported(((JsxFunction) annotation).value(), expectedBrowserName, browserVersionNumeric)) { classConfiguration.addFunction(method); } } else if (annotation instanceof JsxStaticGetter) { final JsxStaticGetter jsxStaticGetter = (JsxStaticGetter) annotation; if (isSupported(jsxStaticGetter.value(), expectedBrowserName, browserVersionNumeric)) { final int prefix = method.getName().startsWith("is") ? 2 : 3; String property = method.getName().substring(prefix); property = Character.toLowerCase(property.charAt(0)) + property.substring(1); classConfiguration.addStaticProperty(property, method, null); } } else if (annotation instanceof JsxStaticFunction) { if (isSupported(((JsxStaticFunction) annotation).value(), expectedBrowserName, browserVersionNumeric)) { classConfiguration.addStaticFunction(method); } } else if (annotation instanceof JsxConstructor) { if (isSupported(((JsxConstructor) annotation).value(), expectedBrowserName, browserVersionNumeric)) { classConfiguration.setJSConstructor(method); } } } } for (final Field field : classConfiguration.getHostClass().getDeclaredFields()) { final JsxConstant jsxConstant = field.getAnnotation(JsxConstant.class); if (jsxConstant != null && isSupported(jsxConstant.value(), expectedBrowserName, browserVersionNumeric)) { classConfiguration.addConstant(field.getName()); } } for (final Entry<String, Method> getterEntry : allGetters.entrySet()) { final String property = getterEntry.getKey(); classConfiguration.addProperty(property, getterEntry.getValue(), allSetters.get(property)); } }