/** * Synthesizes a composite from a collection of composites using inclusion. A counter is maintained for each include name and used to generate include * names in situations where they may clash, e.g. when two composites from different contributions with the same name are deployed together. * * @param composites the composites to synthesize * @return the synthesized composite */ private Composite synthesizeComposite(List<Composite> composites) { Composite synthesized = new Composite(SYNTHETIC_COMPOSITE); Map<QName, AtomicInteger> counters = new HashMap<>(); for (Composite composite : composites) { Include include = new Include(); QName name = composite.getName(); include.setName(name); include.setIncluded(composite); if (synthesized.getIncludes().containsKey(name)) { AtomicInteger counter = counters.get(name); if (counter == null) { counter = new AtomicInteger(); counters.put(name, counter); } include.setName(new QName(name.getNamespaceURI(), name.getLocalPart() + counter.incrementAndGet())); } synthesized.add(include); } return synthesized; }
/** * Synthesizes a composite from a collection of composites using inclusion. A counter is maintained for each include name and used to generate include * names in situations where they may clash, e.g. when two composites from different contributions with the same name are deployed together. * * @param composites the composites to synthesize * @return the synthesized composite */ private Composite synthesizeComposite(List<Composite> composites) { Composite synthesized = new Composite(SYNTHETIC_COMPOSITE); Map<QName, AtomicInteger> counters = new HashMap<>(); for (Composite composite : composites) { Include include = new Include(); QName name = composite.getName(); include.setName(name); include.setIncluded(composite); if (synthesized.getIncludes().containsKey(name)) { AtomicInteger counter = counters.get(name); if (counter == null) { counter = new AtomicInteger(); counters.put(name, counter); } include.setName(new QName(name.getNamespaceURI(), name.getLocalPart() + counter.incrementAndGet())); } synthesized.add(include); } return synthesized; }
private Resource createResource(Contribution contribution, Composite composite) { QNameSymbol symbol = new QNameSymbol(composite.getName()); ResourceElement<QNameSymbol, Composite> element = new ResourceElement<>(symbol, composite); Resource resource = new Resource(contribution, null, Constants.COMPOSITE_CONTENT_TYPE); resource.addResourceElement(element); resource.setState(ResourceState.PROCESSED); return resource; }
/** * Includes the composite in the current composite. * * @param included the name of the composite to include * @return the builder */ public CompositeBuilder include(Composite included) { checkState(); Include include = new Include(); include.setIncluded(included); include.setName(included.getName()); composite.add(include); return this; }
public void instantiateChannels(Composite composite, LogicalCompositeComponent parent, InstantiationContext context) { for (Channel definition : composite.getChannels().values()) { URI uri = URI.create(parent.getUri() + "/" + definition.getName()); if (parent.getChannel(uri) != null) { DuplicateChannel error = new DuplicateChannel(uri, parent); context.addError(error); continue; } LogicalChannel channel = new LogicalChannel(uri, definition, parent); for (Binding binding : definition.getBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, channel); channel.addBinding(logicalBinding); } channel.setDeployable(composite.getName()); parent.addChannel(channel); } }
private void addCompositeToContribution(Composite wrapper) { QName compositeName = wrapper.getName(); URI uri = ContributionResolver.getContribution(); Contribution contribution = metaDataStore.find(uri); Resource resource = new Resource(contribution, null, Constants.COMPOSITE_CONTENT_TYPE); QNameSymbol symbol = new QNameSymbol(compositeName); ResourceElement<QNameSymbol, Composite> element = new ResourceElement<>(symbol, wrapper); resource.addResourceElement(element); resource.setState(ResourceState.PROCESSED); contribution.addResource(resource); }
private void addCompositeToContribution(Composite wrapper) { QName compositeName = wrapper.getName(); URI uri = ContributionResolver.getContribution(); Contribution contribution = metaDataStore.find(uri); Resource resource = new Resource(contribution, null, Constants.COMPOSITE_CONTENT_TYPE); QNameSymbol symbol = new QNameSymbol(compositeName); ResourceElement<QNameSymbol, Composite> element = new ResourceElement<>(symbol, wrapper); resource.addResourceElement(element); resource.setState(ResourceState.PROCESSED); contribution.addResource(resource); }
private void addCompositeToContribution(Composite wrapper) { QName compositeName = wrapper.getName(); URI uri = ContributionResolver.getContribution(); Contribution contribution = metaDataStore.find(uri); Resource resource = new Resource(contribution, null, Constants.COMPOSITE_CONTENT_TYPE); QNameSymbol symbol = new QNameSymbol(compositeName); ResourceElement<QNameSymbol, Composite> element = new ResourceElement<>(symbol, wrapper); resource.addResourceElement(element); resource.setState(ResourceState.PROCESSED); contribution.addResource(resource); }
public void instantiateChannels(Composite composite, LogicalCompositeComponent parent, InstantiationContext context) { for (Channel definition : composite.getChannels().values()) { URI uri = URI.create(parent.getUri() + "/" + definition.getName()); if (parent.getChannel(uri) != null) { DuplicateChannel error = new DuplicateChannel(uri, parent); context.addError(error); continue; } LogicalChannel channel = new LogicalChannel(uri, definition, parent); for (Binding binding : definition.getBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, channel); channel.addBinding(logicalBinding); } channel.setDeployable(composite.getName()); parent.addChannel(channel); } }
/** * Adds the composite as a resource to the contribution. * * @param contribution the contribution * @param composite the composite */ private static void addResource(Contribution contribution, Composite composite) { Source source = new UrlSource(COMPOSITE_URL); Resource resource = new Resource(contribution, source, Constants.COMPOSITE_CONTENT_TYPE); QName compositeName = composite.getName(); QNameSymbol symbol = new QNameSymbol(compositeName); ResourceElement<QNameSymbol, Composite> element = new ResourceElement<>(symbol, composite); resource.addResourceElement(element); resource.setState(ResourceState.PROCESSED); contribution.addResource(resource); }
/** * Adds the composite as a resource to the contribution. * * @param contribution the contribution * @param composite the composite */ private static void addResource(Contribution contribution, Composite composite) { Source source = new UrlSource(COMPOSITE_URL); Resource resource = new Resource(contribution, source, Constants.COMPOSITE_CONTENT_TYPE); QName compositeName = composite.getName(); QNameSymbol symbol = new QNameSymbol(compositeName); ResourceElement<QNameSymbol, Composite> element = new ResourceElement<>(symbol, composite); resource.addResourceElement(element); resource.setState(ResourceState.PROCESSED); contribution.addResource(resource); }
public void onInstall(Contribution contribution) { if (!isWar(contribution)) { return; } if (hasImplementation(contribution)) { return; // web component was explicitly configured in the contribution } // synthesize a web implementation URI uri = createWebUri(contribution); WebImplementation implementation = new WebImplementation(uri); // retrieve the component type introspected during contribution indexing or create one if no web artifacts resulted in it being generated WebComponentType componentType = getComponentType(contribution); implementation.setComponentType(componentType); // synthesize a deployable composite IndexHelper.indexImplementation(implementation, contribution); Composite composite = createComposite(implementation, contribution); contribution.getManifest().addDeployable(new Deployable(composite.getName())); contribution.addResource(createResource(contribution, composite)); }
/** * Instantiates and deploys the given composite. * * @param composite the composite to instantiate and deploy * @throws Fabric3Exception if a deployment error occurs */ private void instantiateAndDeploy(Composite composite) throws Fabric3Exception { LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); QName name = composite.getName(); QNameSymbol symbol = new QNameSymbol(name); ResourceElement<QNameSymbol, Composite> element = metadataStore.find(Composite.class, symbol); if (element == null) { throw new Fabric3Exception("Composite not found in metadata store: " + name); } Contribution contribution = element.getResource().getContribution(); if (ContributionState.STORED == contribution.getState()) { throw new Fabric3Exception("Contribution is not installed: " + contribution.getUri()); } InstantiationContext context = logicalModelInstantiator.include(composite, domain); if (context.hasErrors()) { throw new AssemblyException(context.getErrors()); } deploy(domain); contribution.deploy(); }
/** * Instantiates and deploys the given composite. * * @param composite the composite to instantiate and deploy * @throws Fabric3Exception if a deployment error occurs */ private void instantiateAndDeploy(Composite composite) throws Fabric3Exception { LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); QName name = composite.getName(); QNameSymbol symbol = new QNameSymbol(name); ResourceElement<QNameSymbol, Composite> element = metadataStore.find(Composite.class, symbol); if (element == null) { throw new Fabric3Exception("Composite not found in metadata store: " + name); } Contribution contribution = element.getResource().getContribution(); if (ContributionState.STORED == contribution.getState()) { throw new Fabric3Exception("Contribution is not installed: " + contribution.getUri()); } InstantiationContext context = logicalModelInstantiator.include(composite, domain); if (context.hasErrors()) { throw new AssemblyException(context.getErrors()); } deploy(domain); contribution.deploy(); }
QName name = composite.getName(); List<ValidationFailure> errors = context.getErrors(); List<ValidationFailure> warnings = context.getWarnings();
QName name = composite.getName(); List<ValidationFailure> errors = context.getErrors(); List<ValidationFailure> warnings = context.getWarnings();