private Signature getCallback(Class<?> implClass, String name) { while (Object.class != implClass) { try { Method callback = implClass.getDeclaredMethod(name); return new Signature(callback); } catch (NoSuchMethodException e) { implClass = implClass.getSuperclass(); } } return null; }
private Signature getCallback(Class<?> implClass, Class<? extends Annotation> annotation) { while (Object.class != implClass) { for (Method method : implClass.getDeclaredMethods()) { if (method.isAnnotationPresent(annotation)) { return new Signature(method); } } implClass = implClass.getSuperclass(); } return null; }
public Set<Method> getInjectionMethods(Class<?> type, Collection<AbstractService> services) { Set<Signature> exclude = getOperations(services); Set<Method> methods = new HashSet<Method>(); while (type != null) { for (Method method : type.getDeclaredMethods()) { // check method accessibility int modifiers = method.getModifiers(); if (Modifier.isStatic(modifiers) || Modifier.isAbstract(modifiers)) { continue; } if (!(Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers))) { continue; } if (!isSetter(method)) { continue; } // exclude methods we have seen already (i.e. in a contract or overriden in a subclass) // we check using the signature as the method itself will have been declared on a different class Signature signature = new Signature(method); if (exclude.contains(signature)) { continue; } exclude.add(signature); methods.add(method); } type = type.getSuperclass(); } return methods; }
public void visitMethod(Init annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { if (!validate(method, context, componentType)) { return; } componentType.setInitMethod(new Signature(method)); }
public void visitMethod(Destroy annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { if (!validate(method, context, componentType)) { return; } componentType.setDestroyMethod(new Signature(method)); }
private Set<Signature> getOperations(Collection<AbstractService> services) { Set<Signature> operations = new HashSet<Signature>(); for (AbstractService definition : services) { List<? extends Operation> ops = definition.getServiceContract().getOperations(); for (Operation operation : ops) { String name = operation.getName(); List<? extends DataType<?>> inputTypes = operation.getInputTypes(); List<String> paramTypes = new ArrayList<String>(inputTypes.size()); for (DataType<?> inputType : inputTypes) { paramTypes.add(inputType.getPhysical().getName()); } operations.add(new Signature(name, paramTypes)); } } return operations; }
private void introspect(Object instance, ManagementInfo info) { for (Method method : instance.getClass().getMethods()) { ManagementOperation annotation = method.getAnnotation(ManagementOperation.class); if (annotation == null) { continue; } String description = annotation.description(); if (description.trim().length() == 0) { description = null; } Signature signature = new Signature(method); String[] roleNames = annotation.rolesAllowed(); Set<Role> roles = new HashSet<Role>(); for (String name : roleNames) { roles.add(new Role(name)); } String path = annotation.path(); ManagementOperationInfo operationInfo = new ManagementOperationInfo(signature, path, OperationType.UNDEFINED, description, roles); info.addOperation(operationInfo); } }
private Signature findConstructor(Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { Constructor<?>[] constructors = implClass.getDeclaredConstructors(); Constructor<?> selected = null; if (constructors.length == 1) { selected = constructors[0]; } else { for (Constructor<?> constructor : constructors) { if (constructor.isAnnotationPresent(org.oasisopen.sca.annotation.Constructor.class)) { if (selected != null) { context.addError(new AmbiguousConstructor(implClass, componentType)); return null; } selected = constructor; } } if (selected == null) { context.addError(new NoConstructorFound(implClass, componentType)); return null; } } return new Signature(selected); }
public void visitMethod(ManagementOperation annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { ManagementInfo info = componentType.getManagementInfo(); if (info == null) { // there was no management annotation on the type - record an error Class<?> clazz = method.getDeclaringClass(); context.addError(new InvalidAnnotation("Implementation is missing @" + Management.class.getSimpleName(), clazz)); return; } String description = annotation.description(); if (description.trim().length() == 0) { description = null; } Signature signature = new Signature(method); Set<Role> roles = new HashSet<Role>(); for (String roleName : annotation.rolesAllowed()) { roles.add(new Role(roleName)); } String path = annotation.path(); org.fabric3.api.annotation.management.OperationType operationType = annotation.type(); OperationType type = OperationType.valueOf(operationType.toString()); ManagementOperationInfo operationInfo = new ManagementOperationInfo(signature, path, type, description, roles); info.addOperation(operationInfo); }
public void visitMethod(Consumer annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { if (method.getParameterTypes().length > 1) { InvalidConsumerMethod failure = new InvalidConsumerMethod("Consumer method " + method + " has more than one parameter", method, componentType); context.addError(failure); return; } TypeMapping typeMapping = context.getTypeMapping(implClass); List<DataType<?>> types = introspectParameterTypes(method, typeMapping); // TODO handle policies String name = helper.getSiteName(method, annotation.value()); Signature signature = new Signature(method); ConsumerDefinition definition = new ConsumerDefinition(name, types); int sequence = annotation.sequence(); if (sequence < 0) { context.addError(new InvalidConsumerMethod("Sequence number cannot be negative: " + method, method, componentType)); } else { definition.setSequence(sequence); } componentType.add(definition, signature); }