use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class ConsolePluginService method init.
/**
* <p> Initialize the available {@link IntegrationPoint}s.</p>
*/
protected synchronized void init() {
if (initialized) {
return;
}
initialized = true;
// First find the parser
if ((providers != null) && (providers.iterator().hasNext())) {
// Get our parser...
ConfigParser parser = new ConfigParser(habitat);
URL url = null;
String id = null;
// Loop through the configs and add them all
for (ConsoleProvider provider : providers) {
// Read the contents from the URL
url = provider.getConfiguration();
if (url == null) {
url = provider.getClass().getClassLoader().getResource(ConsoleProvider.DEFAULT_CONFIG_FILENAME);
}
if (url == null) {
if (logger.isLoggable(Level.INFO)) {
logger.info("Unable to find " + ConsoleProvider.DEFAULT_CONFIG_FILENAME + " file for provider '" + provider.getClass().getName() + "'");
}
continue;
}
// System.out.println("Provider *"+provider+"* : url=*"+url+"*");
DomDocument doc = parser.parse(url);
// Get the New IntegrationPoints
ConsoleConfig config = (ConsoleConfig) doc.getRoot().get();
// Save the ClassLoader for later
// System.out.println("Storing: " + config.getId() + " : " + provider.getClass().getClassLoader());
id = config.getId();
moduleClassLoaderMap.put(id, provider.getClass().getClassLoader());
classLoaderModuleMap.put(provider.getClass().getClassLoader(), id);
// Add the new IntegrationPoints
addIntegrationPoints(config.getIntegrationPoints(), id);
}
}
// Log some trace messages
if (logger.isLoggable(Level.FINE)) {
logger.fine("Console Plugin Service has been Initialized!");
if (logger.isLoggable(Level.FINEST)) {
logger.finest(pointsByType.toString());
}
}
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class ConsolePluginService method getHelpIndex.
/**
* <p> This method returns a merged Table Of Contents for all found help
* sets for the given locale.</p>
*/
public synchronized Index getHelpIndex(String locale) {
if (locale == null) {
// Use this as the default...
locale = "en";
}
Index mergedIndex = helpSetIndexMap.get(locale);
if (mergedIndex != null) {
// Already calculated...
return mergedIndex;
}
// TOC
Map<String, List<URL>> mapUrls = getResources(locale + "/help/index.xml");
// Get our parser...
ConfigParser parser = new ConfigParser(habitat);
// Setup a new "merged" TOC...
mergedIndex = new Index();
mergedIndex.setIndexItems(new ArrayList<IndexItem>());
mergedIndex.setVersion("2.0");
// Loop through the urls and add them all
// module id
String id = null;
// prefix (minus module id)
String prefix = "/" + locale + "/help/";
// URLs to TOC files w/i each plugin module
List<URL> urls = null;
for (Map.Entry<String, List<URL>> entry : mapUrls.entrySet()) {
id = entry.getKey();
urls = entry.getValue();
for (URL url : urls) {
DomDocument doc = parser.parse(url);
// Merge all the TOC's...
Index index = (Index) doc.getRoot().get();
for (IndexItem item : index.getIndexItems()) {
insertIndexItem(mergedIndex.getIndexItems(), item, id + prefix);
}
}
}
// FIXME: Sort?
return mergedIndex;
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class ConfigApiTest method getDocument.
@Override
public DomDocument getDocument(ServiceLocator habitat) {
DomDocument doc = habitat.getService(GlassFishDocument.class);
if (doc == null) {
return new GlassFishDocument(habitat, Executors.newCachedThreadPool(new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
}
}));
}
return doc;
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class GadgetHandlers method getGadgetModule.
/**
* <p> This method returns a {@link GadgetModule} for the given URL.</p>
*/
public static GadgetModule getGadgetModule(URL url) {
if (url == null) {
return null;
}
// FIXME: Cache?
// Get our parser...
ConfigParser parser = new ConfigParser(GuiUtil.getHabitat());
String id = null;
// Read the document...
DomDocument doc = parser.parse(url);
// Get the GadgetModule
GadgetModule module = (GadgetModule) doc.getRoot().get();
return module;
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class ResourcesGeneratorBase method generateSingle.
/**
* Generate REST resource for a single config model.
*/
@Override
public void generateSingle(ConfigModel model, DomDocument domDocument) {
configModelVisited(model);
// processRedirectsAnnotation(model); // TODO need to extract info from RestRedirect Annotations
String serverConfigName = ResourceUtil.getUnqualifiedTypeName(model.targetTypeName);
String beanName = getBeanName(serverConfigName);
String className = getClassName(beanName);
if (alreadyGenerated(className)) {
return;
}
String baseClassName = "TemplateRestResource";
String resourcePath = null;
if (beanName.equals("Domain")) {
baseClassName = "org.glassfish.admin.rest.resources.GlassFishDomainResource";
resourcePath = "domain";
}
ClassWriter classWriter = getClassWriter(className, baseClassName, resourcePath);
if (classWriter != null) {
generateCommandResources(beanName, classWriter);
generateGetDeleteCommandMethod(beanName, classWriter);
generateCustomResourceMapping(beanName, classWriter);
for (String elementName : model.getElementNames()) {
ConfigModel.Property childElement = model.getElement(elementName);
if (elementName.equals("*")) {
ConfigModel.Node node = (ConfigModel.Node) childElement;
ConfigModel childModel = node.getModel();
List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, domDocument);
for (ConfigModel subChildConfigModel : subChildConfigModels) {
if (ResourceUtil.isOnlyATag(childModel) || ResourceUtil.isOnlyATag(subChildConfigModel) || subChildConfigModel.getAttributeNames().isEmpty() || hasSingletonAnnotation(subChildConfigModel)) {
String childResourceClassName = getClassName(ResourceUtil.getUnqualifiedTypeName(subChildConfigModel.targetTypeName));
String childPath = subChildConfigModel.getTagName();
classWriter.createGetChildResource(childPath, childResourceClassName);
generateSingle(subChildConfigModel, domDocument);
} else {
processNonLeafChildConfigModel(subChildConfigModel, childElement, domDocument, classWriter);
}
}
} else if (childElement.isLeaf()) {
if (childElement.isCollection()) {
// handle the CollectionLeaf config objects.
// JVM Options is an example of CollectionLeaf object.
String childResourceBeanName = getBeanName(elementName);
String childResourceClassName = getClassName(childResourceBeanName);
classWriter.createGetChildResource(elementName, childResourceClassName);
// create resource class
generateCollectionLeafResource(childResourceBeanName);
} else {
String childResourceBeanName = getBeanName(elementName);
String childResourceClassName = getClassName(childResourceBeanName);
classWriter.createGetChildResource(elementName, childResourceClassName);
// create resource class
generateLeafResource(childResourceBeanName);
}
} else {
// => !childElement.isLeaf()
processNonLeafChildElement(elementName, childElement, domDocument, classWriter);
}
}
classWriter.done();
}
}
Aggregations