use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class StatusGenerator method getHtml.
@GET
@Produces({ MediaType.TEXT_HTML })
public String getHtml() {
try {
Domain entity = serviceLocator.getService(Domain.class);
Dom dom = Dom.unwrap(entity);
DomDocument document = dom.document;
ConfigModel rootModel = dom.document.getRoot().model;
ResourcesGenerator resourcesGenerator = new NOOPResourcesGenerator(serviceLocator);
resourcesGenerator.generateSingle(rootModel, document);
resourcesGenerator.endGeneration();
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
status.append("<h4>All Commands used in REST Admin</h4>\n<ul>\n");
for (String ss : commandsUsed) {
status.append("<li>").append(ss).append("</li>\n");
}
listOfCommands();
for (String ss : commandsUsed) {
allCommands.remove(ss);
}
status.append("</ul>\n<hr/>\n").append("<h4>Missing Commands not used in REST Admin</h4>\n<ul>\n");
for (String ss : allCommands) {
if (hasTargetParam(ss)) {
status.append("<li>").append(ss).append(" has a target param.</li>\n");
} else {
status.append("<li>").append(ss).append("</li>\n");
}
}
status.append("</ul>\n<hr/>\n").append("<h4>REST-REDIRECT Commands defined on ConfigBeans</h4>\n<ul>\n");
for (String ss : restRedirectCommands) {
status.append("<li>").append(ss).append("</li>\n");
}
status.append("</ul>\n<hr/>\n").append("<h4>Commands to Resources Mapping Usage in REST Admin</h4>\n").append("<table border=\"1\" style=\"border-collapse: collapse\">\n").append("<tr><th>Command</th><th>Target</th><th>Resource</th></tr>\n");
for (String ss : commandsToResources.keySet()) {
status.append("<tr><td>").append(ss).append("</td><td>").append(hasTargetParam(ss) ? "target" : "").append("</td><td>").append(commandsToResources.get(ss)).append("</td></tr>\n");
}
status.append("</table>\n<hr/>\n").append("<h4>Resources with Delete Commands in REST Admin (not counting RESTREDIRECT)</h4>\n").append("<table border=\"1\" style=\"border-collapse: collapse\">\n").append("<tr><th>Resource</th><th>Delete Command</th></tr>\n");
for (String ss : resourcesToDeleteCommands.keySet()) {
status.append("<tr><td>").append(ss).append("</td><td>").append(resourcesToDeleteCommands.get(ss)).append("</td></tr>\n");
}
status.append("</table>");
FileOutputStream f = null;
try {
f = new FileOutputStream(System.getProperty("user.home") + "/GlassFishI18NData.properties");
propsI18N.store(f, "");
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
} finally {
if (f != null) {
try {
f.close();
} catch (IOException ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
}
}
return status.toString();
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class ResourceUtil method getRealChildConfigModels.
public static List<ConfigModel> getRealChildConfigModels(ConfigModel childModel, DomDocument domDocument) {
List<ConfigModel> retlist = new ArrayList<ConfigModel>();
try {
Class<?> subType = childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
List<ConfigModel> list = domDocument.getAllModelsImplementing(subType);
if (list != null) {
for (ConfigModel el : list) {
if (isOnlyATag(el)) {
// this is just a tag element
retlist.addAll(getRealChildConfigModels(el, domDocument));
} else {
retlist.add(el);
}
}
} else {
// https://glassfish.dev.java.net/issues/show_bug.cgi?id=12654
if (!isOnlyATag(childModel)) {
// this is just a tag element
retlist.add(childModel);
}
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return retlist;
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class ConfigBeanJMXSupport method getTypesImplementing.
/**
* works only for @Configured types
*/
public static Class[] getTypesImplementing(final Class<?> clazz) {
final DomDocument domDoc = new DomDocument(InjectedValues.getInstance().getHabitat());
try {
final List<ConfigModel> models = domDoc.getAllModelsImplementing(clazz);
final Class[] interfaces = new Class[models == null ? 0 : models.size()];
if (models != null) {
int i = 0;
for (final ConfigModel model : models) {
final String classname = model.targetTypeName;
final Class<?> intf = model.classLoaderHolder.loadClass(classname);
interfaces[i] = intf;
// System.out.println( "Loaded: " + intf + " with tagName of " + model.getTagName() );
++i;
}
}
return interfaces;
} catch (final Exception e) {
AMXLoggerInfo.getLogger().log(Level.INFO, AMXLoggerInfo.cantGetTypesImplementing, new Object[] { clazz, e.getLocalizedMessage() });
throw new RuntimeException(e);
}
}
use of org.jvnet.hk2.config.DomDocument 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;
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class ResourcesGeneratorBase method processNonLeafChildElement.
private void processNonLeafChildElement(String elementName, ConfigModel.Property childElement, DomDocument domDocument, ClassWriter classWriter) {
ConfigModel.Node node = (ConfigModel.Node) childElement;
ConfigModel childModel = node.getModel();
String beanName = ResourceUtil.getUnqualifiedTypeName(childModel.targetTypeName);
if (beanName.equals("Property")) {
classWriter.createGetChildResource("property", "PropertiesBagResource");
} else if (beanName.equals("MonitoredAttribute")) {
classWriter.createGetChildResource("monitored-attribute", "MonitoredAttributeBagResource");
} else {
String childResourceClassName = getClassName(beanName);
if (childElement.isCollection()) {
childResourceClassName = "List" + childResourceClassName;
}
classWriter.createGetChildResource(/*
* childModel.getTagName()
*/
elementName, childResourceClassName);
}
if (childElement.isCollection()) {
generateList(childModel, domDocument);
} else {
generateSingle(childModel, domDocument);
}
}
Aggregations