Skip to content

Commit

Permalink
AS7-1854 Add a basis for extensions to better encapsulate the notion …
Browse files Browse the repository at this point in the history
…of a 'resource'
  • Loading branch information
bstansberry committed Sep 20, 2011
1 parent b0014c6 commit f1e743c
Show file tree
Hide file tree
Showing 25 changed files with 594 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
import java.util.Set;

import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.DescriptionProviderFactory;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.as.controller.persistence.SubsystemXmlWriterRegistry;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.staxmapper.XMLElementWriter;
Expand Down Expand Up @@ -91,41 +89,33 @@ public ManagementResourceRegistration registerSubsystemModel(final DescriptionPr
if (descriptionProvider == null) {
throw new IllegalArgumentException("descriptionProvider is null");
}
return registerSubsystemModel(new DescriptionProviderFactory() {
@Override
public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration resourceRegistration) {
return descriptionProvider;
}
});
PathElement pathElement = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, name);
return registerSubsystemModel(new SimpleResourceDefinition(pathElement, descriptionProvider));
}

@Override
public ManagementResourceRegistration registerSubsystemModel(DescriptionProviderFactory descriptionProviderFactory) {
if (descriptionProviderFactory == null) {
public ManagementResourceRegistration registerSubsystemModel(ResourceDefinition resourceDefinition) {
if (resourceDefinition == null) {
throw new IllegalArgumentException("descriptionProviderFactory is null");
}
return profileRegistration.registerSubModel(new PathElement("subsystem", name), descriptionProviderFactory);
return profileRegistration.registerSubModel(resourceDefinition);
}

@Override
public ManagementResourceRegistration registerDeploymentModel(final DescriptionProvider descriptionProvider) {
if (descriptionProvider == null) {
throw new IllegalArgumentException("descriptionProvider is null");
}
return registerDeploymentModel(new DescriptionProviderFactory() {
@Override
public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration resourceRegistration) {
return descriptionProvider;
}
});
PathElement pathElement = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, name);
return registerDeploymentModel(new SimpleResourceDefinition(pathElement, descriptionProvider));
}

@Override
public ManagementResourceRegistration registerDeploymentModel(DescriptionProviderFactory descriptionProviderFactory) {
if (descriptionProviderFactory == null) {
public ManagementResourceRegistration registerDeploymentModel(ResourceDefinition resourceDefinition) {
if (resourceDefinition == null) {
throw new IllegalArgumentException("descriptionProviderFactory is null");
}
return subsystemDeploymentRegistration.registerSubModel(new PathElement("subsystem", name), descriptionProviderFactory);
return subsystemDeploymentRegistration.registerSubModel(resourceDefinition);
}

@Override
Expand Down Expand Up @@ -229,9 +219,9 @@ public ManagementResourceRegistration registerSubModel(PathElement address, Desc
}

@Override
public ManagementResourceRegistration registerSubModel(PathElement address, DescriptionProviderFactory descriptionProviderFactory) {
ManagementResourceRegistration depl = deployments.registerSubModel(address, descriptionProviderFactory);
ManagementResourceRegistration subdepl = subdeployments.registerSubModel(address, descriptionProviderFactory);
public ManagementResourceRegistration registerSubModel(ResourceDefinition resourceDefinition) {
ManagementResourceRegistration depl = deployments.registerSubModel(resourceDefinition);
ManagementResourceRegistration subdepl = subdeployments.registerSubModel(resourceDefinition);
return new DeploymentManagementResourceRegistration(depl, subdepl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,27 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.as.controller.descriptions;
package org.jboss.as.controller;

import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;

/**
* Factory for a {@link DescriptionProvider}.
* Provides essential information defining a management resource.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public interface DescriptionProviderFactory {
public interface ResourceDefinition {

/**
* Gets the path element that describes how to navigate to this resource from its parent resource, or {@code null}
* if this is a definition of a root resource.
*
* @return the path element, or {@code null} if this is a definition of a root resource.
*/
PathElement getPathElement();

/**
* Gets a {@link DescriptionProvider} for the given resource.
Expand All @@ -39,28 +50,17 @@ public interface DescriptionProviderFactory {
*/
DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration resourceRegistration);

/** A default implementation of this interface */
class DefaultFactory implements DescriptionProviderFactory {
public static DescriptionProviderFactory create(final String keyPrefix,
final String bundleBaseName,
final ClassLoader bundleLoader) {
StandardResourceDescriptionResolver resolver =
new StandardResourceDescriptionResolver(keyPrefix, bundleBaseName, bundleLoader);
return new DefaultFactory(resolver);
}

public static DescriptionProviderFactory create(ResourceDescriptionResolver descriptionResolver) {
return new DefaultFactory(descriptionResolver);
}

final ResourceDescriptionResolver descriptionResolver;
private DefaultFactory(final ResourceDescriptionResolver descriptionResolver) {
this.descriptionResolver = descriptionResolver;
}
/**
* Register operations associated with this resource.
*
* @param resourceRegistration a {@link ManagementResourceRegistration} created from this definition
*/
void registerOperations(final ManagementResourceRegistration resourceRegistration);

@Override
public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration resourceRegistration) {
return new DefaultResourceDescriptionProvider(resourceRegistration, descriptionResolver);
}
}
/**
* Register operations associated with this resource.
*
* @param resourceRegistration a {@link ManagementResourceRegistration} created from this definition
*/
void registerAttributes(final ManagementResourceRegistration resourceRegistration);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.as.controller;

import org.jboss.as.controller.descriptions.DefaultResourceAddDescriptionProvider;
import org.jboss.as.controller.descriptions.DefaultResourceDescriptionProvider;
import org.jboss.as.controller.descriptions.DefaultResourceRemoveDescriptionProvider;
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.ManagementResourceRegistration;

/**
* Basic implementation of {@link ResourceDefinition}.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class SimpleResourceDefinition implements ResourceDefinition {

private final PathElement pathElement;
private final ResourceDescriptionResolver descriptionResolver;
private final DescriptionProvider descriptionProvider;
private final OperationStepHandler addHandler;
private final OperationStepHandler removeHandler;

/**
* {@link ResourceDefinition} that uses the given {code descriptionProvider} to describe the resource.
*
* @param pathElement the path. Cannot be {@code null}.
* @param descriptionProvider the description provider. Cannot be {@code null}
*
* @throws IllegalArgumentException if any parameter is {@code null}.
*/
public SimpleResourceDefinition(final PathElement pathElement, final DescriptionProvider descriptionProvider) {
if (pathElement == null) {
throw new IllegalArgumentException("pathElement is null");
}
if (descriptionProvider == null) {
throw new IllegalArgumentException("descriptionProvider is null");
}
this.pathElement = pathElement;
this.descriptionResolver = null;
this.descriptionProvider = descriptionProvider;
this.addHandler = null;
this.removeHandler = null;
}

/**
* {@link ResourceDefinition} that uses the given {code descriptionResolver} to configure a
* {@link DefaultResourceDescriptionProvider} to describe the resource.
*
* @param pathElement the path. Cannot be {@code null}.
* @param descriptionResolver the description resolver to use in the description provider. Cannot be {@code null}
*
* @throws IllegalArgumentException if any parameter is {@code null}.
*/
public SimpleResourceDefinition(final PathElement pathElement, final ResourceDescriptionResolver descriptionResolver) {
this(pathElement, descriptionResolver, null, null);
}

/**
* {@link ResourceDefinition} that uses the given {code descriptionResolver} to configure a
* {@link DefaultResourceDescriptionProvider} to describe the resource.
*
* @param pathElement the path. Cannot be {@code null}.
* @param descriptionResolver the description resolver to use in the description provider. Cannot be {@code null} *
* @param addHandler a handler to {@link #registerOperations(ManagementResourceRegistration) register} for the resource "add" operation.
* Can be {@null}
* @param removeHandler a handler to {@link #registerOperations(ManagementResourceRegistration) register} for the resource "remove" operation.
* Can be {@null}
*
* @throws IllegalArgumentException if any parameter is {@code null}.
*/
public SimpleResourceDefinition(final PathElement pathElement, final ResourceDescriptionResolver descriptionResolver,
final OperationStepHandler addHandler, final OperationStepHandler removeHandler) {
if (pathElement == null) {
throw new IllegalArgumentException("pathElement is null");
}
if (descriptionResolver == null) {
throw new IllegalArgumentException("descriptionResolver is null");
}
this.pathElement = pathElement;
this.descriptionResolver = descriptionResolver;
this.descriptionProvider = null;
this.addHandler = addHandler;
this.removeHandler = removeHandler;
}

@Override
public PathElement getPathElement() {
return pathElement;
}

@Override
public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration resourceRegistration) {
return descriptionProvider == null
? new DefaultResourceDescriptionProvider(resourceRegistration, descriptionResolver)
: descriptionProvider;
}

/**
* {@inheritDoc}
* Registers an add operation handler or a remove operation handler if one was provided to the constructor.
*/
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
if (addHandler != null) {
registerAddOperation(resourceRegistration, addHandler);
}
if (removeHandler != null) {
registerRemoveOperation(resourceRegistration, removeHandler);
}
}

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
// no-op
}

/**
* Gets the {@link ResourceDescriptionResolver} used by this resource definition, or {@code null}
* if a {@code ResourceDescriptionResolver} is not used.
*
* @return the resource description resolver, or {@code null}
*/
public ResourceDescriptionResolver getResourceDescriptionResolver() {
return descriptionResolver;
}

protected void registerAddOperation(final ManagementResourceRegistration registration, final OperationStepHandler handler) {
DescriptionProvider provider = handler instanceof DescriptionProvider
? (DescriptionProvider) handler
: new DefaultResourceAddDescriptionProvider(registration, descriptionResolver);
registration.registerOperationHandler(ModelDescriptionConstants.ADD, handler, provider);
}

protected void registerRemoveOperation(final ManagementResourceRegistration registration, final OperationStepHandler handler) {
DescriptionProvider provider = handler instanceof DescriptionProvider
? (DescriptionProvider) handler
: new DefaultResourceRemoveDescriptionProvider(descriptionResolver);
registration.registerOperationHandler(ModelDescriptionConstants.REMOVE, handler, provider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package org.jboss.as.controller;

import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.DescriptionProviderFactory;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.staxmapper.XMLElementWriter;
Expand All @@ -36,6 +35,7 @@
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
public interface SubsystemRegistration {

/**
* Get the model node registration for this subsystem.
*
Expand All @@ -48,10 +48,10 @@ public interface SubsystemRegistration {
/**
* Get the model node registration for this subsystem.
*
* @param descriptionProviderFactory factory for the provider of the description of the subsystem's root management resource
* @param resourceDefinition factory for the provider of the description of the subsystem's root management resource
* @return the subsystem-level model node registration
*/
ManagementResourceRegistration registerSubsystemModel(DescriptionProviderFactory descriptionProviderFactory);
ManagementResourceRegistration registerSubsystemModel(ResourceDefinition resourceDefinition);

/**
* Get the deployment model node registration for this subsystem.
Expand All @@ -64,10 +64,10 @@ public interface SubsystemRegistration {
/**
* Get the deployment model node registration for this subsystem.
*
* @param descriptionProviderFactory factory for the provider of the description of the subsystem's root deployment-level management resource
* @param resourceDefinition factory for the provider of the description of the subsystem's root deployment-level management resource
* @return the deployment-level model node registration
*/
ManagementResourceRegistration registerDeploymentModel(DescriptionProviderFactory descriptionProviderFactory);
ManagementResourceRegistration registerDeploymentModel(ResourceDefinition resourceDefinition);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.DescriptionProviderFactory;
import org.jboss.as.controller.registry.OperationEntry.EntryType;

/**
Expand All @@ -56,17 +57,12 @@ abstract class AbstractResourceRegistration implements ManagementResourceRegistr
/** {@inheritDoc} */
@Override
public final ManagementResourceRegistration registerSubModel(final PathElement address, final DescriptionProvider descriptionProvider) {
return registerSubModel(address, new DescriptionProviderFactory() {
@Override
public DescriptionProvider getDescriptionProvider(ImmutableManagementResourceRegistration resourceRegistration) {
return descriptionProvider;
}
});
return registerSubModel(new SimpleResourceDefinition(address, descriptionProvider));
}

/** {@inheritDoc} */
@Override
public abstract ManagementResourceRegistration registerSubModel(final PathElement address, final DescriptionProviderFactory descriptionProviderFactory);
public abstract ManagementResourceRegistration registerSubModel(final ResourceDefinition resourceDefinition);

/** {@inheritDoc} */
@Override
Expand Down
Loading

0 comments on commit f1e743c

Please sign in to comment.