Search in sources :

Example 26 with Dom

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

the class V2DottedNameSupport method getAllSubDottedNames.

protected void getAllSubDottedNames(String prefix, Dom parent, Map<Dom, String> result) {
    Set<String> elementNames = parent.getElementNames();
    for (String childName : elementNames) {
        // by default, it's a collection unless I can find the model for it
        // and ensure this is one or not.
        // not finding the model usually means that it was a "*" element therefore
        // a collection.
        boolean collection = true;
        if (parent.model.findIgnoreCase(childName) != null) {
            // if this is a leaf node, we should really treat it as an attribute.
            if (parent.model.getElement(childName).isLeaf())
                continue;
            collection = parent.model.getElement(childName).isCollection();
        }
        List<Dom> childNodes;
        synchronized (parent) {
            childNodes = parent.nodeElements(childName);
        }
        for (Dom child : childNodes) {
            StringBuilder newPrefix = new StringBuilder();
            if (prefix == null) {
                newPrefix.append(childName);
            } else {
                newPrefix.append(prefix).append(".").append(childName);
            }
            if (collection) {
                String name = child.getKey();
                if (name == null) {
                    name = child.attribute("name");
                }
                if (name != null) {
                    newPrefix.append(".").append(name);
                }
                // now traverse the child
                getAllSubDottedNames(newPrefix.toString(), child, result);
            } else {
                getAllSubDottedNames(newPrefix.toString(), child, result);
            }
        }
    }
    if (prefix != null) {
        result.put(parent, prefix);
    }
}
Also used : Dom(org.jvnet.hk2.config.Dom)

Example 27 with Dom

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

the class ConfigTest method testHabitatFromDom.

// @Test
public void testHabitatFromDom() {
    SimpleConnector sc = habitat.getService(SimpleConnector.class);
    EjbContainerAvailability ejb = sc.getEjbContainerAvailability();
    Dom ejbDom = Dom.unwrap(ejb);
    assert (ejbDom.getHabitat() != null);
}
Also used : Dom(org.jvnet.hk2.config.Dom)

Example 28 with Dom

use of org.jvnet.hk2.config.Dom 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)

Example 29 with Dom

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

the class ConfigTest method testDomTx.

// @Test
public void testDomTx() {
    SimpleConnector sc = habitat.getService(SimpleConnector.class);
    EjbContainerAvailability ejb = sc.getEjbContainerAvailability();
    Dom ejbDom = Dom.unwrap(ejb);
    assert (ejbDom.getHabitat() != null);
    String avEnabled = ejb.getAvailabilityEnabled();
    try {
        ConfigSupport.apply(new SingleConfigCode<EjbContainerAvailability>() {

            @Override
            public Object run(EjbContainerAvailability param) throws PropertyVetoException, TransactionFailure {
                param.setSfsbHaPersistenceType("coherence");
                param.setSfsbCheckpointEnabled("**MUST BE**");
                return null;
            }
        }, ejb);
        // printEjb("AFTER CHANGES", ejb);
        assert (ejb.getSfsbHaPersistenceType().equals("coherence") && ejb.getSfsbCheckpointEnabled().equals("**MUST BE**") && ejb.getAvailabilityEnabled().equals(avEnabled));
    } catch (Exception e) {
        e.printStackTrace();
        assert (false);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Dom(org.jvnet.hk2.config.Dom) PropertyVetoException(java.beans.PropertyVetoException)

Example 30 with Dom

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

the class ExampleConfigUpdateOnlyOnDAS method execute.

@Override
public void execute(AdminCommandContext context) {
    // obtain the correct configuration
    Config configVal = targetUtil.getConfig(target);
    ExampleServiceConfiguration serviceConfig = configVal.getExtensionByType(ExampleServiceConfiguration.class);
    if (serviceConfig != null) {
        try {
            // to perform a transaction on the domain.xml you need to use this construct
            // see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
            ConfigSupport.apply(new SingleConfigCode<ExampleServiceConfiguration>() {

                @Override
                public Object run(ExampleServiceConfiguration config) {
                    config.setMessage(message);
                    return null;
                }
            }, serviceConfig);
        } catch (TransactionFailure ex) {
            // set failure
            context.getActionReport().failure(Logger.getLogger(SetExampleServiceMessage.class.getName()), "Failed to update message", ex);
        }
    } else {
        context.getActionReport().failure(Logger.getLogger(this.getClass().getCanonicalName()), "No configuration with name " + target);
    }
}
Also used : ExampleServiceConfiguration(fish.payara.service.example.config.ExampleServiceConfiguration) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config)

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