Search in sources :

Example 6 with ConfigModel

use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.

the class GenericCrudCommand method elementName.

/**
 * Returns the element name used by the parent to store instances of the child
 *
 * @param document the dom document this configuration element lives in.
 * @param parent type of the parent
 * @param child type of the child
 * @return the element name holding child's instances in the parent
 * @throws ClassNotFoundException when subclasses cannot be loaded
 */
public static String elementName(DomDocument document, Class<?> parent, Class<?> child) throws ClassNotFoundException {
    ConfigModel cm = document.buildModel(parent);
    for (String elementName : cm.getElementNames()) {
        ConfigModel.Property prop = cm.getElement(elementName);
        if (prop instanceof ConfigModel.Node) {
            ConfigModel childCM = ((ConfigModel.Node) prop).getModel();
            String childTypeName = childCM.targetTypeName;
            if (childTypeName.equals(child.getName())) {
                return childCM.getTagName();
            }
            // check the inheritance hierarchy
            List<ConfigModel> subChildrenModels = document.getAllModelsImplementing(childCM.classLoaderHolder.loadClass(childTypeName));
            if (subChildrenModels != null) {
                for (ConfigModel subChildModel : subChildrenModels) {
                    if (subChildModel.targetTypeName.equals(child.getName())) {
                        return subChildModel.getTagName();
                    }
                }
            }
        }
    }
    return null;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel)

Example 7 with ConfigModel

use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.

the class ConfigModularityUtils method getCurrentConfigBeanForDefaultValue.

public <T extends ConfigBeanProxy> T getCurrentConfigBeanForDefaultValue(ConfigBeanDefaultValue defaultValue) throws InvocationTargetException, IllegalAccessException {
    // TODO make this method target aware!
    Class parentClass = getOwningClassForLocation(defaultValue.getLocation());
    Class configBeanClass = getClassForFullName(defaultValue.getConfigBeanClassName());
    Method m = findSuitableCollectionGetter(parentClass, configBeanClass);
    if (m != null) {
        ConfigParser configParser = new ConfigParser(serviceLocator);
        // I don't use the GlassFish document here as I don't need persistence
        final DomDocument doc = new DomDocument<GlassFishConfigBean>(serviceLocator) {

            @Override
            public Dom make(final ServiceLocator serviceLocator, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
                // by default, people get the translated view.
                return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
            }
        };
        ConfigBeanProxy parent = getOwningObject(defaultValue.getLocation());
        ConfigurationPopulator populator = new ConfigurationPopulator(defaultValue.getXmlConfiguration(), doc, parent);
        populator.run(configParser);
        ConfigBeanProxy configBean = doc.getRoot().createProxy(configBeanClass);
        Collection col = (Collection) m.invoke(parent);
        return (T) getConfigBeanFromCollection(col, configBean, configBeanClass);
    }
    return null;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigModel(org.jvnet.hk2.config.ConfigModel) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) GlassFishConfigBean(org.glassfish.config.support.GlassFishConfigBean) ConfigurationPopulator(com.sun.enterprise.config.modularity.parser.ConfigurationPopulator) ConfigParser(org.jvnet.hk2.config.ConfigParser) Collection(java.util.Collection) Method(java.lang.reflect.Method) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 8 with ConfigModel

use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.

the class ConfigurationParser method parseAndSetConfigBean.

/**
 * @param <T> the ConfigBeanProxy type we are looking for
 */
public <T extends ConfigBeanProxy> void parseAndSetConfigBean(List<ConfigBeanDefaultValue> values) {
    ConfigParser configParser = new ConfigParser(serviceLocator);
    // I don't use the GlassFish document here as I don't need persistence
    final DomDocument doc = new DomDocument<GlassFishConfigBean>(serviceLocator) {

        @Override
        public Dom make(final ServiceLocator serviceLocator, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
            return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
        }
    };
    // the solution is to put the loop into the apply method...  But it would be some fine amount of work
    for (final ConfigBeanDefaultValue configBeanDefaultValue : values) {
        final ConfigBeanProxy parent = configModularityUtils.getOwningObject(configBeanDefaultValue.getLocation());
        if (parent == null)
            continue;
        ConfigurationPopulator populator = null;
        if (replaceSystemProperties)
            try {
                populator = new ConfigurationPopulator(configModularityUtils.replacePropertiesWithCurrentValue(configBeanDefaultValue.getXmlConfiguration(), configBeanDefaultValue), doc, parent);
            } catch (Exception e) {
                LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
            }
        else {
            // Check that parent is not null!
            populator = new ConfigurationPopulator(configBeanDefaultValue.getXmlConfiguration(), doc, parent);
        }
        populator.run(configParser);
        synchronized (configModularityUtils) {
            boolean oldValue = configModularityUtils.isIgnorePersisting();
            try {
                Class configBeanClass = configModularityUtils.getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
                final ConfigBeanProxy pr = doc.getRoot().createProxy(configBeanClass);
                configModularityUtils.setIgnorePersisting(true);
                ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {

                    public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
                        configModularityUtils.setConfigBean(pr, configBeanDefaultValue, param);
                        return param;
                    }
                }, parent);
            } catch (TransactionFailure e) {
                LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
            } finally {
                configModularityUtils.setIgnorePersisting(oldValue);
            }
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigParser(org.jvnet.hk2.config.ConfigParser) PropertyVetoException(java.beans.PropertyVetoException) DomDocument(org.jvnet.hk2.config.DomDocument) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PropertyVetoException(java.beans.PropertyVetoException) ConfigModel(org.jvnet.hk2.config.ConfigModel) ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) GlassFishConfigBean(org.glassfish.config.support.GlassFishConfigBean)

Example 9 with ConfigModel

use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.

the class GeneratorResource method get.

@GET
@Produces({ "text/plain" })
public String get(@QueryParam("outputDir") String outputDir) {
    if (outputDir == null) {
        outputDir = DEFAULT_OUTPUT_DIR;
    }
    String retVal = "Code Generation done at : " + outputDir;
    try {
        LocatorBridge locatorBridge = habitat.getService(LocatorBridge.class);
        Dom dom = Dom.unwrap(locatorBridge.getRemoteLocator().<Domain>getService(Domain.class));
        DomDocument document = dom.document;
        ConfigModel rootModel = dom.document.getRoot().model;
        ResourcesGenerator resourcesGenerator = new TextResourcesGenerator(outputDir, habitat);
        resourcesGenerator.generateSingle(rootModel, document);
        resourcesGenerator.endGeneration();
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
        retVal = "Exception encountered during generation process: " + ex.toString() + "\nPlease look at server.log for more information.";
    }
    return retVal;
}
Also used : Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel) ResourcesGenerator(org.glassfish.admin.rest.generator.ResourcesGenerator) TextResourcesGenerator(org.glassfish.admin.rest.generator.TextResourcesGenerator) TextResourcesGenerator(org.glassfish.admin.rest.generator.TextResourcesGenerator) LocatorBridge(org.glassfish.admin.rest.adapter.LocatorBridge) Domain(com.sun.enterprise.config.serverbeans.Domain) DomDocument(org.jvnet.hk2.config.DomDocument) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with ConfigModel

use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.

the class StatusGenerator method getPlain.

@GET
@Produces({ "text/plain" })
public String getPlain() {
    // status.append("Status of Command usage\n");
    try {
        Domain entity = serviceLocator.getService(Domain.class);
        Dom dom = Dom.unwrap(entity);
        DomDocument document = dom.document;
        ConfigModel rootModel = dom.document.getRoot().model;
        ResourcesGenerator resourcesGenerator = new NOOPResourcesGenerator(serviceLocator);
        resourcesGenerator.generateSingle(rootModel, document);
        resourcesGenerator.endGeneration();
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    // retVal = "Exception encountered during generation process: " + ex.toString() + "\nPlease look at server.log for more information.";
    }
    status.append("\n------------------------");
    status.append("All Commands used in REST Admin:\n");
    for (String ss : commandsUsed) {
        status.append(ss + "\n");
    }
    listOfCommands();
    for (String ss : commandsUsed) {
        allCommands.remove(ss);
    }
    status.append("\n------------------------");
    status.append("Missing Commands not used in REST Admin:\n");
    for (String ss : allCommands) {
        if (hasTargetParam(ss)) {
            status.append(ss + "          has a target param " + "\n");
        } else {
            status.append(ss + "\n");
        }
    }
    status.append("\n------------------------");
    status.append("REST-REDIRECT Commands defined on ConfigBeans:\n");
    for (String ss : restRedirectCommands) {
        status.append(ss + "\n");
    }
    status.append("\n------------------------");
    status.append("Commands to Resources Mapping Usage in REST Admin:\n");
    for (String ss : commandsToResources.keySet()) {
        if (hasTargetParam(ss)) {
            status.append(ss + "   :::target:::   " + commandsToResources.get(ss) + "\n");
        } else {
            status.append(ss + "      :::      " + commandsToResources.get(ss) + "\n");
        }
    }
    status.append("\n------------------------");
    status.append("Resources with Delete Commands in REST Admin (not counting RESTREDIRECT:\n");
    for (String ss : resourcesToDeleteCommands.keySet()) {
        status.append(ss + "      :::      " + resourcesToDeleteCommands.get(ss) + "\n");
    }
    FileOutputStream f = null;
    try {
        f = new FileOutputStream(System.getProperty("user.home") + "/GlassFishI18NData.properties");
        propsI18N.store(f, "");
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    } finally {
        if (f != null) {
            try {
                f.close();
            } catch (IOException ex) {
                RestLogging.restLogger.log(Level.SEVERE, null, ex);
            }
        }
    }
    return status.toString();
}
Also used : Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel) FileOutputStream(java.io.FileOutputStream) ResourcesGenerator(org.glassfish.admin.rest.generator.ResourcesGenerator) IOException(java.io.IOException) Domain(com.sun.enterprise.config.serverbeans.Domain) IOException(java.io.IOException) MultiException(org.glassfish.hk2.api.MultiException) DomDocument(org.jvnet.hk2.config.DomDocument) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ConfigModel (org.jvnet.hk2.config.ConfigModel)20 DomDocument (org.jvnet.hk2.config.DomDocument)8 MultiException (org.glassfish.hk2.api.MultiException)6 Dom (org.jvnet.hk2.config.Dom)6 Domain (com.sun.enterprise.config.serverbeans.Domain)5 Method (java.lang.reflect.Method)5 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 ResourcesGenerator (org.glassfish.admin.rest.generator.ResourcesGenerator)3 GlassFishConfigBean (org.glassfish.config.support.GlassFishConfigBean)3 Attribute (org.jvnet.hk2.config.Attribute)3 PropertyVetoException (java.beans.PropertyVetoException)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 MethodMetaData (org.glassfish.admin.rest.provider.MethodMetaData)2