use of org.jvnet.hk2.config.Dom in project Payara by payara.
the class VerifyDomainXmlCommand method executeCommand.
/**
*/
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
File domainXMLFile = getDomainXml();
logger.log(Level.FINER, "Domain XML file = {0}", domainXMLFile);
try {
// get the list of JAR files from the modules directory
ArrayList<URL> urls = new ArrayList<URL>();
File idir = new File(System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
File mdir = new File(idir, "modules");
for (File f : mdir.listFiles()) {
if (f.toString().endsWith(".jar")) {
urls.add(f.toURI().toURL());
}
}
final URL[] urlsA = urls.toArray(new URL[urls.size()]);
ClassLoader cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
return new URLClassLoader(urlsA, Globals.class.getClassLoader());
}
});
ModulesRegistry registry = new StaticModulesRegistry(cl);
ServiceLocator serviceLocator = registry.createServiceLocator("default");
ConfigParser parser = new ConfigParser(serviceLocator);
URL domainURL = domainXMLFile.toURI().toURL();
DomDocument doc = parser.parse(domainURL);
Dom domDomain = doc.getRoot();
Domain domain = domDomain.createProxy(Domain.class);
DomainXmlVerifier validator = new DomainXmlVerifier(domain);
if (validator.invokeConfigValidator())
return 1;
} catch (Exception e) {
throw new CommandException(e);
}
return 0;
}
use of org.jvnet.hk2.config.Dom in project Payara by payara.
the class GlassFishDomainResource method setBaseServiceLocator.
// called when jersey is injecting the habitat...
@Context
public void setBaseServiceLocator(LocatorBridge hab) {
Dom dom1 = Dom.unwrap(hab.getRemoteLocator().<Domain>getService(Domain.class));
childModel = dom1.document.getRoot().model;
entity = dom1.document.getRoot();
}
use of org.jvnet.hk2.config.Dom in project Payara by payara.
the class PropertiesBagResource method getExistingProperties.
protected Map<String, Property> getExistingProperties() {
Map<String, Property> properties = new HashMap<>();
if (parent != null) {
List<Dom> children;
synchronized (parent) {
children = parent.nodeElements(tagName);
}
for (Dom child : children) {
Property property = child.createProxy();
properties.put(property.getName(), property);
}
}
return properties;
}
use of org.jvnet.hk2.config.Dom 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.Dom in project Payara by payara.
the class TemplateRestResource method setBeanByKey.
/*
* This method is called by the ASM generated code change very carefully
*/
public void setBeanByKey(List<Dom> parentList, String id, String tag) {
this.tagName = tag;
try {
childID = URLDecoder.decode(id, "UTF-8");
} catch (UnsupportedEncodingException ex) {
childID = id;
}
if (parentList != null) {
// Believe it or not, this can happen
for (Dom c : parentList) {
String keyAttributeName = null;
ConfigModel model = c.model;
if (model.key == null) {
try {
for (String s : model.getAttributeNames()) {
// no key, by default use the name attr
if (s.equals("name")) {
keyAttributeName = s;
}
}
if (keyAttributeName == null) {
// nothing, so pick the first one
keyAttributeName = model.getAttributeNames().iterator().next();
}
} catch (Exception e) {
// no attr choice fo a key!!! Error!!!
keyAttributeName = "ThisIsAModelBug:NoKeyAttr";
}
// firstone
} else {
keyAttributeName = model.key.substring(1, model.key.length());
}
String keyvalue = c.attribute(keyAttributeName.toLowerCase(Locale.US));
if (keyvalue.equals(childID)) {
setEntity((ConfigBean) c);
}
}
}
}
Aggregations