KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > webservices > adminapi > sdk > Entry


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.webservices.adminapi.sdk;
19
20 import java.io.IOException JavaDoc;
21 import java.io.StringWriter JavaDoc;
22 import java.io.Writer JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import org.jdom.Document;
25 import org.jdom.Namespace;
26 import org.jdom.output.Format;
27 import org.jdom.output.XMLOutputter;
28
29 /**
30  * This class is the abstract notion of an entry.
31  * Weblog resources are represented by sets of entries.
32  */

33 public abstract class Entry {
34     protected static final Namespace NAMESPACE = Namespace.getNamespace("http://purl.org/apache/roller/aapp#");
35     
36     /** Entry types. */
37     public static interface Types {
38         /**
39          * User entry.
40          * A user entry is contained within a user entry set.
41          */

42         public static final String JavaDoc USER = "user";
43         /**
44          * Weblog entry.
45          * A weblog entry is contained within a weblog entry set.
46          */

47         public static final String JavaDoc WEBLOG = "weblog";
48         /**
49          * Member entry.
50          * A member entry is contained within a member entry set.
51          */

52         public static final String JavaDoc MEMBER = "member";
53         /**
54          * Collection entry.
55          * A collection entry is contained within a workspace, which is
56          * contained within a service.
57          */

58         public static final String JavaDoc COLLECTION = "collection";
59     }
60     
61     /** XML attributes common to all entry types. */
62     protected static interface Attributes {
63         public static final String JavaDoc HREF = "href";
64     }
65     
66     private String JavaDoc href = null;
67     
68     /** Get the HREF that identifies this entry. */
69     public String JavaDoc getHref() {
70         return href;
71     }
72     
73     /** Set the HREF that identifies this entry. */
74     public void setHref(String JavaDoc href) {
75         this.href = href;
76     }
77     
78     /** This entry, as a JDOM Document object. */
79     public abstract Document toDocument();
80     
81     /**
82      * This entry, as a String (XML).
83      */

84     public String JavaDoc toString() {
85         Writer JavaDoc writer = new StringWriter JavaDoc();
86         XMLOutputter outputter = new XMLOutputter();
87         outputter.setFormat(Format.getPrettyFormat());
88         try {
89             outputter.output(toDocument(), writer);
90             writer.close();
91         } catch (IOException JavaDoc ioe) {
92             throw new IllegalStateException JavaDoc(ioe.getMessage());
93         }
94         
95         return writer.toString();
96     }
97     
98     public abstract String JavaDoc getType();
99     
100     public boolean equals(Object JavaDoc o) {
101         if ( o == null || o.getClass() != this.getClass()) {
102             return false;
103         }
104                 
105         Entry other = (Entry)o;
106         
107         if (!areEqual(getHref(), other.getHref())) {
108             return false;
109         }
110         if (!areEqual(getType(), other.getType())) {
111             return false;
112         }
113         
114         return true;
115     }
116     
117     protected static boolean areEqual(Object JavaDoc o1, Object JavaDoc o2) {
118         return o1 == null ? o2 == null : o1.equals(o2);
119     }
120     
121     protected static boolean areEqual(Object JavaDoc[] oa1, Object JavaDoc[] oa2) {
122         return oa1 == null ? oa2 == null : Arrays.equals(oa1, oa2);
123     }
124 }
125
Popular Tags