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: /*
038: * SequenceAcknowledgementElement.java
039: *
040: * @author Mike Grogan
041: * Created on October 23, 2005, 9:51 AM
042: *
043: */
044:
045: package com.sun.xml.ws.rm.v200502;
046:
047: import com.sun.xml.ws.rm.protocol.AbstractSequenceAcknowledgement;
048:
049: import javax.xml.bind.annotation.*;
050: import javax.xml.namespace.QName;
051: import java.math.BigInteger;
052: import java.util.ArrayList;
053: import java.util.HashMap;
054: import java.util.List;
055: import java.util.Map;
056:
057: /**
058: * Abstraction of the <code>SequenceAcknowledgement</code> WS-RM protocol element.
059: * Based on a JAXB schema compiler generated class that has properties for each
060: * child element of the SequenceAcknowledgement element. A property used to
061: * serialize/ deserialize the <code>BufferRemaining</code> extensibility element is added.
062: *
063: */
064: @XmlAccessorType(XmlAccessType.FIELD)
065: @XmlType(name="",propOrder={"identifier","acknowledgementRange","bufferRemaining","nack","any"})
066: @XmlRootElement(name="SequenceAcknowledgement",namespace="http://schemas.xmlsoap.org/ws/2005/02/rm")
067: public class SequenceAcknowledgementElement extends
068: AbstractSequenceAcknowledgement {
069:
070: @XmlElement(name="Identifier",namespace="http://schemas.xmlsoap.org/ws/2005/02/rm")
071: protected Identifier identifier;
072:
073: @XmlElement(name="AcknowledgementRange",namespace="http://schemas.xmlsoap.org/ws/2005/02/rm")
074: protected List<SequenceAcknowledgementElement.AcknowledgementRange> acknowledgementRange;
075:
076: @XmlElement(name="Nack",namespace="http://schemas.xmlsoap.org/ws/2005/02/rm")
077: protected List<BigInteger> nack;
078:
079: @XmlElement(name="BufferRemaining",namespace="http://schemas.microsoft.com/ws/2006/05/rm")
080: public Integer bufferRemaining;
081:
082: @XmlAnyElement(lax=true)
083: protected List<Object> any;
084:
085: @XmlAnyAttribute
086: private Map<QName, String> otherAttributes = new HashMap<QName, String>();
087:
088: public SequenceAcknowledgementElement() {
089:
090: }
091:
092: /**
093: * Gets the value of the identifier property.
094: * @return The value of the property.
095: */
096: public Identifier getIdentifier() {
097: return identifier;
098: }
099:
100: /**
101: * Sets the value of the identifier property.
102: *
103: * @param value The new value of the property.
104: */
105: public void setIdentifier(Identifier value) {
106: this .identifier = value;
107: }
108:
109: /**
110: * Gets the value of the acknowledgementRange property.
111: *
112: * @return The value of the property, which is a list of AcknowledgementRange
113: * objects
114: */
115: public List<SequenceAcknowledgementElement.AcknowledgementRange> getAcknowledgementRange() {
116: if (acknowledgementRange == null) {
117: acknowledgementRange = new ArrayList<SequenceAcknowledgementElement.AcknowledgementRange>();
118: }
119: return this .acknowledgementRange;
120: }
121:
122: /**
123: * Gets the value of the nack property.
124: *
125: * @return The value of the property, which is a list of BigIntegers
126: *
127: *
128: */
129: public List<BigInteger> getNack() {
130: if (nack == null) {
131: nack = new ArrayList<BigInteger>();
132: }
133: return this .nack;
134: }
135:
136: /**
137: * Gets the value of the any property representing extensibility elements
138: *
139: * @return The list of elements.
140: *
141: */
142: public List<Object> getAny() {
143: if (any == null) {
144: any = new ArrayList<Object>();
145: }
146: return this .any;
147: }
148:
149: /**
150: * Gets a map that contains attributes that aren't bound to any typed property on this class.
151: *
152: * @return The value of the property
153: */
154: public Map<QName, String> getOtherAttributes() {
155: return otherAttributes;
156: }
157:
158: public void setId(String id) {
159: Identifier identifier = new Identifier();
160: identifier.setValue(id);
161: setIdentifier(identifier);
162: }
163:
164: public String getId() {
165: return getIdentifier().getValue();
166: }
167:
168: public int getBufferRemaining() {
169: if (bufferRemaining == null) {
170: return -1;
171: }
172: return bufferRemaining;
173: }
174:
175: public void setBufferRemaining(int value) {
176: bufferRemaining = value;
177: }
178:
179: public void addAckRange(long lower, long upper) {
180: if (nack != null) {
181: throw new IllegalArgumentException(
182: Messages.BOTH_ACKS_AND_NACKS_MESSAGE.format());
183: }
184: //check validity of indices
185: if (lower > upper) {
186: throw new IllegalArgumentException(
187: Messages.UPPERBOUND_LESSTHAN_LOWERBOUND_MESSAGE
188: .format());
189: }
190:
191: //TODO Further validity checking
192: SequenceAcknowledgementElement.AcknowledgementRange range = new SequenceAcknowledgementElement.AcknowledgementRange();
193: range.setLower(BigInteger.valueOf(lower));
194: range.setUpper(BigInteger.valueOf(upper));
195: getAcknowledgementRange().add(range);
196:
197: }
198:
199: public void addNack(long index) {
200: if (acknowledgementRange != null) {
201: throw new IllegalArgumentException(
202: Messages.BOTH_ACKS_AND_NACKS_MESSAGE.format());
203: }
204:
205: getNack().add(BigInteger.valueOf(index));
206: }
207:
208: public String toString() {
209:
210: String ret = Messages.SEQUENCE_ACKNOWLEDGEMENT_TOSTRING_STRING
211: .format(getId(), getBufferRemaining());
212: List<AcknowledgementRange> ranges = getAcknowledgementRange();
213: if (ranges != null) {
214: for (AcknowledgementRange range : ranges) {
215: ret += "\t\t" + range.toString() + "\n";
216: }
217: }
218: return ret;
219: }
220:
221: @XmlAccessorType(XmlAccessType.FIELD)
222: @XmlType(name="")
223: public static class AcknowledgementRange {
224:
225: @XmlAttribute(name="Lower",required=true)
226: protected BigInteger lower;
227: @XmlAttribute(name="Upper",required=true)
228: protected BigInteger upper;
229: @XmlAnyAttribute
230: private Map<QName, String> otherAttributes = new HashMap<QName, String>();
231:
232: /**
233: * Gets the value of the lower property.
234: *
235: * @return
236: * possible object is
237: * {@link BigInteger }
238: *
239: */
240: public BigInteger getLower() {
241: return lower;
242: }
243:
244: /**
245: * Sets the value of the lower property.
246: *
247: * @param value
248: * allowed object is
249: * {@link BigInteger }
250: *
251: */
252: public void setLower(BigInteger value) {
253: this .lower = value;
254: }
255:
256: /**
257: * Gets the value of the upper property.
258: *
259: * @return
260: * possible object is
261: * {@link BigInteger }
262: *
263: */
264: public BigInteger getUpper() {
265: return upper;
266: }
267:
268: /**
269: * Sets the value of the upper property.
270: *
271: * @param value
272: * allowed object is
273: * {@link BigInteger }
274: *
275: */
276: public void setUpper(BigInteger value) {
277: this .upper = value;
278: }
279:
280: /**
281: * Gets a map that contains attributes that aren't bound to any typed property on this class.
282: *
283: * <p>
284: * the map is keyed by the name of the attribute and
285: * the value is the string value of the attribute.
286: *
287: * the map returned by this method is live, and you can add new attribute
288: * by updating the map directly. Because of this design, there's no setter.
289: *
290: *
291: * @return
292: * always non-null
293: */
294: public Map<QName, String> getOtherAttributes() {
295: return otherAttributes;
296: }
297:
298: public String toString() {
299: return "AcknowledgementRange (" + lower.intValue() + ","
300: + upper.intValue() + ")";
301: }
302: }
303: }
|