author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.xml.internal.ws.policy.sourcemodel; |
|
27 |
||
28 |
import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages; |
|
29 |
import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; |
|
30 |
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; |
|
31 |
import java.net.URI; |
|
32 |
import java.net.URISyntaxException; |
|
33 |
||
34 |
/** |
|
35 |
* |
|
36 |
* @author Marek Potociar |
|
37 |
*/ |
|
38 |
final class PolicyReferenceData { |
|
39 |
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyReferenceData.class); |
|
40 |
||
41 |
private static final URI DEFAULT_DIGEST_ALGORITHM_URI; |
|
42 |
private static final URISyntaxException CLASS_INITIALIZATION_EXCEPTION; |
|
43 |
static { |
|
44 |
URISyntaxException tempEx = null; |
|
45 |
URI tempUri = null; |
|
46 |
try { |
|
47 |
tempUri = new URI("http://schemas.xmlsoap.org/ws/2004/09/policy/Sha1Exc"); |
|
48 |
} catch (URISyntaxException e) { |
|
49 |
tempEx = e; |
|
50 |
} finally { |
|
51 |
DEFAULT_DIGEST_ALGORITHM_URI = tempUri; |
|
52 |
CLASS_INITIALIZATION_EXCEPTION = tempEx; |
|
53 |
} |
|
54 |
} |
|
55 |
||
56 |
private final URI referencedModelUri; |
|
57 |
private final String digest; |
|
58 |
private final URI digestAlgorithmUri; |
|
59 |
||
60 |
/** Creates a new instance of PolicyReferenceData */ |
|
61 |
public PolicyReferenceData(URI referencedModelUri) { |
|
62 |
this.referencedModelUri = referencedModelUri; |
|
63 |
this.digest = null; |
|
64 |
this.digestAlgorithmUri = null; |
|
65 |
} |
|
66 |
||
67 |
public PolicyReferenceData(URI referencedModelUri, String expectedDigest, URI usedDigestAlgorithm) { |
|
68 |
if (CLASS_INITIALIZATION_EXCEPTION != null) { |
|
69 |
throw LOGGER.logSevereException(new IllegalStateException(LocalizationMessages.WSP_0015_UNABLE_TO_INSTANTIATE_DIGEST_ALG_URI_FIELD(), CLASS_INITIALIZATION_EXCEPTION)); |
|
70 |
} |
|
71 |
||
72 |
if (usedDigestAlgorithm != null && expectedDigest == null) { |
|
73 |
throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0072_DIGEST_MUST_NOT_BE_NULL_WHEN_ALG_DEFINED())); |
|
74 |
} |
|
75 |
||
76 |
this.referencedModelUri = referencedModelUri; |
|
77 |
if (expectedDigest == null) { |
|
78 |
this.digest = null; |
|
79 |
this.digestAlgorithmUri = null; |
|
80 |
} else { |
|
81 |
this.digest = expectedDigest; |
|
82 |
||
83 |
if (usedDigestAlgorithm == null) { |
|
84 |
this.digestAlgorithmUri = DEFAULT_DIGEST_ALGORITHM_URI; |
|
85 |
} else { |
|
86 |
this.digestAlgorithmUri = usedDigestAlgorithm; |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
public URI getReferencedModelUri() { |
|
92 |
return referencedModelUri; |
|
93 |
} |
|
94 |
||
95 |
public String getDigest() { |
|
96 |
return digest; |
|
97 |
} |
|
98 |
||
99 |
public URI getDigestAlgorithmUri() { |
|
100 |
return digestAlgorithmUri; |
|
101 |
} |
|
102 |
||
103 |
/** |
|
104 |
* An {@code Object.toString()} method override. |
|
105 |
*/ |
|
106 |
@Override |
|
107 |
public String toString() { |
|
108 |
return toString(0, new StringBuffer()).toString(); |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* A helper method that appends indented string representation of this instance to the input string buffer. |
|
113 |
* |
|
114 |
* @param indentLevel indentation level to be used. |
|
115 |
* @param buffer buffer to be used for appending string representation of this instance |
|
116 |
* @return modified buffer containing new string representation of the instance |
|
117 |
*/ |
|
118 |
public StringBuffer toString(final int indentLevel, final StringBuffer buffer) { |
|
119 |
final String indent = PolicyUtils.Text.createIndent(indentLevel); |
|
120 |
final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1); |
|
121 |
||
122 |
buffer.append(indent).append("reference data {").append(PolicyUtils.Text.NEW_LINE); |
|
123 |
buffer.append(innerIndent).append("referenced policy model URI = '").append(referencedModelUri).append('\'').append(PolicyUtils.Text.NEW_LINE); |
|
124 |
if (digest == null) { |
|
125 |
buffer.append(innerIndent).append("no digest specified").append(PolicyUtils.Text.NEW_LINE); |
|
126 |
} else { |
|
127 |
buffer.append(innerIndent).append("digest algorith URI = '").append(digestAlgorithmUri).append('\'').append(PolicyUtils.Text.NEW_LINE); |
|
128 |
buffer.append(innerIndent).append("digest = '").append(digest).append('\'').append(PolicyUtils.Text.NEW_LINE); |
|
129 |
} |
|
130 |
buffer.append(indent).append('}'); |
|
131 |
||
132 |
return buffer; |
|
133 |
} |
|
134 |
} |