Search in sources :

Example 41 with Dom

use of org.jvnet.hk2.config.Dom in project Payara by payara.

the class TemplateRestResource method buildPath.

/**
 * This method will build the path string as needed by ConfigModularityUtils.getOwningObject().
 * There is a mismatch between what the method expects and the way the REST URIs are constructed.
 * For example, for the transaction-service element, the REST URI, stripped of the HTTP and
 * server context information, looks like this:
 * /domain/configs/config/server-config/transaction-service.  The format expected by the
 * getOwningObject(), however, looks like this:
 * domain/configs/server-config/transaction-service. In the REST URIs, if there is a collection of
 * Named items, the type of the collection is inserted into the URI ("config" here) followed by
 * the name of the particular instance ("server-config").  In building the path, we must identify
 * Named instances and insert the name of the instance rather than the type.  We apply this logic
 * as we recurse up to the top of the Dom tree to finish building the path desired.
 * @param node
 * @return
 */
private String buildPath(Dom node) {
    final Dom parentNode = node.parent();
    String part = node.model.getTagName();
    String name = node.attribute("name");
    if (name != null) {
        part = name;
    }
    return (parentNode != null) ? (buildPath(parentNode) + "/" + part) : part;
}
Also used : Dom(org.jvnet.hk2.config.Dom)

Example 42 with Dom

use of org.jvnet.hk2.config.Dom in project Payara by payara.

the class TemplateRestResource method setParentAndTagName.

public void setParentAndTagName(Dom parent, String tagName) {
    if (parent == null) {
        // prevent https://glassfish.dev.java.net/issues/show_bug.cgi?id=14125
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    this.parent = parent;
    this.tagName = tagName;
    synchronized (parent) {
        entity = parent.nodeElement(tagName);
    }
    if (entity == null) {
        // In some cases, the tagName requested is not found in the DOM tree.  This is true,
        // for example, for the various ZeroConf elements (e.g., transaction-service).  If
        // the zero conf element is not in domain.xml, then it won't be in the Dom tree
        // returned by HK2.  If that's the case, we can use ConfigModularityUtils.getOwningObject()
        // to find the ConfigBean matching the path requested, which will add the node to
        // the Dom tree. Once that's done, we can return that node and proceed as normal
        String location = buildPath(parent) + "/" + tagName;
        if (location.startsWith("domain/configs")) {
            final ConfigModularityUtils cmu = locatorBridge.getRemoteLocator().<ConfigModularityUtils>getService(ConfigModularityUtils.class);
            ConfigBeanProxy cbp = cmu.getOwningObject(location);
            if (cbp == null) {
                cbp = cmu.getConfigBeanInstanceFor(cmu.getOwningClassForLocation(location));
            }
            if (cbp != null) {
                entity = Dom.unwrap(cbp);
                childModel = entity.model;
            }
        }
    // throw new WebApplicationException(new Exception("Trying to create an entity using generic create"),Response.Status.INTERNAL_SERVER_ERROR);
    } else {
        childModel = entity.model;
    }
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigModularityUtils(com.sun.enterprise.config.modularity.ConfigModularityUtils)

Example 43 with Dom

use of org.jvnet.hk2.config.Dom in project Payara by payara.

the class FindHttpProtocolResource method get.

@GET
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public ActionReportResult get() {
    Dom dom = getEntity();
    NetworkListener nl = dom.createProxy(NetworkListener.class);
    Protocol p = nl.findHttpProtocol();
    RestActionReporter ar = new RestActionReporter();
    ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ar.getTopMessagePart().getProps().put("protocol", p.getName());
    ActionReportResult result = new ActionReportResult("find-http-protocol", ar, new OptionsResult());
    return result;
}
Also used : Dom(org.jvnet.hk2.config.Dom) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 44 with Dom

use of org.jvnet.hk2.config.Dom in project Payara by payara.

the class SystemPropertiesCliResource method getCluster.

protected Dom getCluster(Dom domain, String clusterName) {
    List<Dom> configs;
    Dom clusterElements;
    synchronized (domain) {
        clusterElements = domain.nodeElements("clusters").get(0);
    }
    synchronized (clusterElements) {
        configs = clusterElements.nodeElements("cluster");
    }
    for (Dom config : configs) {
        if (config.attribute("name").equals(clusterName)) {
            return config;
        }
    }
    return null;
}
Also used : Dom(org.jvnet.hk2.config.Dom)

Example 45 with Dom

use of org.jvnet.hk2.config.Dom in project Payara by payara.

the class SystemPropertiesCliResource method deleteRemovedProperties.

// returns null if successful or the Response which contains the error msg.
protected Response deleteRemovedProperties(Map<String, String> newProps) {
    List<String> existingList = new ArrayList<>();
    Dom parent = getEntity();
    List<Dom> existingProps;
    synchronized (parent) {
        existingProps = parent.nodeElements(TAG_SYSTEM_PROPERTY);
    }
    for (Dom existingProp : existingProps) {
        existingList.add(existingProp.attribute("name"));
    }
    // no existing properites,return null
    if (existingList.isEmpty()) {
        return null;
    }
    // delete the props thats no longer in the new list.
    for (String onePropName : existingList) {
        if (!newProps.containsKey(onePropName)) {
            Response resp = deleteProperty(null, onePropName);
            if (resp.getStatus() != HttpURLConnection.HTTP_OK) {
                return resp;
            }
        }
    }
    return null;
}
Also used : Response(javax.ws.rs.core.Response) Dom(org.jvnet.hk2.config.Dom) ArrayList(java.util.ArrayList)

Aggregations

Dom (org.jvnet.hk2.config.Dom)37 ConfigModel (org.jvnet.hk2.config.ConfigModel)14 Domain (com.sun.enterprise.config.serverbeans.Domain)12 DomDocument (org.jvnet.hk2.config.DomDocument)9 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)8 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)8 PropertyVetoException (java.beans.PropertyVetoException)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 MultiException (org.glassfish.hk2.api.MultiException)5 Config (com.sun.enterprise.config.serverbeans.Config)4 TreeMap (java.util.TreeMap)4 ConfigParser (org.jvnet.hk2.config.ConfigParser)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ResourcesGenerator (org.glassfish.admin.rest.generator.ResourcesGenerator)3 ExampleServiceConfiguration (fish.payara.service.example.config.ExampleServiceConfiguration)2