Skip to content

Commit

Permalink
Merge pull request #1472 from bstansberry/WFCORE-1450
Browse files Browse the repository at this point in the history
[WFCORE-1450] Use a copy constructor instead of a subclass
  • Loading branch information
bstansberry committed Mar 30, 2016
2 parents 14c8bee + 2041027 commit da8b13c
Showing 1 changed file with 51 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ResourceBuilderRoot implements ResourceBuilder {
private final List<AttributeBinding> attributes = new LinkedList<>();
private final List<OperationBinding> operations = new LinkedList<>();
private final List<Capability> capabilities = new LinkedList<>();
private ResourceDescriptionResolver attributeResolver = null;
private ResourceDescriptionResolver attributeResolver = null; // TODO field is never read except in copy c'tor
private OperationStepHandler addHandler;
private OperationStepHandler removeHandler;
private DeprecationData deprecationData;
Expand All @@ -53,6 +53,7 @@ class ResourceBuilderRoot implements ResourceBuilder {
private boolean isRuntime = false;


/** Normal constructor */
private ResourceBuilderRoot(PathElement pathElement, StandardResourceDescriptionResolver resourceResolver,
OperationStepHandler addHandler,
OperationStepHandler removeHandler,
Expand All @@ -64,6 +65,22 @@ private ResourceBuilderRoot(PathElement pathElement, StandardResourceDescription
this.removeHandler = removeHandler;
}

/**
* Copy constructor for {@link #pushChild(ResourceBuilder)} to use when integrating a child built externally.
*/
private ResourceBuilderRoot(final ResourceBuilderRoot toCopy, final ResourceBuilderRoot parent) {
this(toCopy.pathElement, toCopy.resourceResolver, toCopy.addHandler, toCopy.removeHandler, parent);
this.attributes.addAll(toCopy.attributes);
this.operations.addAll(toCopy.operations);
this.capabilities.addAll(toCopy.capabilities);
this.children.addAll(toCopy.children);
this.addHandler = toCopy.addHandler;
this.removeHandler = toCopy.removeHandler;
this.deprecationData = toCopy.deprecationData;
this.isRuntime = parent.isRuntime;
this.attributeResolver = toCopy.attributeResolver; // TODO Remove if this field is unneeded
}

static ResourceBuilder create(PathElement pathElement, StandardResourceDescriptionResolver resourceDescriptionResolver) {
return new ResourceBuilderRoot(pathElement, resourceDescriptionResolver, null, null, null);
}
Expand Down Expand Up @@ -198,7 +215,7 @@ public ResourceBuilder pushChild(final PathElement pathElement, StandardResource

@Override
public ResourceBuilder pushChild(final ResourceBuilder child) {
ResourceBuilderRoot childDelegate = new ChildBuilderDelegate((ResourceBuilderRoot) child, this);
ResourceBuilderRoot childDelegate = new ResourceBuilderRoot((ResourceBuilderRoot) child, this);
children.add(childDelegate);
return childDelegate;
}
Expand Down Expand Up @@ -273,55 +290,46 @@ public void registerChildren(ManagementResourceRegistration resourceRegistration
}
}

static final class ChildBuilderDelegate extends ResourceBuilderRoot {
ChildBuilderDelegate(final ResourceBuilderRoot child, final ResourceBuilderRoot parent) {
super(child.pathElement, child.resourceResolver, child.addHandler, child.removeHandler, parent);
getChildren().addAll(child.children);
getAttributes().addAll(child.attributes);
getOperations().addAll(child.operations);
private static final class AttributeBinding {
private final AttributeDefinition attribute;
private final OperationStepHandler readOp;
private final OperationStepHandler writeOp;
private final AttributeAccess.AccessType accessType;

AttributeBinding(AttributeDefinition attribute, OperationStepHandler readOp, OperationStepHandler writeOp, AttributeAccess.AccessType accessType) {
this.attribute = attribute;
this.readOp = readOp;
this.writeOp = writeOp;
this.accessType = accessType;
}
}
}

final class AttributeBinding {
private final AttributeDefinition attribute;
private final OperationStepHandler readOp;
private final OperationStepHandler writeOp;
private final AttributeAccess.AccessType accessType;

AttributeBinding(AttributeDefinition attribute, OperationStepHandler readOp, OperationStepHandler writeOp, AttributeAccess.AccessType accessType) {
this.attribute = attribute;
this.readOp = readOp;
this.writeOp = writeOp;
this.accessType = accessType;
}

void register(ManagementResourceRegistration registration) {
if (accessType == AttributeAccess.AccessType.READ_ONLY) {
registration.registerReadOnlyAttribute(attribute, readOp);
} else if (accessType == AttributeAccess.AccessType.READ_WRITE) {
registration.registerReadWriteAttribute(attribute, readOp, writeOp);
} else if (accessType == AttributeAccess.AccessType.METRIC) {
registration.registerMetric(attribute, readOp);
void register(ManagementResourceRegistration registration) {
if (accessType == AttributeAccess.AccessType.READ_ONLY) {
registration.registerReadOnlyAttribute(attribute, readOp);
} else if (accessType == AttributeAccess.AccessType.READ_WRITE) {
registration.registerReadWriteAttribute(attribute, readOp, writeOp);
} else if (accessType == AttributeAccess.AccessType.METRIC) {
registration.registerMetric(attribute, readOp);
}
}

}

}
private static final class OperationBinding {
private OperationDefinition definition;
private OperationStepHandler handler;
private boolean inherited;

final class OperationBinding {
private OperationDefinition definition;
private OperationStepHandler handler;
private boolean inherited;
OperationBinding(OperationDefinition definition, OperationStepHandler handler, boolean inherited) {
this.definition = definition;
this.handler = handler;
this.inherited = inherited;
}

OperationBinding(OperationDefinition definition, OperationStepHandler handler, boolean inherited) {
this.definition = definition;
this.handler = handler;
this.inherited = inherited;
public void register(ManagementResourceRegistration registration) {
registration.registerOperationHandler(definition, handler, inherited);
}
}

public void register(ManagementResourceRegistration registration) {
registration.registerOperationHandler(definition, handler, inherited);
}
}


0 comments on commit da8b13c

Please sign in to comment.