Search in sources :

Example 36 with ConfigBeanProxy

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

the class ConfigInstanceListener method lifecycleEvent.

/* (non-Javadoc)
     * @see org.glassfish.hk2.api.InstanceLifecycleListener#lifecycleEvent(org.glassfish.hk2.api.InstanceLifecycleEvent)
     */
@Override
public void lifecycleEvent(InstanceLifecycleEvent lifecycleEvent) {
    if (!lifecycleEvent.getEventType().equals(InstanceLifecycleEventType.POST_PRODUCTION)) {
        return;
    }
    Map<Injectee, Object> injectees = lifecycleEvent.getKnownInjectees();
    if (injectees == null)
        return;
    ConfigListener listener = (ConfigListener) lifecycleEvent.getLifecycleObject();
    for (Object injectee : injectees.values()) {
        if (!(injectee instanceof ConfigBeanProxy))
            continue;
        ConfigBeanProxy configBeanProxy = (ConfigBeanProxy) injectee;
        Object impl = ConfigSupport.getImpl(configBeanProxy);
        if (!(impl instanceof ObservableBean))
            continue;
        ObservableBean ob = (ObservableBean) impl;
        ob.addListener(listener);
    }
}
Also used : Injectee(org.glassfish.hk2.api.Injectee) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigListener(org.jvnet.hk2.config.ConfigListener) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Example 37 with ConfigBeanProxy

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

the class CommandSecurityChecker method resourceNameFromRestEndpoint.

private static String resourceNameFromRestEndpoint(Class<? extends ConfigBeanProxy> c, final String path, final ServiceLocator locator) {
    ConfigBeanProxy b = locator.getService(c);
    String name = (b != null ? AccessRequired.Util.resourceNameFromConfigBeanProxy(b) : "?");
    if (path != null) {
        name += '/' + path;
    }
    return name;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy)

Example 38 with ConfigBeanProxy

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

the class DomainXmlVerifier method checkDuplicate.

private void checkDuplicate(Collection<? extends Dom> beans) {
    if (beans == null || beans.size() <= 1) {
        return;
    }
    WeakHashMap keyBeanMap = new WeakHashMap();
    ArrayList<String> keys = new ArrayList<String>(beans.size());
    for (Dom b : beans) {
        String key = b.getKey();
        keyBeanMap.put(key, b);
        keys.add(key);
    }
    WeakHashMap<String, Class<ConfigBeanProxy>> errorKeyBeanMap = new WeakHashMap<String, Class<ConfigBeanProxy>>();
    String[] strKeys = keys.toArray(new String[beans.size()]);
    for (int i = 0; i < strKeys.length; i++) {
        boolean foundDuplicate = false;
        for (int j = i + 1; j < strKeys.length; j++) {
            // we have a duplicate. So output that error
            if ((strKeys[i].equals(strKeys[j]))) {
                foundDuplicate = true;
                errorKeyBeanMap.put(strKeys[i], ((Dom) keyBeanMap.get(strKeys[i])).getProxyType());
                error = true;
                break;
            }
        }
    }
    for (Map.Entry e : errorKeyBeanMap.entrySet()) {
        Result result = new Result(strings.get("VerifyDupKey", e.getKey(), e.getValue()));
        output(result);
    }
}
Also used : Dom(org.jvnet.hk2.config.Dom) ArrayList(java.util.ArrayList) Result(com.sun.enterprise.util.Result) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) WeakHashMap(java.util.WeakHashMap)

Example 39 with ConfigBeanProxy

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

the class TemplateListOfResource method getPostCommand.

/**
 * allows for remote files to be put in a tmp area and we pass the
 * local location of this file to the corresponding command instead of the content of the file
 * * Yu need to add  enctype="multipart/form-data" in the form
 * for ex:  <form action="http://localhost:4848/management/domain/applications/application" method="post" enctype="multipart/form-data">
 * then any param of type="file" will be uploaded, stored locally and the param will use the local location
 * on the server side (ie. just the path)
 */
public String getPostCommand() {
    ConfigModel.Property p = parent.model.getElement(tagName);
    if (p == null) {
        // "*"
        ConfigModel.Property childElement = parent.model.getElement("*");
        if (childElement != null) {
            ConfigModel.Node node = (ConfigModel.Node) childElement;
            ConfigModel childModel = node.getModel();
            List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, parent.document);
            for (ConfigModel subChildConfigModel : subChildConfigModels) {
                if (subChildConfigModel.getTagName().equals(tagName)) {
                    return ResourceUtil.getCommand(RestRedirect.OpType.POST, subChildConfigModel);
                }
            }
        }
    } else {
        ConfigModel.Node n = (ConfigModel.Node) p;
        String command = ResourceUtil.getCommand(RestRedirect.OpType.POST, n.getModel());
        if (command != null) {
            return command;
        }
        // last  possible case...the @Create annotation on a parent method
        Class<? extends ConfigBeanProxy> cbp = null;
        try {
            cbp = (Class<? extends ConfigBeanProxy>) parent.model.classLoaderHolder.loadClass(parent.model.targetTypeName);
        } catch (MultiException e) {
            // 
            return null;
        }
        Create create = null;
        for (Method m : cbp.getMethods()) {
            ConfigModel.Property pp = parent.model.toProperty(m);
            if ((pp != null) && (pp.xmlName.equals(tagName)) && (m.isAnnotationPresent(Create.class))) {
                create = m.getAnnotation(Create.class);
                break;
            }
        }
        if (create != null) {
            return create.value();
        }
    }
    return null;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) Create(org.glassfish.config.support.Create) Method(java.lang.reflect.Method) MultiException(org.glassfish.hk2.api.MultiException)

Example 40 with ConfigBeanProxy

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

the class TemplateRestResource method getDeleteCommand.

protected String getDeleteCommand() {
    if (entity == null) {
        return null;
    }
    String result = ResourceUtil.getCommand(RestRedirect.OpType.DELETE, getEntity().model);
    if ((result == null) && (entity.parent() != null)) {
        // trying @Delete annotation that as a generic CRUD delete command, possibly...
        Class<? extends ConfigBeanProxy> cbp = null;
        try {
            cbp = (Class<? extends ConfigBeanProxy>) entity.parent().model.classLoaderHolder.loadClass(entity.parent().model.targetTypeName);
        } catch (MultiException e) {
            // 
            return null;
        }
        Delete del = null;
        for (Method m : cbp.getMethods()) {
            ConfigModel.Property pp = entity.parent().model.toProperty(m);
            if ((pp != null) && (pp.xmlName.equals(tagName)) && m.isAnnotationPresent(Delete.class)) {
                del = m.getAnnotation(Delete.class);
                break;
            }
        }
        if (del != null) {
            return del.value();
        }
    }
    return result;
}
Also used : Delete(org.glassfish.config.support.Delete) ConfigModel(org.jvnet.hk2.config.ConfigModel) Method(java.lang.reflect.Method) MultiException(org.glassfish.hk2.api.MultiException)

Aggregations

ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)41 PropertyVetoException (java.beans.PropertyVetoException)21 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)14 Method (java.lang.reflect.Method)11 ArrayList (java.util.ArrayList)11 ConfigCode (org.jvnet.hk2.config.ConfigCode)10 Config (com.sun.enterprise.config.serverbeans.Config)8 Server (com.sun.enterprise.config.serverbeans.Server)6 IOException (java.io.IOException)6 List (java.util.List)6 ActionReport (org.glassfish.api.ActionReport)6 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)6 Protocol (org.glassfish.grizzly.config.dom.Protocol)6 MultiException (org.glassfish.hk2.api.MultiException)6 ConfigModel (org.jvnet.hk2.config.ConfigModel)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 ConfigBean (org.jvnet.hk2.config.ConfigBean)5 Property (org.jvnet.hk2.config.types.Property)5