Search in sources :

Example 11 with RegistrationException

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"));
        }
    }
}
Also used : RegistrationException(com.sun.enterprise.registration.RegistrationException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 12 with RegistrationException

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);
        }
    }
}
Also used : RegistrationException(com.sun.enterprise.registration.RegistrationException) Element(org.w3c.dom.Element) IOException(java.io.IOException) RegistrationException(com.sun.enterprise.registration.RegistrationException)

Example 13 with RegistrationException

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();
}
Also used : RegistrationException(com.sun.enterprise.registration.RegistrationException) Element(org.w3c.dom.Element)

Example 14 with RegistrationException

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);
            }
        }
    }
}
Also used : RegistrationException(com.sun.enterprise.registration.RegistrationException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) RegistrationException(com.sun.enterprise.registration.RegistrationException)

Aggregations

RegistrationException (com.sun.enterprise.registration.RegistrationException)14 Element (org.w3c.dom.Element)6 IOException (java.io.IOException)5 Image (com.sun.pkg.client.Image)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 ServiceTag (com.sun.enterprise.registration.impl.ServiceTag)1 SysnetRegistrationService (com.sun.enterprise.registration.impl.SysnetRegistrationService)1 SystemInfo (com.sun.pkg.client.SystemInfo)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 NodeList (org.w3c.dom.NodeList)1