use of org.jvnet.hk2.config.Element 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.Element 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.Element in project Payara by payara.
the class ResourceUtil method getRealChildConfigModels.
public static List<ConfigModel> getRealChildConfigModels(ConfigModel childModel, DomDocument domDocument) {
List<ConfigModel> retlist = new ArrayList<ConfigModel>();
try {
Class<?> subType = childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
List<ConfigModel> list = domDocument.getAllModelsImplementing(subType);
if (list != null) {
for (ConfigModel el : list) {
if (isOnlyATag(el)) {
// this is just a tag element
retlist.addAll(getRealChildConfigModels(el, domDocument));
} else {
retlist.add(el);
}
}
} else {
// https://glassfish.dev.java.net/issues/show_bug.cgi?id=12654
if (!isOnlyATag(childModel)) {
// this is just a tag element
retlist.add(childModel);
}
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return retlist;
}
use of org.jvnet.hk2.config.Element in project Payara by payara.
the class AdminRESTConfigUpgrade method postConstruct.
@Override
public void postConstruct() {
for (Config config : configs.getConfig()) {
// we only want to handle configs that have an admin listener
try {
if (config.getAdminListener() == null) {
LogRecord lr = new LogRecord(Level.FINE, String.format("Skipping config %s. No admin listener.", config.getName()));
lr.setLoggerName(getClass().getName());
EarlyLogHandler.earlyMessages.add(lr);
continue;
}
} catch (IllegalStateException ise) {
/*
* I've only seen the exception rather than
* getAdminListener returning null. This should
* typically happen for any config besides
* <server-config>, but we'll proceed if any
* config has an admin listener.
*/
LogRecord lr = new LogRecord(Level.FINE, String.format("Skipping config %s. getAdminListener threw: %s", config.getName(), ise.getLocalizedMessage()));
lr.setLoggerName(getClass().getName());
EarlyLogHandler.earlyMessages.add(lr);
continue;
}
Protocols ps = config.getNetworkConfig().getProtocols();
if (ps != null) {
for (Protocol p : ps.getProtocol()) {
Http h = p.getHttp();
if (h != null && "__asadmin".equals(h.getDefaultVirtualServer())) {
try {
ConfigSupport.apply(new HttpConfigCode(), h);
} catch (TransactionFailure tf) {
LogRecord lr = new LogRecord(Level.SEVERE, "Could not upgrade http element for admin console: " + tf);
lr.setLoggerName(getClass().getName());
EarlyLogHandler.earlyMessages.add(lr);
}
}
}
}
}
}
use of org.jvnet.hk2.config.Element in project Payara by payara.
the class ApplicationConfigListener method transactionCommited.
public void transactionCommited(final List<PropertyChangeEvent> changes) {
boolean isUpdatingAttribute = true;
for (PropertyChangeEvent event : changes) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if (event.getSource() instanceof Applications) {
if (event.getPropertyName().equals(ServerTags.APPLICATION)) {
if (oldValue == null || newValue == null) {
// we are adding/removing application element here
// and updating existing attribute
isUpdatingAttribute = false;
break;
}
}
} else if (event.getSource() instanceof Server || event.getSource() instanceof Cluster) {
if (event.getPropertyName().equals(ServerTags.APPLICATION_REF)) {
if (oldValue == null || newValue == null) {
// we are adding/removing application-ref element here
// and updating existing attribute
isUpdatingAttribute = false;
break;
}
}
}
}
if (!isUpdatingAttribute) {
// skip the config listener
return;
}
for (PropertyChangeEvent event : changes) {
if (event.getSource() instanceof Application || event.getSource() instanceof ApplicationRef || event.getSource() instanceof Property) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
String propertyName = null;
if (oldValue != null && newValue != null && oldValue instanceof String && newValue instanceof String && !((String) oldValue).equals((String) newValue)) {
// if it's an attribute change of the application
// element or application-ref element
Object parent = event.getSource();
String appName = null;
if (parent instanceof Application) {
appName = ((Application) parent).getName();
propertyName = event.getPropertyName();
} else if (parent instanceof ApplicationRef) {
appName = ((ApplicationRef) parent).getRef();
propertyName = event.getPropertyName();
} else if (parent instanceof Property) {
appName = ((Property) parent).getParent(Application.class).getName();
propertyName = ((Property) parent).getName();
}
// anything
if (applications.getApplication(appName) == null) {
return;
}
if (ServerTags.ENABLED.equals(propertyName)) {
// enable or disable application accordingly
handleAppEnableChange(event.getSource(), appName, Boolean.valueOf((String) newValue));
} else if (ServerTags.CONTEXT_ROOT.equals(propertyName) || ServerTags.VIRTUAL_SERVERS.equals(propertyName) || ServerTags.AVAILABILITY_ENABLED.equals(propertyName) || ServerTags.CDI_DEV_MODE_ENABLED_PROP.equals(propertyName)) {
// for other changes, reload the application
handleOtherAppConfigChanges(event.getSource(), appName);
}
}
}
}
}
Aggregations