use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class GeneratorResource method get.
@GET
@Produces({ "text/plain" })
public String get(@QueryParam("outputDir") String outputDir) {
if (outputDir == null) {
outputDir = DEFAULT_OUTPUT_DIR;
}
String retVal = "Code Generation done at : " + outputDir;
try {
LocatorBridge locatorBridge = habitat.getService(LocatorBridge.class);
Dom dom = Dom.unwrap(locatorBridge.getRemoteLocator().<Domain>getService(Domain.class));
DomDocument document = dom.document;
ConfigModel rootModel = dom.document.getRoot().model;
ResourcesGenerator resourcesGenerator = new TextResourcesGenerator(outputDir, habitat);
resourcesGenerator.generateSingle(rootModel, document);
resourcesGenerator.endGeneration();
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
retVal = "Exception encountered during generation process: " + ex.toString() + "\nPlease look at server.log for more information.";
}
return retVal;
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class StatusGenerator method getPlain.
@GET
@Produces({ "text/plain" })
public String getPlain() {
// status.append("Status of Command usage\n");
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);
// retVal = "Exception encountered during generation process: " + ex.toString() + "\nPlease look at server.log for more information.";
}
status.append("\n------------------------");
status.append("All Commands used in REST Admin:\n");
for (String ss : commandsUsed) {
status.append(ss + "\n");
}
listOfCommands();
for (String ss : commandsUsed) {
allCommands.remove(ss);
}
status.append("\n------------------------");
status.append("Missing Commands not used in REST Admin:\n");
for (String ss : allCommands) {
if (hasTargetParam(ss)) {
status.append(ss + " has a target param " + "\n");
} else {
status.append(ss + "\n");
}
}
status.append("\n------------------------");
status.append("REST-REDIRECT Commands defined on ConfigBeans:\n");
for (String ss : restRedirectCommands) {
status.append(ss + "\n");
}
status.append("\n------------------------");
status.append("Commands to Resources Mapping Usage in REST Admin:\n");
for (String ss : commandsToResources.keySet()) {
if (hasTargetParam(ss)) {
status.append(ss + " :::target::: " + commandsToResources.get(ss) + "\n");
} else {
status.append(ss + " ::: " + commandsToResources.get(ss) + "\n");
}
}
status.append("\n------------------------");
status.append("Resources with Delete Commands in REST Admin (not counting RESTREDIRECT:\n");
for (String ss : resourcesToDeleteCommands.keySet()) {
status.append(ss + " ::: " + resourcesToDeleteCommands.get(ss) + "\n");
}
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 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.DomDocument in project Payara by payara.
the class Utils method getNewHabitat.
private static synchronized ServiceLocator getNewHabitat(final ConfigApiTest test) {
final ServiceLocator sl = getNewHabitat();
final String fileName = test.getFileName();
ConfigParser configParser = new ConfigParser(sl);
long now = System.currentTimeMillis();
URL url = Utils.class.getClassLoader().getResource(fileName + ".xml");
if (url != null) {
try {
DomDocument testDocument = test.getDocument(sl);
DomDocument document = configParser.parse(url, testDocument);
ServiceLocatorUtilities.addOneConstant(sl, document);
test.decorate(sl);
} catch (Exception e) {
e.printStackTrace();
}
Logger.getAnonymousLogger().fine("time to parse domain.xml : " + String.valueOf(System.currentTimeMillis() - now));
}
return sl;
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class DomainXmlPersistence method save.
@Override
public void save(DomDocument doc) throws IOException {
if (modularityUtils.isIgnorePersisting() && !modularityUtils.isCommandInvocation()) {
if (skippedDoc != null) {
assert (doc == skippedDoc);
}
skippedDoc = doc;
return;
}
File destination = getDestination();
if (destination == null) {
String msg = localStrings.getLocalString("NoLocation", "domain.xml cannot be persisted, null destination");
logger.severe(msg);
throw new IOException(msg);
}
Lock writeLock = null;
try {
try {
writeLock = accessWrite();
} catch (TimeoutException e) {
String msg = localStrings.getLocalString("Timeout", "Timed out when waiting for write lock on configuration file");
logger.log(Level.SEVERE, msg);
throw new IOException(msg, e);
}
// get a temporary file
File f = File.createTempFile("domain", ".xml", destination.getParentFile());
if (!f.exists()) {
throw new IOException(localStrings.getLocalString("NoTmpFile", "Cannot create temporary file when saving domain.xml"));
}
// write to the temporary file
XMLStreamWriter writer = null;
OutputStream fos = getOutputStream(f);
try {
writer = xmlFactory.createXMLStreamWriter(new BufferedOutputStream(fos));
IndentingXMLStreamWriter indentingXMLStreamWriter = new IndentingXMLStreamWriter(writer);
doc.writeTo(indentingXMLStreamWriter);
indentingXMLStreamWriter.close();
} catch (XMLStreamException e) {
String msg = localStrings.getLocalString("TmpFileNotSaved", "Configuration could not be saved to temporary file");
logger.log(Level.SEVERE, msg, e);
throw new IOException(e.getMessage(), e);
// return after calling finally clause, because since temp file couldn't be saved,
// renaming should not be attempted
} finally {
if (writer != null) {
try {
writer.close();
} catch (XMLStreamException e) {
logger.log(Level.SEVERE, localStrings.getLocalString("CloseFailed", "Cannot close configuration writer stream"), e);
throw new IOException(e.getMessage(), e);
}
}
fos.close();
}
// backup the current file
File backup = new File(env.getConfigDirPath(), "domain.xml.bak");
if (destination.exists() && backup.exists() && !backup.delete()) {
String msg = localStrings.getLocalString("BackupDeleteFailed", "Could not delete previous backup file at {0}", backup.getAbsolutePath());
logger.severe(msg);
throw new IOException(msg);
}
if (destination.exists() && !FileUtils.renameFile(destination, backup)) {
String msg = localStrings.getLocalString("TmpRenameFailed", "Could not rename {0} to {1}", destination.getAbsolutePath(), backup.getAbsolutePath());
logger.severe(msg);
throw new IOException(msg);
}
// save the temp file to domain.xml
if (!FileUtils.renameFile(f, destination)) {
String msg = localStrings.getLocalString("TmpRenameFailed", "Could not rename {0} to {1}", f.getAbsolutePath(), destination.getAbsolutePath());
// try to rename backup to domain.xml (so that at least something is there)
if (!FileUtils.renameFile(backup, destination)) {
msg += "\n" + localStrings.getLocalString("RenameFailed", "Could not rename backup to {0}", destination.getAbsolutePath());
}
logger.severe(msg);
throw new IOException(msg);
}
} catch (IOException e) {
logger.log(Level.SEVERE, localStrings.getLocalString("ioexception", "IOException while saving the configuration, changes not persisted"), e);
throw e;
} finally {
if (writeLock != null) {
writeLock.unlock();
}
}
skippedDoc = null;
saved(destination);
}
Aggregations