use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.
the class AbstractConfigModularityCommand method getAccessChecksForDefaultValue.
protected Collection<AccessRequired.AccessCheck> getAccessChecksForDefaultValue(List<ConfigBeanDefaultValue> values, String target, List<String> actions) {
Collection<AccessRequired.AccessCheck> checks = new ArrayList<AccessRequired.AccessCheck>();
for (ConfigBeanDefaultValue val : values) {
String location = val.getLocation();
for (String s : actions) {
AccessRequired.AccessCheck check = new AccessRequired.AccessCheck(configModularityUtils.getOwningObject(location), s, true);
checks.add(check);
}
}
return checks;
}
use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.
the class DeleteModuleConfigCommand method execute.
@Override
public void execute(AdminCommandContext context) {
report = context.getActionReport();
if (target != null) {
Config newConfig = getConfigForName(target, serviceLocator, domain);
if (newConfig != null) {
config = newConfig;
}
if (config == null) {
report.setMessage(localStrings.getLocalString("delete.module.config.target.name.invalid", "The target name specified is invalid. Please double check the target name and try again."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
if (serviceName == null) {
report.setMessage(localStrings.getLocalString("delete.module.config.service.name.is.required", "The service name is required, please specify which service you want to delete its default configuration."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
final String className = configModularityUtils.convertConfigElementNameToClassName(serviceName);
Class configBeanType = configModularityUtils.getClassFor(serviceName);
if (configBeanType == null) {
String msg = localStrings.getLocalString("delete.module.config.not.such.a.service.found", "Your service name does not match any service installed on this domain.");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (configModularityUtils.hasCustomConfig(configBeanType)) {
List<ConfigBeanDefaultValue> defaults = configModularityUtils.getDefaultConfigurations(configBeanType, configModularityUtils.getRuntimeTypePrefix(serverenv.getStartupContext()));
deleteDependentConfigElements(defaults);
} else {
deleteTopLevelExtensionByType(config, className, configBeanType);
}
}
use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue 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 com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.
the class GetActiveConfigCommand method getCompleteConfiguration.
private String getCompleteConfiguration(List<ConfigBeanDefaultValue> defaults) throws InvocationTargetException, IllegalAccessException {
StringBuilder builder = new StringBuilder();
for (ConfigBeanDefaultValue value : defaults) {
builder.append(localStrings.getLocalString("at.location", "At Location: "));
builder.append(replaceExpressionsWithValues(value.getLocation()));
builder.append(LINE_SEPARATOR);
String substituted = configModularityUtils.replacePropertiesWithCurrentValue(getDependentConfigElement(value), value);
builder.append(substituted);
builder.append(LINE_SEPARATOR);
}
builder.deleteCharAt(builder.length() - 1);
return builder.toString();
}
use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.
the class ConfigModularityUtils method getDefaultConfigurations.
/**
* If exists, locate and return a URL to the configuration snippet for the given config bean class.
*
* @param configBeanClass the config bean type we want to check for its configuration snippet
* @return A url to the file or null of not exists
*/
public List<ConfigBeanDefaultValue> getDefaultConfigurations(Class configBeanClass, String runtimeType) {
// Determine if it is DAS or instance
CustomConfiguration c = (CustomConfiguration) configBeanClass.getAnnotation(CustomConfiguration.class);
List<ConfigBeanDefaultValue> defaults = Collections.emptyList();
if (c.usesOnTheFlyConfigGeneration()) {
Method m = getGetDefaultValuesMethod(configBeanClass);
if (m != null) {
try {
defaults = (List<ConfigBeanDefaultValue>) m.invoke(null, runtimeType);
} catch (Exception e) {
LogHelper.log(LOG, Level.INFO, cannotGetDefaultConfig, e, configBeanClass.getName());
}
}
} else {
// TODO properly handle the exceptions
LocalStringManager localStrings = new LocalStringManagerImpl(configBeanClass);
ModuleXMLConfigurationFileParser parser = new ModuleXMLConfigurationFileParser(localStrings);
try {
defaults = parser.parseServiceConfiguration(getConfigurationFileUrl(configBeanClass, c.baseConfigurationFileName(), runtimeType).openStream());
} catch (XMLStreamException e) {
LOG.log(Level.SEVERE, cannotParseDefaultDefaultConfig, e);
} catch (IOException e) {
LOG.log(Level.SEVERE, cannotParseDefaultDefaultConfig, e);
}
}
return defaults;
}
Aggregations