001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.addressing;
021:
022: import org.apache.axis2.util.ObjectStateUtils;
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025:
026: import java.io.Externalizable;
027: import java.io.IOException;
028: import java.io.ObjectInput;
029: import java.io.ObjectOutput;
030: import java.util.ArrayList;
031:
032: /**
033: * Class RelatesTo
034: */
035: public class RelatesTo implements Externalizable {
036:
037: /*
038: * setup for logging
039: */
040: private static final Log log = LogFactory.getLog(RelatesTo.class);
041:
042: private static final String myClassName = "RelatesTo";
043:
044: /**
045: * @serial The serialization version ID tracks the version of the class.
046: * If a class definition changes, then the serialization/externalization
047: * of the class is affected. If a change to the class is made which is
048: * not compatible with the serialization/externalization of the class,
049: * then the serialization version ID should be updated.
050: * Refer to the "serialVer" utility to compute a serialization
051: * version ID.
052: */
053: private static final long serialVersionUID = -1120384315333414960L;
054:
055: /**
056: * @serial Tracks the revision level of a class to identify changes to the
057: * class definition that are compatible to serialization/externalization.
058: * If a class definition changes, then the serialization/externalization
059: * of the class is affected.
060: * Refer to the writeExternal() and readExternal() methods.
061: */
062: // supported revision levels, add a new level to manage compatible changes
063: private static final int REVISION_1 = 1;
064: // current revision level of this object
065: private static final int revisionID = REVISION_1;
066:
067: /**
068: * Field relationshipType
069: */
070: private String relationshipType;
071:
072: /**
073: * Field value
074: */
075: private String value;
076:
077: private ArrayList extensibilityAttributes = null;
078:
079: /**
080: * Constructor RelatesTo
081: */
082: public RelatesTo() {
083: }
084:
085: /**
086: * Constructor RelatesTo
087: *
088: * @param value
089: */
090: public RelatesTo(String value) {
091: this .value = value;
092: }
093:
094: /**
095: * Constructor RelatesTo
096: *
097: * @param value
098: * @param relationshipType
099: */
100: public RelatesTo(String value, String relationshipType) {
101: this .value = value;
102: this .relationshipType = relationshipType;
103: }
104:
105: /**
106: * Method getRelationshipType. If the relationship type has not been set it returns
107: * the default value {@link AddressingConstants.Final.WSA_DEFAULT_RELATIONSHIP_TYPE}
108: */
109: public String getRelationshipType() {
110: return (relationshipType != null
111: && !"".equals(relationshipType) ? relationshipType
112: : AddressingConstants.Final.WSA_DEFAULT_RELATIONSHIP_TYPE);
113: }
114:
115: /**
116: * Method getValue
117: */
118: public String getValue() {
119: return value;
120: }
121:
122: /**
123: * Method setRelationshipType
124: *
125: * @param relationshipType
126: */
127: public void setRelationshipType(String relationshipType) {
128: this .relationshipType = relationshipType;
129: }
130:
131: /**
132: * Method setValue
133: *
134: * @param value
135: */
136: public void setValue(String value) {
137: this .value = value;
138: }
139:
140: public ArrayList getExtensibilityAttributes() {
141: return extensibilityAttributes;
142: }
143:
144: public void setExtensibilityAttributes(
145: ArrayList extensibilityAttributes) {
146: this .extensibilityAttributes = extensibilityAttributes;
147: }
148:
149: /*
150: * (non-Javadoc)
151: * @see java.lang.Object#toString()
152: */
153: public String toString() {
154: return "Identifier: " + value + ", Relationship type: "
155: + relationshipType;
156: }
157:
158: /* ===============================================================
159: * Externalizable support
160: * ===============================================================
161: */
162:
163: /**
164: * Save the contents of this object.
165: * <p/>
166: * NOTE: Transient fields and static fields are not saved.
167: *
168: * @param out The stream to write the object contents to
169: * @throws IOException
170: */
171: public void writeExternal(ObjectOutput out) throws IOException {
172: // write out contents of this object
173:
174: // NOTES: For each item, where appropriate,
175: // write out the following information, IN ORDER:
176: // the class name
177: // the active or empty flag
178: // the data length, if appropriate
179: // the data
180:
181: //---------------------------------------------------------
182: // in order to handle future changes to the object
183: // definition, be sure to maintain the
184: // object level identifiers
185: //---------------------------------------------------------
186: // serialization version ID
187: out.writeLong(serialVersionUID);
188:
189: // revision ID
190: out.writeInt(revisionID);
191:
192: //---------------------------------------------------------
193: // various strings
194: //---------------------------------------------------------
195:
196: // String relationshipType
197: ObjectStateUtils.writeString(out, relationshipType,
198: "RelatesTo.relationshipType");
199:
200: // String value
201: ObjectStateUtils.writeString(out, value, "RelatesTo.value");
202:
203: //---------------------------------------------------------
204: // collections and lists
205: //---------------------------------------------------------
206:
207: ObjectStateUtils.writeArrayList(out, extensibilityAttributes,
208: "RelatesTo.extensibilityAttributes");
209:
210: }
211:
212: /**
213: * Restore the contents of the object that was
214: * previously saved.
215: * <p/>
216: * NOTE: The field data must read back in the same order and type
217: * as it was written. Some data will need to be validated when
218: * resurrected.
219: *
220: * @param in The stream to read the object contents from
221: * @throws IOException
222: * @throws ClassNotFoundException
223: */
224: public void readExternal(ObjectInput in) throws IOException,
225: ClassNotFoundException {
226: // serialization version ID
227: long suid = in.readLong();
228:
229: // revision ID
230: int revID = in.readInt();
231:
232: // make sure the object data is in a version we can handle
233: if (suid != serialVersionUID) {
234: throw new ClassNotFoundException(
235: ObjectStateUtils.UNSUPPORTED_SUID);
236: }
237:
238: // make sure the object data is in a revision level we can handle
239: if (revID != REVISION_1) {
240: throw new ClassNotFoundException(
241: ObjectStateUtils.UNSUPPORTED_REVID);
242: }
243:
244: //---------------------------------------------------------
245: // various strings
246: //---------------------------------------------------------
247:
248: // String relationshipType
249: relationshipType = ObjectStateUtils.readString(in,
250: "RelatesTo.relationshipType");
251:
252: // String value
253: value = ObjectStateUtils.readString(in, "RelatesTo.value");
254:
255: //---------------------------------------------------------
256: // collections and lists
257: //---------------------------------------------------------
258:
259: // ArrayList extensibilityAttributes
260: ArrayList tmpAL2 = ObjectStateUtils.readArrayList(in,
261: "RelatesTo.extensibilityAttributes");
262: if (tmpAL2 != null) {
263: extensibilityAttributes = new ArrayList(tmpAL2);
264: } else {
265: extensibilityAttributes = null;
266: }
267:
268: }
269:
270: }
|