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.security.impl.policy;
038:
039: import com.sun.xml.ws.policy.AssertionSet;
040: import com.sun.xml.ws.policy.PolicyAssertion;
041: import com.sun.xml.ws.policy.PolicyException;
042: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
043: import java.util.Collection;
044: import java.util.Map;
045: import javax.xml.namespace.QName;
046:
047: /**
048: *
049: * @author K.Venugopal@sun.com
050: */
051: public class Header extends PolicyAssertion implements
052: com.sun.xml.ws.security.policy.Header {
053:
054: String name = "";
055: String uri = "";
056: int hashCode = 0;
057:
058: /**
059: * Creates a new instance of Header
060: */
061: @Deprecated
062: public Header(String localName, String uri) {
063: Map<QName, String> attrs = this .getAttributes();
064: attrs.put(NAME, localName);
065: attrs.put(URI, uri);
066: }
067:
068: public Header(AssertionData name,
069: Collection<PolicyAssertion> nestedAssertions,
070: AssertionSet nestedAlternative) throws PolicyException {
071: super (name, nestedAssertions, nestedAlternative);
072:
073: String tmp = this .getAttributeValue(NAME);
074: if (tmp != null) {
075: this .name = tmp;
076: }
077:
078: this .uri = this .getAttributeValue(URI);
079:
080: if (uri == null || uri.length() == 0) {
081: throw new PolicyException(
082: "Namespace attribute is required under Header element ");
083: }
084:
085: }
086:
087: public boolean equals(Object object) {
088: if (object instanceof Header) {
089: Header header = (Header) object;
090: if (header.getLocalName() != null
091: && header.getLocalName().equals(getLocalName())) {
092: if (header.getURI().equals(getURI())) {
093: return true;
094: }
095: }
096: }
097: return false;
098: }
099:
100: public int hashCode() {
101: if (hashCode == 0) {
102: if (uri != null) {
103: hashCode = uri.hashCode();
104: }
105: if (name != null) {
106: hashCode = hashCode + name.hashCode();
107: }
108: }
109: return hashCode;
110: }
111:
112: public String getLocalName() {
113: return name;
114: }
115:
116: public String getURI() {
117: return uri;
118: }
119: }
|