Search in sources :

Example 1 with ConfigModel

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

the class AllModelsImplementingTest method checkResources.

@Test
public void checkResources() throws ClassNotFoundException {
    ServiceLocator habitat = getHabitat();
    Resources resources = habitat.<Domain>getService(Domain.class).getResources();
    Dom dom = Dom.unwrap(resources);
    List<ConfigModel> models = dom.document.getAllModelsImplementing(Resource.class);
    for (ConfigModel model : models) {
        Logger.getAnonymousLogger().fine(model.targetTypeName);
    }
    assertTrue(models.size() > 0);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel) Resources(com.sun.enterprise.config.serverbeans.Resources) Domain(com.sun.enterprise.config.serverbeans.Domain) Test(org.junit.Test)

Example 2 with ConfigModel

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

the class ResourcesGeneratorBase method generateSingle.

/**
 * Generate REST resource for a single config model.
 */
@Override
public void generateSingle(ConfigModel model, DomDocument domDocument) {
    configModelVisited(model);
    // processRedirectsAnnotation(model); // TODO need to extract info from RestRedirect Annotations
    String serverConfigName = ResourceUtil.getUnqualifiedTypeName(model.targetTypeName);
    String beanName = getBeanName(serverConfigName);
    String className = getClassName(beanName);
    if (alreadyGenerated(className)) {
        return;
    }
    String baseClassName = "TemplateRestResource";
    String resourcePath = null;
    if (beanName.equals("Domain")) {
        baseClassName = "org.glassfish.admin.rest.resources.GlassFishDomainResource";
        resourcePath = "domain";
    }
    ClassWriter classWriter = getClassWriter(className, baseClassName, resourcePath);
    if (classWriter != null) {
        generateCommandResources(beanName, classWriter);
        generateGetDeleteCommandMethod(beanName, classWriter);
        generateCustomResourceMapping(beanName, classWriter);
        for (String elementName : model.getElementNames()) {
            ConfigModel.Property childElement = model.getElement(elementName);
            if (elementName.equals("*")) {
                ConfigModel.Node node = (ConfigModel.Node) childElement;
                ConfigModel childModel = node.getModel();
                List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, domDocument);
                for (ConfigModel subChildConfigModel : subChildConfigModels) {
                    if (ResourceUtil.isOnlyATag(childModel) || ResourceUtil.isOnlyATag(subChildConfigModel) || subChildConfigModel.getAttributeNames().isEmpty() || hasSingletonAnnotation(subChildConfigModel)) {
                        String childResourceClassName = getClassName(ResourceUtil.getUnqualifiedTypeName(subChildConfigModel.targetTypeName));
                        String childPath = subChildConfigModel.getTagName();
                        classWriter.createGetChildResource(childPath, childResourceClassName);
                        generateSingle(subChildConfigModel, domDocument);
                    } else {
                        processNonLeafChildConfigModel(subChildConfigModel, childElement, domDocument, classWriter);
                    }
                }
            } else if (childElement.isLeaf()) {
                if (childElement.isCollection()) {
                    // handle the CollectionLeaf config objects.
                    // JVM Options is an example of CollectionLeaf object.
                    String childResourceBeanName = getBeanName(elementName);
                    String childResourceClassName = getClassName(childResourceBeanName);
                    classWriter.createGetChildResource(elementName, childResourceClassName);
                    // create resource class
                    generateCollectionLeafResource(childResourceBeanName);
                } else {
                    String childResourceBeanName = getBeanName(elementName);
                    String childResourceClassName = getClassName(childResourceBeanName);
                    classWriter.createGetChildResource(elementName, childResourceClassName);
                    // create resource class
                    generateLeafResource(childResourceBeanName);
                }
            } else {
                // => !childElement.isLeaf()
                processNonLeafChildElement(elementName, childElement, domDocument, classWriter);
            }
        }
        classWriter.done();
    }
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel)

Example 3 with ConfigModel

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

the class ClientGenerator method processElements.

protected Set<String> processElements(ClientClassWriter writer, ConfigModel model) {
    Set<String> processed = new HashSet<String>();
    for (String elementName : model.getElementNames()) {
        if (processed.contains(elementName)) {
            continue;
        }
        processed.add(elementName);
        ConfigModel.Property childElement = model.getElement(elementName);
        if (elementName.equals("*")) {
            ConfigModel.Node node = (ConfigModel.Node) childElement;
            ConfigModel childModel = node.getModel();
            List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, document);
            for (ConfigModel subChildConfigModel : subChildConfigModels) {
                if (ResourceUtil.isOnlyATag(childModel)) {
                    String childResourceClassName = ResourceUtil.getUnqualifiedTypeName(subChildConfigModel.targetTypeName);
                    writer.createGetChildResource(subChildConfigModel, childResourceClassName, childResourceClassName);
                    generateSingle(subChildConfigModel);
                } else {
                    processNonLeafChildConfigModel(writer, subChildConfigModel, childElement);
                }
            }
        } else if (childElement.isLeaf()) {
            if (processed.contains(childElement.xmlName)) {
                continue;
            }
            processed.add(childElement.xmlName);
            if (childElement.isCollection()) {
                // generateCollectionLeafResource
                System.out.println("generateCollectionLeafResource for " + elementName + " off of " + model.getTagName());
                generateCollectionLeafResource(writer, childElement.xmlName);
            } else {
                System.out.println("generateLeafResource for " + elementName + " off of " + model.getTagName());
                // generateSingle(document.getModelByElementName(elementName));
                generateLeafResource(writer, childElement.xmlName);
            }
        } else {
            processNonLeafChildElement(writer, elementName, childElement);
        }
    }
    return processed;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) HashSet(java.util.HashSet)

Example 4 with ConfigModel

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

the class ClientGenerator method processAttributes.

protected void processAttributes(ClientClassWriter writer, ConfigModel model, Set<String> processed) {
    Class clazz = model.getProxyType();
    for (Method method : clazz.getMethods()) {
        String methodName = method.getName();
        Attribute a = method.getAnnotation(Attribute.class);
        Param p = method.getAnnotation(Param.class);
        if ((a != null) || (p != null)) {
            String type = "String";
            if (a != null) {
                type = a.dataType().getName();
            }
            if (methodName.startsWith("get") || methodName.startsWith("set")) {
                methodName = methodName.substring(3);
            }
            String fieldName = Util.lowerCaseFirstLetter(methodName);
            if (processed.contains(fieldName)) {
                continue;
            }
            processed.add(fieldName);
            writer.generateGettersAndSetters(type, methodName, fieldName);
        }
    }
}
Also used : Attribute(org.jvnet.hk2.config.Attribute) Param(org.glassfish.api.Param) Method(java.lang.reflect.Method)

Example 5 with ConfigModel

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

the class BaseProvider method getResourceLinks.

protected Map<String, String> getResourceLinks(Dom dom) {
    Map<String, String> links = new TreeMap<String, String>();
    Set<String> elementNames = dom.model.getElementNames();
    for (String elementName : elementNames) {
        // for each element
        if (elementName.equals("*")) {
            ConfigModel.Node node = (ConfigModel.Node) dom.model.getElement(elementName);
            ConfigModel childModel = node.getModel();
            List<ConfigModel> lcm = ResourceUtil.getRealChildConfigModels(childModel, dom.document);
            Collections.sort(lcm, new ConfigModelComparator());
            if (lcm != null) {
                Collections.sort(lcm, new ConfigModelComparator());
                for (ConfigModel cmodel : lcm) {
                    links.put(cmodel.getTagName(), ProviderUtil.getElementLink(uriInfo.get(), cmodel.getTagName()));
                }
            }
        } else {
            links.put(elementName, ProviderUtil.getElementLink(uriInfo.get(), elementName));
        }
    }
    return links;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) ConfigModelComparator(org.glassfish.admin.rest.utils.ConfigModelComparator) TreeMap(java.util.TreeMap)

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