001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: package org.apache.roller.webservices.adminapi.sdk;
019:
020: import java.util.Arrays;
021: import java.util.List;
022: import org.jdom.Document;
023: import org.jdom.Element;
024:
025: /**
026: * This class is the abstract notion of a set of entries.
027: * Weblog resources are represented by sets of entries.
028: *
029: * @author jtb
030: */
031: public abstract class EntrySet extends Entry {
032: /** Entry set types. */
033: public static interface Types {
034: /*
035: * Set of user entries.
036: * A user entry describes a user of the weblog server.
037: */
038: public static final String USERS = "users";
039: /**
040: * Set of weblog entries.
041: * Note that this is not a set of entries in a weblog, but rather,
042: * a set of entries that describe the weblog itself.
043: */
044: public static final String WEBLOGS = "weblogs";
045: /**
046: * Set of member entries.
047: * A member entry describes a user's membership to and
048: * permission with a particular weblog.
049: */
050: public static final String MEMBERS = "members";
051: /**
052: * Set of workspace entries.
053: * This type, along with WORKSPACE and COLLECTION, define
054: * the element that describe the introspection document
055: * for the AAPP service.
056: * <p>
057: * A service is a set of workspaces, and a workspace is a set of
058: * collections.
059: */
060: public static final String SERVICE = "service";
061: /** Set of collection entries. */
062: public static final String WORKSPACE = "workspace";
063: }
064:
065: private List entries = null;
066:
067: /** Get the type of this object. */
068: public abstract String getType();
069:
070: /** Get the entries in this object. */
071: public Entry[] getEntries() {
072: return (Entry[]) entries.toArray(new Entry[0]);
073: }
074:
075: /** Set the entries of this object. */
076: public void setEntries(Entry[] entryArray) {
077: entries = Arrays.asList(entryArray);
078: }
079:
080: /** Is this entry set empty? */
081: public boolean isEmpty() {
082: return entries == null || entries.size() == 0;
083: }
084:
085: /** This object as a JDOM Document */
086: public Document toDocument() {
087: Element e = new Element(getType(), NAMESPACE);
088: Document doc = new Document(e);
089:
090: // href
091: e.setAttribute(Attributes.HREF, getHref());
092:
093: // entries
094: for (int i = 0; i < getEntries().length; i++) {
095: e.addContent(getEntries()[i].toDocument()
096: .detachRootElement());
097: }
098:
099: return doc;
100: }
101:
102: public boolean equals(Object o) {
103: if (o == null || o.getClass() != this .getClass()) {
104: return false;
105: }
106:
107: EntrySet other = (EntrySet) o;
108:
109: if (!areEqual(getHref(), other.getHref())) {
110: return false;
111: }
112: if (!areEqual(getType(), other.getType())) {
113: return false;
114: }
115: if (!areEqual(getEntries(), other.getEntries())) {
116: return false;
117: }
118:
119: return true;
120: }
121: }
|