use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ExtensionPatternInvocationImpl method handleExtension.
@Override
public ConfigBeanProxy handleExtension(Object owner, Class ownerType, Object[] params) {
if (((Class) params[0]).getName().equals("com.sun.enterprise.config.serverbeans.SystemProperty"))
return null;
ConfigBeanProxy configExtension = null;
List<ConfigBeanProxy> extensions = configModularityUtils.getExtensions(((ConfigBean) owner).createProxy(ownerType));
for (ConfigBeanProxy extension : extensions) {
try {
configExtension = (ConfigBeanProxy) ((Class) params[0]).cast(extension);
return configExtension;
} catch (Exception e) {
// ignore, not the right type.
}
}
try {
ConfigBeanProxy pr = ((ConfigBean) owner).createProxy(ownerType);
ConfigBeanProxy returnValue = moduleConfigurationLoader.createConfigBeanForType((Class) params[0], pr);
return returnValue;
} catch (TransactionFailure transactionFailure) {
LogHelper.log(LOG, Level.INFO, "Cannot get extension type {0} for {1}.", transactionFailure, new Object[] { owner.getClass().getName(), ownerType.getName() });
return null;
}
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ConfigurationParser method parseAndSetConfigBean.
/**
* @param <T> the ConfigBeanProxy type we are looking for
*/
public <T extends ConfigBeanProxy> void parseAndSetConfigBean(List<ConfigBeanDefaultValue> values) {
ConfigParser configParser = new ConfigParser(serviceLocator);
// I don't use the GlassFish document here as I don't need persistence
final DomDocument doc = new DomDocument<GlassFishConfigBean>(serviceLocator) {
@Override
public Dom make(final ServiceLocator serviceLocator, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
}
};
// the solution is to put the loop into the apply method... But it would be some fine amount of work
for (final ConfigBeanDefaultValue configBeanDefaultValue : values) {
final ConfigBeanProxy parent = configModularityUtils.getOwningObject(configBeanDefaultValue.getLocation());
if (parent == null)
continue;
ConfigurationPopulator populator = null;
if (replaceSystemProperties)
try {
populator = new ConfigurationPopulator(configModularityUtils.replacePropertiesWithCurrentValue(configBeanDefaultValue.getXmlConfiguration(), configBeanDefaultValue), doc, parent);
} catch (Exception e) {
LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
}
else {
// Check that parent is not null!
populator = new ConfigurationPopulator(configBeanDefaultValue.getXmlConfiguration(), doc, parent);
}
populator.run(configParser);
synchronized (configModularityUtils) {
boolean oldValue = configModularityUtils.isIgnorePersisting();
try {
Class configBeanClass = configModularityUtils.getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
final ConfigBeanProxy pr = doc.getRoot().createProxy(configBeanClass);
configModularityUtils.setIgnorePersisting(true);
ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {
public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
configModularityUtils.setConfigBean(pr, configBeanDefaultValue, param);
return param;
}
}, parent);
} catch (TransactionFailure e) {
LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
} finally {
configModularityUtils.setIgnorePersisting(oldValue);
}
}
}
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ConfigurationPopulator method run.
public void run(ConfigParser parser) {
try {
InputStream is = new ByteArrayInputStream(xmlContent.getBytes());
XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(is, "utf-8");
parser.parse(reader, doc, Dom.unwrap((ConfigBeanProxy) parent));
} catch (XMLStreamException e) {
LOG.log(Level.SEVERE, ConfigApiLoggerInfo.DEFAULT_CFG_READ_FAILED, e);
}
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class TemplateListOfResource method getElementTypeByName.
public static Class<? extends ConfigBeanProxy> getElementTypeByName(Dom parentDom, String elementName) throws ClassNotFoundException {
DomDocument document = parentDom.document;
ConfigModel.Property a = parentDom.model.getElement(elementName);
if (a != null) {
if (a.isLeaf()) {
// : I am not too sure, but that should be a String @Element
return null;
} else {
ConfigModel childModel = ((ConfigModel.Node) a).getModel();
return (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
}
}
// global lookup
ConfigModel model = document.getModelByElementName(elementName);
if (model != null) {
return (Class<? extends ConfigBeanProxy>) model.classLoaderHolder.loadClass(model.targetTypeName);
}
return null;
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class UpdateResourceRef method execute.
/**
* Execution method for updating the configuration of a ResourceRef. Will be
* replicated if the target is a cluster.
*
* @param context context for the command.
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
// Make a list of all ResourceRefs that need to change
List<ResourceRef> resourceRefsToChange = new ArrayList<>();
// Add the ResourceRef from a named server if the target is a server
Server server = domain.getServerNamed(target);
// if the target is a server
if (server != null) {
ResourceRef serverResourceRef = server.getResourceRef(name);
// if the ResourceRef doesn't exist
if (serverResourceRef == null) {
report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
return;
}
resourceRefsToChange.add(serverResourceRef);
}
// Add the ResourceRef from a named config if the target is a config
Config config = domain.getConfigNamed(target);
// if the target is a config
if (config != null) {
ResourceRef configResourceRef = config.getResourceRef(name);
// if the ResourceRef doesn't exist
if (configResourceRef == null) {
report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
return;
}
resourceRefsToChange.add(configResourceRef);
}
// Add the ResourceRefs from a named cluster if the target is a cluster
Cluster cluster = domain.getClusterNamed(target);
// if the target is a cluster
if (cluster != null) {
ResourceRef clusterResourceRef = cluster.getResourceRef(name);
// if the ResourceRef doesn't exist
if (clusterResourceRef == null) {
report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
return;
}
resourceRefsToChange.add(clusterResourceRef);
for (Server instance : cluster.getInstances()) {
ResourceRef instanceResourceRef = instance.getResourceRef(name);
// if the server in the cluster contains the ResourceRef
if (instanceResourceRef != null) {
resourceRefsToChange.add(instanceResourceRef);
}
}
}
// Add the ResourceRefs from a named Deployment Group if the target is a Deployment Group
DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
if (dg != null) {
ResourceRef ref = dg.getResourceRef(name);
if (ref == null) {
report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
return;
}
resourceRefsToChange.add(ref);
for (Server instance : dg.getInstances()) {
ResourceRef instanceResourceRef = instance.getResourceRef(name);
// if the server in the dg contains the ResourceRef
if (instanceResourceRef != null) {
resourceRefsToChange.add(instanceResourceRef);
}
}
}
// Apply the configuration to the listed ResourceRefs
try {
ConfigSupport.apply(new ConfigCode() {
@Override
public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
for (ConfigBeanProxy proxy : params) {
if (proxy instanceof ResourceRef) {
ResourceRef resourceRefProxy = (ResourceRef) proxy;
if (enabled != null) {
resourceRefProxy.setEnabled(enabled.toString());
}
}
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return true;
}
}, resourceRefsToChange.toArray(new ResourceRef[] {}));
} catch (TransactionFailure ex) {
report.failure(logger, ex.getLocalizedMessage());
}
}
Aggregations