use of org.jvnet.hk2.config.Dom in project Payara by payara.
the class SystemPropertiesCliResource method getSystemProperties.
protected void getSystemProperties(Map<String, Map<String, String>> properties, Dom dom, boolean getDefaults) {
List<Dom> sysprops;
synchronized (dom) {
sysprops = dom.nodeElements("system-property");
}
if ((sysprops != null) && (!sysprops.isEmpty())) {
for (Dom sysprop : sysprops) {
String name = sysprop.attribute("name");
Map<String, String> currValue = properties.get(name);
if (currValue == null) {
currValue = new HashMap<String, String>();
currValue.put("name", name);
currValue.put(getDefaults ? "defaultValue" : "value", sysprop.attribute("value"));
if (sysprop.attribute("description") != null) {
currValue.put("description", sysprop.attribute("description"));
}
properties.put(name, currValue);
} else {
// Only add a default value if there isn't one already
if (currValue.get("defaultValue") == null) {
currValue.put("defaultValue", sysprop.attribute("value"));
}
}
}
}
// Figure out how to recurse
if (dom.getProxyType().equals(Server.class)) {
// Clustered instance
if (((Server) dom.createProxy()).getCluster() != null) {
getSystemProperties(properties, getCluster(dom.parent().parent(), ((Server) dom.createProxy()).getCluster().getName()), true);
} else {
// Standalone instance or DAS
getSystemProperties(properties, getConfig(dom.parent().parent(), dom.attribute("config-ref")), true);
}
} else if (dom.getProxyType().equals(Cluster.class)) {
getSystemProperties(properties, getConfig(dom.parent().parent(), dom.attribute("config-ref")), true);
}
}
use of org.jvnet.hk2.config.Dom in project Payara by payara.
the class DefaultConfigParser method parseContainerConfig.
@Override
public <T extends Container> T parseContainerConfig(ServiceLocator habitat, final URL configuration, Class<T> configType) throws IOException {
// I don't use the GlassFish document here as I don't need persistence
final DomDocument doc = new DomDocument<GlassFishConfigBean>(habitat) {
@Override
public Dom make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
// by default, people get the translated view.
return new GlassFishConfigBean(habitat, this, dom, configModel, xmlStreamReader);
}
};
// add the new container configuration to the server config
final T container = doc.getRoot().createProxy(configType);
try {
ConfigSupport.apply(new SingleConfigCode<Config>() {
@Override
public Object run(Config config) throws PropertyVetoException, TransactionFailure {
config.getContainers().add(container);
return null;
}
}, config);
} catch (TransactionFailure e) {
logger.log(Level.SEVERE, KernelLoggerInfo.exceptionAddContainer, e);
}
return container;
}
use of org.jvnet.hk2.config.Dom in project Payara by payara.
the class ContextRootCheckValidator method isValid.
@Override
public boolean isValid(Application app, ConstraintValidatorContext cvc) throws UnexpectedTypeException {
if (app == null) {
return true;
}
Dom dom = Dom.unwrap(app);
ServiceLocator locator = dom.getHabitat();
if (locator == null)
return true;
ConfigBeansUtilities cbu = locator.getService(ConfigBeansUtilities.class);
if (cbu == null)
return true;
Domain domain = cbu.getDomain();
String appName = app.getName();
String contextRoot = app.getContextRoot();
if (contextRoot != null && !contextRoot.startsWith("/")) {
contextRoot = "/" + contextRoot;
}
boolean result = true;
List<String> targets = domain.getAllReferencedTargetsForApplication(appName);
for (String target : targets) {
List<Server> servers = domain.getServersInTarget(target);
for (Server server : servers) {
ApplicationRef applicationRef = domain.getApplicationRefInServer(server.getName(), appName);
if (applicationRef != null) {
for (Application application : domain.getApplications().getApplications()) {
if (isSameApp(appName, application.getName())) {
// skip the check if the validation is for different versions of the same application
} else if ((application.getContextRoot() != null) && application.getContextRoot().equals(contextRoot)) {
String virtualServers = applicationRef.getVirtualServers();
List<String> vsList = Arrays.asList(virtualServers.split(","));
ApplicationRef thisAppRef = domain.getApplicationRefInServer(server.getName(), application.getName());
if (thisAppRef != null) {
virtualServers = thisAppRef.getVirtualServers();
List<String> thisVsList = Arrays.asList(virtualServers.split(","));
for (String vs : thisVsList) {
if (vsList.contains(vs)) {
result = false;
break;
}
}
}
}
}
}
}
}
return result;
}
use of org.jvnet.hk2.config.Dom in project Payara by payara.
the class ReferenceValidator method isValid.
@Override
public boolean isValid(ConfigBeanProxy config, ConstraintValidatorContext cvc) throws UnexpectedTypeException {
if (config == null) {
return true;
}
Dom dom = Dom.unwrap(config);
if (rc.skipDuringCreation() && dom.getKey() == null) {
// During creation the coresponding DOM is not fully loaded.
return true;
}
Collection<RemoteKeyInfo> remoteKeys = findRemoteKeys(config);
if (remoteKeys != null && !remoteKeys.isEmpty()) {
ServiceLocator habitat = dom.getHabitat();
boolean result = true;
boolean disableGlobalMessage = true;
for (RemoteKeyInfo remoteKeyInfo : remoteKeys) {
if (remoteKeyInfo.method.getParameterTypes().length > 0) {
throw new UnexpectedTypeException(localStrings.getLocalString("referenceValidator.not.getter", "The RemoteKey annotation must be on a getter method."));
}
try {
Object value = remoteKeyInfo.method.invoke(config);
if (value instanceof String) {
String key = (String) value;
ConfigBeanProxy component = habitat.getService(remoteKeyInfo.annotation.type(), key);
if (component == null) {
result = false;
if (remoteKeyInfo.annotation.message().isEmpty()) {
disableGlobalMessage = false;
} else {
cvc.buildConstraintViolationWithTemplate(remoteKeyInfo.annotation.message()).addNode(Dom.convertName(remoteKeyInfo.method.getName())).addConstraintViolation();
}
}
} else {
throw new UnexpectedTypeException(localStrings.getLocalString("referenceValidator.not.string", "The RemoteKey annotation must identify a method that returns a String."));
}
} catch (Exception ex) {
return false;
}
}
if (!result && disableGlobalMessage) {
cvc.disableDefaultConstraintViolation();
}
return result;
}
return true;
}
use of org.jvnet.hk2.config.Dom in project Payara by payara.
the class ServerHelper method translateAddressAndPort.
/**
* @param adminListener
* @param server
* @param config
* @return ret[0] == address, ret[1] == port
*/
private static String[] translateAddressAndPort(NetworkListener adminListener, Server server, Config config) {
NetworkListener adminListenerRaw = null;
String[] ret = new String[2];
String portString = null;
String addressString = null;
try {
Dom serverDom = Dom.unwrap(server);
Domain domain = serverDom.getHabitat().getService(Domain.class);
adminListenerRaw = GlassFishConfigBean.getRawView(adminListener);
portString = adminListenerRaw.getPort();
addressString = adminListenerRaw.getAddress();
PropertyResolver resolver = new PropertyResolver(domain, server.getName());
if (isToken(portString))
ret[1] = resolver.getPropertyValue(portString);
else
ret[1] = portString;
if (isToken(addressString))
ret[0] = resolver.getPropertyValue(addressString);
else
ret[0] = addressString;
} catch (ClassCastException e) {
// jc: workaround for issue 12354
// TODO severe error
ret[0] = translatePortOld(addressString, server, config);
ret[1] = translatePortOld(portString, server, config);
}
return ret;
}
Aggregations