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
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.lib.collab.xmpp.jso.impl.x.pubsub;
043:
044: import java.io.*;
045: import java.util.Iterator;
046: import java.util.List;
047:
048: import org.jabberstudio.jso.Extension;
049: import org.jabberstudio.jso.JID;
050: import org.jabberstudio.jso.NSI;
051: import org.jabberstudio.jso.util.Utilities;
052: import org.jabberstudio.jso.io.StreamBuilder;
053: import org.jabberstudio.jso.StreamDataFactory;
054: import org.jabberstudio.jso.StreamElement;
055: import org.jabberstudio.jso.StreamNode;
056: import org.jabberstudio.jso.StreamDataFactory;
057: import org.jabberstudio.jso.StreamObject;
058: import org.jabberstudio.jso.x.core.RosterExtension;
059: import org.jabberstudio.jso.x.core.RosterItem;
060: import org.jabberstudio.jso.x.core.RosterQuery;
061:
062: import org.netbeans.lib.collab.xmpp.jso.iface.x.pubsub.PubSubQuery;
063: import org.netbeans.lib.collab.xmpp.jso.iface.x.pubsub.PubSubElement;
064: import org.netbeans.lib.collab.xmpp.jso.iface.x.pubsub.PubSubEntityElement;
065: import org.netbeans.lib.collab.xmpp.jso.iface.x.pubsub.EntityContainer;
066:
067: import net.outer_planes.jso.DataFactory;
068: import net.outer_planes.jso.ElementBuilder;
069:
070: //import net.outer_planes.jso.ElementDecorator;
071: import net.outer_planes.jso.ExtensionBuilder;
072: import net.outer_planes.jso.ElementNode;
073: import net.outer_planes.jso.ExtensionNode;
074:
075: /**
076: *
077: * Note about subclass naming:
078: * Create, Subscribe are confusing and uninformative names for objects.
079: * suggest you use PubSubCreateElement, PubSubSubscribeElement, etc...
080: *
081:
082:
083: *
084: */
085: public class PubSubQueryNode extends ExtensionNode implements
086: PubSubQuery {
087:
088: // The streamelement used to create a pubsub node
089: // This class does not add anything at all to the PubSubElementNode
090:
091: public static final NSI NSI_CREATE = new NSI("create", NAMESPACE);
092:
093: public static final NSI NSI_DELETE = new NSI("delete", NAMESPACE);
094:
095: public static final NSI NSI_SUBSCRIBE = new NSI("subscribe",
096: NAMESPACE);
097:
098: public static final NSI NSI_UNSUBSCRIBE = new NSI("unsubscribe",
099: NAMESPACE);
100:
101: public static final NSI NSI_PUBLISH = new NSI("publish", NAMESPACE);
102:
103: public static final NSI NSI_RETRACT = new NSI("retract", NAMESPACE);
104:
105: public static final NSI NSI_AFFILIATIONS = new NSI("affiliations",
106: NAMESPACE);
107:
108: public static final NSI NSI_ENTITIES = new NSI("entities",
109: NAMESPACE);
110:
111: public static final NSI NSI_CONFIGURE = new NSI("configure",
112: NAMESPACE_OWNER);
113:
114: public static class PubSubPublishElement extends PubSubElementNode {
115:
116: private int _Id = 0;
117:
118: public static final NSI NAME = new NSI("publish", NAMESPACE);
119:
120: public PubSubPublishElement(StreamDataFactory sdf) {
121: super (sdf, NAME);
122: }
123:
124: public PubSubPublishElement(StreamDataFactory sdf, String node) {
125: this (sdf);
126: setNodeIdentifier(node);
127: }
128:
129: public PubSubPublishElement(StreamDataFactory sdf, String node,
130: String msgId, String publishContent) {
131: this (sdf, node);
132: addPubSubItem(msgId, publishContent);
133: }
134:
135: public PubSubPublishElement(StreamDataFactory sdf,
136: StreamElement base) {
137: this (sdf);
138: reset(base);
139: }
140:
141: public PubSubPublishElement(StreamElement parent,
142: PubSubPublishElement base) {
143: super (parent, base);
144: }
145:
146: public PubSubItemElement addPubSubItem(String msgId,
147: StreamElement content) {
148: PubSubItemElement item = null;
149:
150: StreamElement item1 = addElement(PubSubItemElement.NAME,
151: PubSubItemElement.class);
152: item = (PubSubItemElement) item1;
153: item.setID(msgId);
154: item.add(content);
155: return item;
156:
157: }
158:
159: public PubSubItemElement addPubSubItem(String msgId,
160: String content) {
161:
162: PubSubItemElement item = null;
163:
164: // PubSubQuery.PubSubItemElement item = (PubSubQuery.PubSubItemElement)addElement(PubSubItemElement.NAME,
165: // PubSubItemElement.class);
166: StreamElement item1 = addElement(PubSubItemElement.NAME,
167: PubSubItemElement.class);
168: item = (PubSubItemElement) item1;
169: item.setID(msgId);
170: item.setContent(content);
171: return item;
172:
173: }
174:
175: public PubSubItemElement removePubSubItem(String itemId) {
176: PubSubItemElement item = null;
177:
178: // There might be a better way to do this, a ready made method
179: // in jso to get element based on an attribute.
180:
181: for (Iterator i = listPubSubItems().iterator(); i.hasNext();) {
182: item = (PubSubItemElement) i.next();
183: if (item.getID().equalsIgnoreCase(itemId)) {
184: item.detach();
185: break;
186: }
187: }
188:
189: return item;
190:
191: }
192:
193: public PubSubItemElement getPubSubItem(String itemId) {
194: PubSubItemElement item = null;
195:
196: for (Iterator i = listPubSubItems().iterator(); i.hasNext();) {
197: item = (PubSubItemElement) i.next();
198: if (item.getID().equalsIgnoreCase(itemId)) {
199: return item;
200: }
201: }
202: return item;
203: }
204:
205: public List listPubSubItems() {
206: return listElements(PubSubItemElement.class);
207: }
208:
209: public void clearPubSubItems() {
210: clearElements(PubSubItemElement.class);
211: }
212:
213: protected int nextId() {
214: return ++_Id;
215: }
216:
217: public StreamObject copy(StreamElement parent) {
218: return new PubSubPublishElement(parent, this );
219: }
220:
221: }
222:
223: // This is similar to the publish element except that item elements
224: // in publish have content also.
225:
226: public static class PubSubRetractElement extends PubSubElementNode {
227:
228: public static final NSI NAME = new NSI("retract", NAMESPACE);
229:
230: public PubSubRetractElement(StreamDataFactory sdf) {
231: super (sdf, NAME);
232: }
233:
234: public PubSubRetractElement(StreamDataFactory sdf, String node,
235: String msgId) {
236: this (sdf);
237: setNodeIdentifier(node);
238: addPubSubItem(msgId);
239: }
240:
241: public PubSubRetractElement(StreamDataFactory sdf,
242: StreamElement base) {
243: super (sdf, NAME);
244: reset(base);
245: }
246:
247: public PubSubRetractElement(StreamElement parent,
248: PubSubRetractElement base) {
249: super (parent, base);
250: }
251:
252: public PubSubItemElement addPubSubItem(String msgId) {
253: PubSubItemElement item = (PubSubItemElement) addElement(
254: PubSubItemElement.NAME, PubSubItemElement.class);
255: item.setID(msgId);
256: return item;
257: }
258:
259: public void removePubSubItem(String itemId) {
260: PubSubItemElement item;
261:
262: // There might be a better way to do this, a ready made method in jso
263: // to get element based on an attribute.
264: for (Iterator i = listPubSubItems().iterator(); i.hasNext();) {
265: item = (PubSubItemElement) i.next();
266: if (item.getID().equalsIgnoreCase(itemId)) {
267: item.detach();
268: break;
269: }
270: }
271:
272: }
273:
274: public PubSubItemElement getPubSubItem(String itemId) {
275: PubSubItemElement item = null;
276: for (Iterator i = listPubSubItems().iterator(); i.hasNext();) {
277: item = (PubSubItemElement) i.next();
278: if (item.getID().equalsIgnoreCase(itemId)) {
279: return item;
280: }
281: }
282: return item;
283: }
284:
285: public List listPubSubItems() {
286: return listElements(PubSubItemElement.NAME,
287: PubSubItemElement.class);
288: }
289:
290: public StreamObject copy(StreamElement parent) {
291: return new PubSubRetractElement(parent, this );
292: }
293: }
294:
295: public static class EntityContainerElement extends
296: PubSubElementNode implements EntityContainer {
297:
298: public EntityContainerElement(StreamDataFactory sdf, NSI name) {
299: super (sdf, name);
300: }
301:
302: public EntityContainerElement(StreamDataFactory sdf, NSI name,
303: StreamElement base) {
304: this (sdf, name);
305: reset(base);
306: }
307:
308: public EntityContainerElement(StreamElement parent,
309: EntityContainerElement base) {
310: super (parent, base);
311:
312: }
313:
314: public PubSubEntityElement addPubSubEntity(String node) {
315: PubSubEntityElement entityElem = (PubSubEntityElement) addElement(
316: PubSubEntityElement.NAME, PubSubEntityElement.class);
317: entityElem.setNodeIdentifier(node);
318: add(entityElem);
319: return entityElem;
320:
321: }
322:
323: public PubSubEntityElement addPubSubEntity(String node,
324: JID jid, String affiliation, String subscriptionStatus)
325: throws IllegalArgumentException {
326: PubSubEntityElement entityElem = (PubSubEntityElement) getDataFactory()
327: .createElementNode(PubSubEntityElement.NAME);
328: entityElem.setSubscriberJID(jid);
329: if (node != null) {
330: entityElem.setNodeIdentifier(node);
331: }
332:
333: if (PubSubEntityElement.OWNER.equals(affiliation)) {
334: entityElem.setAffiliation(PubSubEntityElement.OWNER);
335: } else if (PubSubEntityElement.PUBLISHER
336: .equals(affiliation)) {
337: entityElem
338: .setAffiliation(PubSubEntityElement.PUBLISHER);
339: } else if (PubSubEntityElement.OUTCAST.equals(affiliation)) {
340: entityElem.setAffiliation(PubSubEntityElement.OUTCAST);
341: } else if (PubSubEntityElement.AFFIL_NONE
342: .equals(affiliation)) {
343: entityElem
344: .setAffiliation(PubSubEntityElement.AFFIL_NONE);
345: } else {
346: throw new IllegalArgumentException(affiliation
347: + " is not a valid affiliation");
348: }
349:
350: if (PubSubEntityElement.PENDING.equals(subscriptionStatus)) {
351: entityElem
352: .setSubscriptionStatus(PubSubEntityElement.PENDING);
353: } else if (PubSubEntityElement.SUBSCRIBED
354: .equals(subscriptionStatus)) {
355: entityElem
356: .setSubscriptionStatus(PubSubEntityElement.SUBSCRIBED);
357: } else if (PubSubEntityElement.UNCONFIGURED
358: .equals(subscriptionStatus)) {
359: entityElem
360: .setSubscriptionStatus(PubSubEntityElement.UNCONFIGURED);
361: } else if (PubSubEntityElement.NONE
362: .equals(subscriptionStatus)) {
363: entityElem
364: .setSubscriptionStatus(PubSubEntityElement.NONE);
365: } else {
366: throw new IllegalArgumentException(subscriptionStatus
367: + " is not a valid subscription status");
368: }
369: add(entityElem);
370: return entityElem;
371: }
372:
373: public void addPubSubEntity(PubSubEntityElement elem) {
374: add(elem);
375: }
376:
377: public PubSubEntityElement removePubSubEntity(String nodeId,
378: JID affiliatedEntity) {
379:
380: PubSubEntityElement entityElem = null;
381:
382: for (Iterator i = listPubSubEntities().iterator(); i
383: .hasNext();) {
384:
385: entityElem = (PubSubEntityElement) i.next();
386: String this NodeId = entityElem.getNodeIdentifier();
387: JID this SubscriberJID = entityElem.getSubscriberJID();
388:
389: if (this NodeId.equals(nodeId)
390: && this SubscriberJID.equals(affiliatedEntity)) {
391: remove(entityElem);
392: break;
393: }
394:
395: }
396: return entityElem;
397: }
398:
399: public List listPubSubEntities() {
400: return listElements(PubSubEntityElement.NAME,
401: PubSubEntityElement.class);
402: //return listElements(new NSI("entity", null));
403: }
404:
405: public StreamObject copy(StreamElement parent) {
406: return new EntityContainerElement(parent, this );
407: }
408:
409: }
410:
411: public static class PubSubEntityElementNode extends
412: PubSubElementNode implements PubSubEntityElement {
413:
414: public static final NSI NAME = new NSI("entity", NAMESPACE);
415: public static final NSI ATTRNAME_SUBSCRIPTION = new NSI(
416: "subscription", null);
417: public static final NSI ATTRNAME_AFFILIATION = new NSI(
418: "affiliation", null);
419:
420: public PubSubEntityElementNode(StreamDataFactory sdf) {
421: super (sdf, NAME);
422: }
423:
424: public PubSubEntityElementNode(StreamDataFactory sdf,
425: StreamElement base) {
426: this (sdf);
427: reset(base);
428: }
429:
430: public PubSubEntityElementNode(StreamElement parent,
431: PubSubEntityElementNode base) {
432: super (parent, base);
433: }
434:
435: public JID getSubscriberJID() {
436: return getJID();
437: }
438:
439: public void setSubscriberJID(JID jid) {
440: setJID(jid);
441: }
442:
443: public PubSubEntityElement.SubscriptionStatus getSubscriptionStatus()
444: throws IllegalArgumentException {
445: Object val = getAttributeObject(ATTRNAME_SUBSCRIPTION);
446: PubSubEntityElement.SubscriptionStatus subStat = null;
447:
448: if (val instanceof PubSubEntityElement.SubscriptionStatus) {
449: subStat = (PubSubEntityElement.SubscriptionStatus) val;
450: } else if (val != null) {
451: String temp = val.toString();
452: if (Utilities
453: .equateStrings(temp, SUBSCRIBED.toString())) {
454: subStat = SUBSCRIBED;
455: } else if (Utilities.equateStrings(temp, PENDING
456: .toString())) {
457: subStat = PENDING;
458: } else if (Utilities.equateStrings(temp, UNCONFIGURED
459: .toString())) {
460: subStat = UNCONFIGURED;
461: } else {
462: subStat = NONE;
463: }
464: setAttributeObject(ATTRNAME_SUBSCRIPTION, subStat);
465: }
466: return subStat;
467: }
468:
469: public void setSubscriptionStatus(
470: PubSubEntityElement.SubscriptionStatus subStatus) {
471: //setAttributeObject(ATTRNAME_SUBSCRIPTION,subStatus);
472: setAttributeValue(ATTRNAME_SUBSCRIPTION.getLocalName(),
473: subStatus.toString());
474:
475: }
476:
477: public boolean hasSubscriptionStatus(
478: PubSubEntityElement.SubscriptionStatus subStatus) {
479: //PubSubEntityElement.SubscriptionStatus subStat = (PubSubEntityElement.SubscriptionStatus)getAttributeObject(ATTRNAME_SUBSCRIPTION);
480: return (getSubscriptionStatus() == subStatus);
481: }
482:
483: public void setAffiliation(
484: PubSubEntityElement.Affiliation affilType) {
485: setAttributeObject(ATTRNAME_AFFILIATION, affilType);
486: }
487:
488: public PubSubEntityElement.Affiliation getAffiliation() {
489:
490: Object val = getAttributeObject(ATTRNAME_AFFILIATION);
491: PubSubEntityElement.Affiliation affilType = null;
492:
493: if (val instanceof PubSubEntityElement.Affiliation) {
494: affilType = (PubSubEntityElement.Affiliation) val;
495: } else if (val != null) {
496: String temp = val.toString();
497: if (Utilities.equateStrings(temp, OWNER.toString())) {
498: affilType = OWNER;
499: } else if (Utilities.equateStrings(temp, PUBLISHER
500: .toString())) {
501: affilType = PUBLISHER;
502: } else if (Utilities.equateStrings(temp, OUTCAST
503: .toString())) {
504: affilType = OUTCAST;
505: } else {
506: affilType = AFFIL_NONE;
507: }
508: }
509: return affilType;
510: }
511:
512: public boolean hasAffiliation(
513: PubSubEntityElement.Affiliation affiliationType) {
514:
515: PubSubEntityElement.Affiliation affil = (PubSubEntityElement.Affiliation) getAttributeObject(ATTRNAME_AFFILIATION);
516: return affil.equals(affiliationType);
517:
518: }
519:
520: public StreamObject copy(StreamElement parent) {
521: return new PubSubEntityElementNode(parent, this );
522: }
523:
524: }
525:
526: public static class PubSubItemElement extends ElementNode implements
527: StreamElement {
528:
529: public static final NSI NAME = new NSI("item", NAMESPACE);
530:
531: public PubSubItemElement(StreamElement parent, ElementNode base) {
532: super (parent, base);
533: }
534:
535: public PubSubItemElement(StreamDataFactory sdf, NSI name) {
536: super (sdf, name);
537: }
538:
539: public PubSubItemElement(StreamDataFactory sdf) {
540: this (sdf, NAME);
541: }
542:
543: public String getContent() {
544: return normalizeText();
545: }
546:
547: public void setContent(String content) {
548: addText(content);
549: }
550:
551: public void setContent(StreamElement content) {
552: add(content);
553: }
554:
555: public StreamObject copy(StreamElement parent) {
556: return new PubSubItemElement(parent, this );
557: }
558:
559: }
560:
561: public PubSubQueryNode(StreamDataFactory sdf) {
562: super (sdf, NAME);
563: }
564:
565: public PubSubQueryNode(StreamDataFactory sdf, NSI name) {
566: super (sdf, name);
567: }
568:
569: public PubSubQueryNode(StreamElement p, PubSubQueryNode base) {
570: super (p, base);
571: }
572:
573: public PubSubElement createCreateElement(String node)
574: throws IllegalArgumentException {
575: PubSubElement createElement = (PubSubElement) getDataFactory()
576: .createElementNode(NSI_CREATE);
577: createElement.setNodeIdentifier(node);
578: return createElement;
579: }
580:
581: public PubSubElement createDeleteElement(String node)
582: throws IllegalArgumentException {
583: PubSubElement deleteElement = (PubSubElement) getDataFactory()
584: .createElementNode(NSI_DELETE);
585: deleteElement.setNodeIdentifier(node);
586: return deleteElement;
587: }
588:
589: public PubSubElement createSubscribeElement(String node,
590: JID subscriber) throws IllegalArgumentException {
591: PubSubElement subscribeElement = (PubSubElement) getDataFactory()
592: .createElementNode(NSI_SUBSCRIBE);
593: subscribeElement.setNodeIdentifier(node);
594: subscribeElement.setJID(subscriber);
595: return subscribeElement;
596: }
597:
598: public PubSubElement createUnSubscribeElement(String node,
599: JID subscriber) throws IllegalArgumentException {
600: PubSubElement unsubscribeElement = (PubSubElement) getDataFactory()
601: .createElementNode(NSI_UNSUBSCRIBE);
602: unsubscribeElement.setNodeIdentifier(node);
603: unsubscribeElement.setJID(subscriber);
604: return unsubscribeElement;
605: }
606:
607: public PubSubElement createPublishElement(String node)
608: throws IllegalArgumentException {
609: PubSubElement publishElement = (PubSubElement) getDataFactory()
610: .createElementNode(
611: PubSubQueryNode.PubSubPublishElement.NAME);
612: publishElement.setNodeIdentifier(node);
613: return publishElement;
614: }
615:
616: public PubSubElement createPublishElement(String node,
617: String msgId, String publishContent)
618: throws IllegalArgumentException {
619: PubSubPublishElement publishElement = (PubSubPublishElement) getDataFactory()
620: .createElementNode(
621: PubSubQueryNode.PubSubPublishElement.NAME);
622: publishElement.setNodeIdentifier(node);
623: publishElement.addPubSubItem(msgId, publishContent);
624: return publishElement;
625:
626: }
627:
628: public EntityContainer createAffiliationsElement(List entities)
629: throws IllegalArgumentException {
630: return null;
631: }
632:
633: public EntityContainer createAffiliationsElement() {
634: EntityContainer affilElement = (EntityContainer) getDataFactory()
635: .createElementNode(NSI_AFFILIATIONS);
636: return affilElement;
637: }
638:
639: public EntityContainer createEntitiesElement(String node)
640: throws IllegalArgumentException {
641: EntityContainer entitiesElement = (EntityContainer) getDataFactory()
642: .createElementNode(NSI_ENTITIES);
643: entitiesElement.setNodeIdentifier(node);
644: return entitiesElement;
645: }
646:
647: public PubSubElement createConfigureElement(String node)
648: throws IllegalArgumentException {
649: PubSubElement configureElement = (PubSubElement) getDataFactory()
650: .createElementNode(NSI_CONFIGURE);
651: configureElement.setNodeIdentifier(node);
652: return configureElement;
653: }
654:
655: public PubSubElement createConfigureElement() {
656: PubSubElement configureElement = (PubSubElement) getDataFactory()
657: .createElementNode(NSI_CONFIGURE);
658: return configureElement;
659: }
660:
661: public PubSubEntityElement createEntityElement(String node,
662: JID jid, String affiliation, String subscriptionStatus)
663: throws IllegalArgumentException {
664:
665: PubSubEntityElement entityElem = (PubSubEntityElement) getDataFactory()
666: .createElementNode(PubSubEntityElement.NAME);
667: entityElem.setSubscriberJID(jid);
668: if (node != null) {
669: entityElem.setNodeIdentifier(node);
670: }
671:
672: if (PubSubEntityElement.OWNER.equals(affiliation)) {
673: entityElem.setAffiliation(PubSubEntityElement.OWNER);
674: } else if (PubSubEntityElement.PUBLISHER.equals(affiliation)) {
675: entityElem.setAffiliation(PubSubEntityElement.PUBLISHER);
676: } else if (PubSubEntityElement.OUTCAST.equals(affiliation)) {
677: entityElem.setAffiliation(PubSubEntityElement.OUTCAST);
678: } else if (PubSubEntityElement.AFFIL_NONE.equals(affiliation)) {
679: entityElem.setAffiliation(PubSubEntityElement.AFFIL_NONE);
680: } else {
681: throw new IllegalArgumentException(affiliation
682: + " is not a valid affiliation");
683: }
684:
685: if (PubSubEntityElement.PENDING.equals(subscriptionStatus)) {
686: entityElem
687: .setSubscriptionStatus(PubSubEntityElement.PENDING);
688: } else if (PubSubEntityElement.SUBSCRIBED
689: .equals(subscriptionStatus)) {
690: entityElem
691: .setSubscriptionStatus(PubSubEntityElement.SUBSCRIBED);
692: } else if (PubSubEntityElement.UNCONFIGURED
693: .equals(subscriptionStatus)) {
694: entityElem
695: .setSubscriptionStatus(PubSubEntityElement.UNCONFIGURED);
696: } else if (PubSubEntityElement.NONE.equals(subscriptionStatus)) {
697: entityElem.setSubscriptionStatus(PubSubEntityElement.NONE);
698: } else {
699: throw new IllegalArgumentException(subscriptionStatus
700: + " is not a valid subscription status");
701: }
702: return entityElem;
703: }
704:
705: public PubSubElement createRetractElement(String node, String msgId)
706: throws IllegalArgumentException {
707: PubSubRetractElement retractElement = (PubSubRetractElement) getDataFactory()
708: .createElementNode(
709: PubSubQueryNode.PubSubRetractElement.NAME);
710: retractElement.setNodeIdentifier(node);
711: retractElement.addPubSubItem(msgId);
712: return retractElement;
713: }
714:
715: public PubSubElement getRetractElement() {
716: return (PubSubElement) getFirstElement(PubSubQueryNode.PubSubRetractElement.NAME);
717: }
718:
719: public PubSubElement getCreateElement() {
720: return (PubSubElement) getFirstElement(NSI_CREATE);
721: }
722:
723: public PubSubElement getDeleteElement() {
724: return (PubSubElement) getFirstElement(NSI_DELETE);
725: }
726:
727: public PubSubElement getSubscribeElement() {
728: return (PubSubElement) getFirstElement(NSI_SUBSCRIBE);
729: }
730:
731: public PubSubElement getUnSubscribeElement() {
732: return (PubSubElement) getFirstElement(NSI_UNSUBSCRIBE);
733: }
734:
735: public PubSubElement getPublishElement() {
736: return (PubSubElement) getFirstElement(NSI_PUBLISH);
737: }
738:
739: public PubSubElement getConfigureElement() {
740: return (PubSubElement) getFirstElement(NSI_CONFIGURE);
741: }
742:
743: public PubSubElement getPubSubRetractElement() {
744: return (PubSubElement) getFirstElement(NSI_RETRACT);
745: }
746:
747: public StreamObject copy(StreamElement parent) {
748: return new PubSubQueryNode(parent, this);
749: }
750:
751: }
|