/** * Returns the children name associated with this config instance. This is by definition a subset * of the element names as known to the model {#see ConfigModel.getElementNames(). @Return list of * elements names associated with this config instance */ public Set<String> getElementNames() { Set<String> names = new HashSet<String>(); for (Child child : children) { names.add(child.name); } return names; }
/* package */ void ensureConstraints(List<Child> children) { Set<String> nullElements = new HashSet<String>(model.getElementNames()); for (Child child : children) { nullElements.remove(child.name); } for (String s : nullElements) { ConfigModel.Property p = model.getElement(s); for (String annotation : p.getAnnotations()) { if (annotation.equals(NotNull.class.getName())) { if (p instanceof ConfigModel.Node) { ConfigModel childModel = ((ConfigModel.Node) p).model; Dom child = document.make(getHabitat(), null, this, childModel); child.register(); children.add(new Dom.NodeChild(s, child)); // recursive call to ensure the children constraints are also respected List<Child> grandChildren = new ArrayList<Child>(); child.ensureConstraints(grandChildren); if (!grandChildren.isEmpty()) { child.setChildren(grandChildren); } child.initializationCompleted(); } } } } }
/* package */ @SuppressWarnings({"unchecked"}) void register() { ServiceLocator locator = getServiceLocator(); ActiveDescriptor<?> myselfReified = locator.reifyDescriptor(this); DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); DynamicConfiguration dc = dcs.createDynamicConfiguration(); // habitat.add(this); HK2Loader loader = this.model.classLoaderHolder; Set<Type> ctrs = new HashSet<Type>(); ctrs.add(myselfReified.getImplementationClass()); if (ConfigBean.class.isAssignableFrom(this.getClass())) { ctrs.add(ConfigBean.class); } DomDescriptor<Dom> domDesc = new DomDescriptor<Dom>( this, ctrs, Singleton.class, getImplementation(), new HashSet<Annotation>()); domDesc.setLoader(loader); domDescriptor = dc.addActiveDescriptor(domDesc, false); String key = getKey(); for (String contract : model.contracts) { ActiveDescriptor<Dom> alias = new AliasDescriptor<Dom>(locator, domDescriptor, contract, key); dc.addActiveDescriptor(alias, false); } if (key != null) { ActiveDescriptor<Dom> alias = new AliasDescriptor<Dom>(locator, domDescriptor, model.targetTypeName, key); dc.addActiveDescriptor(alias, false); } dc.commit(); serviceHandle = getHabitat().getServiceHandle(domDescriptor); }
public boolean removeListener(ConfigListener listener) { return listeners.remove(listener); }
public void addListener(ConfigListener listener) { if (listener == null) { throw new IllegalArgumentException("Listener cannot be null"); } listeners.add(listener); }