Search in sources :

Example 46 with Dom

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

the class SystemPropertiesCliResource method getSystemProperties.

protected void getSystemProperties(Map<String, Map<String, String>> properties, Dom dom, boolean getDefaults) {
    List<Dom> sysprops;
    synchronized (dom) {
        sysprops = dom.nodeElements("system-property");
    }
    if ((sysprops != null) && (!sysprops.isEmpty())) {
        for (Dom sysprop : sysprops) {
            String name = sysprop.attribute("name");
            Map<String, String> currValue = properties.get(name);
            if (currValue == null) {
                currValue = new HashMap<String, String>();
                currValue.put("name", name);
                currValue.put(getDefaults ? "defaultValue" : "value", sysprop.attribute("value"));
                if (sysprop.attribute("description") != null) {
                    currValue.put("description", sysprop.attribute("description"));
                }
                properties.put(name, currValue);
            } else {
                // Only add a default value if there isn't one already
                if (currValue.get("defaultValue") == null) {
                    currValue.put("defaultValue", sysprop.attribute("value"));
                }
            }
        }
    }
    // Figure out how to recurse
    if (dom.getProxyType().equals(Server.class)) {
        // Clustered instance
        if (((Server) dom.createProxy()).getCluster() != null) {
            getSystemProperties(properties, getCluster(dom.parent().parent(), ((Server) dom.createProxy()).getCluster().getName()), true);
        } else {
            // Standalone instance or DAS
            getSystemProperties(properties, getConfig(dom.parent().parent(), dom.attribute("config-ref")), true);
        }
    } else if (dom.getProxyType().equals(Cluster.class)) {
        getSystemProperties(properties, getConfig(dom.parent().parent(), dom.attribute("config-ref")), true);
    }
}
Also used : Dom(org.jvnet.hk2.config.Dom) Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 47 with Dom

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

the class DefaultConfigParser method parseContainerConfig.

@Override
public <T extends Container> T parseContainerConfig(ServiceLocator habitat, final URL configuration, Class<T> configType) throws IOException {
    // I don't use the GlassFish document here as I don't need persistence
    final DomDocument doc = new DomDocument<GlassFishConfigBean>(habitat) {

        @Override
        public Dom make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
            // by default, people get the translated view.
            return new GlassFishConfigBean(habitat, this, dom, configModel, xmlStreamReader);
        }
    };
    // add the new container configuration to the server config
    final T container = doc.getRoot().createProxy(configType);
    try {
        ConfigSupport.apply(new SingleConfigCode<Config>() {

            @Override
            public Object run(Config config) throws PropertyVetoException, TransactionFailure {
                config.getContainers().add(container);
                return null;
            }
        }, config);
    } catch (TransactionFailure e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.exceptionAddContainer, e);
    }
    return container;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigModel(org.jvnet.hk2.config.ConfigModel) GlassFishConfigBean(org.glassfish.config.support.GlassFishConfigBean) Config(com.sun.enterprise.config.serverbeans.Config) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 48 with Dom

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

the class ContextRootCheckValidator method isValid.

@Override
public boolean isValid(Application app, ConstraintValidatorContext cvc) throws UnexpectedTypeException {
    if (app == null) {
        return true;
    }
    Dom dom = Dom.unwrap(app);
    ServiceLocator locator = dom.getHabitat();
    if (locator == null)
        return true;
    ConfigBeansUtilities cbu = locator.getService(ConfigBeansUtilities.class);
    if (cbu == null)
        return true;
    Domain domain = cbu.getDomain();
    String appName = app.getName();
    String contextRoot = app.getContextRoot();
    if (contextRoot != null && !contextRoot.startsWith("/")) {
        contextRoot = "/" + contextRoot;
    }
    boolean result = true;
    List<String> targets = domain.getAllReferencedTargetsForApplication(appName);
    for (String target : targets) {
        List<Server> servers = domain.getServersInTarget(target);
        for (Server server : servers) {
            ApplicationRef applicationRef = domain.getApplicationRefInServer(server.getName(), appName);
            if (applicationRef != null) {
                for (Application application : domain.getApplications().getApplications()) {
                    if (isSameApp(appName, application.getName())) {
                    // skip the check if the validation is for different versions of the same application
                    } else if ((application.getContextRoot() != null) && application.getContextRoot().equals(contextRoot)) {
                        String virtualServers = applicationRef.getVirtualServers();
                        List<String> vsList = Arrays.asList(virtualServers.split(","));
                        ApplicationRef thisAppRef = domain.getApplicationRefInServer(server.getName(), application.getName());
                        if (thisAppRef != null) {
                            virtualServers = thisAppRef.getVirtualServers();
                            List<String> thisVsList = Arrays.asList(virtualServers.split(","));
                            for (String vs : thisVsList) {
                                if (vsList.contains(vs)) {
                                    result = false;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Dom(org.jvnet.hk2.config.Dom) List(java.util.List)

Example 49 with Dom

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

the class ReferenceValidator method isValid.

@Override
public boolean isValid(ConfigBeanProxy config, ConstraintValidatorContext cvc) throws UnexpectedTypeException {
    if (config == null) {
        return true;
    }
    Dom dom = Dom.unwrap(config);
    if (rc.skipDuringCreation() && dom.getKey() == null) {
        // During creation the coresponding DOM is not fully loaded.
        return true;
    }
    Collection<RemoteKeyInfo> remoteKeys = findRemoteKeys(config);
    if (remoteKeys != null && !remoteKeys.isEmpty()) {
        ServiceLocator habitat = dom.getHabitat();
        boolean result = true;
        boolean disableGlobalMessage = true;
        for (RemoteKeyInfo remoteKeyInfo : remoteKeys) {
            if (remoteKeyInfo.method.getParameterTypes().length > 0) {
                throw new UnexpectedTypeException(localStrings.getLocalString("referenceValidator.not.getter", "The RemoteKey annotation must be on a getter method."));
            }
            try {
                Object value = remoteKeyInfo.method.invoke(config);
                if (value instanceof String) {
                    String key = (String) value;
                    ConfigBeanProxy component = habitat.getService(remoteKeyInfo.annotation.type(), key);
                    if (component == null) {
                        result = false;
                        if (remoteKeyInfo.annotation.message().isEmpty()) {
                            disableGlobalMessage = false;
                        } else {
                            cvc.buildConstraintViolationWithTemplate(remoteKeyInfo.annotation.message()).addNode(Dom.convertName(remoteKeyInfo.method.getName())).addConstraintViolation();
                        }
                    }
                } else {
                    throw new UnexpectedTypeException(localStrings.getLocalString("referenceValidator.not.string", "The RemoteKey annotation must identify a method that returns a String."));
                }
            } catch (Exception ex) {
                return false;
            }
        }
        if (!result && disableGlobalMessage) {
            cvc.disableDefaultConstraintViolation();
        }
        return result;
    }
    return true;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Dom(org.jvnet.hk2.config.Dom) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) UnexpectedTypeException(javax.validation.UnexpectedTypeException) UnexpectedTypeException(javax.validation.UnexpectedTypeException)

Example 50 with Dom

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

the class ServerHelper method translateAddressAndPort.

/**
 * @param adminListener
 * @param server
 * @param config
 * @return ret[0] == address, ret[1] == port
 */
private static String[] translateAddressAndPort(NetworkListener adminListener, Server server, Config config) {
    NetworkListener adminListenerRaw = null;
    String[] ret = new String[2];
    String portString = null;
    String addressString = null;
    try {
        Dom serverDom = Dom.unwrap(server);
        Domain domain = serverDom.getHabitat().getService(Domain.class);
        adminListenerRaw = GlassFishConfigBean.getRawView(adminListener);
        portString = adminListenerRaw.getPort();
        addressString = adminListenerRaw.getAddress();
        PropertyResolver resolver = new PropertyResolver(domain, server.getName());
        if (isToken(portString))
            ret[1] = resolver.getPropertyValue(portString);
        else
            ret[1] = portString;
        if (isToken(addressString))
            ret[0] = resolver.getPropertyValue(addressString);
        else
            ret[0] = addressString;
    } catch (ClassCastException e) {
        // jc: workaround for issue 12354
        // TODO severe error
        ret[0] = translatePortOld(addressString, server, config);
        ret[1] = translatePortOld(portString, server, config);
    }
    return ret;
}
Also used : Dom(org.jvnet.hk2.config.Dom) Domain(com.sun.enterprise.config.serverbeans.Domain) PropertyResolver(org.glassfish.config.support.PropertyResolver) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

Dom (org.jvnet.hk2.config.Dom)37 ConfigModel (org.jvnet.hk2.config.ConfigModel)14 Domain (com.sun.enterprise.config.serverbeans.Domain)12 DomDocument (org.jvnet.hk2.config.DomDocument)9 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)8 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)8 PropertyVetoException (java.beans.PropertyVetoException)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 MultiException (org.glassfish.hk2.api.MultiException)5 Config (com.sun.enterprise.config.serverbeans.Config)4 TreeMap (java.util.TreeMap)4 ConfigParser (org.jvnet.hk2.config.ConfigParser)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ResourcesGenerator (org.glassfish.admin.rest.generator.ResourcesGenerator)3 ExampleServiceConfiguration (fish.payara.service.example.config.ExampleServiceConfiguration)2