/** * Create annotation. * * @param annotationExpr the annotation expression * @param cl the classloader to use * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(String annotationExpr, ClassLoader cl) throws Exception { return createAnnotation(getRootExpr(annotationExpr), null, cl); }
public static Object createAnnotation(ASTAnnotation node, Class annotation) throws Exception { return createAnnotation(node, annotation, null); }
private static ASTAnnotation getRootExpr(final String annotationExpr) throws Exception { return getRootExpr(annotationExpr, null, false); }
public Object visit(ASTAnnotation node, Object data) { try { Class<?> subAnnotation = loader.loadClass(node.getIdentifier()); typeValue = createAnnotation(node, subAnnotation); } catch (Exception e) { throw new RuntimeException(e); } return null; }
/** * Should we wrap the original * in order to get the name we created. * * @param original the original * @param name the new created name * @param exposedInterface the exposed interface * @return jmx annoation instance * @throws Throwable for any error */ protected JMX wrapJMX(JMX original, String name, Class<?> exposedInterface) throws Throwable { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("exposedInterface", exposedInterface); attributes.put("name", name); attributes.put("registerDirectly", original.registerDirectly()); return (JMX)AnnotationProxy.createProxy(attributes, JMX.class); }
public void validate(Map map, Class annotation) { ArrayList<String> notAssignedAttributes = null; Method[] methods = getDeclaredMethods(annotation); for (int i = 0 ; i < methods.length ; i++) { if (map.get(methods[i].getName()) == null) { if (notAssignedAttributes == null) { notAssignedAttributes = new ArrayList<String>(); } notAssignedAttributes.add(methods[i].getName()); } } if (notAssignedAttributes != null) { throw new AnnotationValidationException("Unable to fill in default attributes for " + annotation + " " + notAssignedAttributes); } }
/** * Create a proxy implementation for the annotation class. * @param map - map of the annotation values * @param annotation - the annotation class * @return an instance implementing the annotation * @throws Exception for any error */ public static Object createProxy(Map map, Class annotation) throws Exception { AnnotationProxy proxyHandler = new AnnotationProxy(annotation, map); return java.lang.reflect.Proxy.newProxyInstance(annotation.getClassLoader(), new Class[]{annotation}, proxyHandler); } }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param annotation the annotation class * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(final String annotationExpr, final Class<?> annotation) throws Exception { return createAnnotation(getRootExpr(annotationExpr), annotation, null); }
public Object visit(ASTAnnotation node, Object data) { try { Class subAnnotation = Thread.currentThread().getContextClassLoader().loadClass(node.getIdentifier()); typeValue = createAnnotation(node, subAnnotation); } catch (Exception e) { throw new RuntimeException(e); } return null; }
/** * Create annotation. * * @param node the ast annotation node * @param annotation the annotation class * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(ASTAnnotation node, Class<?> annotation) throws Exception { return createAnnotation(node, annotation, null); }
/** * Should we wrap the original * in order to get the name we created. * * @param original the original * @param name the new created name * @param exposedInterface the exposed interface * @return jmx annoation instance * @throws Throwable for any error */ protected JMX wrapJMX(JMX original, String name, Class<?> exposedInterface) throws Throwable { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("exposedInterface", exposedInterface); attributes.put("name", name); attributes.put("registerDirectly", original.registerDirectly()); return (JMX)AnnotationProxy.createProxy(attributes, JMX.class); }
public void validate(Map<String, Object> map, Class<?> annotation) { ArrayList<String> notAssignedAttributes = null; Method[] methods = getDeclaredMethods(annotation); for (int i = 0 ; i < methods.length ; i++) { if (map.get(methods[i].getName()) == null) { if (notAssignedAttributes == null) { notAssignedAttributes = new ArrayList<String>(); } notAssignedAttributes.add(methods[i].getName()); } } if (notAssignedAttributes != null) { throw new AnnotationValidationException("Unable to fill in default attributes for " + annotation + " " + notAssignedAttributes); } }
/** * Create a proxy implementation for the annotation class. * @param map - map of the annotation values * @param annotation - the annotation class * @return an instance implementing the annotation * @throws Exception for any error */ public static Object createProxy(Map<String, Object> map, Class<?> annotation) throws Exception { AnnotationProxy proxyHandler = new AnnotationProxy(annotation, map); return java.lang.reflect.Proxy.newProxyInstance(annotation.getClassLoader(), new Class[]{annotation}, proxyHandler); } }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param cl the classloader to use * @param properties the properties to use for replacement * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(String annotationExpr, ClassLoader cl, Properties properties) throws Exception { return createAnnotation(getRootExpr(annotationExpr, properties), null, cl); } }
@SuppressWarnings("unchecked") protected Object extractAnnotation(Object value, Class annotation) { if (value == null) return null; if (value instanceof String) { String expr = (String) value; try { return AnnotationCreator.createAnnotation(expr, annotation); } catch (Exception e) { throw new RuntimeException("Bad annotation expression " + expr, e); } } return value; }
public static Object createAnnotation(final String annotationExpr, final Class annotation) throws Exception { return createAnnotation(getRootExpr(annotationExpr), annotation, null); }
public static Object createAnnotation(String annotationExpr, ClassLoader cl) throws Exception { return createAnnotation(getRootExpr(annotationExpr), null, cl); }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param annotation the annotation class * @param properties the properties to use for replacement * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(final String annotationExpr, final Class<?> annotation, Properties properties) throws Exception { return createAnnotation(getRootExpr(annotationExpr, properties), annotation, null); }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param annotation the annotation class * @param replace should we replace possible properties in expression * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(final String annotationExpr, final Class<?> annotation, boolean replace) throws Exception { return createAnnotation(getRootExpr(annotationExpr, null, replace), annotation, null); }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param cl the classloader to use * @param replace should we replace possible properties in expression * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(String annotationExpr, ClassLoader cl, boolean replace) throws Exception { return createAnnotation(getRootExpr(annotationExpr, null, replace), null, cl); }