use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ModuleConfigSource method deleteValue.
public boolean deleteValue(String propertyName) throws TransactionFailure {
boolean result = false;
Application app = domainConfiguration.getApplications().getApplication(configurationName);
if (app != null) {
Module m = app.getModule(moduleName);
for (Property object : m.getProperty()) {
if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(m), (ConfigBean) ConfigBean.unwrap(object));
result = true;
}
}
}
return result;
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ApplicationConfigSource method deleteValue.
public boolean deleteValue(String propertyName) throws TransactionFailure {
boolean result = false;
Application app = domainConfiguration.getApplications().getApplication(configurationName);
if (app != null) {
for (Property object : app.getProperty()) {
if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(app), (ConfigBean) ConfigBean.unwrap(object));
result = true;
}
}
}
return result;
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ServerConfigSource method deleteValue.
public boolean deleteValue(String propertyName) throws TransactionFailure {
boolean result = false;
Server config = domainConfiguration.getServerNamed(configurationName);
if (config != null) {
for (Property object : config.getProperty()) {
if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(config), (ConfigBean) ConfigBean.unwrap(object));
result = true;
}
}
}
return result;
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class WriteableView method commit.
/**
* Commit this Transaction.
*
* @param t the transaction commiting.
* @throws TransactionFailure
* if the transaction commit failed
*/
@Override
public synchronized List<PropertyChangeEvent> commit(Transaction t) throws TransactionFailure {
if (currentTx == t) {
currentTx = null;
}
// a key attribute must be non-null and have length >= 1
final ConfigBean master = getMasterView();
final String keyStr = master.model.key;
if (keyStr != null) {
final String key = stripMarkers(keyStr);
final String value = getPropertyValue(key);
if (value == null) {
throw new TransactionFailure("Key value cannot be null: " + key);
}
if (value.length() == 0) {
throw new TransactionFailure("Key value cannot be empty string: " + key);
}
}
try {
List<PropertyChangeEvent> appliedChanges = new ArrayList<>();
for (PropertyChangeEvent event : changedAttributes.values()) {
ConfigModel.Property property = bean.model.findIgnoreCase(event.getPropertyName());
ConfigBeanInterceptor<?> interceptor = bean.getOptionalFeature(ConfigBeanInterceptor.class);
try {
if (interceptor != null) {
interceptor.beforeChange(event);
}
} catch (PropertyVetoException e) {
throw new TransactionFailure(e.getMessage(), e);
}
property.set(bean, event.getNewValue());
if (interceptor != null) {
interceptor.afterChange(event, System.currentTimeMillis());
}
appliedChanges.add(event);
}
for (ProtectedList<?> entry : changedCollections.values()) {
commitListChanges(entry, appliedChanges);
}
changedAttributes.clear();
changedCollections.clear();
return appliedChanges;
} catch (TransactionFailure e) {
throw e;
} catch (Exception e) {
throw new TransactionFailure(e.getMessage(), e);
} finally {
bean.getLock().unlock();
}
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class DeleteModuleConfigCommand method deleteDependentConfigElement.
private void deleteDependentConfigElement(final ConfigBeanDefaultValue defaultValue) {
Class parentClass = configModularityUtils.getOwningClassForLocation(defaultValue.getLocation());
final Class configBeanClass = configModularityUtils.getClassForFullName(defaultValue.getConfigBeanClassName());
final Method m = configModularityUtils.findSuitableCollectionGetter(parentClass, configBeanClass);
if (m != null) {
try {
final ConfigBeanProxy parent = configModularityUtils.getOwningObject(defaultValue.getLocation());
ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {
@Override
public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
List col = null;
ConfigBeanProxy configBean = null;
try {
col = (List) m.invoke(param);
if (col != null) {
configBean = configModularityUtils.getCurrentConfigBeanForDefaultValue(defaultValue);
}
} catch (Exception e) {
String message = localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements ");
report.setMessage(message);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
LOG.log(Level.INFO, DELETE_MODULE_CONFIG_FAILED_DELETING_DEPENDENT, e);
}
if (configBean != null) {
boolean deleted = configModularityUtils.deleteConfigurationForConfigBean(configBean, col, defaultValue);
if (!deleted) {
for (int i = 0; i < col.size(); i++) {
if (configBeanClass.isAssignableFrom(col.get(i).getClass())) {
col.remove(col.get(i));
removeCustomTokens(defaultValue, configBean, parent);
return param;
}
}
}
}
return param;
}
}, parent);
} catch (Exception e) {
String message = localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements ");
report.setMessage(message);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
LOG.log(Level.INFO, DELETE_MODULE_CONFIG_FAILED_DELETING_DEPENDENT, e);
}
} else {
report.setMessage(localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements "));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
Aggregations