/** * 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; }
/** * 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; }