@SuppressWarnings("unchecked") private <C extends LogicalComponent<?>> ComponentGenerator<C> getGenerator(C component) throws GeneratorNotFoundException { Implementation<?> implementation = component.getDefinition().getImplementation(); return (ComponentGenerator<C>) generatorRegistry.getComponentGenerator(implementation.getClass()); }
private void initializeDomainComposite() { Composite type = new Composite(null); CompositeImplementation impl = new CompositeImplementation(); impl.setComponentType(type); ComponentDefinition<CompositeImplementation> definition = new ComponentDefinition<CompositeImplementation>(domainUri.toString()); definition.setImplementation(impl); definition.setContributionUri(Names.BOOT_CONTRIBUTION); type.setAutowire(autowire); domain = new LogicalCompositeComponent(domainUri, definition, null); domain.setState(LogicalState.PROVISIONED); domain.setAutowire(autowire); }
/** * Returns true if the reference is not keyed, true if the reference is keyed and the target specifies a key, false if the reference is keyed and * the target does not specify a key. * * @param logicalReference the logical reference * @param target the target * @return true if the reference is not keyed, true if the reference is keyed and the target specifies a key, false if the reference is keyed and * the target does not specify a key */ private boolean validKey(LogicalReference logicalReference, LogicalComponent<?> target) { return !logicalReference.getDefinition().isKeyed() || target.getDefinition().getKey() != null || target.getDefinition().getComponentType().getKey() != null; } }
private void validateRequiredProperties(ComponentDefinition<? extends Implementation<?>> definition, XMLStreamReader reader, IntrospectionContext context) { AbstractComponentType<?, ?, ?, ?> type = definition.getImplementation().getComponentType(); Map<String, ? extends Property> properties = type.getProperties(); Map<String, PropertyValue> values = definition.getPropertyValues(); for (Property property : properties.values()) { if (property.isRequired() && !values.containsKey(property.getName())) { RequiredPropertyNotProvided failure = new RequiredPropertyNotProvided(property, definition.getName(), reader); context.addError(failure); } } }
/** * Adds the contribution URI to the system composite and its children. * * @param contributionUri the contribution URI * @param composite the composite */ private static void addContributionUri(URI contributionUri, Composite composite) { composite.setContributionUri(contributionUri); for (ComponentDefinition<?> definition : composite.getComponents().values()) { Implementation<?> implementation = definition.getImplementation(); if (CompositeImplementation.class.isInstance(implementation)) { CompositeImplementation compositeImplementation = CompositeImplementation.class.cast(implementation); Composite componentType = compositeImplementation.getComponentType(); addContributionUri(contributionUri, componentType); } else { definition.setContributionUri(contributionUri); } } }
@SuppressWarnings({"unchecked"}) public LogicalComponent instantiate(ComponentDefinition<?> definition, LogicalCompositeComponent parent, InstantiationContext context) { URI uri = URI.create(parent.getUri() + "/" + definition.getName()); LogicalComponent<?> component = new LogicalComponent(uri, definition, parent); if (parent.getComponent(uri) != null) { DuplicateComponent error = new DuplicateComponent(uri, parent); context.addError(error); } parent.addComponent(component); Implementation<?> impl = definition.getImplementation(); if (impl == null) { return component; } ComponentType componentType = impl.getComponentType(); if (componentTypeOverride) { // SCA policy conformance: override policy sets configured on the component type component.getPolicySets().removeAll(definition.getPolicySets()); } initializeProperties(component, definition, context); createServices(definition, component, componentType); createReferences(definition, component, componentType); createProducers(definition, component, componentType); createConsumers(definition, component, componentType); createResourceReferences(component, componentType); return component; }
public DuplicateChannel(URI channelUri, LogicalCompositeComponent composite) { super(channelUri, composite.getDefinition().getContributionUri(), Collections.singletonList(composite)); }
public PhysicalComponentDefinition generate(LogicalComponent<SpringImplementation> component) throws GenerationException { URI uri = component.getUri(); ComponentDefinition<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); SpringComponentDefinition.LocationType locationType = SpringComponentDefinition.LocationType.valueOf(implementation.getLocationType().toString()); SpringComponentDefinition physical = new SpringComponentDefinition(uri, baseLocation, contextLocations, mappings, locationType); processPropertyValues(component, physical); return physical; }
@SuppressWarnings("unchecked") protected PhysicalComponentDefinition generateDefinition(LogicalComponent<?> component) throws GenerationException { Implementation<?> implementation = component.getDefinition().getImplementation(); Class<? extends Implementation> type = implementation.getClass(); ComponentGenerator generator = generatorRegistry.getComponentGenerator(type); if (generator == null) { throw new GeneratorNotFoundException(type); } PhysicalComponentDefinition definition = generator.generate(component); URI uri = component.getUri(); definition.setComponentUri(uri); definition.setClassLoaderId(component.getDefinition().getContributionUri()); QName deployable = component.getDeployable(); definition.setDeployable(deployable); return definition; }
/** * Returns the key specified on the component definition, 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 Implementation implementation = component.getDefinition().getImplementation(); if (implementation != null && implementation.getComponentType() != null) { key = implementation.getComponentType().getKey(); } } return key; }
/** * Returns the key specified on the component definition, component type, or {@link Integer#MIN_VALUE} * * @param component the component * @return the key or null */ private int getOrder(LogicalComponent component) { int order = component.getDefinition().getOrder(); if (order == Integer.MIN_VALUE) { ComponentDefinition<?> definition = component.getDefinition(); Implementation<?> implementation = definition.getImplementation(); if (implementation != null && implementation.getComponentType() != null) { order = implementation.getComponentType().getOrder(); } } return order; }
private void parseReference(ComponentDefinition<Implementation<?>> componentDefinition, AbstractComponentType<?, ?, ?, ?> componentType, XMLStreamReader reader, IntrospectionContext context) throws XMLStreamException, UnrecognizedElementException { ComponentReference reference; reference = registry.load(reader, ComponentReference.class, context); if (reference == null) { // there was an error with the reference configuration, just skip it return; } if (!componentType.hasReference(reference.getName())) { // ensure the reference exists ComponentReferenceNotFound failure = new ComponentReferenceNotFound(reference.getName(), componentDefinition, reader); context.addError(failure); return; } String refKey = reference.getName(); if (componentDefinition.getReferences().containsKey(refKey)) { DuplicateComponentReference failure = new DuplicateComponentReference(refKey, componentDefinition.getName(), reader); context.addError(failure); } else { componentDefinition.add(reference); } }
private void handleComponent(Composite type, XMLStreamReader reader, IntrospectionContext childContext) throws XMLStreamException, UnrecognizedElementException { ComponentDefinition<?> componentDefinition = registry.load(reader, ComponentDefinition.class, childContext); if (componentDefinition == null) { // errror encountered loading the componentDefinition return; } String key = componentDefinition.getName(); if (type.getComponents().containsKey(key)) { DuplicateComponentName failure = new DuplicateComponentName(key, reader); childContext.addError(failure); return; } if (type.getAutowire() != Autowire.INHERITED && componentDefinition.getAutowire() == Autowire.INHERITED) { componentDefinition.setAutowire(type.getAutowire()); } type.add(componentDefinition); }
private void parseService(ComponentDefinition<Implementation<?>> componentDefinition, AbstractComponentType<?, ?, ?, ?> componentType, XMLStreamReader reader, IntrospectionContext context) throws XMLStreamException, UnrecognizedElementException { ComponentService service; service = registry.load(reader, ComponentService.class, context); if (service == null) { // there was an error with the service configuration, just skip it return; } if (!componentType.hasService(service.getName())) { // ensure the service exists ComponentServiceNotFound failure = new ComponentServiceNotFound(service.getName(), componentDefinition, reader); context.addError(failure); return; } if (componentDefinition.getServices().containsKey(service.getName())) { String id = service.getName(); DuplicateComponentService failure = new DuplicateComponentService(id, componentDefinition.getName(), reader); context.addError(failure); } else { componentDefinition.add(service); } }
public ComponentPropertyNotFound(String propertyName, ComponentDefinition definition, XMLStreamReader reader) { super("The component " + definition.getName() + " does not have a property " + propertyName, reader); this.propertyName = propertyName; this.definition = definition; }
ComponentDefinition<Implementation<?>> componentDefinition = new ComponentDefinition<Implementation<?>>(name); Autowire autowire = Autowire.fromString(reader.getAttributeValue(null, "autowire")); componentDefinition.setAutowire(autowire); loadInitLevel(componentDefinition, reader, context); loadKey(componentDefinition, reader); componentDefinition.setImplementation(impl); AbstractComponentType<?, ?, ?, ?> componentType = impl.getComponentType();
private Composite createComposite(Contribution contribution) { URI contributionUri = contribution.getUri(); String localPart = createLocalPart(contributionUri); QName compositeName = new QName(Namespaces.SYNTHESIZED, localPart); Composite composite = new Composite(compositeName); composite.setContributionUri(contributionUri); WebComponentType componentType = new WebComponentType(); WebImplementation impl = new WebImplementation(); impl.setComponentType(componentType); ComponentDefinition<WebImplementation> component = new ComponentDefinition<WebImplementation>(localPart, impl); component.setContributionUri(contributionUri); composite.add(component); return composite; }
Map<String, PropertyValue> propertyValues = definition.getPropertyValues(); ComponentType componentType = definition.getComponentType(); LogicalCompositeComponent parent = component.getParent();
private void validateServicePromotions(Composite type, XMLStreamReader reader, IntrospectionContext childContext) { for (CompositeService service : type.getServices().values()) { URI promotedUri = service.getPromote(); String componentName = UriHelper.getDefragmentedNameAsString(promotedUri); ComponentDefinition promoted = type.getComponents().get(componentName); if (promoted == null) { PromotionNotFound error = new PromotionNotFound("Component " + componentName + " referenced by " + service.getName() + " not found", reader); childContext.addError(error); } else { String serviceName = promotedUri.getFragment(); if (serviceName == null && promoted.getComponentType().getServices().size() != 1) { PromotionNotFound error = new PromotionNotFound("A promoted service must be specified for " + service.getName(), reader); childContext.addError(error); } if (serviceName != null && !promoted.getComponentType().getServices().containsKey(serviceName)) { PromotionNotFound error = new PromotionNotFound("Service " + serviceName + " promoted by " + service.getName() + " not found", reader); childContext.addError(error); } } } }
private Map<String, String> handleDefaultReferenceMappings(ComponentDefinition<SpringImplementation> componentDefinition, ComponentType type) { Map<String, String> mappings = new HashMap<String, String>(); for (ReferenceDefinition reference : type.getReferences().values()) { SpringReferenceDefinition springReference = (SpringReferenceDefinition) reference; String defaultStr = springReference.getDefaultValue(); if (defaultStr == null) { continue; } String refName = springReference.getName(); if (componentDefinition.getReferences().containsKey(refName)) { continue; } mappings.put(defaultStr, refName); } return mappings; }