001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.policy.sourcemodel;
038:
039: import com.sun.xml.ws.policy.PolicyConstants;
040: import com.sun.xml.ws.policy.privateutil.LocalizationMessages;
041: import com.sun.xml.ws.policy.privateutil.PolicyLogger;
042: import com.sun.xml.ws.policy.privateutil.PolicyUtils;
043: import java.net.URI;
044: import java.net.URISyntaxException;
045: import javax.xml.namespace.QName;
046:
047: /**
048: *
049: * @author Marek Potociar
050: */
051: final class PolicyReferenceData {
052: private static final PolicyLogger LOGGER = PolicyLogger
053: .getLogger(PolicyReferenceData.class);
054:
055: public static final QName ATTRIBUTE_URI = new QName(
056: PolicyConstants.POLICY_NAMESPACE_URI, "URI");
057: public static final QName ATTRIBUTE_DIGEST = new QName(
058: PolicyConstants.POLICY_NAMESPACE_URI, "Digest");
059: public static final QName ATTRIBUTE_DIGEST_ALGORITHM = new QName(
060: PolicyConstants.POLICY_NAMESPACE_URI, "DigestAlgorithm");
061:
062: private static final URI DEFAULT_DIGEST_ALGORITHM_URI;
063: private static final URISyntaxException CLASS_INITIALIZATION_EXCEPTION;
064: static {
065: URISyntaxException tempEx = null;
066: URI tempUri = null;
067: try {
068: tempUri = new URI(
069: "http://schemas.xmlsoap.org/ws/2004/09/policy/Sha1Exc");
070: } catch (URISyntaxException e) {
071: tempEx = e;
072: } finally {
073: DEFAULT_DIGEST_ALGORITHM_URI = tempUri;
074: CLASS_INITIALIZATION_EXCEPTION = tempEx;
075: }
076: }
077:
078: private final URI referencedModelUri;
079: private final String digest;
080: private final URI digestAlgorithmUri;
081:
082: /** Creates a new instance of PolicyReferenceData */
083: public PolicyReferenceData(URI referencedModelUri) {
084: this .referencedModelUri = referencedModelUri;
085: this .digest = null;
086: this .digestAlgorithmUri = null;
087: }
088:
089: public PolicyReferenceData(URI referencedModelUri,
090: String expectedDigest, URI usedDigestAlgorithm) {
091: if (CLASS_INITIALIZATION_EXCEPTION != null) {
092: throw LOGGER
093: .logSevereException(new IllegalStateException(
094: LocalizationMessages
095: .WSP_0015_UNABLE_TO_INSTANTIATE_DIGEST_ALG_URI_FIELD(),
096: CLASS_INITIALIZATION_EXCEPTION));
097: }
098:
099: if (usedDigestAlgorithm != null && expectedDigest == null) {
100: throw LOGGER
101: .logSevereException(new IllegalArgumentException(
102: LocalizationMessages
103: .WSP_0072_DIGEST_MUST_NOT_BE_NULL_WHEN_ALG_DEFINED()));
104: }
105:
106: this .referencedModelUri = referencedModelUri;
107: if (expectedDigest == null) {
108: this .digest = null;
109: this .digestAlgorithmUri = null;
110: } else {
111: this .digest = expectedDigest;
112:
113: if (usedDigestAlgorithm == null) {
114: this .digestAlgorithmUri = DEFAULT_DIGEST_ALGORITHM_URI;
115: } else {
116: this .digestAlgorithmUri = usedDigestAlgorithm;
117: }
118: }
119: }
120:
121: public URI getReferencedModelUri() {
122: return referencedModelUri;
123: }
124:
125: public String getDigest() {
126: return digest;
127: }
128:
129: public URI getDigestAlgorithmUri() {
130: return digestAlgorithmUri;
131: }
132:
133: /**
134: * An {@code Object.toString()} method override.
135: */
136: public String toString() {
137: return toString(0, new StringBuffer()).toString();
138: }
139:
140: /**
141: * A helper method that appends indented string representation of this instance to the input string buffer.
142: *
143: * @param indentLevel indentation level to be used.
144: * @param buffer buffer to be used for appending string representation of this instance
145: * @return modified buffer containing new string representation of the instance
146: */
147: public StringBuffer toString(final int indentLevel,
148: final StringBuffer buffer) {
149: final String indent = PolicyUtils.Text
150: .createIndent(indentLevel);
151: final String innerIndent = PolicyUtils.Text
152: .createIndent(indentLevel + 1);
153:
154: buffer.append(indent).append("reference data {").append(
155: PolicyUtils.Text.NEW_LINE);
156: buffer.append(innerIndent).append(
157: "referenced policy model URI = '").append(
158: referencedModelUri).append('\'').append(
159: PolicyUtils.Text.NEW_LINE);
160: if (digest == null) {
161: buffer.append(innerIndent).append("no digest specified")
162: .append(PolicyUtils.Text.NEW_LINE);
163: } else {
164: buffer.append(innerIndent)
165: .append("digest algorith URI = '").append(
166: digestAlgorithmUri).append('\'').append(
167: PolicyUtils.Text.NEW_LINE);
168: buffer.append(innerIndent).append("digest = '").append(
169: digest).append('\'').append(
170: PolicyUtils.Text.NEW_LINE);
171: }
172: buffer.append(indent).append('}');
173:
174: return buffer;
175: }
176: }
|