public Resource removeResource(final PathAddress requestAddress) { final PathAddress address = activeStep.address.append(requestAddress); assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null) { throw MESSAGES.operationAlreadyComplete(); } if (currentStage != Stage.MODEL) { throw MESSAGES.stageAlreadyComplete(Stage.MODEL); } if (!isModelAffected()) { takeWriteLock(); model = model.clone(); } affectsModel.put(address, NULL); Resource model = this.model; final Iterator<PathElement> i = address.iterator(); while (i.hasNext()) { final PathElement element = i.next(); if (element.isMultiTarget()) { throw MESSAGES.cannotRemove("*"); } if (!i.hasNext()) { model = model.removeChild(element); } else { model = requireChild(model, element, address); } } return model; }
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) { if (context.isResourceServiceRestartAllowed()) { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String name = address.getLastElement().getValue(); context.removeService(serviceName(name)); } else { context.reloadRequired(); } }
@Override public void parse( final XMLExtendedStreamReader reader, PathAddress parentAddress, List<ModelNode> list) throws XMLStreamException { if (getXmlWrapperElement() != null) { if (reader.getLocalName().equals(getXmlWrapperElement())) { if (reader.hasNext()) { if (reader.nextTag() == END_ELEMENT) { return; } } } else { throw ParseUtils.unexpectedElement(reader); } } boolean wildcard = getPathElement().isWildcard(); String name = null; ModelNode op = Util.createAddOperation(); Map<String, AttributeDefinition> attributes = getAttributeMap(); for (int i = 0; i < reader.getAttributeCount(); i++) { String attributeName = reader.getAttributeLocalName(i); String value = reader.getAttributeValue(i); if (wildcard && NAME.equals(attributeName)) { name = value; } else if (attributes.containsKey(attributeName)) { AttributeDefinition def = attributes.get(attributeName); if (def instanceof SimpleAttributeDefinition) { ((SimpleAttributeDefinition) def).parseAndSetParameter(value, op, reader); } else if (def instanceof StringListAttributeDefinition) { ((StringListAttributeDefinition) def).parseAndSetParameter(value, op, reader); } else { throw new IllegalArgumentException("we should know how to handle " + def); } } else { throw ParseUtils.unexpectedAttribute(reader, i); } } if (wildcard && name == null) { throw MESSAGES.missingRequiredAttributes(new StringBuilder(NAME), reader.getLocation()); } PathElement path = wildcard ? PathElement.pathElement(getPathElement().getKey(), name) : getPathElement(); PathAddress address = parentAddress.append(path); op.get(ADDRESS).set(address.toModelNode()); list.add(op); parseChildren(reader, address, list); if (getXmlWrapperElement() != null) { ParseUtils.requireNoContent(reader); } }
private static Resource requireChild( final Resource resource, final PathElement childPath, final PathAddress fullAddress) { if (resource.hasChild(childPath)) { return resource.requireChild(childPath); } else { PathAddress missing = PathAddress.EMPTY_ADDRESS; for (PathElement search : fullAddress) { missing = missing.append(search); if (search.equals(childPath)) { break; } } throw ControllerMessages.MESSAGES.managementResourceNotFound(missing); } }
public ModelNode readModelForUpdate(final PathAddress requestAddress) { final PathAddress address = activeStep.address.append(requestAddress); assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null) { throw MESSAGES.operationAlreadyComplete(); } if (currentStage != Stage.MODEL) { throw MESSAGES.stageAlreadyComplete(Stage.MODEL); } if (!isModelAffected()) { takeWriteLock(); model = model.clone(); } affectsModel.put(address, NULL); Resource model = this.model; final Iterator<PathElement> i = address.iterator(); while (i.hasNext()) { final PathElement element = i.next(); if (element.isMultiTarget()) { throw MESSAGES.cannotWriteTo("*"); } if (!i.hasNext()) { final String key = element.getKey(); if (!model.hasChild(element)) { final PathAddress parent = address.subAddress(0, address.size() - 1); final Set<String> childrenNames = modelController.getRootRegistration().getChildNames(parent); if (!childrenNames.contains(key)) { throw MESSAGES.noChildType(key); } final Resource newModel = Resource.Factory.create(); model.registerChild(element, newModel); model = newModel; } else { model = requireChild(model, element, address); } } else { model = requireChild(model, element, address); } } if (model == null) { throw new IllegalStateException(); } return model.getModel(); }
public void addResource(PathAddress relativeAddress, Resource toAdd) { final PathAddress absoluteAddress = activeStep.address.append(relativeAddress); assert isControllingThread(); Stage currentStage = this.currentStage; if (currentStage == null) { throw MESSAGES.operationAlreadyComplete(); } if (currentStage != Stage.MODEL) { throw MESSAGES.stageAlreadyComplete(Stage.MODEL); } if (absoluteAddress.size() == 0) { throw MESSAGES.duplicateResourceAddress(absoluteAddress); } if (!isModelAffected()) { takeWriteLock(); model = model.clone(); } affectsModel.put(absoluteAddress, NULL); Resource model = this.model; final Iterator<PathElement> i = absoluteAddress.iterator(); while (i.hasNext()) { final PathElement element = i.next(); if (element.isMultiTarget()) { throw MESSAGES.cannotWriteTo("*"); } if (!i.hasNext()) { final String key = element.getKey(); if (model.hasChild(element)) { throw MESSAGES.duplicateResourceAddress(absoluteAddress); } else { final PathAddress parent = absoluteAddress.subAddress(0, absoluteAddress.size() - 1); final Set<String> childrenNames = modelController.getRootRegistration().getChildNames(parent); if (!childrenNames.contains(key)) { throw MESSAGES.noChildType(key); } model.registerChild(element, toAdd); model = toAdd; } } else { model = model.getChild(element); if (model == null) { PathAddress ancestor = PathAddress.EMPTY_ADDRESS; for (PathElement pe : absoluteAddress) { ancestor = ancestor.append(pe); if (element.equals(pe)) { break; } } throw MESSAGES.resourceNotFound(ancestor, absoluteAddress); } } } }
/** * Determines the dynamic portion of the dependent capability's name. Only invoked if {@code * dynamicDependent} is set to {@code true} in the constructor. * * <p>This base implementation returns the value of the last element in {@code currentAddress}. * Subclasses that wish to extract the relevant name from some other element in the address may * override this. * * @param currentAddress the address of the resource currently being processed. Will not be * {@code null} * @return the dynamic portion of the dependenty capability name. Cannot be {@code null} */ protected String getDynamicDependentName(PathAddress currentAddress) { return currentAddress.getLastElement().getValue(); }