use of com.sun.enterprise.registration.RegistrationException in project Payara by payara.
the class RepositoryManager method setSubElementValue.
private void setSubElementValue(Element rootElement, String subElementName, String value, boolean force) throws RegistrationException {
NodeList nodes = rootElement.getElementsByTagName(subElementName);
if (nodes.getLength() > 0) {
Element subElement = ((Element) nodes.item(0));
subElement.setTextContent(value);
} else {
if (force) {
Element element = document.createElement(subElementName);
element.setTextContent(value);
rootElement.appendChild(element);
} else {
throw new RegistrationException(StringManager.getString("rpmgr.noSuchElement"));
}
}
}
use of com.sun.enterprise.registration.RegistrationException in project Payara by payara.
the class RepositoryManager method loadOrCreateDocument.
/**
* Initializes the cached Document for the repository.
* <p>
* If the specified file exists, reads the document from that file. If the
* file does not exist, creates a new document and populates it with the
* top-level registry element and the default registrationstatus element.
* @throws RegistrationException for errors reading the registration into
* the in-memory cache
*/
private synchronized void loadOrCreateDocument() throws RegistrationException {
if (document == null) {
if (registrationFile.exists()) {
try {
document = documentBuilder.parse(registrationFile);
registryElement = findRegistryElement();
} catch (Exception e) {
throw new RegistrationException(e);
}
} else {
document = documentBuilder.newDocument();
registryElement = document.createElement(REGISTRY_TAG);
document.appendChild(registryElement);
Element registrationStatusElement = document.createElement(REGISTRATION_REMINDER_TAG);
registrationStatusElement.setTextContent(REGISTRATION_REMINDER_DEFAULT_VALUE.toString());
registryElement.appendChild(registrationStatusElement);
}
}
}
use of com.sun.enterprise.registration.RegistrationException in project Payara by payara.
the class RepositoryManager method setStatus.
public void setStatus(ServiceTag serviceTag, ServiceTag.Status status) throws RegistrationException {
Element st = findServiceTag(serviceTag);
if (st == null) {
throw new RegistrationException(StringManager.getString("rpmgr.noSuchSrvTag"));
}
setSubElementValue(st, ServiceTag.STATUS, status.toString());
writeToFile();
}
use of com.sun.enterprise.registration.RegistrationException in project Payara by payara.
the class RepositoryManager method writeToFile.
/**
* Writes the cached document to the on-disk file.
* @throws RegistrationException for errors writing the cache into the file
*/
private void writeToFile() throws RegistrationException {
OutputStream os = null;
try {
os = new FileOutputStream(registrationFile);
write(os);
} catch (Exception e) {
throw new RegistrationException(e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException ex) {
throw new RegistrationException(StringManager.getString("rpmgr.errClosingRepos"), ex);
}
}
}
}
Aggregations