@Override public void add(String id, T object, String... constraints) { T coerced = object == null ? null : typeCoercer.coerce(object, expectedType); // https://issues.apache.org/jira/browse/TAP5-1565 // Order each added contribution after the previously added contribution // (in the same method) if no other constraint is supplied. if (constraints.length == 0 && priorId != null) { // Ugly: reassigning parameters is yuck. constraints = new String[]{"after:" + priorId}; } orderer.add(id, coerced, constraints); priorId = id; }
private void initializeGraph() { trailer = new DependencyNode<T>(logger, new Orderable<T>("*-trailer-*", null)); addNodes(); addDependencies(); }
private Collection<DependencyNode<T>> findDependencies(String sourceId, String patternList) { IdMatcher matcher = buildMatcherForPattern(patternList); Collection<DependencyNode<T>> result = newList(); for (String id : dependencyNodesById.keySet()) { if (sourceId.equals(id)) continue; if (matcher.matches(id)) result.add(dependencyNodesById.get(id)); } return result; }
@Override public List<ServiceAdvisor> findAdvisorsForService(ServiceDef3 serviceDef) { lock.check(); assert serviceDef != null; Logger logger = getServiceLogger(serviceDef.getServiceId()); Orderer<ServiceAdvisor> orderer = new Orderer<ServiceAdvisor>(logger); for (Module module : moduleToServiceDefs.keySet()) { Set<AdvisorDef> advisorDefs = module.findMatchingServiceAdvisors(serviceDef); if (advisorDefs.isEmpty()) continue; ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, proxyFactory, logger); for (AdvisorDef advisorDef : advisorDefs) { ServiceAdvisor advisor = advisorDef.createAdvisor(module, resources); orderer.add(advisorDef.getAdvisorId(), advisor, advisorDef.getConstraints()); } } return orderer.getOrdered(); }
public void addMixin(String mixinId, Instantiator instantiator, String... order) { if (mixinIdToComponentResources == null) { mixinIdToComponentResources = NamedSet.create(); components = CollectionFactory.newList(); } String mixinExtension = "$" + mixinId.toLowerCase(); InternalComponentResourcesImpl resources = new InternalComponentResourcesImpl(page, this, coreResources, elementResources, completeId + mixinExtension, nestedId + mixinExtension, instantiator, true); mixinIdToComponentResources.put(mixinId, resources); // note that since we're using explicit ordering now, // we don't add anything to components until we page load; instead, we add // to the orderers. if (order == null) order = InternalConstants.EMPTY_STRING_ARRAY; if (resources.getComponentModel().isMixinAfter()) { if (mixinAfterOrderer == null) mixinAfterOrderer = new Orderer<Component>(getLogger()); mixinAfterOrderer.add(mixinId, resources.getComponent(), order); } else { if (mixinBeforeOrderer == null) mixinBeforeOrderer = new Orderer<Component>(getLogger()); mixinBeforeOrderer.add(mixinId, resources.getComponent(), order); } }
private void pageLoaded() { // If this component has mixins, order them according to: // mixins. if (components != null) { List<Component> ordered = CollectionFactory.newList(); if (mixinBeforeOrderer != null) ordered.addAll(mixinBeforeOrderer.getOrdered()); ordered.add(coreComponent); // Add the remaining, late executing mixins if (mixinAfterOrderer != null) ordered.addAll(mixinAfterOrderer.getOrdered()); components = ordered; // no need to keep the orderers around. mixinBeforeOrderer = null; mixinAfterOrderer = null; } initializeRenderPhases(); page.addVerifyCallback(new Runnable() { public void run() { // For some parameters, bindings (from defaults) are provided inside the callback method, so // that is invoked first, before we check for unbound parameters. verifyRequiredParametersAreBound(); } }); loaded = true; }
private void addDependencies() { for (Orderable<T> orderable : orderables) { addDependencies(orderable); } }
void apply() { try { orderer.override(id, replacementObject, constraints); } catch (Exception ex) { String message = String.format("Failure processing override from %s: %s", contribDef, ExceptionUtils.toMessage(ex)); throw new RuntimeException(message, ex); } }
public List<T> getOrdered() { lock.lock(); initializeGraph(); List<T> result = newList(); for (Orderable<T> orderable : trailer.getOrdered()) { T target = orderable.getTarget(); // Nulls are placeholders that are skipped. if (target != null) result.add(target); } return result; }
private void linkNodes(String sourceId, String patternList, DependencyLinker<T> linker) { Collection<DependencyNode<T>> nodes = findDependencies(sourceId, patternList); DependencyNode<T> source = dependencyNodesById.get(sourceId); for (DependencyNode<T> target : nodes) { linker.link(source, target); } }
private void addDependencies(String sourceId, String constraint) { int colonx = constraint.indexOf(':'); String type = colonx > 0 ? constraint.substring(0, colonx) : null; DependencyLinker<T> linker = null; if ("after".equals(type)) linker = _after; else if ("before".equals(type)) linker = _before; if (linker == null) { logger.warn(UtilMessages.constraintFormat(constraint, sourceId)); return; } String patternList = constraint.substring(colonx + 1); linkNodes(sourceId, patternList, linker); }
@Override public List<ServiceAdvisor> findAdvisorsForService(ServiceDef3 serviceDef) { lock.check(); assert serviceDef != null; Logger logger = getServiceLogger(serviceDef.getServiceId()); Orderer<ServiceAdvisor> orderer = new Orderer<ServiceAdvisor>(logger); for (Module module : moduleToServiceDefs.keySet()) { Set<AdvisorDef> advisorDefs = module.findMatchingServiceAdvisors(serviceDef); if (advisorDefs.isEmpty()) continue; ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, proxyFactory, logger); for (AdvisorDef advisorDef : advisorDefs) { ServiceAdvisor advisor = advisorDef.createAdvisor(module, resources); orderer.add(advisorDef.getAdvisorId(), advisor, advisorDef.getConstraints()); } } return orderer.getOrdered(); }
private void addDependencies() { for (Orderable<T> orderable : orderables) { addDependencies(orderable); } }
void apply() { try { orderer.override(id, replacementObject, constraints); } catch (Exception ex) { String message = String.format("Failure processing override from %s: %s", contribDef, ExceptionUtils.toMessage(ex)); throw new RuntimeException(message, ex); } }
public List<T> getOrdered() { lock.lock(); initializeGraph(); List<T> result = newList(); for (Orderable<T> orderable : trailer.getOrdered()) { T target = orderable.getTarget(); // Nulls are placeholders that are skipped. if (target != null) result.add(target); } return result; }
private void linkNodes(String sourceId, String patternList, DependencyLinker<T> linker) { Collection<DependencyNode<T>> nodes = findDependencies(sourceId, patternList); DependencyNode<T> source = dependencyNodesById.get(sourceId); for (DependencyNode<T> target : nodes) { linker.link(source, target); } }
private void addDependencies(String sourceId, String constraint) { int colonx = constraint.indexOf(':'); String type = colonx > 0 ? constraint.substring(0, colonx) : null; DependencyLinker<T> linker = null; if ("after".equals(type)) linker = _after; else if ("before".equals(type)) linker = _before; if (linker == null) { logger.warn(UtilMessages.constraintFormat(constraint, sourceId)); return; } String patternList = constraint.substring(colonx + 1); linkNodes(sourceId, patternList, linker); }
Logger logger = getServiceLogger(serviceId); Orderer<T> orderer = new Orderer<T>(logger); Map<String, OrderedConfigurationOverride<T>> overrides = CollectionFactory.newCaseInsensitiveMap(); orderer.add("ServiceByMarker", (T) contribution); override.apply(); final List<T> result = orderer.getOrdered();
@Override public void add(String id, T object, String... constraints) { T coerced = object == null ? null : typeCoercer.coerce(object, expectedType); // https://issues.apache.org/jira/browse/TAP5-1565 // Order each added contribution after the previously added contribution // (in the same method) if no other constraint is supplied. if (constraints.length == 0 && priorId != null) { // Ugly: reassigning parameters is yuck. constraints = new String[]{"after:" + priorId}; } orderer.add(id, coerced, constraints); priorId = id; }
private void initializeGraph() { trailer = new DependencyNode<T>(logger, new Orderable<T>("*-trailer-*", null)); addNodes(); addDependencies(); }