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);
}
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations