Search in sources :

Example 1 with TYPE

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

the class ConfigDomainParser method parseIDEntry.

private void parseIDEntry(ProviderConfig pConfig, Map<String, GFServerConfigProvider.InterceptEntry> newConfig, String intercept) throws IOException {
    String id = pConfig.getProviderId();
    String type = pConfig.getProviderType();
    String moduleClass = pConfig.getClassName();
    MessagePolicy requestPolicy = parsePolicy((RequestPolicy) pConfig.getRequestPolicy());
    MessagePolicy responsePolicy = parsePolicy((ResponsePolicy) pConfig.getResponsePolicy());
    // get the module options
    Map<String, Object> options = new HashMap<>();
    List<Property> pList = pConfig.getProperty();
    if (pList != null) {
        Iterator<Property> pit = pList.iterator();
        while (pit.hasNext()) {
            Property property = pit.next();
            try {
                options.put(property.getName(), PropertyExpander.expand(property.getValue(), false));
            } catch (ExpandException ee) {
                // interpret value itself.
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "jmac.unexpandedproperty");
                }
                options.put(property.getName(), property.getValue());
            }
        }
    }
    if (_logger.isLoggable(FINE)) {
        _logger.fine("ID Entry: " + "\n    module class: " + moduleClass + "\n    id: " + id + "\n    type: " + type + "\n    request policy: " + requestPolicy + "\n    response policy: " + responsePolicy + "\n    options: " + options);
    }
    // create ID entry
    GFServerConfigProvider.IDEntry idEntry = new GFServerConfigProvider.IDEntry(type, moduleClass, requestPolicy, responsePolicy, options);
    GFServerConfigProvider.InterceptEntry intEntry = newConfig.get(intercept);
    if (intEntry == null) {
        throw new IOException("intercept entry for " + intercept + " must be specified before ID entries");
    }
    if (intEntry.idMap == null) {
        intEntry.idMap = new HashMap<>();
    }
    // map id to Intercept
    intEntry.idMap.put(id, idEntry);
}
Also used : HashMap(java.util.HashMap) ExpandException(sun.security.util.PropertyExpander.ExpandException) IOException(java.io.IOException) AuthMessagePolicy(com.sun.enterprise.security.jmac.AuthMessagePolicy) MessagePolicy(javax.security.auth.message.MessagePolicy) Property(org.jvnet.hk2.config.types.Property)

Example 2 with TYPE

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

the class ConfigModularityUtils method setConfigBean.

public <T extends ConfigBeanProxy> T setConfigBean(T finalConfigBean, ConfigBeanDefaultValue configBeanDefaultValue, ConfigBeanProxy parent) {
    Class owningClassForLocation = getOwningClassForLocation(configBeanDefaultValue.getLocation());
    Class configBeanClass = getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
    try {
        ConfigBeanProxy configBeanInstance = null;
        if (getNameForConfigBean(finalConfigBean, configBeanClass) == null) {
            List<ConfigBeanProxy> extensions = getExtensions(parent);
            for (ConfigBeanProxy extension : extensions) {
                try {
                    configBeanInstance = (ConfigBeanProxy) configBeanClass.cast(extension);
                    break;
                } catch (Exception e) {
                // ignore, not the right type.
                }
            }
            if (!configBeanDefaultValue.replaceCurrentIfExists() || !stackPositionHigher(finalConfigBean, configBeanInstance)) {
                if (configBeanInstance != null)
                    return (T) configBeanInstance;
            }
            if (configBeanInstance != null) {
                extensions.remove(configBeanInstance);
            }
        }
    } catch (InvocationTargetException e) {
        LOG.log(Level.INFO, cannotSetConfigBean, e);
    } catch (IllegalAccessException e) {
        LOG.log(Level.INFO, cannotSetConfigBean, e);
    }
    Method m = getMatchingSetterMethod(owningClassForLocation, configBeanClass);
    if (m != null) {
        try {
            if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
                applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
            }
            m.invoke(parent, finalConfigBean);
        } catch (Exception e) {
            LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
        }
        return finalConfigBean;
    }
    m = findSuitableCollectionGetter(owningClassForLocation, configBeanClass);
    if (m != null) {
        try {
            Collection col = (Collection) m.invoke(parent);
            String name = getNameForConfigBean(finalConfigBean, configBeanClass);
            ConfigBeanProxy itemToRemove = getNamedConfigBeanFromCollection(col, name, configBeanClass);
            if (configBeanDefaultValue.replaceCurrentIfExists()) {
                try {
                    if (itemToRemove != null) {
                        if (stackPositionHigher(finalConfigBean, itemToRemove)) {
                            col.remove(itemToRemove);
                        }
                    }
                } catch (Exception ex) {
                    LogHelper.log(LOG, Level.INFO, cannotRemoveConfigBean, ex, finalConfigBean.getClass().getName());
                }
            }
            if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
                applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
            }
            if (itemToRemove != null && !configBeanDefaultValue.replaceCurrentIfExists()) {
                // Check for duplication here.
                if (((ConfigView) Proxy.getInvocationHandler(itemToRemove)).getProxyType().isAssignableFrom(configBeanClass)) {
                    return finalConfigBean;
                }
            }
            col.add(finalConfigBean);
            return finalConfigBean;
        } catch (Exception e) {
            LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
        }
    }
    return null;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Collection(java.util.Collection) Method(java.lang.reflect.Method) HasCustomizationTokens(com.sun.enterprise.config.modularity.annotation.HasCustomizationTokens) PropertyVetoException(java.beans.PropertyVetoException) XMLStreamException(javax.xml.stream.XMLStreamException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with TYPE

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

the class ExtensionPatternInvocationImpl method handleExtension.

@Override
public ConfigBeanProxy handleExtension(Object owner, Class ownerType, Object[] params) {
    if (((Class) params[0]).getName().equals("com.sun.enterprise.config.serverbeans.SystemProperty"))
        return null;
    ConfigBeanProxy configExtension = null;
    List<ConfigBeanProxy> extensions = configModularityUtils.getExtensions(((ConfigBean) owner).createProxy(ownerType));
    for (ConfigBeanProxy extension : extensions) {
        try {
            configExtension = (ConfigBeanProxy) ((Class) params[0]).cast(extension);
            return configExtension;
        } catch (Exception e) {
        // ignore, not the right type.
        }
    }
    try {
        ConfigBeanProxy pr = ((ConfigBean) owner).createProxy(ownerType);
        ConfigBeanProxy returnValue = moduleConfigurationLoader.createConfigBeanForType((Class) params[0], pr);
        return returnValue;
    } catch (TransactionFailure transactionFailure) {
        LogHelper.log(LOG, Level.INFO, "Cannot get extension type {0} for {1}.", transactionFailure, new Object[] { owner.getClass().getName(), ownerType.getName() });
        return null;
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigBean(org.jvnet.hk2.config.ConfigBean)

Example 4 with TYPE

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

the class ActionReportResultHtmlProvider method getContent.

@Override
public String getContent(ActionReportResult proxy) {
    RestActionReporter ar = (RestActionReporter) proxy.getActionReport();
    StringBuilder result = new StringBuilder(ProviderUtil.getHtmlHeader(getBaseUri()));
    final String message = ResourceUtil.encodeString(ar.getCombinedMessage());
    if (!message.isEmpty()) {
        result.append("<h3>").append(message).append(HEADING_END);
    }
    if (proxy.isError()) {
        result.append("<h2>").append(ar.getActionDescription()).append(" Error:</h2>").append(proxy.getErrorMessage());
    } else {
        final Map<String, String> childResources = (Map<String, String>) ar.getExtraProperties().get("childResources");
        final List<Map<String, String>> commands = (List<Map<String, String>>) ar.getExtraProperties().get("commands");
        final MethodMetaData postMetaData = proxy.getMetaData().getMethodMetaData("POST");
        final MethodMetaData deleteMetaData = proxy.getMetaData().getMethodMetaData(DELETE);
        final MethodMetaData getMetaData = proxy.getMetaData().getMethodMetaData("GET");
        final ConfigBean entity = proxy.getEntity();
        if ((proxy.getCommandDisplayName() != null) && (getMetaData != null)) {
            // for commands, we want the output of the command before the form
            if (entity == null) {
                // show extra properties only for non entity pages
                result.append(processReport(ar));
            }
        }
        if ((postMetaData != null) && (entity == null)) {
            String postCommand = getHtmlRespresentationsForCommand(postMetaData, "POST", (proxy.getCommandDisplayName() == null) ? "Create" : proxy.getCommandDisplayName(), uriInfo.get());
            result.append(getHtmlForComponent(postCommand, "Create " + ar.getActionDescription(), ""));
        }
        if ((deleteMetaData != null) && (entity == null)) {
            String deleteCommand = getHtmlRespresentationsForCommand(deleteMetaData, DELETE, (proxy.getCommandDisplayName() == null) ? "Delete" : proxy.getCommandDisplayName(), uriInfo.get());
            result.append(getHtmlForComponent(deleteCommand, "Delete " + ar.getActionDescription(), ""));
        }
        if ((getMetaData != null) && (entity == null) && (proxy.getCommandDisplayName() != null)) {
            String getCommand = getHtmlRespresentationsForCommand(getMetaData, "GET", (proxy.getCommandDisplayName() == null) ? "Get" : proxy.getCommandDisplayName(), uriInfo.get());
            result.append(getHtmlForComponent(getCommand, "Get " + ar.getActionDescription(), ""));
        }
        if (entity != null) {
            String attributes = ProviderUtil.getHtmlRepresentationForAttributes(proxy.getEntity(), uriInfo.get());
            result.append(ProviderUtil.getHtmlForComponent(attributes, ar.getActionDescription() + " Attributes", ""));
            String deleteCommand = ProviderUtil.getHtmlRespresentationsForCommand(proxy.getMetaData().getMethodMetaData(DELETE), DELETE, (proxy.getCommandDisplayName() == null) ? "Delete" : proxy.getCommandDisplayName(), uriInfo.get());
            result.append(ProviderUtil.getHtmlForComponent(deleteCommand, "Delete " + entity.model.getTagName(), ""));
        } else if (proxy.getLeafContent() != null) {
            // it is a single leaf @Element
            String content = "<form action=\"" + uriInfo.get().getAbsolutePath().toString() + "\" method=\"post\">" + "<dl><dt>" + "<label for=\"" + proxy.getLeafContent().name + "\">" + proxy.getLeafContent().name + ":&nbsp;</label>" + "</dt><dd>" + "<input name=\"" + proxy.getLeafContent().name + "\" value =\"" + proxy.getLeafContent().value + "\" type=\"text\" >" + "</dd><dt class=\"button\"></dt><dd class=\"button\"><input value=\"Update\" type=\"submit\"></dd></dl>" + "</form><br><hr class=\"separator\"/";
            result.append(content);
        } else {
            // This is a monitoring result!!!
            final Map vals = (Map) ar.getExtraProperties().get("entity");
            if ((vals != null) && (!vals.isEmpty())) {
                result.append("<ul>");
                for (Map.Entry entry : (Set<Map.Entry>) vals.entrySet()) {
                    Object object = entry.getValue();
                    if (object == null) {
                    // do nothing
                    } else if (object instanceof Collection) {
                        if (!((Collection) object).isEmpty()) {
                            Collection c = ((Collection) object);
                            Iterator i = c.iterator();
                            result.append("<li>").append(entry.getKey());
                            result.append("<ul>");
                            while (i.hasNext()) {
                                result.append("<li>").append(getHtmlRepresentation(i.next())).append(LIST_ITEM_END);
                            }
                            result.append(LIST_END);
                            result.append(LIST_ITEM_END);
                        }
                    } else if (object instanceof Map) {
                        if (!((Map) object).isEmpty()) {
                            Map m = (Map) object;
                            if (vals.size() != 1) {
                                // add a link if more than 1 child
                                result.append("<li>").append(ANCHOR_OPEN).append(uriInfo.get().getAbsolutePath().toString()).append("/").append(entry.getKey()).append("\">").append(entry.getKey()).append("</a>");
                            } else {
                                result.append("<li>").append(entry.getKey());
                            }
                            result.append("<ul>");
                            for (Map.Entry anEntry : (Set<Map.Entry>) m.entrySet()) {
                                final String htmlRepresentation = getHtmlRepresentation(anEntry.getValue());
                                if (htmlRepresentation != null) {
                                    result.append("<li>").append(anEntry.getKey()).append(" : ").append(htmlRepresentation).append(LIST_ITEM_END);
                                }
                            }
                            result.append(LIST_END);
                            result.append(LIST_ITEM_END);
                        }
                    } else {
                        result.append("<li>").append(entry.getKey()).append(" : ").append(object.toString()).append(LIST_ITEM_END);
                    }
                }
                result.append(LIST_END);
            } else {
                // no values to show... give an hint
                if ((childResources == null) || (childResources.isEmpty())) {
                    if ((uriInfo != null) && (uriInfo.get().getPath().equalsIgnoreCase("domain"))) {
                        result.append(getHint(uriInfo.get(), MediaType.TEXT_HTML));
                    }
                }
            }
        }
        if ((childResources != null) && (!childResources.isEmpty())) {
            String childResourceLinks = getResourcesLinks(childResources);
            result.append(ProviderUtil.getHtmlForComponent(childResourceLinks, "Child Resources", ""));
        }
        if ((commands != null) && (!commands.isEmpty())) {
            String commandLinks = getCommandLinks(commands);
            result.append(ProviderUtil.getHtmlForComponent(commandLinks, "Commands", ""));
        }
    }
    return result.append("</div></body></html>").toString();
}
Also used : ConfigBean(org.jvnet.hk2.config.ConfigBean) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) Map(java.util.Map)

Example 5 with TYPE

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

the class ConfigBeanJMXSupport method getTypeString.

public String getTypeString(final Class<? extends ConfigBeanProxy> intf) {
    String type = null;
    final Configured configuredAnnotation = intf.getAnnotation(Configured.class);
    if (configuredAnnotation != null && configuredAnnotation.name().length() != 0) {
        type = configuredAnnotation.name();
        if (type == null || type.length() == 0) {
            throw new IllegalArgumentException("ConfigBeanJMXSupport.getTypeString(): Malformed @Configured annotation on " + intf.getName());
        }
    } else {
        final Package pkg = intf.getPackage();
        String simple = intf.getName().substring(pkg.getName().length() + 1, intf.getName().length());
        type = Util.typeFromName(simple);
        if (type == null || type.length() == 0) {
            throw new IllegalArgumentException("ConfigBeanJMXSupport.getTypeString(): Malformed type generated from " + intf.getName());
        }
    }
    return type;
}
Also used : Configured(org.jvnet.hk2.config.Configured)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)15 Property (org.jvnet.hk2.config.types.Property)15 IOException (java.io.IOException)13 ActionReport (org.glassfish.api.ActionReport)13 PropertyVetoException (java.beans.PropertyVetoException)12 List (java.util.List)10 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)10 Method (java.lang.reflect.Method)9 HashMap (java.util.HashMap)9 Map (java.util.Map)7 Logger (java.util.logging.Logger)7 Service (org.jvnet.hk2.annotations.Service)7 ArrayList (java.util.ArrayList)6 Inject (javax.inject.Inject)6 MultiException (org.glassfish.hk2.api.MultiException)6 ConfigBean (org.jvnet.hk2.config.ConfigBean)6 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)4 Collection (java.util.Collection)4 DeploymentException (org.glassfish.deployment.common.DeploymentException)4