private TypeMapping getTypeMapping(Class<?> type, Class<?> baseClass, IntrospectionContext context) { TypeMapping typeMapping = context.getTypeMapping(baseClass); if (typeMapping == null) { typeMapping = new TypeMapping(); context.addTypeMapping(type, typeMapping); helper.resolveTypeParameters(type, typeMapping); } return typeMapping; }
private TypeMapping getTypeMapping(Class<?> type, Class<?> baseClass, IntrospectionContext context) { TypeMapping typeMapping = context.getTypeMapping(baseClass); if (typeMapping == null) { typeMapping = new TypeMapping(); context.addTypeMapping(type, typeMapping); helper.resolveTypeParameters(type, typeMapping); } return typeMapping; }
public Map<AccessibleObject, Supplier<Object>> getInjectors(Class<?> clazz) { Map<AccessibleObject, Supplier<Object>> injectors = new HashMap<>(); // introspect class InjectingComponentType componentType = new InjectingComponentType(clazz); DefaultIntrospectionContext context = new DefaultIntrospectionContext(); TypeMapping typeMapping = new TypeMapping(); context.addTypeMapping(clazz, typeMapping); introspectionHelper.resolveTypeParameters(clazz, typeMapping); classVisitor.visit(componentType, clazz, context); for (PostProcessor postProcessor : postProcessors) { postProcessor.process(componentType, clazz, context); } // process injection sites for (Map.Entry<ModelObject, InjectionSite> entry : componentType.getInjectionSiteMappings().entrySet()) { ModelObject key = entry.getKey(); InjectionSite value = entry.getValue(); if (key instanceof Reference) { Reference<?> reference = (Reference) key; handleReference(reference, value, clazz, injectors); } else if (key instanceof Producer) { Producer producer = (Producer) key; throw new UnsupportedOperationException("Not yet implemented"); } else if (key instanceof Consumer) { throw new UnsupportedOperationException("Not yet implemented"); } } return injectors; }
public Map<AccessibleObject, Supplier<Object>> getInjectors(Class<?> clazz) { Map<AccessibleObject, Supplier<Object>> injectors = new HashMap<>(); // introspect class InjectingComponentType componentType = new InjectingComponentType(clazz); DefaultIntrospectionContext context = new DefaultIntrospectionContext(); TypeMapping typeMapping = new TypeMapping(); context.addTypeMapping(clazz, typeMapping); introspectionHelper.resolveTypeParameters(clazz, typeMapping); classVisitor.visit(componentType, clazz, context); for (PostProcessor postProcessor : postProcessors) { postProcessor.process(componentType, clazz, context); } // process injection sites for (Map.Entry<ModelObject, InjectionSite> entry : componentType.getInjectionSiteMappings().entrySet()) { ModelObject key = entry.getKey(); InjectionSite value = entry.getValue(); if (key instanceof Reference) { Reference<?> reference = (Reference) key; handleReference(reference, value, clazz, injectors); } else if (key instanceof Producer) { Producer producer = (Producer) key; throw new UnsupportedOperationException("Not yet implemented"); } else if (key instanceof Consumer) { throw new UnsupportedOperationException("Not yet implemented"); } } return injectors; }
@SuppressWarnings("unchecked") private void processAnnotations(Object instance, Component<?> definition, IntrospectionContext context) { InjectingComponentType componentType = (InjectingComponentType) definition.getComponentType(); Class<?> implClass = instance.getClass(); // handle consumer annotations AnnotationProcessor consumerProcessor = annotationProcessors.get(org.fabric3.api.annotation.Consumer.class); for (Method method : implClass.getDeclaredMethods()) { org.fabric3.api.annotation.Consumer consumer = method.getAnnotation(org.fabric3.api.annotation.Consumer.class); if (consumer == null) { continue; } TypeMapping mapping = context.getTypeMapping(implClass); if (mapping == null) { mapping = new TypeMapping(); context.addTypeMapping(implClass, mapping); } helper.resolveTypeParameters(implClass, mapping); consumerProcessor.visitMethod(consumer, method, implClass, componentType, context); } // add automatic configuration for consumer annotations for (Consumer<ComponentType> consumer : componentType.getConsumers().values()) { String name = consumer.getName(); Consumer<Component> componentConsumer = new Consumer<>(name); componentConsumer.setSources(Collections.singletonList(URI.create(name))); definition.add(componentConsumer); } }
public void introspect(InjectingComponentType componentType, IntrospectionContext context) { componentType.setScope(Scope.COMPOSITE); Class<?> implClass = componentType.getImplClass(); if (implClass.isInterface()) { InvalidImplementation failure = new InvalidImplementation("Implementation class is an interface", implClass, componentType); context.addError(failure); return; } TypeMapping mapping = context.getTypeMapping(implClass); if (mapping == null) { mapping = new TypeMapping(); context.addTypeMapping(implClass, mapping); helper.resolveTypeParameters(implClass, mapping); } classVisitor.visit(componentType, implClass, context); heuristic.applyHeuristics(componentType, implClass, context); } }
public void introspect(InjectingComponentType componentType, IntrospectionContext context) { componentType.setScope(Scope.STATELESS); Class<?> implClass = componentType.getImplClass(); if (implClass.isInterface()) { InvalidImplementation failure = new InvalidImplementation("Implementation class is an interface", implClass, componentType); context.addError(failure); return; } TypeMapping mapping = context.getTypeMapping(implClass); if (mapping == null) { mapping = new TypeMapping(); context.addTypeMapping(implClass, mapping); helper.resolveTypeParameters(implClass, mapping); } try { classVisitor.visit(componentType, implClass, context); heuristic.applyHeuristics(componentType, implClass, context); } catch (NoClassDefFoundError e) { // May be thrown as a result of a referenced class not being on the classpath context.addError(new ImplementationArtifactNotFound(implClass.getName(), e.getMessage(), componentType)); } validateScope(componentType, implClass, context); for (PostProcessor postProcessor : postProcessors) { postProcessor.process(componentType, implClass, context); } }
public Resource introspect(Class<?> clazz, Contribution contribution, IntrospectionContext context) { ResourceElement<WebComponentTypeSymbol, WebComponentType> element = getTypeElement(contribution); WebComponentType componentType = element.getValue(); // introspect the class and generate a component type that will be merged into the web component type WebArtifactImplementation artifactImpl = new WebArtifactImplementation(); InjectingComponentType tempType = new InjectingComponentType(clazz); artifactImpl.setComponentType(tempType); TypeMapping mapping = context.getTypeMapping(clazz); if (mapping == null) { mapping = new TypeMapping(); context.addTypeMapping(clazz, mapping); helper.resolveTypeParameters(clazz, mapping); } classVisitor.visit(tempType, clazz, context); mergeComponentTypes(componentType, tempType, context); return element.getResource(); }
protected void createPropertyFactories(PCD definition, ImplementationManagerFactory factory) throws BuilderException { List<PhysicalPropertyDefinition> propertyDefinitions = definition.getPropertyDefinitions(); TypeMapping typeMapping = new TypeMapping(); helper.resolveTypeParameters(factory.getImplementationClass(), typeMapping); for (PhysicalPropertyDefinition propertyDefinition : propertyDefinitions) { String name = propertyDefinition.getName(); Document value = propertyDefinition.getValue(); Injectable source = new Injectable(InjectableType.PROPERTY, name); Type type = factory.getGenericType(source); DataType<?> dataType = getDataType(type, typeMapping); ClassLoader classLoader = classLoaderRegistry.getClassLoader(definition.getClassLoaderId()); boolean many = propertyDefinition.isMany(); ObjectFactory<?> objectFactory = propertyBuilder.createFactory(name, dataType, value, many, classLoader); factory.setObjectFactory(source, objectFactory); } }
mapping = new TypeMapping(); context.addTypeMapping(implClass, mapping); helper.resolveTypeParameters(implClass, mapping);
public void introspect(WebImplementation implementation, IntrospectionContext context) { WebComponentType componentType = new WebComponentType(); implementation.setComponentType(componentType); // load the servlet, filter and context listener classes referenced in the web.xml descriptor List<Class<?>> artifacts = xmlIntrospector.introspectArtifactClasses(context); for (Class<?> artifact : artifacts) { // introspect each class and generate a component type that will be merged into the web component type WebArtifactImplementation artifactImpl = new WebArtifactImplementation(); InjectingComponentType type = new InjectingComponentType(artifact.getName()); artifactImpl.setComponentType(type); TypeMapping mapping = context.getTypeMapping(artifact); if (mapping == null) { mapping = new TypeMapping(); context.addTypeMapping(artifact, mapping); helper.resolveTypeParameters(artifact, mapping); } IntrospectionContext childContext = new DefaultIntrospectionContext(context); classVisitor.visit(type, artifact, childContext); if (childContext.hasErrors()) { context.addErrors(childContext.getErrors()); } if (childContext.hasWarnings()) { context.addWarnings(childContext.getWarnings()); } // TODO apply heuristics mergeComponentTypes(implementation.getComponentType(), type, context); } }
helper.resolveTypeParameters(factory.getImplementationClass(), typeMapping);
helper.resolveTypeParameters(factory.getImplementationClass(), typeMapping);