/** * @param annotation signature of annotation * @return the visitor in the map or empty visitor */ public IAnnotationVisitor getAnnotationVisitor(final JAnnotation annotation) { return annotationVisitors.get(annotation.getClassName()); }
/** * Override because * {@link org.ow2.easybeans.enhancer.interceptors.InterceptorClassAdapter} * use it. * @return the method name */ @Override public String getMethodName() { return getJMethod().getName(); }
/** * Gets a signature entry for a given method. * @param methodMetadata the metadata used to extract signature * @return a signature string */ public static String getSignature(final ICommonMethodMetadata<?, ?, ?> methodMetadata) { return methodMetadata.getJMethod().getName() + methodMetadata.getJMethod().getDescriptor().hashCode(); }
/** * Gets the ENC name for the given metadata. * @param commonMetadata the metadata to analyze. * @param o the given object associated to the metadata (used for logging). * @return the given ENC name * @throws ENCBindingException if no name has been defined on the given name * and the metadata is invalid. */ private String getName(final ISharedMetadata commonMetadata, final Object o) throws ENCBindingException { if (commonMetadata instanceof CommonFieldMetadata) { CommonFieldMetadata<?, ?, ?> fieldAnnotationMetadata = (CommonFieldMetadata<?, ?, ?>) commonMetadata; return fieldAnnotationMetadata.getClassMetadata().getJClass().getName().replace("/", ".") + "/" + fieldAnnotationMetadata.getJField().getName(); } if (commonMetadata instanceof CommonMethodMetadata) { CommonMethodMetadata<?, ?, ?> methodAnnotationMetadata = (CommonMethodMetadata<?, ?, ?>) commonMetadata; StringBuilder propertyBuilder = new StringBuilder(methodAnnotationMetadata.getJMethod().getName()); propertyBuilder.delete(0, GETTER_LENGTH); propertyBuilder.setCharAt(0, Character.toLowerCase(propertyBuilder.charAt(0))); propertyBuilder.insert(0, methodAnnotationMetadata.getClassMetadata().getJClass().getName().replace("/", ".") + "/"); return propertyBuilder.toString(); } // Last case is the Class case. throw new ENCBindingException("There is no defined name in the object '" + o + "' that is defined on the class '" + commonMetadata + "'."); }
Type typeInterface = Type.getType(fieldAnnotationMetadata.getJField().getDescriptor()); return typeInterface.getClassName(); } else if (commonMetadata instanceof CommonMethodMetadata) { Type[] args = Type.getArgumentTypes(jMethod.getDescriptor()); if (args.length != 1) { throw new ENCBindingException("Method args '" + Arrays.asList(args) + "' for method '" + jMethod
@Override public void visitEnd() { String value = getValue(); if (value == null || value.equals("")) { // Set the class name if there is no value value = getAnnotationMetadata().getJClass().getName(); if (value.contains("/")) { value = value.substring(value.lastIndexOf("/") + 1); } } getAnnotationMetadata().setManagedBeanName(value); }
private static Map<String, IWarClassMetadata> findPOJOWebService(final IWarDeployableMetadata warDeployableMetadata) { Map<String, IWarClassMetadata> services = new Hashtable<String, IWarClassMetadata>(); Collection<IWarClassMetadata> classes = warDeployableMetadata.getWarClassMetadataCollection(); for (IWarClassMetadata clazz : classes) { // 512 is the marker byte for interface in ASM boolean isInterface = (clazz.getJClass().getAccess() & 512) != 0; boolean isAbstract= (clazz.getJClass().getAccess() & 1024) != 0; // Only deal with concrete classes annotated with @WebService or @WebServiceProvider boolean isAnnotated = (clazz.getWebServiceMarker() != null); if (!isInterface && !isAbstract && isAnnotated) { String classname = clazz.getJClass().getName().replace('/', '.'); services.put(classname, clazz); } } return services; }
/** * @param name annotation name * @param visible annotation visibility * @return a visitor */ @Override public AnnotationVisitor visitAnnotation(final String name, final boolean visible) { JAnnotation jAnnotation = new JAnnotation(name, visible); List<IAnnotationVisitor> result = new ArrayList<IAnnotationVisitor>(); for (T configurator : configurators) { IAnnotationVisitor annotationVisitor = configurator.getAnnotationVisitor(jAnnotation); result.add(annotationVisitor); } return new ScanAnnotationVisitor(result); }
/** * visit the class. * @param version the version * @param access access (public, ...) * @param name class name * @param signature signature * @param superName super class name * @param interfaces implemented interfaces name */ @Override public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { List<IClassConfigurator> classConfigurators = new ArrayList<IClassConfigurator>(); JClass jClass = new JClass(version, access, name, signature, superName, interfaces); for (IArchiveConfigurator archiveConfigurator : archiveConfigurators) { classConfigurators.add(archiveConfigurator.createClassConfigurator(jClass)); } setConfigurators(classConfigurators); }
/** * Add a @{@link javax.interceptor.AroundInvoke} method of this class. * @param aroundInvokeMethodMetadata the method. */ public void addAroundInvokeMethodMetadata(final EasyBeansEjbJarMethodMetadata aroundInvokeMethodMetadata) { if (this.aroundInvokeMethodsMetadata == null) { this.aroundInvokeMethodsMetadata = new LinkedList<EasyBeansEjbJarMethodMetadata>(); } // Check not yet present for (EasyBeansEjbJarMethodMetadata methodMetadata : this.aroundInvokeMethodsMetadata) { if (aroundInvokeMethodMetadata.getClassMetadata().getClassName().equals(methodMetadata.getClassMetadata().getClassName())) { if (aroundInvokeMethodMetadata.getJMethod().equals(methodMetadata.getJMethod())) { return; } } } this.aroundInvokeMethodsMetadata.addFirst(aroundInvokeMethodMetadata); }
/** * Gets the ENC name for the given metadata. * @param commonMetadata the metadata to analyze. * @param o the given object associated to the metadata (used for logging). * @return the given ENC name * @throws ENCBindingException if no name has been defined on the given name * and the metadata is invalid. */ private String getName(final ISharedMetadata commonMetadata, final Object o) throws ENCBindingException { if (commonMetadata instanceof CommonFieldMetadata) { CommonFieldMetadata<?, ?, ?> fieldAnnotationMetadata = (CommonFieldMetadata<?, ?, ?>) commonMetadata; return fieldAnnotationMetadata.getClassMetadata().getJClass().getName().replace("/", ".") + "/" + fieldAnnotationMetadata.getJField().getName(); } if (commonMetadata instanceof CommonMethodMetadata) { CommonMethodMetadata<?, ?, ?> methodAnnotationMetadata = (CommonMethodMetadata<?, ?, ?>) commonMetadata; StringBuilder propertyBuilder = new StringBuilder(methodAnnotationMetadata.getJMethod().getName()); propertyBuilder.delete(0, GETTER_LENGTH); propertyBuilder.setCharAt(0, Character.toLowerCase(propertyBuilder.charAt(0))); propertyBuilder.insert(0, methodAnnotationMetadata.getClassMetadata().getJClass().getName().replace("/", ".") + "/"); return propertyBuilder.toString(); } // Last case is the Class case. throw new ENCBindingException("There is no defined name in the object '" + o + "' that is defined on the class '" + commonMetadata + "'."); }
/** * Gets a signature entry for a given method. * @param methodMetadata the metadata used to extract signature * @return a signature string */ public static String getSignature(final ICommonMethodMetadata<?, ?, ?> methodMetadata) { return methodMetadata.getJMethod().getName() + methodMetadata.getJMethod().getDescriptor().hashCode(); }
Type typeInterface = Type.getType(fieldAnnotationMetadata.getJField().getDescriptor()); return typeInterface.getClassName(); } else if (commonMetadata instanceof CommonMethodMetadata) { Type[] args = Type.getArgumentTypes(jMethod.getDescriptor()); if (args.length != 1) { throw new ENCBindingException("Method args '" + Arrays.asList(args) + "' for method '" + jMethod
/** * {@inheritDoc} */ public List<? extends SM> searchSpecificMethodMetadata(final String methodName) { if (methodName == null) { throw new IllegalArgumentException("Cannot search null methods"); } List<SM> list = new ArrayList<SM>(); for (SM method : methodsAnnotationMetadata.values()) { if (methodName.equals(method.getJMethod().getName())) { list.add(method); } } return list; }
@Override public void visitEnd() { String value = getValue(); if (value == null || value.equals("")) { // Set the class name if there is no value value = getAnnotationMetadata().getJClass().getName(); if (value.contains("/")) { value = value.substring(value.lastIndexOf("/") + 1); } } getAnnotationMetadata().setManagedBeanName(value); }
/** * @param name annotation name * @param visible annotation visibility * @return a visitor */ @Override public AnnotationVisitor visitAnnotation(final String name, final boolean visible) { JAnnotation jAnnotation = new JAnnotation(name, visible); List<IAnnotationVisitor> result = new ArrayList<IAnnotationVisitor>(); for (T configurator : configurators) { IAnnotationVisitor annotationVisitor = configurator.getAnnotationVisitor(jAnnotation); result.add(annotationVisitor); } return new ScanAnnotationVisitor(result); }
/** * visit the class. * @param version the version * @param access access (public, ...) * @param name class name * @param signature signature * @param superName super class name * @param interfaces implemented interfaces name */ @Override public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { List<IClassConfigurator> classConfigurators = new ArrayList<IClassConfigurator>(); JClass jClass = new JClass(version, access, name, signature, superName, interfaces); for (IArchiveConfigurator archiveConfigurator : archiveConfigurators) { classConfigurators.add(archiveConfigurator.createClassConfigurator(jClass)); } setConfigurators(classConfigurators); }
/** * Add the given ENC name for the given field or method. * @param encName the name of the ENC value * @param commonMetadata the field or method or null object */ protected void addFieldOrMethodENC(final String encName, final ISharedMetadata commonMetadata) { // Don't do anything if there is no field/method if (commonMetadata == null) { return; } // Add ENC injection target if (commonMetadata instanceof CommonFieldMetadata) { CommonFieldMetadata<?, ?, ?> fieldAnnotationMetadata = (CommonFieldMetadata<?, ?, ?>) commonMetadata; String fieldName = fieldAnnotationMetadata.getJField().getName(); this.bindingHolder.addFieldInjectionTarget(fieldAnnotationMetadata.getClassMetadata().getJClass().getName().replace('/', '.'), new InjectionTargetEncImpl(fieldName, encName)); } else if (commonMetadata instanceof CommonMethodMetadata) { CommonMethodMetadata<?, ?, ?> methodAnnotationMetadata = (CommonMethodMetadata<?, ?, ?>) commonMetadata; String methodName = methodAnnotationMetadata.getJMethod().getName(); this.bindingHolder.addMethodInjectionTarget(methodAnnotationMetadata.getClassMetadata().getJClass().getName().replace('/', '.'), new InjectionTargetEncImpl(methodName, encName)); } }
/** * Returns the value of the @RunAs annotation if present, null otherwise * @param servlet The given servlet * @param metadata The webapp metadata * @return The value of the @RunAs annotation if present, null otherwise */ private String runAsAnnotationValue(final Servlet servlet, final IWarDeployableMetadata metadata) { Collection<IWarClassMetadata> classes = metadata.getWarClassMetadataCollection(); for (IWarClassMetadata clazz : classes) { String className = clazz.getJClass().getName(); className = className.replace("/", "."); // Found a @RunAs annotation declaration into the servlet class if (className.equals(servlet.getServletClass()) && clazz.getRunAs() != null) { return clazz.getRunAs(); } } // No @RunAs annotation found return null; }
/** * Add the given ENC name for the given field or method. * @param encName the name of the ENC value * @param commonMetadata the field or method or null object */ protected void addFieldOrMethodENC(final String encName, final ISharedMetadata commonMetadata) { // Don't do anything if there is no field/method if (commonMetadata == null) { return; } // Add ENC injection target if (commonMetadata instanceof CommonFieldMetadata) { CommonFieldMetadata<?, ?, ?> fieldAnnotationMetadata = (CommonFieldMetadata<?, ?, ?>) commonMetadata; String fieldName = fieldAnnotationMetadata.getJField().getName(); this.bindingHolder.addFieldInjectionTarget(fieldAnnotationMetadata.getClassMetadata().getJClass().getName().replace('/', '.'), new InjectionTargetEncImpl(fieldName, encName)); } else if (commonMetadata instanceof CommonMethodMetadata) { CommonMethodMetadata<?, ?, ?> methodAnnotationMetadata = (CommonMethodMetadata<?, ?, ?>) commonMetadata; String methodName = methodAnnotationMetadata.getJMethod().getName(); this.bindingHolder.addMethodInjectionTarget(methodAnnotationMetadata.getClassMetadata().getJClass().getName().replace('/', '.'), new InjectionTargetEncImpl(methodName, encName)); } }