Skip to content

Commit

Permalink
Deprecate ExpressionResolver.DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
bstansberry committed Jan 19, 2013
1 parent fdd71d6 commit 360d847
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ protected AbstractControllerService(final ProcessType processType, final Running
final ControlledProcessState processState, final DescriptionProvider rootDescriptionProvider,
final OperationStepHandler prepareStep, final ExpressionResolver expressionResolver) {
assert rootDescriptionProvider != null : "Null root description provider";
assert expressionResolver != null : "Null expressionResolver";
this.processType = processType;
this.runningModeControl = runningModeControl;
this.configurationPersister = configurationPersister;
this.rootDescriptionProvider = rootDescriptionProvider;
this.rootResourceDefinition = null;
this.processState = processState;
this.prepareStep = prepareStep;
this.expressionResolver = expressionResolver != null ? expressionResolver : ExpressionResolver.DEFAULT;
this.expressionResolver = expressionResolver;
}

/**
Expand All @@ -149,14 +150,15 @@ protected AbstractControllerService(final ProcessType processType, final Running
final ControlledProcessState processState, final ResourceDefinition rootResourceDefinition,
final OperationStepHandler prepareStep, final ExpressionResolver expressionResolver) {
assert rootResourceDefinition != null : "Null root resource definition";
assert expressionResolver != null : "Null expressionResolver";
this.processType = processType;
this.runningModeControl = runningModeControl;
this.configurationPersister = configurationPersister;
this.rootDescriptionProvider = null;
this.rootResourceDefinition = rootResourceDefinition;
this.processState = processState;
this.prepareStep = prepareStep;
this.expressionResolver = expressionResolver != null ? expressionResolver : ExpressionResolver.DEFAULT;
this.expressionResolver = expressionResolver;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public final void validateAndSet(ModelNode operationObject, final ModelNode mode
*/
@Deprecated
public ModelNode validateResolvedOperation(final ModelNode operationObject) throws OperationFailedException {
return resolveModelAttribute(NO_OPERATION_CONTEXT_FOR_RESOLVING_MODEL_PARAMETERS, operationObject);
return resolveModelAttribute(ExpressionResolver.REJECTING, operationObject);
}

/**
Expand Down Expand Up @@ -623,11 +623,4 @@ public boolean isDeprecated() {
public DeprecationData getDeprecationData() {
return deprecationData;
}

private static final ExpressionResolver NO_OPERATION_CONTEXT_FOR_RESOLVING_MODEL_PARAMETERS = new ExpressionResolver() {
@Override
public ModelNode resolveExpressions(ModelNode node) throws OperationFailedException {
return ExpressionResolver.DEFAULT.resolveExpressions(node);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2603,4 +2603,6 @@ public interface ControllerMessages {
@Message(id = 14892, value = "Transforming operation %s at resource %s for host controller '%s' to subsystem '%s' model version '%s' -- attributes %s are not understood in that model version and this resource will need to be ignored on that host.")
OperationFailedException newAttributesSubsystemModelOperationTransformerFoundDefinedAttributes(ModelNode op, PathAddress pathAddress, String legacyHostName, String subsystem, ModelVersion modelVersion, Set<String> attributeNames);

@Message(id = 14893, value="Node contains an unresolved expression %s -- a resolved model is required")
OperationFailedException illegalUnresolvedModel(String expression);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
package org.jboss.as.controller;

import java.util.regex.Pattern;

import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

Expand All @@ -46,6 +48,36 @@ public interface ExpressionResolver {
*/
ModelNode resolveExpressions(ModelNode node) throws OperationFailedException;

/** Default {@code ExpressionResolver} that simply calls {@link ModelNode#resolve()}. */
ExpressionResolver DEFAULT = new ExpressionResolverImpl();
/**
* An {@code ExpressionResolver} suitable for test cases that simply calls {@link ModelNode#resolve()}.
* Should not be used for production code as it does not support resolution from a security vault.
*/
ExpressionResolver TEST_RESOLVER = new ExpressionResolverImpl();

/**
* Default {@code ExpressionResolver} that simply calls {@link ModelNode#resolve()}.
* Should not be used for production code as it does not support resolution from a security vault.
*
* @deprecated use {@link #TEST_RESOLVER} for test cases
*/
@Deprecated
ExpressionResolver DEFAULT = TEST_RESOLVER;

/**
* An expression resolver that throws an {@code OperationFailedException} if any expressions are found.
* Intended for use with APIs where an {@code ExpressionResolver} is required but the caller requires
* that all expression have already been resolved.
*/
ExpressionResolver REJECTING = new ExpressionResolverImpl() {
private final Pattern EXPRESSION_PATTERN = Pattern.compile(".*\\$\\{.*\\}.*");
@Override
protected void resolvePluggableExpression(ModelNode node) throws OperationFailedException {
String expression = node.asString();
if (EXPRESSION_PATTERN.matcher(expression).matches()) {
throw ControllerMessages.MESSAGES.illegalUnresolvedModel(expression);
}
// It wasn't an expression any way; convert the node to type STRING
node.set(expression);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final ModelNode resolveExpressions(final ModelNode node) throws Operation
}
}

private ModelNode resolveExpressionsRecursively(final ModelNode node) {
private ModelNode resolveExpressionsRecursively(final ModelNode node) throws OperationFailedException {
if (!node.isDefined()) {
return node;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ private ModelNode resolveExpressionsRecursively(final ModelNode node) {
return resolved;
}

protected void resolvePluggableExpression(ModelNode node) {
protected void resolvePluggableExpression(ModelNode node) throws OperationFailedException {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ private NamespaceAddHandler() {
}

protected void updateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
ModelNode ns = NAMESPACE.resolveModelAttribute(ExpressionResolver.DEFAULT, operation);
ModelNode uri = URI.resolveModelAttribute(ExpressionResolver.DEFAULT, operation);
ModelNode ns = NAMESPACE.resolveModelAttribute(ExpressionResolver.REJECTING, operation);
ModelNode uri = URI.resolveModelAttribute(ExpressionResolver.REJECTING, operation);
ModelNode namespaces = model.get(NAMESPACES);
validate(ns, namespaces);
namespaces.add(ns.asString(), uri.asString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ private SchemaLocationAddHandler() {
}

protected void updateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
ModelNode uri = URI.resolveModelAttribute(ExpressionResolver.DEFAULT, operation);
ModelNode location = SCHEMA_LOCATION.resolveModelAttribute(ExpressionResolver.DEFAULT, operation);
ModelNode uri = URI.resolveModelAttribute(ExpressionResolver.REJECTING, operation);
ModelNode location = SCHEMA_LOCATION.resolveModelAttribute(ExpressionResolver.REJECTING, operation);
ModelNode locations = model.get(SCHEMA_LOCATIONS);
validate(uri, locations);
locations.add(uri.asString(), location.asString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ExpressionResolverUnitTestCase {
@Test(expected = OperationFailedException.class)
public void testDefaultExpressionResolverWithNoResolutions() throws OperationFailedException {
ModelNode unresolved = createModelNode();
ExpressionResolver.DEFAULT.resolveExpressions(unresolved);
ExpressionResolver.TEST_RESOLVER.resolveExpressions(unresolved);
fail("Did not fail with ISE: " + unresolved);
}

Expand All @@ -49,7 +49,7 @@ public void testDefaultExpressionResolverWithSystemPropertyResolutions() throws
System.setProperty("test.prop.three", "THREE");
System.setProperty("test.prop.prop", "PROP");
try {
ModelNode node = ExpressionResolver.DEFAULT.resolveExpressions(createModelNode());
ModelNode node = ExpressionResolver.TEST_RESOLVER.resolveExpressions(createModelNode());
checkResolved(node);
} finally {
System.clearProperty("test.prop.expr");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ protected TestModelControllerService(final ConfigurationPersister configurationP

protected TestModelControllerService(final ProcessType processType, final ConfigurationPersister configurationPersister, final ControlledProcessState processState,
final ResourceDefinition rootDescriptionProvider) {
super(processType, new RunningModeControl(RunningMode.NORMAL), configurationPersister, processState, rootDescriptionProvider, null, ExpressionResolver.DEFAULT);
super(processType, new RunningModeControl(RunningMode.NORMAL), configurationPersister, processState, rootDescriptionProvider, null, ExpressionResolver.TEST_RESOLVER);
this.processState = processState;
}

protected TestModelControllerService(final ProcessType processType, final ConfigurationPersister configurationPersister, final ControlledProcessState processState,
final DescriptionProvider rootDescriptionProvider) {
super(processType, new RunningModeControl(RunningMode.NORMAL), configurationPersister, processState, rootDescriptionProvider, null, ExpressionResolver.DEFAULT);
super(processType, new RunningModeControl(RunningMode.NORMAL), configurationPersister, processState, rootDescriptionProvider, null, ExpressionResolver.TEST_RESOLVER);
this.processState = processState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ public interface ManagedServerBootConfiguration {
boolean isManagementSubsystemEndpoint();

/**
* Get the subsystem endpoint configuration, in case we use the subsystem.
* Get the subsystem endpoint configuration, in case we use the subsystem. This will be a
* resolved model node with no unresolved expressions. The model will not, however, store defaults.
*
* @return the subsystem endpoint config
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public abstract class ModelTestModelControllerService extends AbstractController

protected ModelTestModelControllerService(final ProcessType processType, final RunningModeControl runningModeControl, final TransformerRegistry transformerRegistry,
final StringConfigurationPersister persister, boolean validateOps, final DescriptionProvider rootDescriptionProvider, ControlledProcessState processState) {
// Fails in core-model-test transformation testing if ExpressionResolver.TEST_RESOLVER is used because not present in 7.1.x
super(processType, runningModeControl, persister,
processState == null ? new ControlledProcessState(true) : processState, rootDescriptionProvider, null, ExpressionResolver.DEFAULT);
this.persister = persister;
Expand All @@ -89,7 +90,7 @@ protected ModelTestModelControllerService(final ProcessType processType, final R
final StringConfigurationPersister persister, final boolean validateOps, final DelegatingResourceDefinition rootResourceDefinition, ControlledProcessState processState) {
super(processType, runningModeControl, persister,
processState == null ? new ControlledProcessState(true) : processState, rootResourceDefinition, null,
ExpressionResolver.DEFAULT);
ExpressionResolver.TEST_RESOLVER);
this.persister = persister;
this.transformerRegistry = transformerRegistry;
this.validateOps = validateOps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ModelNode getModelDescription(Locale locale) {
*/
protected PlatformMBeanTestModelControllerService() {
super(ProcessType.EMBEDDED_SERVER, new RunningModeControl(RunningMode.NORMAL), new NullConfigurationPersister(), new ControlledProcessState(true),
ResourceBuilder.Factory.create(PathElement.pathElement("root"),new NonResolvingResourceDescriptionResolver()).build(), null, ExpressionResolver.DEFAULT);
ResourceBuilder.Factory.create(PathElement.pathElement("root"),new NonResolvingResourceDescriptionResolver()).build(), null, ExpressionResolver.TEST_RESOLVER);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.as.clustering.infinispan.subsystem.EmbeddedCacheManagerService;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.ExpressionResolver;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
Expand Down Expand Up @@ -223,7 +222,7 @@ private boolean processMapping(OperationContext context, String securityDomain,
for (Property moduleProperty : node.asPropertyList()) {
ModelNode module = moduleProperty.getValue();
MappingInfo mappingInfo = new MappingInfo(securityDomain);
String codeName = extractCode(module, ModulesMap.MAPPING_MAP);
String codeName = extractCode(context, module, ModulesMap.MAPPING_MAP);

String mappingType;
if (module.hasDefined(TYPE)) {
Expand Down Expand Up @@ -327,7 +326,7 @@ private boolean processAuthorization(OperationContext context, String securityDo
AuthorizationInfo authzInfo = new AuthorizationInfo(securityDomain);
for (Property moduleProperty : node.asPropertyList()) {
ModelNode module = moduleProperty.getValue();
String codeName = extractCode(module, ModulesMap.AUTHORIZATION_MAP);
String codeName = extractCode(context, module, ModulesMap.AUTHORIZATION_MAP);
String flag = LoginModuleResourceDefinition.FLAG.resolveModelAttribute(context, module).asString();
ControlFlag controlFlag = ControlFlag.valueOf(flag);
Map<String, Object> options = extractOptions(context, module);
Expand Down Expand Up @@ -370,7 +369,7 @@ public void addAppConfigurationEntry(AppConfigurationEntry entry) {
}
for (Property moduleProperty : node.get(AUTH_MODULE).asPropertyList()) {
ModelNode authModule = moduleProperty.getValue();
String code = extractCode(authModule, ModulesMap.AUTHENTICATION_MAP);
String code = extractCode(context, authModule, ModulesMap.AUTHENTICATION_MAP);
String loginStackRef = null;
if (authModule.hasDefined(LOGIN_MODULE_STACK_REF)) {
loginStackRef = JASPIMappingModuleDefinition.LOGIN_MODULE_STACK_REF.resolveModelAttribute(context, authModule).asString();
Expand Down Expand Up @@ -398,8 +397,8 @@ public void addAppConfigurationEntry(AppConfigurationEntry entry) {
return true;
}

private static String extractCode(ModelNode node, Map<String, String> substitutions) throws OperationFailedException {
String code = LoginModuleResourceDefinition.CODE.resolveModelAttribute(ExpressionResolver.DEFAULT, node).asString();
private static String extractCode(OperationContext context, ModelNode node, Map<String, String> substitutions) throws OperationFailedException {
String code = LoginModuleResourceDefinition.CODE.resolveModelAttribute(context, node).asString();
if (substitutions.containsKey(code)) { code = substitutions.get(code); }
return code;
}
Expand Down Expand Up @@ -439,7 +438,7 @@ private void processLoginModules(OperationContext context, ModelNode node, BaseA
throws OperationFailedException {
for (Property moduleProperty : node.asPropertyList()) {
ModelNode module = moduleProperty.getValue();
String codeName = extractCode(module, ModulesMap.AUTHENTICATION_MAP);
String codeName = extractCode(context, module, ModulesMap.AUTHENTICATION_MAP);
String flag = LoginModuleResourceDefinition.FLAG.resolveModelAttribute(context, module).asString();
LoginModuleControlFlag controlFlag = getControlFlag(flag);
Map<String, Object> options = extractOptions(context, module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public void activate(final ServiceActivatorContext serviceActivatorContext) thro
final ServiceName endpointName = managementSubsystemEndpoint ? RemotingServices.SUBSYSTEM_ENDPOINT : ManagementRemotingServices.MANAGEMENT_ENDPOINT;
final EndpointService.EndpointType endpointType = managementSubsystemEndpoint ? EndpointService.EndpointType.SUBSYSTEM : EndpointService.EndpointType.MANAGEMENT;
try {
// TODO see if we can figure out a way to work in the vault resolver instead of having to use ExpressionResolver.DEFAULT
@SuppressWarnings("deprecation")
final OptionMap options = EndpointConfigFactory.create(ExpressionResolver.DEFAULT, endpointConfig, DEFAULTS);
ManagementRemotingServices.installRemotingEndpoint(serviceTarget, endpointName,
SecurityActions.getSystemProperty(ServerEnvironment.NODE_NAME), endpointType, options, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private static class ModelControllerService extends AbstractControllerService {


ModelControllerService(final ControlledProcessState processState, final StringConfigurationPersister persister, final DelegatingResourceDefinition rootResourceDefinition) {
super(ProcessType.EMBEDDED_SERVER, new RunningModeControl(RunningMode.ADMIN_ONLY), persister, processState, rootResourceDefinition, null, ExpressionResolver.DEFAULT);
super(ProcessType.EMBEDDED_SERVER, new RunningModeControl(RunningMode.ADMIN_ONLY), persister, processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER);
this.persister = persister;
this.processState = processState;
this.rootResourceDefinition = rootResourceDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ class ModelControllerService extends AbstractControllerService {

ModelControllerService(final ProcessType processType, final Setup registration, final ModelNode model) {
super(processType, new RunningModeControl(RunningMode.ADMIN_ONLY), new NullConfigurationPersister(), new ControlledProcessState(true),
ResourceBuilder.Factory.create(PathElement.pathElement("root"), new NonResolvingResourceDescriptionResolver()).build(), null, ExpressionResolver.DEFAULT);
ResourceBuilder.Factory.create(PathElement.pathElement("root"), new NonResolvingResourceDescriptionResolver()).build(), null, ExpressionResolver.TEST_RESOLVER);
this.model = model;
this.registration = registration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ public class ModelControllerService extends AbstractControllerService {

ModelControllerService() {
super(ProcessType.EMBEDDED_SERVER, new RunningModeControl(RunningMode.NORMAL), new TestConfigurationPersister(), new ControlledProcessState(true),
ResourceBuilder.Factory.create(PathElement.pathElement("root"), new NonResolvingResourceDescriptionResolver()).build(), null, ExpressionResolver.DEFAULT);
ResourceBuilder.Factory.create(PathElement.pathElement("root"), new NonResolvingResourceDescriptionResolver()).build(), null, ExpressionResolver.TEST_RESOLVER);
}

@Override
Expand Down
Loading

0 comments on commit 360d847

Please sign in to comment.