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;
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations