Search in sources :

Example 16 with ConfigBeanProxy

use of org.jvnet.hk2.config.ConfigBeanProxy 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 17 with ConfigBeanProxy

use of org.jvnet.hk2.config.ConfigBeanProxy 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 18 with ConfigBeanProxy

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

the class ConfigurationPopulator method run.

public void run(ConfigParser parser) {
    try {
        InputStream is = new ByteArrayInputStream(xmlContent.getBytes());
        XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(is, "utf-8");
        parser.parse(reader, doc, Dom.unwrap((ConfigBeanProxy) parent));
    } catch (XMLStreamException e) {
        LOG.log(Level.SEVERE, ConfigApiLoggerInfo.DEFAULT_CFG_READ_FAILED, e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 19 with ConfigBeanProxy

use of org.jvnet.hk2.config.ConfigBeanProxy 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 20 with ConfigBeanProxy

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

the class UpdateResourceRef method execute.

/**
 * Execution method for updating the configuration of a ResourceRef. Will be
 * replicated if the target is a cluster.
 *
 * @param context context for the command.
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    // Make a list of all ResourceRefs that need to change
    List<ResourceRef> resourceRefsToChange = new ArrayList<>();
    // Add the ResourceRef from a named server if the target is a server
    Server server = domain.getServerNamed(target);
    // if the target is a server
    if (server != null) {
        ResourceRef serverResourceRef = server.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (serverResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(serverResourceRef);
    }
    // Add the ResourceRef from a named config if the target is a config
    Config config = domain.getConfigNamed(target);
    // if the target is a config
    if (config != null) {
        ResourceRef configResourceRef = config.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (configResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(configResourceRef);
    }
    // Add the ResourceRefs from a named cluster if the target is a cluster
    Cluster cluster = domain.getClusterNamed(target);
    // if the target is a cluster
    if (cluster != null) {
        ResourceRef clusterResourceRef = cluster.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (clusterResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(clusterResourceRef);
        for (Server instance : cluster.getInstances()) {
            ResourceRef instanceResourceRef = instance.getResourceRef(name);
            // if the server in the cluster contains the ResourceRef
            if (instanceResourceRef != null) {
                resourceRefsToChange.add(instanceResourceRef);
            }
        }
    }
    // Add the ResourceRefs from a named Deployment Group if the target is a Deployment Group
    DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
    if (dg != null) {
        ResourceRef ref = dg.getResourceRef(name);
        if (ref == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(ref);
        for (Server instance : dg.getInstances()) {
            ResourceRef instanceResourceRef = instance.getResourceRef(name);
            // if the server in the dg contains the ResourceRef
            if (instanceResourceRef != null) {
                resourceRefsToChange.add(instanceResourceRef);
            }
        }
    }
    // Apply the configuration to the listed ResourceRefs
    try {
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
                for (ConfigBeanProxy proxy : params) {
                    if (proxy instanceof ResourceRef) {
                        ResourceRef resourceRefProxy = (ResourceRef) proxy;
                        if (enabled != null) {
                            resourceRefProxy.setEnabled(enabled.toString());
                        }
                    }
                }
                report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return true;
            }
        }, resourceRefsToChange.toArray(new ResourceRef[] {}));
    } catch (TransactionFailure ex) {
        report.failure(logger, ex.getLocalizedMessage());
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) PropertyVetoException(java.beans.PropertyVetoException) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

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