Search in sources :

Example 11 with ConfigModel

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

the class TemplateListOfResource method getElementTypeByName.

public static Class<? extends ConfigBeanProxy> getElementTypeByName(Dom parentDom, String elementName) throws ClassNotFoundException {
    DomDocument document = parentDom.document;
    ConfigModel.Property a = parentDom.model.getElement(elementName);
    if (a != null) {
        if (a.isLeaf()) {
            // : I am not too sure, but that should be a String @Element
            return null;
        } else {
            ConfigModel childModel = ((ConfigModel.Node) a).getModel();
            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;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 12 with ConfigModel

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

the class ResourceUtil method getMethodMetaData2.

public static MethodMetaData getMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType) {
    MethodMetaData methodMetaData = new MethodMetaData();
    List<Class<?>> interfaces = new ArrayList<Class<?>>();
    Map<String, ParameterMetaData> params = new HashMap<String, ParameterMetaData>();
    try {
        Class<? extends ConfigBeanProxy> configBeanProxy = (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
        getInterfaces(configBeanProxy, interfaces);
        Set<String> attributeNames = childModel.getAttributeNames();
        for (String attributeName : attributeNames) {
            String methodName = ResourceUtil.getAttributeMethodName(attributeName);
            // camelCase the attributeName before passing out
            attributeName = Util.eleminateHypen(attributeName);
            ParameterMetaData parameterMetaData = params.get(attributeName);
            if (parameterMetaData == null) {
                parameterMetaData = new ParameterMetaData();
                params.put(attributeName, parameterMetaData);
            }
            // Check parent interfaces
            for (int i = interfaces.size() - 1; i >= 0; i--) {
                Class<?> intf = interfaces.get(i);
                try {
                    Method method = intf.getMethod(methodName);
                    Attribute attribute = method.getAnnotation(Attribute.class);
                    if (attribute != null) {
                        ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
                        copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
                        copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
                        copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
                        copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
                    }
                } catch (NoSuchMethodException e) {
                }
            }
            // Check ConfigBean
            try {
                Method method = configBeanProxy.getMethod(methodName);
                Attribute attribute = method.getAnnotation(Attribute.class);
                if (attribute != null) {
                    ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
                    copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
                    copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
                    copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
                    copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
                }
            } catch (NoSuchMethodException e) {
            }
            methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
        }
    } catch (MultiException cnfe) {
        throw new RuntimeException(cnfe);
    }
    return methodMetaData;
}
Also used : HashMap(java.util.HashMap) Attribute(org.jvnet.hk2.config.Attribute) ArrayList(java.util.ArrayList) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) Method(java.lang.reflect.Method) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) MultiException(org.glassfish.hk2.api.MultiException) ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Example 13 with ConfigModel

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

the class ResourceUtil method getMethodMetaData.

/**
 * Constructs and returns the resource method meta-data. This method is
 * called to get meta-data in case of update method (POST).
 *
 * @param configBeanModel the config bean associated with the resource.
 * @return MethodMetaData the meta-data store for the resource method.
 */
public static MethodMetaData getMethodMetaData(ConfigModel configBeanModel) {
    MethodMetaData methodMetaData = new MethodMetaData();
    Class<? extends ConfigBeanProxy> configBeanProxy = null;
    try {
        configBeanProxy = (Class<? extends ConfigBeanProxy>) configBeanModel.classLoaderHolder.loadClass(configBeanModel.targetTypeName);
        Set<String> attributeNames = configBeanModel.getAttributeNames();
        for (String attributeName : attributeNames) {
            String methodName = getAttributeMethodName(attributeName);
            Method method = null;
            try {
                method = configBeanProxy.getMethod(methodName);
            } catch (NoSuchMethodException e) {
                // Method not found, so let's try a brute force method if the method
                // can't be found via the method above.  For example: for
                // Ssl.getSSLInactivityTimeout(), we calculate getSslInactivityTimeout,
                // which doesn't match due to case.
                String booleanMethodName = getAttributeBooleanMethodName(attributeName);
                for (Method m : configBeanProxy.getMethods()) {
                    if (m.getName().equalsIgnoreCase(methodName) || m.getName().equalsIgnoreCase(booleanMethodName)) {
                        method = m;
                    }
                }
            }
            Attribute attribute = method.getAnnotation(Attribute.class);
            if (attribute != null) {
                ParameterMetaData parameterMetaData = getParameterMetaData(attribute);
                if (method.getAnnotation(Deprecated.class) != null) {
                    parameterMetaData.putAttribute(Constants.DEPRECATED, "true");
                }
                // camelCase the attributeName before passing out
                attributeName = eleminateHypen(attributeName);
                methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
            }
        }
    } catch (MultiException e) {
        e.printStackTrace();
    }
    return methodMetaData;
}
Also used : Attribute(org.jvnet.hk2.config.Attribute) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) Method(java.lang.reflect.Method) MultiException(org.glassfish.hk2.api.MultiException) ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Example 14 with ConfigModel

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

the class ResourceUtil method getResourceLinks.

public static Map<String, String> getResourceLinks(Dom dom, UriInfo uriInfo, boolean canShowDeprecated) {
    Map<String, String> links = new TreeMap<String, String>();
    for (String elementName : dom.model.getElementNames()) {
        // for each element
        if (elementName.equals("*")) {
            ConfigModel.Node node = (ConfigModel.Node) dom.model.getElement(elementName);
            ConfigModel childModel = node.getModel();
            List<ConfigModel> lcm = getRealChildConfigModels(childModel, dom.document);
            Collections.sort(lcm, new ConfigModelComparator());
            if (lcm != null) {
                for (ConfigModel cmodel : lcm) {
                    if ((!isDeprecated(cmodel) || canShowDeprecated)) {
                        links.put(cmodel.getTagName(), ProviderUtil.getElementLink(uriInfo, cmodel.getTagName()));
                    }
                }
            }
        } else {
            ConfigModel.Property childElement = dom.model.getElement(elementName);
            boolean deprec = false;
            if (childElement instanceof ConfigModel.Node) {
                ConfigModel.Node node = (ConfigModel.Node) childElement;
                deprec = isDeprecated(node.getModel());
            }
            for (String annotation : childElement.getAnnotations()) {
                if (annotation.equals(Deprecated.class.getName())) {
                    deprec = true;
                }
            }
            if ((!deprec || canShowDeprecated)) {
                links.put(elementName, ProviderUtil.getElementLink(uriInfo, elementName));
            }
        }
    }
    String beanName = getUnqualifiedTypeName(dom.model.targetTypeName);
    for (CommandResourceMetaData cmd : CommandResourceMetaData.getCustomResourceMapping(beanName)) {
        links.put(cmd.resourcePath, ProviderUtil.getElementLink(uriInfo, cmd.resourcePath));
    }
    return links;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) CommandResourceMetaData(org.glassfish.admin.rest.generator.CommandResourceMetaData) TreeMap(java.util.TreeMap)

Example 15 with ConfigModel

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

the class SimpleDocument method make.

@Override
public ConfigBean make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, ConfigBean dom, ConfigModel configModel) {
    ConfigBean configBean = new ConfigBean(habitat, this, dom, configModel, xmlStreamReader);
    configBean.addInterceptor(Object.class, new OnDeleteCascade());
    return configBean;
}
Also used : OnDeleteCascade(org.jvnet.hk2.config.OnDeleteCascade) ConfigBean(org.jvnet.hk2.config.ConfigBean)

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