/** * Gets the component type. * * @return Component type. */ public ComponentType getComponentType() { return implementation != null ? getImplementation().getComponentType() : null; }
private void initializeDomainComposite() { Composite type = new Composite(null); CompositeImplementation impl = new CompositeImplementation(); impl.setComponentType(type); Component<CompositeImplementation> definition = new Component<>(domainUri.toString()); definition.setImplementation(impl); definition.setContributionUri(Names.BOOT_CONTRIBUTION); domain = new LogicalCompositeComponent(domainUri, definition, autowire); domain.setState(LogicalState.PROVISIONED); }
/** * Returns the key specified on the component, component type, or null * * @param component the component * @return the key or null */ private String getKey(LogicalComponent component) { String key = component.getDefinition().getKey(); if (key == null) { // check if the key was specified in the component type if (component.getDefinition().getComponentType() != null) { key = component.getDefinition().getComponentType().getKey(); } } return key; }
/** * Returns the key specified on the component, component type, or {@link Integer#MIN_VALUE} * * @param logicalComponent the component * @return the key or null */ private int getOrder(LogicalComponent logicalComponent) { int order = logicalComponent.getDefinition().getOrder(); if (order == Integer.MIN_VALUE) { Component<?> component = logicalComponent.getDefinition(); if (component.getComponentType() != null) { order = component.getComponentType().getOrder(); } } return order; }
private void setContributionUris(Composite composite) { URI uri = ContributionResolver.getContribution(); composite.setContributionUri(uri); for (Component<? extends Implementation<?>> definition : composite.getComponents().values()) { definition.setContributionUri(uri); if (definition.getComponentType() instanceof Composite) { setContributionUris((Composite) definition.getComponentType()); } } }
protected SystemComponentBuilder(String name, Class<?> clazz) { InjectingComponentType componentType = new InjectingComponentType(clazz); SystemImplementation implementation = new SystemImplementation(clazz); implementation.setComponentType(componentType); component = new Component<>(name); component.setImplementation(implementation); }
private LogicalReference createReference(Class<?> interfaze) { LogicalCompositeComponent domainComponent = lcm.getDomainComposite(); int id = idCounter.getAndIncrement(); String name = "Synthetic" + id; URI componentUri = URI.create(domainComponent.getUri().toString() + "/" + name); URI referenceUri = URI.create(componentUri.toString() + "#reference"); QName qName = new QName(HostNamespaces.SYNTHESIZED, "SyntheticComposite" + id); Composite composite = new Composite(qName); Component<NonManagedImplementation> component = new Component<>(name); component.setParent(composite); component.setContributionUri(Names.HOST_CONTRIBUTION); NonManagedImplementation implementation = new NonManagedImplementation(); component.setImplementation(implementation); Reference<ComponentType> reference = new Reference<>("reference", Multiplicity.ONE_ONE); composite.add(reference); JavaServiceContract contract = introspector.introspect(interfaze); LogicalComponent<NonManagedImplementation> logicalComponent = new LogicalComponent<>(componentUri, component, domainComponent); reference.setServiceContract(contract); LogicalReference logicalReference = new LogicalReference(referenceUri, reference, logicalComponent); logicalReference.setServiceContract(contract); logicalComponent.addReference(logicalReference); return logicalReference; }
public PhysicalComponent generate(LogicalComponent<SpringImplementation> component) throws Fabric3Exception { URI uri = component.getUri(); Component<SpringImplementation> componentDefinition = component.getDefinition(); SpringImplementation implementation = componentDefinition.getImplementation(); // if the app context is in a jar, calculate the base location, otherwise it is null String baseLocation = null; List<String> contextLocations = implementation.getContextLocations(); if (SpringImplementation.LocationType.JAR == implementation.getLocationType() || SpringImplementation.LocationType.DIRECTORY == implementation.getLocationType()) { baseLocation = implementation.getLocation(); } ComponentType type = componentDefinition.getComponentType(); Map<String, String> mappings = handleDefaultReferenceMappings(componentDefinition, type); PhysicalSpringComponent.LocationType locationType = PhysicalSpringComponent.LocationType.valueOf(implementation.getLocationType().toString()); PhysicalSpringComponent physicalComponent = new PhysicalSpringComponent(uri, baseLocation, contextLocations, mappings, locationType); processPropertyValues(component, physicalComponent); return physicalComponent; }
public InvalidPropertyFile(String name, LogicalComponent component, Throwable cause, URI file) { super(component.getUri(), component.getDefinition().getContributionUri(), Collections.singletonList(component)); this.name = name; this.cause = cause; this.file = file; }
public LogicalComponent<CompositeImplementation> instantiate(Component<CompositeImplementation> component, LogicalCompositeComponent parent, InstantiationContext context) { URI uri = URI.create(parent.getUri() + "/" + component.getName()); Composite composite = Composite.class.cast(component.getComponentType()); LogicalCompositeComponent logicalComponent = new LogicalCompositeComponent(uri, component, parent); initializeProperties(logicalComponent, component, context); instantiateChildComponents(logicalComponent, composite, context); wireInstantiator.instantiateCompositeWires(composite, logicalComponent, context); instantiateResources(logicalComponent, composite); wireInstantiator.instantiateCompositeWires(composite, logicalComponent, context); if (channelInstantiator != null) { channelInstantiator.instantiateChannels(composite, logicalComponent, context); } if (parent.getComponent(uri) != null) { DuplicateComponent error = new DuplicateComponent(uri, parent); context.addError(error); } parent.addComponent(logicalComponent); return logicalComponent; }
@SuppressWarnings("unchecked") protected PhysicalComponent generateDefinition(LogicalComponent<?> component) throws Fabric3Exception { Implementation<?> implementation = component.getDefinition().getImplementation(); Class<? extends Implementation> type = implementation.getClass(); ComponentGenerator generator = generatorRegistry.getComponentGenerator(type); if (generator == null) { throw new Fabric3Exception("Generator not found: " + type.getName()); } PhysicalComponent physicalComponent = generator.generate(component); URI uri = component.getUri(); physicalComponent.setComponentUri(uri); URI contributionUri = component.getDefinition().getContributionUri(); physicalComponent.setContributionUri(contributionUri); physicalComponent.setClassLoader(classLoaderRegistry.getClassLoader(contributionUri)); return physicalComponent; }
/** * Determines the service transaction type. * * @param component the component * @return the transaction type */ private SessionType getSessionType(LogicalComponent<?> component) { List<String> policies = component.getDefinition().getComponentType().getPolicies(); if (policies.contains(MANAGED_TRANSACTION) || policies.contains(MANAGED_TRANSACTION_GLOBAL) || policies.contains(MANAGED_TRANSACTION_LOCAL)) { return SessionType.GLOBAL_TRANSACTED; } return SessionType.AUTO_ACKNOWLEDGE; }
private Composite createComposite(WebImplementation implementation, Contribution contribution) { URI contributionUri = contribution.getUri(); String localPart = createLocalPart(contributionUri); QName compositeName = new QName(HostNamespaces.SYNTHESIZED, localPart); Composite composite = new Composite(compositeName); composite.setContributionUri(contributionUri); Component<WebImplementation> component = new Component<>(localPart, implementation); component.setContributionUri(contributionUri); composite.add(component); return composite; }
private Map<String, String> handleDefaultReferenceMappings(Component<SpringImplementation> component, ComponentType type) { Map<String, String> mappings = new HashMap<>(); for (Reference reference : type.getReferences().values()) { SpringReference springReference = (SpringReference) reference; String defaultStr = springReference.getDefaultValue(); if (defaultStr == null) { continue; } String refName = springReference.getName(); if (component.getReferences().containsKey(refName)) { continue; } mappings.put(defaultStr, refName); } return mappings; }
@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 deploy(Component<?> component) throws Fabric3Exception { URI uri = ContributionResolver.getContribution(); DefaultIntrospectionContext context = new DefaultIntrospectionContext(uri, getClass().getClassLoader()); component.setContributionUri(uri); componentProcessor.process(component, context); checkErrors(context); Composite wrapper = createWrapperComposite(component.getName()); wrapper.add(component); domain.include(wrapper); }
public void process(Component<JavaImplementation> component, Class<?> clazz, IntrospectionContext context) { JavaImplementation implementation = createImplementation(clazz, context); component.setImplementation(implementation); process(component, context); }
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); }
private LogicalReference createReference(Class<?> interfaze) { LogicalCompositeComponent domainComponent = lcm.getDomainComposite(); int id = idCounter.getAndIncrement(); String name = "Synthetic" + id; URI componentUri = URI.create(domainComponent.getUri().toString() + "/" + name); URI referenceUri = URI.create(componentUri.toString() + "#reference"); QName qName = new QName(HostNamespaces.SYNTHESIZED, "SyntheticComposite" + id); Composite composite = new Composite(qName); Component<NonManagedImplementation> component = new Component<>(name); component.setParent(composite); component.setContributionUri(Names.HOST_CONTRIBUTION); NonManagedImplementation implementation = new NonManagedImplementation(); component.setImplementation(implementation); Reference<ComponentType> reference = new Reference<>("reference", Multiplicity.ONE_ONE); composite.add(reference); JavaServiceContract contract = introspector.introspect(interfaze); LogicalComponent<NonManagedImplementation> logicalComponent = new LogicalComponent<>(componentUri, component, domainComponent); reference.setServiceContract(contract); LogicalReference logicalReference = new LogicalReference(referenceUri, reference, logicalComponent); logicalReference.setServiceContract(contract); logicalComponent.addReference(logicalReference); return logicalReference; }