protected JavaImplementation createImplementation(Class<?> clazz, IntrospectionContext context) { JavaImplementation implementation = new JavaImplementation(); implementation.setImplementationClass(clazz); InjectingComponentType componentType = new InjectingComponentType(clazz); implementation.setComponentType(componentType); return implementation; }
public String getImplementationName() { return getImplementationClass().getName(); }
public void generate(PhysicalJavaComponent physicalComponent, LogicalComponent<? extends JavaImplementation> component) { Component<? extends JavaImplementation> logical = component.getDefinition(); JavaImplementation implementation = logical.getImplementation(); InjectingComponentType type = implementation.getComponentType(); Scope scope = type.getScope(); // create the instance factory definition ImplementationManagerDefinition managerDefinition = new ImplementationManagerDefinition(); managerDefinition.setReinjectable(Scope.COMPOSITE == scope); managerDefinition.setConstructor(type.getConstructor()); managerDefinition.setInitMethod(type.getInitMethod()); managerDefinition.setDestroyMethod(type.getDestroyMethod()); managerDefinition.setImplementationClass(implementation.getImplementationClass()); managerDefinition.setClassLoaderUri(component.getDefinition().getContributionUri()); helper.processInjectionSites(type, managerDefinition); // create the physical component definition physicalComponent.setScope(scope); physicalComponent.setEagerInit(type.isEagerInit()); physicalComponent.setManagerDefinition(managerDefinition); physicalComponent.setManaged(type.isManaged()); physicalComponent.setManagementInfo(type.getManagementInfo()); helper.processPropertyValues(component, physicalComponent); }
private JavaComponentBuilder implementation(Class<?> clazz) { component.getImplementation().setImplementationClass(clazz); return this; }
public void process(Component<JavaImplementation> component, IntrospectionContext context) { JavaImplementation implementation = component.getImplementation(); Object instance = implementation.getInstance(); InjectingComponentType componentType = implementation.getComponentType(); if (instance == null) { introspector.introspect(componentType, context); } else { componentType.setScope(Scope.COMPOSITE); if (componentType.getServices().isEmpty()) { // introspect services if not defined addServiceDefinitions(instance, componentType, context); } processAnnotations(instance, component, context); for (PostProcessor postProcessor : postProcessors) { postProcessor.process(componentType, instance.getClass(), context); } } }
@SuppressWarnings({"unchecked"}) public void generateWireTarget(JavaWireTarget target, LogicalService service) { LogicalComponent<JavaImplementation> component = (LogicalComponent<JavaImplementation>) service.getParent(); URI uri = URI.create(component.getUri().toString() + "#" + service.getUri().getFragment()); target.setUri(uri); // assume only wires to composite scope components can be optimized Component<JavaImplementation> componentDefinition = component.getDefinition(); JavaImplementation implementation = componentDefinition.getImplementation(); InjectingComponentType componentType = implementation.getComponentType(); Scope scope = componentType.getScope(); target.setOptimizable(scope.isSingleton()); }
public PhysicalComponent generate(LogicalComponent<JavaImplementation> component) { Object instance = component.getDefinition().getImplementation().getInstance(); if (instance != null) { // deploying an unmanaged instance PhysicalJavaComponent physicalComponent = new PhysicalJavaComponent(instance); physicalComponent.setScope(Scope.COMPOSITE); return physicalComponent; } PhysicalJavaComponent physicalComponent = new PhysicalJavaComponent(); generationHelper.generate(physicalComponent, component); return physicalComponent; }
public void generateCallbackWireSource(JavaWireSource source, LogicalComponent<? extends JavaImplementation> component, JavaServiceContract contract) { InjectingComponentType type = component.getDefinition().getImplementation().getComponentType(); String name = null; for (Callback entry : type.getCallbacks().values()) { // NB: This currently only supports the case where one callback injection site of the same type is on an implementation. ServiceContract candidate = entry.getServiceContract(); MatchResult result = matcher.isAssignableFrom(candidate, contract, false); if (result.isAssignable()) { name = entry.getName(); break; } } if (name == null) { String interfaze = contract.getQualifiedInterfaceName(); throw new Fabric3Exception("Callback injection site not found for type: " + interfaze); } Injectable injectable = new Injectable(InjectableType.CALLBACK, name); source.setInjectable(injectable); source.setInterfaceClass(contract.getInterfaceClass()); URI uri = URI.create(component.getUri().toString() + "#" + name); source.setUri(uri); source.setOptimizable(false); }
protected JavaComponentBuilder(String name, Class<?> clazz) { String className = clazz.getName(); InjectingComponentType componentType = new InjectingComponentType(clazz); JavaImplementation implementation = new JavaImplementation(); implementation.setImplementationClass(clazz); implementation.setComponentType(componentType); component = new Component<>(name); component.setImplementation(implementation); }
@SuppressWarnings({"unchecked"}) public void generateConnectionTarget(JavaConnectionTarget target, LogicalConsumer consumer) { // Create an injectable for the consumer. Note in cases where the consumer is a method that is connected via an event stream and is used to receive // events rather than act as a setter for a direct connection, the injector will never be activated. Injectable injectable = new Injectable(InjectableType.CONSUMER, consumer.getUri().getFragment()); target.setInjectable(injectable); LogicalComponent<? extends JavaImplementation> component = (LogicalComponent<? extends JavaImplementation>) consumer.getParent(); URI uri = component.getUri(); target.setUri(uri); ServiceContract serviceContract = consumer.getDefinition().getServiceContract(); Class<?> interfaze = serviceContract.getInterfaceClass(); target.setServiceInterface(interfaze); InjectingComponentType type = component.getDefinition().getImplementation().getComponentType(); AccessibleObject object = type.getConsumerSite(consumer.getUri().getFragment()); if (object == null) { // programming error throw new Fabric3Exception("Consumer not found on: " + consumer.getUri()); } target.setConsumerSite(object); }
protected JavaComponentBuilder(String name, Object instance) { Class<?> clazz = instance.getClass(); String className = clazz.getName(); InjectingComponentType componentType = new InjectingComponentType(clazz); JavaImplementation implementation = new JavaImplementation(instance); implementation.setComponentType(componentType); implementation.setImplementationClass(clazz); component = new Component<>(name); component.setImplementation(implementation); }
public JavaImplementation load(XMLStreamReader reader, IntrospectionContext introspectionContext) throws XMLStreamException { Location startLocation = reader.getLocation(); JavaImplementation implementation = new JavaImplementation(); validateAttributes(reader, introspectionContext, implementation); String implClass = reader.getAttributeValue(null, "class"); if (implClass == null) { MissingAttribute failure = new MissingAttribute("The class attribute was not specified", startLocation); introspectionContext.addError(failure); LoaderUtil.skipToEndElement(reader); return implementation; } Class<?> clazz; try { clazz = introspectionContext.getClassLoader().loadClass(implClass); } catch (ClassNotFoundException e) { ImplementationArtifactNotFound failure = new ImplementationArtifactNotFound(implClass, e.getMessage(), implementation); introspectionContext.addError(failure); LoaderUtil.skipToEndElement(reader); return null; } LoaderUtil.skipToEndElement(reader); implementation.setImplementationClass(clazz); InjectingComponentType componentType = new InjectingComponentType(clazz); introspector.introspect(componentType, introspectionContext); implementation.setComponentType(componentType); return implementation; }