001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: /*
024: * AttributeNS.java
025: *
026: * Created on August 21, 2005, 9:37 PM
027: *
028: * To change this template, choose Tools | Options and locate the template under
029: * the Source Creation and Management node. Right-click the template and choose
030: * Open. You can then make changes to the template in the Source Editor.
031: */
032:
033: package com.sun.xml.wss.impl.c14n;
034:
035: import java.io.ByteArrayOutputStream;
036:
037: /**
038: *
039: * @author K.Venugopal@sun.com
040: */
041: public class AttributeNS implements Cloneable, Comparable {
042: private String uri;
043: private String prefix;
044: private boolean written = false;
045: byte[] utf8Data = null;
046: int code = 0;
047:
048: /** Creates a new instance of AttributeNS */
049: public AttributeNS() {
050: }
051:
052: public String getUri() {
053: return uri;
054: }
055:
056: public void setUri(String uri) {
057: this .uri = uri;
058: }
059:
060: public String getPrefix() {
061: return prefix;
062: }
063:
064: public void setPrefix(String prefix) {
065: this .prefix = prefix;
066: }
067:
068: public boolean isWritten() {
069: return written;
070: }
071:
072: public void setWritten(boolean written) {
073: this .written = written;
074: }
075:
076: public Object clone() throws CloneNotSupportedException {
077: AttributeNS attrNS = new AttributeNS();
078: attrNS.setPrefix(this .prefix);
079: attrNS.setUri(this .uri);
080: return attrNS;
081: }
082:
083: public boolean equals(Object obj) {
084: if (!(obj instanceof AttributeNS)) {
085: return false;
086: }
087: AttributeNS attrNS = (AttributeNS) obj;
088: if (this .uri == null || this .prefix == null) {
089: return false;
090: }
091: if (this .prefix.equals(attrNS.getPrefix())
092: && this .uri.equals(attrNS.getUri())) {
093: return true;
094: }
095: return false;
096: }
097:
098: public int hashCode() {
099: if (code == 0) {
100: if (uri != null) {
101: code = uri.hashCode();
102: }
103: if (prefix != null) {
104: code = code + prefix.hashCode();
105: }
106: }
107: return code;
108: }
109:
110: public byte[] getUTF8Data(ByteArrayOutputStream tmpBuffer) {
111: if (utf8Data == null) {
112: try {
113: BaseCanonicalizer.outputAttrToWriter("xmlns", prefix,
114: uri, tmpBuffer);
115: utf8Data = tmpBuffer.toByteArray();
116: } catch (Exception ex) {
117: utf8Data = null;
118: //should not occur
119: //log
120: }
121: }
122: return utf8Data;
123: }
124:
125: public int compareTo(Object cmp) {
126: return sortNamespaces(cmp, this );
127: }
128:
129: protected int sortNamespaces(Object object, Object object0) {
130: AttributeNS attr = (AttributeNS) object;
131: AttributeNS attr0 = (AttributeNS) object0;
132: //assume namespace processing is on.
133: String lN = attr.getPrefix();
134: String lN0 = attr0.getPrefix();
135: return lN.compareTo(lN0);
136: }
137:
138: public void reset() {
139: utf8Data = null;
140: prefix = null;
141: written = false;
142: uri = null;
143: }
144: }
|