Java Code Examples for org.jboss.as.controller.PathAddress#iterator()

The following examples show how to use org.jboss.as.controller.PathAddress#iterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathAddressFilter.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public boolean accepts(PathAddress address) {
    final Iterator<PathElement> i = address.iterator();
    Node node = this.node;
    while (i.hasNext()) {
        final PathElement element = i.next();
        final Node key = node.children.get(element.getKey());
        if (key == null) {
            return node.accept;
        }
        node = key.children.get(element.getValue());
        if (node == null) {
            node = key.children.get("*");
        }
        if (node == null) {
            return key.accept;
        }
        if (!i.hasNext()) {
            return node.accept;
        }
    }
    return accept;
}
 
Example 2
Source File: PathAddressFilter.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void addReject(final PathAddress address) {
    final Iterator<PathElement> i = address.iterator();
    Node node = this.node;
    while (i.hasNext()) {

        final PathElement element = i.next();
        final String elementKey = element.getKey();
        Node key = node.children.get(elementKey);
        if (key == null) {
            key = new Node(element.getKey());
            node.children.put(elementKey, key);
        }
        final String elementValue = element.getValue();
        Node value = key.children.get(elementValue);
        if (value == null) {
            value = new Node(elementValue);
            key.children.put(elementValue, value);
        }
        if (!i.hasNext()) {
            value.accept = false;
        }
    }
}
 
Example 3
Source File: ConcreteNotificationHandlerRegistration.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerNotificationHandler(PathAddress source, NotificationHandler handler, NotificationFilter filter) {
    NotificationHandlerEntry entry = new NotificationHandlerEntry(handler, filter);
    if (source == ANY_ADDRESS) {
        anyAddressEntries.add(entry);
        return;
    }

    ListIterator<PathElement> iterator = source.iterator();
    rootRegistry.registerEntry(iterator, entry);
}
 
Example 4
Source File: ConcreteNotificationHandlerRegistration.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void unregisterNotificationHandler(PathAddress source, NotificationHandler handler, NotificationFilter filter) {
    NotificationHandlerEntry entry = new NotificationHandlerEntry(handler, filter);
    if (source == ANY_ADDRESS) {
        anyAddressEntries.remove(entry);
        return;
    }

    ListIterator<PathElement> iterator = source.iterator();
    rootRegistry.unregisterEntry(iterator, entry);
}
 
Example 5
Source File: OperationTransformerRegistry.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Resolve an operation transformer entry.
 *
 * @param address the address
 * @param operationName the operation name
 * @param placeholderResolver a placeholder resolver used to resolve children of a placeholder registration
 * @return the transformer entry
 */
public OperationTransformerEntry resolveOperationTransformer(final PathAddress address, final String operationName, PlaceholderResolver placeholderResolver) {
    final Iterator<PathElement> iterator = address.iterator();
    final OperationTransformerEntry entry = resolveOperationTransformer(iterator, operationName, placeholderResolver);
    if(entry != null) {
        return entry;
    }
    // Default is forward unchanged
    return FORWARD;
}
 
Example 6
Source File: OperationTransformerRegistry.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get a list of path transformers for a given address.
 *
 * @param address the path address
 * @param placeholderResolver a placeholder resolver used to resolve children of a placeholder registration
 * @return a list of path transformations
 */
public List<PathAddressTransformer> getPathTransformations(final PathAddress address, PlaceholderResolver placeholderResolver) {
    final List<PathAddressTransformer> list = new ArrayList<PathAddressTransformer>();
    final Iterator<PathElement> iterator = address.iterator();
    resolvePathTransformers(iterator, list, placeholderResolver);
    if(iterator.hasNext()) {
        while(iterator.hasNext()) {
            iterator.next();
            list.add(PathAddressTransformer.DEFAULT);
        }
    }
    return list;
}
 
Example 7
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create a resource based on the result of the {@code ReadMasterDomainModelHandler}.
 *
 * @param result        the operation result
 * @param extensions    set to track extensions
 * @return the resource
 */
static Resource createResourceFromDomainModelOp(final ModelNode result, final Set<String> extensions) {
    final Resource root = Resource.Factory.create();
    for (ModelNode model : result.asList()) {

        final PathAddress resourceAddress = PathAddress.pathAddress(model.require(DOMAIN_RESOURCE_ADDRESS));

        if (resourceAddress.size() == 1) {
            final PathElement element = resourceAddress.getElement(0);
            if (element.getKey().equals(EXTENSION)) {
                if (!extensions.contains(element.getValue())) {
                    extensions.add(element.getValue());
                }
            }
        }

        Resource resource = root;
        final Iterator<PathElement> i = resourceAddress.iterator();
        if (!i.hasNext()) { //Those are root attributes
            resource.getModel().set(model.require(DOMAIN_RESOURCE_MODEL));
        }
        while (i.hasNext()) {
            final PathElement e = i.next();

            if (resource.hasChild(e)) {
                resource = resource.getChild(e);
            } else {
                /*
                {
                    "domain-resource-address" => [
                        ("profile" => "test"),
                        ("subsystem" => "test")
                    ],
                    "domain-resource-model" => {},
                    "domain-resource-properties" => {"ordered-child-types" => ["ordered-child"]}
                }*/
                final Resource nr;
                if (model.hasDefined(DOMAIN_RESOURCE_PROPERTIES, ORDERED_CHILD_TYPES_PROPERTY)) {
                    List<ModelNode> list = model.get(DOMAIN_RESOURCE_PROPERTIES, ORDERED_CHILD_TYPES_PROPERTY).asList();
                    Set<String> orderedChildTypes = new HashSet<String>(list.size());
                    for (ModelNode type : list) {
                        orderedChildTypes.add(type.asString());
                    }
                    nr = Resource.Factory.create(false, orderedChildTypes);
                } else {
                    nr = Resource.Factory.create();
                }
                resource.registerChild(e, nr);
                resource = nr;
            }

            if (!i.hasNext()) {
                resource.getModel().set(model.require(DOMAIN_RESOURCE_MODEL));
            }
        }
    }
    return root;
}
 
Example 8
Source File: ResourceTransformationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ResourceTransformationContext addTransformedRecursiveResourceFromRoot(final PathAddress absoluteAddress, final PathAddress read, final Resource toAdd) {
    Resource model = this.root;
    Resource parent = null;
    if (absoluteAddress.size() > 0) {
        final Iterator<PathElement> i = absoluteAddress.iterator();
        while (i.hasNext()) {
            final PathElement element = i.next();
            if (element.isMultiTarget()) {
                throw ControllerLogger.ROOT_LOGGER.cannotWriteTo("*");
            }
            if (!i.hasNext()) {
                if (model.hasChild(element)) {
                    throw ControllerLogger.ROOT_LOGGER.duplicateResourceAddress(absoluteAddress);
                } else {
                    parent = model;
                    model.registerChild(element, toAdd);
                    model = toAdd;
                    if (read.size() > 0) {
                        //We might be able to deal with this better in the future, but for now
                        //throw an error if the address was renamed and it was an ordered child type.
                        Set<String> parentOrderedChildren = parent.getOrderedChildTypes();
                        String readType = read.getLastElement().getKey();
                        if (parentOrderedChildren.contains(readType)) {
                            if (absoluteAddress.size() == 0 || !absoluteAddress.getLastElement().getKey().equals(readType)) {
                                throw ControllerLogger.ROOT_LOGGER.orderedChildTypeRenamed(read, absoluteAddress, readType, parentOrderedChildren);
                            }
                        }
                    }
                }
            } 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 ControllerLogger.ROOT_LOGGER.resourceNotFound(ancestor, absoluteAddress);
                }
            }
        }
    } else {
        //If this was the root address, replace the resource model
        model.writeModel(toAdd.getModel());
    }
    return new ResourceTransformationContextImpl(root, absoluteAddress, read, originalModel,
            transformerOperationAttachment, ignoredTransformationRegistry);
}
 
Example 9
Source File: ValidateAddressOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    ModelNode addr = VALUE_PARAM.validateOperation(operation);
    final PathAddress pathAddr = PathAddress.pathAddress(addr);
    Resource model = context.readResource(PathAddress.EMPTY_ADDRESS);
    final Iterator<PathElement> iterator = pathAddr.iterator();
    PathAddress current = PathAddress.EMPTY_ADDRESS;
    out: while(iterator.hasNext()) {
        final PathElement next = iterator.next();
        current = current.append(next);

        // Check if the registration is a proxy and dispatch directly
        final ImmutableManagementResourceRegistration registration = context.getResourceRegistration().getSubModel(current);

        if(registration != null && registration.isRemote()) {

            // If the target is a registered proxy return immediately
            if(! iterator.hasNext()) {
                break out;
            }

            // Create the proxy op
            final PathAddress newAddress = pathAddr.subAddress(current.size());
            final ModelNode newOperation = operation.clone();
            newOperation.get(OP_ADDR).set(current.toModelNode());
            newOperation.get(VALUE).set(newAddress.toModelNode());

            // On the DC the host=master is not a proxy but the validate-address is registered at the root
            // Otherwise delegate to the proxy handler
            final OperationStepHandler proxyHandler = registration.getOperationHandler(PathAddress.EMPTY_ADDRESS, OPERATION_NAME);
            if(proxyHandler != null) {
                context.addStep(newOperation, proxyHandler, OperationContext.Stage.MODEL, true);
                return;
            }

        } else if (model.hasChild(next)) {
            model = model.getChild(next);
        } else {
            // Invalid
            context.getResult().get(VALID).set(false);
            context.getResult().get(PROBLEM).set(ControllerLogger.ROOT_LOGGER.childResourceNotFound(next));
            return;
        }
    }

    if (authorize(context, current, operation).getDecision() == Decision.DENY) {
        context.getResult().get(VALID).set(false);
        context.getResult().get(PROBLEM).set(ControllerLogger.ROOT_LOGGER.managementResourceNotFoundMessage(current));
    } else {
        context.getResult().get(VALID).set(true);
    }
}
 
Example 10
Source File: OperationTransformerRegistry.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public OperationTransformerRegistry getChild(final PathAddress address) {
    final Iterator<PathElement> iterator = address.iterator();
    return resolveChild(iterator);
}