use of org.jvnet.hk2.config.Element in project Payara by payara.
the class GenericCrudCommand method elementName.
/**
* Returns the element name used by the parent to store instances of the child
*
* @param document the dom document this configuration element lives in.
* @param parent type of the parent
* @param child type of the child
* @return the element name holding child's instances in the parent
* @throws ClassNotFoundException when subclasses cannot be loaded
*/
public static String elementName(DomDocument document, Class<?> parent, Class<?> child) throws ClassNotFoundException {
ConfigModel cm = document.buildModel(parent);
for (String elementName : cm.getElementNames()) {
ConfigModel.Property prop = cm.getElement(elementName);
if (prop instanceof ConfigModel.Node) {
ConfigModel childCM = ((ConfigModel.Node) prop).getModel();
String childTypeName = childCM.targetTypeName;
if (childTypeName.equals(child.getName())) {
return childCM.getTagName();
}
// check the inheritance hierarchy
List<ConfigModel> subChildrenModels = document.getAllModelsImplementing(childCM.classLoaderHolder.loadClass(childTypeName));
if (subChildrenModels != null) {
for (ConfigModel subChildModel : subChildrenModels) {
if (subChildModel.targetTypeName.equals(child.getName())) {
return subChildModel.getTagName();
}
}
}
}
}
return null;
}
use of org.jvnet.hk2.config.Element in project Payara by payara.
the class PortUtils method checkInternalConsistency.
/**
* Make sure all ports that are specified by the user make sense.
* @param server The new Server element
* @return null if all went OK. Otherwise return a String with the error message.
*/
static void checkInternalConsistency(Server server) throws TransactionFailure {
// Make sure all the system properties for ports have different numbers.
List<SystemProperty> sysProps = server.getSystemProperty();
Set<Integer> ports = new TreeSet<Integer>();
for (SystemProperty sp : sysProps) {
String name = sp.getName();
if (PORTSLIST.contains(name)) {
String val = sp.getValue();
try {
boolean wasAdded = ports.add(Integer.parseInt(val));
if (// TODO unit test
!wasAdded)
throw new TransactionFailure(Strings.get("PortUtils.duplicate_port", val, server.getName()));
} catch (TransactionFailure tf) {
// don't re-wrap the same Exception type!
throw tf;
} catch (Exception e) {
// TODO unit test
throw new TransactionFailure(Strings.get("PortUtils.non_int_port", val, server.getName()));
}
}
}
checkForLegalPorts(ports, server.getName());
}
use of org.jvnet.hk2.config.Element 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;
}
use of org.jvnet.hk2.config.Element in project Payara by payara.
the class ApplicationLifecycle method prepareAppConfigChanges.
// prepare application config change for later registering
// in the domain.xml
@Override
public Transaction prepareAppConfigChanges(final DeploymentContext context) throws TransactionFailure {
final Properties appProps = context.getAppProps();
final DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
Transaction t = new Transaction();
try {
// prepare the application element
ConfigBean newBean = ((ConfigBean) ConfigBean.unwrap(applications)).allocate(Application.class);
Application app = newBean.createProxy();
Application app_w = t.enroll(app);
setInitialAppAttributes(app_w, deployParams, appProps, context);
context.addTransientAppMetaData(ServerTags.APPLICATION, app_w);
} catch (TransactionFailure e) {
t.rollback();
throw e;
} catch (Exception e) {
t.rollback();
throw new TransactionFailure(e.getMessage(), e);
}
return t;
}
use of org.jvnet.hk2.config.Element in project Payara by payara.
the class CreateProfilerTest method testExecuteSuccess.
/**
* Test of execute method, of class CreateProfiler.
* asadmin create-profiler --nativelibrarypath "myNativeLibraryPath"
* --enabled=true --classpath "myProfilerClasspath" testProfiler
*/
@Test
public void testExecuteSuccess() {
// Set the options and operand to pass to the command
parameters.set("classpath", "myProfilerClasspath");
parameters.set("enabled", "true");
parameters.set("nativelibrarypath", "myNativeLibraryPath");
parameters.set("property", "a=x:b=y:c=z");
parameters.set("DEFAULT", "testProfiler");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check that the profiler is created
boolean isCreated = false;
int propertyCount = 0;
Profiler profiler = javaConfig.getProfiler();
if (profiler.getName().equals("testProfiler")) {
assertEquals("myProfilerClasspath", profiler.getClasspath());
assertEquals("true", profiler.getEnabled());
assertEquals("myNativeLibraryPath", profiler.getNativeLibraryPath());
List<Property> properties = profiler.getProperty();
for (Property property : properties) {
if (property.getName().equals("a"))
assertEquals("x", property.getValue());
if (property.getName().equals("b"))
assertEquals("y", property.getValue());
if (property.getName().equals("c"))
assertEquals("z", property.getValue());
propertyCount++;
}
isCreated = true;
logger.fine("Profiler element myProfiler is created.");
}
assertTrue(isCreated);
assertEquals(propertyCount, 3);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check the success message
// assertEquals("Command create-profiler executed successfully.", context.getActionReport().getMessage());
logger.fine("msg: " + context.getActionReport().getMessage());
}
Aggregations