Refine search
/** * Obtains a {@link ConfigModel} for the given class (Which should have {@link Configured} annotation on it.) */ public ConfigModel buildModel(Class<?> clazz) { return buildModel(clazz.getName()); }
public DomDocument parse(XMLStreamReader in) throws XMLStreamException { DomDocument document = new DomDocument(habitat); parse(in, document); return document; }
public static Class<? extends ConfigBeanProxy> getElementTypeByName(ConfigBeanProxy parent, String elementName) throws ClassNotFoundException { final Dom parentDom = Dom.unwrap(parent); DomDocument document = parentDom.document; ConfigModel.Property a = parentDom.model.elements.get(elementName); if (a!=null) { if (a.isLeaf()) { // dochez : I am not too sure, but that should be a String @Element return null; } else { ConfigModel childModel = ((ConfigModel.Node) a).model; return (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName); } } // global lookup ConfigModel model = document.getModelByElementName(elementName); if (model!=null) { return (Class<? extends ConfigBeanProxy>) model.classLoaderHolder.loadClass(model.targetTypeName); } return null; }
/** * Allocate a new ConfigBean object as part of the Transaction * associated with this configuration object. This will eventually * be moved to a factory. * * @param type the request configuration object type * @return the properly constructed configuration object */ public ConfigBean allocate(Class<?> type) { return (ConfigBean) document.make(getHabitat(), null, this, document.buildModel(type)); }
/** * probably a bit slow, calculates all the @Configured interfaces subclassing, useful * to find all possible subclasses of a type. * * @throws ClassNotFoundException */ private void initXRef() throws ClassNotFoundException { // force initialization of all the config models. for (ServiceHandle<?> i : habitat.getAllServiceHandles(ConfigInjector.class)) { buildModel((ActiveDescriptor<? extends ConfigInjector>) i.getActiveDescriptor()); } for (ConfigModel cm : models.values()) { Class targetType = cm.classLoaderHolder.loadClass(cm.targetTypeName); do { Class[] intfs = targetType.getInterfaces(); for (Class intf : intfs) { if (intf.isAnnotationPresent(Configured.class)) { addXRef(intf, cm); } } targetType = targetType.getSuperclass(); } while (targetType!=null); } }
/* 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(); } } } } }
@Override public <T extends Container> T parseContainerConfig(ServiceLocator habitat, final URL configuration, Class<T> configType) throws IOException { // I don't use the GlassFish document here as I don't need persistence final DomDocument doc = new DomDocument<GlassFishConfigBean>(habitat) { @Override public Dom make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) { // by default, people get the translated view. return new GlassFishConfigBean(habitat,this, dom, configModel, xmlStreamReader); } }; // add the new container configuration to the server config final T container = doc.getRoot().createProxy(configType); try { ConfigSupport.apply(new SingleConfigCode<Config>() { @Override public Object run(Config config) throws PropertyVetoException, TransactionFailure { config.getContainers().add(container); return null; } }, config); } catch(TransactionFailure e) { logger.log(Level.SEVERE, KernelLoggerInfo.exceptionAddContainer, e); } return container; } }
}, Dom.unwrap(domain)); final Virtualizations defaultConfig = document.getRoot().createProxy(Virtualizations.class); ConfigSupport.apply(new SingleConfigCode<Virtualizations>() { @Override
public void transactionCommited(List<PropertyChangeEvent> changes) { for (ConfigurationPersistence pers : habitat.getAllByContract(ConfigurationPersistence.class)) { try { if (doc.getRoot().getProxyType().equals(Domain.class)) { Dom domainRoot = doc.getRoot(); domainRoot.attribute("version", Version.getBuildVersion()); } pers.save(doc); } catch (IOException e) { logger.log(Level.SEVERE, "GlassFishDocument.IOException", new String[] { e.getMessage() }); logger.log(Level.FINE, e.getMessage(), e); } catch (XMLStreamException e) { logger.log(Level.SEVERE, "GlassFishDocument.XMLException", new String[] { e.getMessage() }); logger.log(Level.SEVERE, e.getMessage(), e); } } }
throws ClassNotFoundException { ConfigModel cm = document.buildModel(parent); for (String elementName : cm.getElementNames()) { ConfigModel.Property prop = cm.getElement(elementName); List<ConfigModel> subChildrenModels = document.getAllModelsImplementing( childCM.classLoaderHolder.get().loadClass(childTypeName)); if (subChildrenModels!=null) {
/** works only for @Configured types */ public static Class[] getTypesImplementing(final Class<?> clazz) { final DomDocument domDoc = new DomDocument(InjectedValues.getInstance().getHabitat()); try { final List<ConfigModel> models = domDoc.getAllModelsImplementing(clazz); final Class[] interfaces = new Class[models == null ? 0 : models.size()]; if (models != null) { int i = 0; for (final ConfigModel model : models) { final String classname = model.targetTypeName; final Class<?> intf = model.classLoaderHolder.loadClass(classname); interfaces[i] = intf; //System.out.println( "Loaded: " + intf + " with tagName of " + model.getTagName() ); ++i; } } return interfaces; } catch (final Exception e) { AMXLoggerInfo.getLogger().log( Level.INFO, AMXLoggerInfo.cantGetTypesImplementing, new Object[] {clazz, e.getLocalizedMessage()} ); throw new RuntimeException(e); } }
/** * Performs translation with null pass-through. */ private String t(String s) { if(s==null) return null; return document.getTranslator().translate(s); }
/** * Calculates all @Configured interfaces subclassing the passed interface type. * * @param intf a @Configured interface * @return List of all @Configured subclasses * @throws ClassNotFoundException */ public synchronized List<ConfigModel> getAllModelsImplementing(Class intf) throws ClassNotFoundException { if (implementorsOf.size()==0) { initXRef(); } return implementorsOf.getOne(intf); }
ConfigModel model = document.getModelByElementName(in.getLocalName()); if(model==null) { String localName = in.getLocalName();
final Dom dom = document.make(habitat, in, parent, model); dom.fillAttributes(in); children = new ArrayList<Dom.Child>(); dom.ensureConstraints(children); dom.setChildren(children); dom.register();
URL domainURL = domainXMLFile.toURI().toURL(); DomDocument doc = parser.parse(domainURL); Dom domDomain = doc.getRoot(); Domain domain = domDomain.createProxy(Domain.class); DomainXmlVerifier validator = new DomainXmlVerifier(domain);
public void transactionCommited(List<PropertyChangeEvent> changes) { if (!isGlassFishDocumentChanged(changes)) { return; } for (ConfigurationPersistence pers : habitat.<ConfigurationPersistence>getAllServices(ConfigurationPersistence.class)) { try { if (doc.getRoot().getProxyType().equals(Domain.class)) { Dom domainRoot = doc.getRoot(); domainRoot.attribute("version", Version.getBuildVersion()); } pers.save(doc); } catch (IOException e) { logger.log(Level.SEVERE, ConfigApiLoggerInfo.glassFishDocumentIOException,e); } catch (XMLStreamException e) { logger.log(Level.SEVERE, ConfigApiLoggerInfo.glassFishDocumentXmlException,e); } } }
/** * Allocate a new ConfigBean object as part of the Transaction * associated with this configuration object. This will eventually * be moved to a factory. * * @param type the request configuration object type * @return the properly constructed configuration object */ public ConfigBean allocate(Class<?> type) { return (ConfigBean) document.make(habitat, null, this, document.buildModel(type)); }