src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/PolicyReferenceData.java

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     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  */
    26 package com.sun.xml.internal.ws.policy.sourcemodel;
    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;
    34 /**
    35  *
    36  * @author Marek Potociar
    37  */
    38 final class PolicyReferenceData {
    39     private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyReferenceData.class);
    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     }
    56     private final URI referencedModelUri;
    57     private final String digest;
    58     private final URI digestAlgorithmUri;
    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     }
    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         }
    72         if (usedDigestAlgorithm != null && expectedDigest == null) {
    73             throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0072_DIGEST_MUST_NOT_BE_NULL_WHEN_ALG_DEFINED()));
    74         }
    76         this.referencedModelUri = referencedModelUri;
    77         if (expectedDigest == null) {
    78             this.digest = null;
    79             this.digestAlgorithmUri = null;
    80         } else {
    81             this.digest = expectedDigest;
    83             if (usedDigestAlgorithm == null) {
    84                 this.digestAlgorithmUri = DEFAULT_DIGEST_ALGORITHM_URI;
    85             } else {
    86                 this.digestAlgorithmUri = usedDigestAlgorithm;
    87             }
    88         }
    89     }
    91     public URI getReferencedModelUri() {
    92         return referencedModelUri;
    93     }
    95     public String getDigest() {
    96         return digest;
    97     }
    99     public URI getDigestAlgorithmUri() {
   100         return digestAlgorithmUri;
   101     }
   103     /**
   104      * An {@code Object.toString()} method override.
   105      */
   106     @Override
   107     public String toString() {
   108         return toString(0, new StringBuffer()).toString();
   109     }
   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);
   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('}');
   132         return buffer;
   133     }
   134 }

mercurial