Java Code Examples for com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages

The following examples show how to use com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages. These examples are extracted from open source projects. 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
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example 2
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 3
/**
 * Method checks if the storage type is supported and transforms it to XMLEventReader instance which is then returned.
 * Throws PolicyException if the transformation is not succesfull or if the storage type is not supported.
 *
 * @param storage An XMLEventReader instance.
 * @return The storage cast to an XMLEventReader.
 * @throws PolicyException If the XMLEventReader cast failed.
 */
private XMLEventReader createXMLEventReader(final Object storage)
        throws PolicyException {
    if (storage instanceof XMLEventReader) {
        return (XMLEventReader) storage;
    }
    else if (!(storage instanceof Reader)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0022_STORAGE_TYPE_NOT_SUPPORTED(storage.getClass().getName())));
    }

    try {
        return XMLInputFactory.newInstance().createXMLEventReader((Reader) storage);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0014_UNABLE_TO_INSTANTIATE_READER_FOR_STORAGE(), e));
    }

}
 
Example 4
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example 5
/**
 * Method checks if the storage type is supported and transforms it to XMLEventReader instance which is then returned.
 * Throws PolicyException if the transformation is not succesfull or if the storage type is not supported.
 *
 * @param storage An XMLEventReader instance.
 * @return The storage cast to an XMLEventReader.
 * @throws PolicyException If the XMLEventReader cast failed.
 */
private XMLEventReader createXMLEventReader(final Object storage)
        throws PolicyException {
    if (storage instanceof XMLEventReader) {
        return (XMLEventReader) storage;
    }
    else if (!(storage instanceof Reader)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0022_STORAGE_TYPE_NOT_SUPPORTED(storage.getClass().getName())));
    }

    try {
        return XMLInputFactory.newInstance().createXMLEventReader((Reader) storage);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0014_UNABLE_TO_INSTANTIATE_READER_FOR_STORAGE(), e));
    }

}
 
Example 6
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example 7
Source Project: openjdk-8   Source File: PolicyMap.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Places new subject into policy map under the scope identified by it's type and policy map key.
 *
 * @param scopeType the type of the scope the subject belongs to
 * @param key a policy map key to be used to store the subject
 * @param subject actual policy subject to be stored in the policy map
 *
 * @throw IllegalArgumentException in case the scope type is not recognized.
 */
void putSubject(final ScopeType scopeType, final PolicyMapKey key, final PolicySubject subject) {
    switch (scopeType) {
        case SERVICE:
            serviceMap.putSubject(key, subject);
            break;
        case ENDPOINT:
            endpointMap.putSubject(key, subject);
            break;
        case OPERATION:
            operationMap.putSubject(key, subject);
            break;
        case INPUT_MESSAGE:
            inputMessageMap.putSubject(key, subject);
            break;
        case OUTPUT_MESSAGE:
            outputMessageMap.putSubject(key, subject);
            break;
        case FAULT_MESSAGE:
            faultMessageMap.putSubject(key, subject);
            break;
        default:
            throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType)));
    }
}
 
Example 8
Source Project: openjdk-jdk9   Source File: ModelNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
void setReferencedModel(final PolicySourceModel model) {
    if (this.type != Type.POLICY_REFERENCE) {
        throw LOGGER.logSevereException(new UnsupportedOperationException(LocalizationMessages.WSP_0050_OPERATION_NOT_SUPPORTED_FOR_THIS_BUT_POLICY_REFERENCE_NODE_TYPE(type)));
    }

    referencedModel = model;
}
 
Example 9
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
    XMLEvent event = null;
    while (reader.hasNext()) {
        try {
            event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.CHARACTERS:
                    processCharacters(event.asCharacters(), parentElement, map);
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    processEndTag(event.asEndElement(), parentElement);
                    reader.nextEvent();
                    return map;

                case XMLStreamConstants.START_ELEMENT:
                    final StartElement element = event.asStartElement();
                    processStartTag(element, parentElement, reader, map);
                    break;

                case XMLStreamConstants.END_DOCUMENT:
                    return map;

                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
            }
        } catch (XMLStreamException e) {
            final Location location = event == null ? null : event.getLocation();
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
        }
    }
    return map;
}
 
Example 10
private void checkEndTagName(final QName expectedName, final EndElement element) throws PolicyException {
    final QName actualName = element.getName();
    if (!expectedName.equals(actualName)) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0091_END_ELEMENT_NO_MATCH(expectedName, element, element.getLocation())));
    }

}
 
Example 11
/**
 * See {@link PolicyModelUnmarshaller#unmarshalModel(Object) base method documentation}.
 */
public PolicySourceModel unmarshalModel(final Object storage) throws PolicyException {
    final XMLEventReader reader = createXMLEventReader(storage);
    PolicySourceModel model = null;

    loop:
    while (reader.hasNext()) {
        try {
            final XMLEvent event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break; // skipping the comments and start document events
                case XMLStreamConstants.CHARACTERS:
                    processCharacters(ModelNode.Type.POLICY, event.asCharacters(), null);
                    // we advance the reader only if there is no exception thrown from
                    // the processCharacters(...) call. Otherwise we don't modify the stream
                    reader.nextEvent();
                    break;
                case XMLStreamConstants.START_ELEMENT:
                    if (NamespaceVersion.resolveAsToken(event.asStartElement().getName()) == XmlToken.Policy) {
                        StartElement rootElement = reader.nextEvent().asStartElement();

                        model = initializeNewModel(rootElement);
                        unmarshalNodeContent(model.getNamespaceVersion(), model.getRootNode(), rootElement.getName(), reader);

                        break loop;
                    } else {
                        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST()));
                    }
                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST()));
            }
        } catch (XMLStreamException e) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
        }
    }
    return model;
}
 
Example 12
Source Project: openjdk-8-source   Source File: ModelNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method checks the PSM state machine if the creation of new child of given type is plausible for a node element
 * with type set to this type instance.
 *
 * @param childType The type.
 * @return True if the type is supported, false otherwise
 */
private boolean isChildTypeSupported(final Type childType) {
    switch (this) {
        case POLICY:
        case ALL:
        case EXACTLY_ONE:
            switch (childType) {
                case ASSERTION_PARAMETER_NODE:
                    return false;
                default:
                    return true;
            }
        case POLICY_REFERENCE:
            return false;
        case ASSERTION:
            switch (childType) {
                case POLICY:
                case POLICY_REFERENCE:
                case ASSERTION_PARAMETER_NODE:
                    return true;
                default:
                    return false;
            }
        case ASSERTION_PARAMETER_NODE:
            switch (childType) {
                case ASSERTION_PARAMETER_NODE:
                    return true;
                default:
                    return false;
            }
        default:
            throw LOGGER.logSevereException(new IllegalStateException(
                    LocalizationMessages.WSP_0060_POLICY_ELEMENT_TYPE_UNKNOWN(this)));
    }
}
 
Example 13
/**
 * Expands content of 'EXACTLY_ONE' node. Direct 'EXACTLY_ONE' child nodes are dissolved in the process.
 */
private Collection<ModelNode> expandsExactlyOneContent(final Collection<ModelNode> content) throws PolicyException {
    final Collection<ModelNode> result = new LinkedList<ModelNode>();

    final Queue<ModelNode> eoContentQueue = new LinkedList<ModelNode>(content);
    ModelNode node;
    while ((node = eoContentQueue.poll()) != null) {
        // dissolving direct 'EXACTLY_ONE' child nodes
        switch (node.getType()) {
            case POLICY :
            case ALL :
            case ASSERTION :
                result.add(node);
                break;
            case POLICY_REFERENCE :
                result.add(getReferencedModelRootNode(node));
                break;
            case EXACTLY_ONE :
                eoContentQueue.addAll(node.getChildren());
                break;
            default :
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0001_UNSUPPORTED_MODEL_NODE_TYPE(node.getType())));
        }
    }

    return result;
}
 
Example 14
Source Project: openjdk-8   Source File: PolicyMap.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static PolicyMapKey createOperationOrInputOutputMessageKey(final QName service, final QName port, final QName operation) {
    if (service == null || port == null || operation == null) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0029_SERVICE_PORT_OPERATION_PARAM_MUST_NOT_BE_NULL(service, port, operation)));
    }

    return new PolicyMapKey(service, port, operation, operationAndInputOutputMessageKeyHandler);
}
 
Example 15
/**
 * Return true if the value is "true" or "1". Return false if the value is
 * "false" or "0". Throw an exception otherwise. The test is case sensitive.
 *
 * @param value The String representation of the value. Must not be null.
 * @return True if the value is "true" or "1". False if the value is
 *   "false" or "0".
 * @throws PolicyException If the value is not "true", "false", "0" or "1".
 */
private boolean parseBooleanValue(String value) throws PolicyException {
    if ("true".equals(value) || "1".equals(value)) {
        return true;
    }
    else if ("false".equals(value) || "0".equals(value)) {
        return false;
    }
    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0095_INVALID_BOOLEAN_VALUE(value)));
}
 
Example 16
Source Project: hottub   Source File: PolicyMapMutator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * The method is used to connect the policy map mutator instance to the map it should mutate.
 *
 * @param map the policy map instance that will be mutable by this mutator.
 * @throws IllegalStateException in case this mutator object is already connected to a policy map.
 */
public void connect(final PolicyMap map) {
    if (isConnected()) {
        throw LOGGER.logSevereException(new IllegalStateException(LocalizationMessages.WSP_0044_POLICY_MAP_MUTATOR_ALREADY_CONNECTED()));
    }

    this.map = map;
}
 
Example 17
private String unmarshalNodeContent(final NamespaceVersion nsVersion, final ModelNode node, final QName nodeElementName, final XMLEventReader reader) throws PolicyException {
    StringBuilder valueBuffer = null;

    loop:
    while (reader.hasNext()) {
        try {
            final XMLEvent xmlParserEvent = reader.nextEvent();
            switch (xmlParserEvent.getEventType()) {
                case XMLStreamConstants.COMMENT:
                    break; // skipping the comments
                case XMLStreamConstants.CHARACTERS:
                    valueBuffer = processCharacters(node.getType(), xmlParserEvent.asCharacters(), valueBuffer);
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    checkEndTagName(nodeElementName, xmlParserEvent.asEndElement());
                    break loop; // data exctraction for currently processed policy node is done
                case XMLStreamConstants.START_ELEMENT:
                    final StartElement childElement = xmlParserEvent.asStartElement();

                    ModelNode childNode = addNewChildNode(nsVersion, node, childElement);
                    String value = unmarshalNodeContent(nsVersion, childNode, childElement.getName(), reader);

                    if (childNode.isDomainSpecific()) {
                        parseAssertionData(nsVersion, value, childNode, childElement);
                    }
                    break;
                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0011_UNABLE_TO_UNMARSHALL_POLICY_XML_ELEM_EXPECTED()));
            }
        } catch (XMLStreamException e) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
        }
    }

    return (valueBuffer == null) ? null : valueBuffer.toString().trim();
}
 
Example 18
/**
 * Iterates through all contained assertions and adds them to the info model.
 *
 * @param assertionParametersIterator The contained assertions.
 * @param assertionNode The node to which the assertions are added as child nodes
 */
protected void translate(final ModelNode assertionNode, final Iterator<PolicyAssertion> assertionParametersIterator) {
    while (assertionParametersIterator.hasNext()) {
        final PolicyAssertion assertionParameter = assertionParametersIterator.next();
        final AssertionData data = AssertionData.createAssertionParameterData(assertionParameter.getName(), assertionParameter.getValue(), assertionParameter.getAttributes());
        final ModelNode assertionParameterNode = assertionNode.createChildAssertionParameterNode(data);
        if (assertionParameter.hasNestedPolicy()) {
            throw LOGGER.logSevereException(new IllegalStateException(LocalizationMessages.WSP_0005_UNEXPECTED_POLICY_ELEMENT_FOUND_IN_ASSERTION_PARAM(assertionParameter)));
        }
        if (assertionParameter.hasNestedAssertions()) {
            translate(assertionParameterNode, assertionParameter.getNestedAssertionsIterator());
        }
    }
}
 
Example 19
Source Project: openjdk-jdk9   Source File: PolicySubject.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a policy subject instance.
 *
 * @param subject object to which the policies are attached. Must not be {@code null}.
 * @param policies first policy attached to the subject. Must not be {@code null}.
 *
 * @throws IllegalArgumentException in case any of the arguments is {@code null} or
 *         in case {@code policies} argument represents empty collection.
 */
public PolicySubject(Object subject, Collection<Policy> policies) throws IllegalArgumentException {
    if (subject == null || policies == null) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0062_INPUT_PARAMS_MUST_NOT_BE_NULL()));
    }

    if (policies.isEmpty()) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0064_INITIAL_POLICY_COLLECTION_MUST_NOT_BE_EMPTY()));
    }

    this.subject = subject;
    this.policies.addAll(policies);
}
 
Example 20
private void parseAssertionData(NamespaceVersion nsVersion, String value, ModelNode childNode, final StartElement childElement) throws IllegalArgumentException, PolicyException {
    // finish assertion node processing: create and set assertion data...
    final Map<QName, String> attributeMap = new HashMap<QName, String>();
    boolean optional = false;
    boolean ignorable = false;

    final Iterator iterator = childElement.getAttributes();
    while (iterator.hasNext()) {
        final Attribute nextAttribute = (Attribute) iterator.next();
        final QName name = nextAttribute.getName();
        if (attributeMap.containsKey(name)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0059_MULTIPLE_ATTRS_WITH_SAME_NAME_DETECTED_FOR_ASSERTION(nextAttribute.getName(), childElement.getName())));
        } else {
            if (nsVersion.asQName(XmlToken.Optional).equals(name)) {
                optional = parseBooleanValue(nextAttribute.getValue());
            } else if (nsVersion.asQName(XmlToken.Ignorable).equals(name)) {
                ignorable = parseBooleanValue(nextAttribute.getValue());
            } else {
                attributeMap.put(name, nextAttribute.getValue());
            }
        }
    }
    final AssertionData nodeData = new AssertionData(childElement.getName(), value, attributeMap, childNode.getType(), optional, ignorable);

    // check visibility value syntax if present...
    if (nodeData.containsAttribute(PolicyConstants.VISIBILITY_ATTRIBUTE)) {
        final String visibilityValue = nodeData.getAttributeValue(PolicyConstants.VISIBILITY_ATTRIBUTE);
        if (!PolicyConstants.VISIBILITY_VALUE_PRIVATE.equals(visibilityValue)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0004_UNEXPECTED_VISIBILITY_ATTR_VALUE(visibilityValue)));
        }
    }

    childNode.setOrReplaceNodeData(nodeData);
}
 
Example 21
/**
 * The method translates {@link PolicySourceModel} structure into normalized {@link Policy} expression. The resulting Policy
 * is disconnected from its model, thus any additional changes in model will have no effect on the Policy expression.
 *
 * @param model the model to be translated into normalized policy expression. Must not be {@code null}.
 * @return translated policy expression in it's normalized form.
 * @throws PolicyException in case of translation failure
 */
public Policy translate(final PolicySourceModel model) throws PolicyException {
    LOGGER.entering(model);

    if (model == null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0043_POLICY_MODEL_TRANSLATION_ERROR_INPUT_PARAM_NULL()));
    }

    PolicySourceModel localPolicyModelCopy;
    try {
        localPolicyModelCopy = model.clone();
    } catch (CloneNotSupportedException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0016_UNABLE_TO_CLONE_POLICY_SOURCE_MODEL(), e));
    }

    final String policyId = localPolicyModelCopy.getPolicyId();
    final String policyName = localPolicyModelCopy.getPolicyName();

    final Collection<AssertionSet> alternatives = createPolicyAlternatives(localPolicyModelCopy);
    LOGGER.finest(LocalizationMessages.WSP_0052_NUMBER_OF_ALTERNATIVE_COMBINATIONS_CREATED(alternatives.size()));

    Policy policy = null;
    if (alternatives.size() == 0) {
        policy = Policy.createNullPolicy(model.getNamespaceVersion(), policyName, policyId);
        LOGGER.finest(LocalizationMessages.WSP_0055_NO_ALTERNATIVE_COMBINATIONS_CREATED());
    } else if (alternatives.size() == 1 && alternatives.iterator().next().isEmpty()) {
        policy = Policy.createEmptyPolicy(model.getNamespaceVersion(), policyName, policyId);
        LOGGER.finest(LocalizationMessages.WSP_0026_SINGLE_EMPTY_ALTERNATIVE_COMBINATION_CREATED());
    } else {
        policy = Policy.createPolicy(model.getNamespaceVersion(), policyName, policyId, alternatives);
        LOGGER.finest(LocalizationMessages.WSP_0057_N_ALTERNATIVE_COMBINATIONS_M_POLICY_ALTERNATIVES_CREATED(alternatives.size(), policy.getNumberOfAssertionSets()));
    }

    LOGGER.exiting(policy);
    return policy;
}
 
Example 22
Source Project: TencentKona-8   Source File: ModelNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
void setReferencedModel(final PolicySourceModel model) {
    if (this.type != Type.POLICY_REFERENCE) {
        throw LOGGER.logSevereException(new UnsupportedOperationException(LocalizationMessages.WSP_0050_OPERATION_NOT_SUPPORTED_FOR_THIS_BUT_POLICY_REFERENCE_NODE_TYPE(type)));
    }

    referencedModel = model;
}
 
Example 23
private static ModelNode getReferencedModelRootNode(final ModelNode policyReferenceNode) throws PolicyException {
    final PolicySourceModel referencedModel = policyReferenceNode.getReferencedModel();
    if (referencedModel == null) {
        final PolicyReferenceData refData = policyReferenceNode.getPolicyReferenceData();
        if (refData == null) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0041_POLICY_REFERENCE_NODE_FOUND_WITH_NO_POLICY_REFERENCE_IN_IT()));
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0010_UNEXPANDED_POLICY_REFERENCE_NODE_FOUND_REFERENCING(refData.getReferencedModelUri())));
        }
    } else {
        return referencedModel.getRootNode();
    }
}
 
Example 24
Source Project: openjdk-jdk8u   Source File: PolicyMap.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static PolicyMapKey createOperationOrInputOutputMessageKey(final QName service, final QName port, final QName operation) {
    if (service == null || port == null || operation == null) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0029_SERVICE_PORT_OPERATION_PARAM_MUST_NOT_BE_NULL(service, port, operation)));
    }

    return new PolicyMapKey(service, port, operation, operationAndInputOutputMessageKeyHandler);
}
 
Example 25
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
    XMLEvent event = null;
    while (reader.hasNext()) {
        try {
            event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.CHARACTERS:
                    processCharacters(event.asCharacters(), parentElement, map);
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    processEndTag(event.asEndElement(), parentElement);
                    reader.nextEvent();
                    return map;

                case XMLStreamConstants.START_ELEMENT:
                    final StartElement element = event.asStartElement();
                    processStartTag(element, parentElement, reader, map);
                    break;

                case XMLStreamConstants.END_DOCUMENT:
                    return map;

                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
            }
        } catch (XMLStreamException e) {
            final Location location = event == null ? null : event.getLocation();
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
        }
    }
    return map;
}
 
Example 26
private void processUri(final Characters chars, final Map<URI, Policy> map) throws PolicyException {
    final String data = chars.getData().trim();
    try {
        final URI uri = new URI(data);
        if (this.currentPolicy != null) {
            map.put(uri, this.currentPolicy);
            this.currentUri = null;
            this.currentPolicy = null;
        } else {
            this.currentUri = uri;
        }
    } catch (URISyntaxException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0093_INVALID_URI(data, chars.getLocation())), e);
    }
}
 
Example 27
Source Project: openjdk-8   Source File: PolicyScope.java    License: GNU General Public License v2.0 5 votes vote down vote up
void attach(final PolicySubject subject) {
    if (subject == null) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0020_SUBJECT_PARAM_MUST_NOT_BE_NULL()));
    }

    subjects.add(subject);
}
 
Example 28
private void parseAssertionData(NamespaceVersion nsVersion, String value, ModelNode childNode, final StartElement childElement) throws IllegalArgumentException, PolicyException {
    // finish assertion node processing: create and set assertion data...
    final Map<QName, String> attributeMap = new HashMap<QName, String>();
    boolean optional = false;
    boolean ignorable = false;

    final Iterator iterator = childElement.getAttributes();
    while (iterator.hasNext()) {
        final Attribute nextAttribute = (Attribute) iterator.next();
        final QName name = nextAttribute.getName();
        if (attributeMap.containsKey(name)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0059_MULTIPLE_ATTRS_WITH_SAME_NAME_DETECTED_FOR_ASSERTION(nextAttribute.getName(), childElement.getName())));
        } else {
            if (nsVersion.asQName(XmlToken.Optional).equals(name)) {
                optional = parseBooleanValue(nextAttribute.getValue());
            } else if (nsVersion.asQName(XmlToken.Ignorable).equals(name)) {
                ignorable = parseBooleanValue(nextAttribute.getValue());
            } else {
                attributeMap.put(name, nextAttribute.getValue());
            }
        }
    }
    final AssertionData nodeData = new AssertionData(childElement.getName(), value, attributeMap, childNode.getType(), optional, ignorable);

    // check visibility value syntax if present...
    if (nodeData.containsAttribute(PolicyConstants.VISIBILITY_ATTRIBUTE)) {
        final String visibilityValue = nodeData.getAttributeValue(PolicyConstants.VISIBILITY_ATTRIBUTE);
        if (!PolicyConstants.VISIBILITY_VALUE_PRIVATE.equals(visibilityValue)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0004_UNEXPECTED_VISIBILITY_ATTR_VALUE(visibilityValue)));
        }
    }

    childNode.setOrReplaceNodeData(nodeData);
}
 
Example 29
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
    XMLEvent event = null;
    while (reader.hasNext()) {
        try {
            event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.CHARACTERS:
                    processCharacters(event.asCharacters(), parentElement, map);
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    processEndTag(event.asEndElement(), parentElement);
                    reader.nextEvent();
                    return map;

                case XMLStreamConstants.START_ELEMENT:
                    final StartElement element = event.asStartElement();
                    processStartTag(element, parentElement, reader, map);
                    break;

                case XMLStreamConstants.END_DOCUMENT:
                    return map;

                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
            }
        } catch (XMLStreamException e) {
            final Location location = event == null ? null : event.getLocation();
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
        }
    }
    return map;
}
 
Example 30
@Override
public PolicySourceModel translate(final Policy policy) throws PolicyException {
    LOGGER.entering(policy);

    PolicySourceModel model = null;

    if (policy == null) {
        LOGGER.fine(LocalizationMessages.WSP_0047_POLICY_IS_NULL_RETURNING());
    } else {
        model = this.sourceModelCreator.create(policy);
        final ModelNode rootNode = model.getRootNode();
        final ModelNode exactlyOneNode = rootNode.createChildExactlyOneNode();
        for (AssertionSet set : policy) {
            final ModelNode alternativeNode = exactlyOneNode.createChildAllNode();
            for (PolicyAssertion assertion : set) {
                final AssertionData data = AssertionData.createAssertionData(assertion.getName(), assertion.getValue(), assertion.getAttributes(), assertion.isOptional(), assertion.isIgnorable());
                final ModelNode assertionNode = alternativeNode.createChildAssertionNode(data);
                if (assertion.hasNestedPolicy()) {
                    translate(assertionNode, assertion.getNestedPolicy());
                }
                if (assertion.hasParameters()) {
                    translate(assertionNode, assertion.getParametersIterator());
                }
            }
        }
    }

    LOGGER.exiting(model);
    return model;
}