325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.policy.sourcemodel;
325N/A
325N/Aimport com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages;
325N/Aimport com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
325N/Aimport com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
325N/Aimport java.net.URI;
325N/Aimport java.net.URISyntaxException;
325N/A
325N/A/**
325N/A *
325N/A * @author Marek Potociar
325N/A */
325N/Afinal class PolicyReferenceData {
325N/A private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyReferenceData.class);
325N/A
325N/A private static final URI DEFAULT_DIGEST_ALGORITHM_URI;
325N/A private static final URISyntaxException CLASS_INITIALIZATION_EXCEPTION;
325N/A static {
325N/A URISyntaxException tempEx = null;
325N/A URI tempUri = null;
325N/A try {
325N/A tempUri = new URI("http://schemas.xmlsoap.org/ws/2004/09/policy/Sha1Exc");
325N/A } catch (URISyntaxException e) {
325N/A tempEx = e;
325N/A } finally {
325N/A DEFAULT_DIGEST_ALGORITHM_URI = tempUri;
325N/A CLASS_INITIALIZATION_EXCEPTION = tempEx;
325N/A }
325N/A }
325N/A
325N/A private final URI referencedModelUri;
325N/A private final String digest;
325N/A private final URI digestAlgorithmUri;
325N/A
325N/A /** Creates a new instance of PolicyReferenceData */
325N/A public PolicyReferenceData(URI referencedModelUri) {
325N/A this.referencedModelUri = referencedModelUri;
325N/A this.digest = null;
325N/A this.digestAlgorithmUri = null;
325N/A }
325N/A
325N/A public PolicyReferenceData(URI referencedModelUri, String expectedDigest, URI usedDigestAlgorithm) {
325N/A if (CLASS_INITIALIZATION_EXCEPTION != null) {
325N/A throw LOGGER.logSevereException(new IllegalStateException(LocalizationMessages.WSP_0015_UNABLE_TO_INSTANTIATE_DIGEST_ALG_URI_FIELD(), CLASS_INITIALIZATION_EXCEPTION));
325N/A }
325N/A
325N/A if (usedDigestAlgorithm != null && expectedDigest == null) {
325N/A throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0072_DIGEST_MUST_NOT_BE_NULL_WHEN_ALG_DEFINED()));
325N/A }
325N/A
325N/A this.referencedModelUri = referencedModelUri;
325N/A if (expectedDigest == null) {
325N/A this.digest = null;
325N/A this.digestAlgorithmUri = null;
325N/A } else {
325N/A this.digest = expectedDigest;
325N/A
325N/A if (usedDigestAlgorithm == null) {
325N/A this.digestAlgorithmUri = DEFAULT_DIGEST_ALGORITHM_URI;
325N/A } else {
325N/A this.digestAlgorithmUri = usedDigestAlgorithm;
325N/A }
325N/A }
325N/A }
325N/A
325N/A public URI getReferencedModelUri() {
325N/A return referencedModelUri;
325N/A }
325N/A
325N/A public String getDigest() {
325N/A return digest;
325N/A }
325N/A
325N/A public URI getDigestAlgorithmUri() {
325N/A return digestAlgorithmUri;
325N/A }
325N/A
325N/A /**
325N/A * An {@code Object.toString()} method override.
325N/A */
325N/A @Override
325N/A public String toString() {
325N/A return toString(0, new StringBuffer()).toString();
325N/A }
325N/A
325N/A /**
325N/A * A helper method that appends indented string representation of this instance to the input string buffer.
325N/A *
325N/A * @param indentLevel indentation level to be used.
325N/A * @param buffer buffer to be used for appending string representation of this instance
325N/A * @return modified buffer containing new string representation of the instance
325N/A */
325N/A public StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
325N/A final String indent = PolicyUtils.Text.createIndent(indentLevel);
325N/A final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);
325N/A
325N/A buffer.append(indent).append("reference data {").append(PolicyUtils.Text.NEW_LINE);
325N/A buffer.append(innerIndent).append("referenced policy model URI = '").append(referencedModelUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
325N/A if (digest == null) {
325N/A buffer.append(innerIndent).append("no digest specified").append(PolicyUtils.Text.NEW_LINE);
325N/A } else {
325N/A buffer.append(innerIndent).append("digest algorith URI = '").append(digestAlgorithmUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
325N/A buffer.append(innerIndent).append("digest = '").append(digest).append('\'').append(PolicyUtils.Text.NEW_LINE);
325N/A }
325N/A buffer.append(indent).append('}');
325N/A
325N/A return buffer;
325N/A }
325N/A}