View Javadoc

1   /*
2    * Copyright 2004 Sun Microsystems, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not 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.
15   *
16   */
17  package com.sun.syndication.feed.atom;
18  
19  import com.sun.syndication.feed.impl.ObjectBean;
20  
21  import java.io.Serializable;
22  import java.util.HashSet;
23  import java.util.Set;
24  
25  /***
26   * Bean for link elements of Atom feeds.
27   * <p>
28   * @author Alejandro Abdelnur
29   *
30   */
31  public class Link implements Cloneable,Serializable {
32      public static final String ALTERNATE    = "alternate";
33      public static final String START        = "start";
34      public static final String NEXT         = "next";
35      public static final String PREV         = "prev";
36      public static final String SERVICE_EDIT = "service.edit";
37      public static final String SERVICE_POST = "service.post";
38      public static final String SERVICE_FEED = "service.feed";
39  
40      private static final Set RELS = new HashSet();
41  
42      static {
43          RELS.add(ALTERNATE   );
44          RELS.add(START       );
45          RELS.add(NEXT        );
46          RELS.add(PREV        );
47          RELS.add(SERVICE_EDIT);
48          RELS.add(SERVICE_POST);
49          RELS.add(SERVICE_FEED);
50      }
51  
52      private ObjectBean _objBean;
53      private String _rel;
54      private String _type;
55      private String _href;
56      private String _title;
57  
58      /***
59       * Default constructor. All properties are set to <b>null</b>.
60       * <p>
61       *
62       */
63      public Link() {
64          _objBean = new ObjectBean(this.getClass(),this);
65      }
66  
67      /***
68       * Creates a deep 'bean' clone of the object.
69       * <p>
70       * @return a clone of the object.
71       * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
72       *
73       */
74      public Object clone() throws CloneNotSupportedException {
75          return _objBean.clone();
76      }
77  
78      /***
79       * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
80       * <p>
81       * @param other he reference object with which to compare.
82       * @return <b>true</b> if 'this' object is equal to the 'other' object.
83       *
84       */
85      public boolean equals(Object other) {
86          return _objBean.equals(other);
87      }
88  
89      /***
90       * Returns a hashcode value for the object.
91       * <p>
92       * It follows the contract defined by the Object hashCode() method.
93       * <p>
94       * @return the hashcode of the bean object.
95       *
96       */
97      public int hashCode() {
98          return _objBean.hashCode();
99      }
100 
101     /***
102      * Returns the String representation for the object.
103      * <p>
104      * @return String representation for the object.
105      *
106      */
107     public String toString() {
108         return _objBean.toString();
109     }
110 
111     /***
112      * Returns the link rel.
113      * <p>
114      * @return the link rel, <b>null</b> if none.
115      *
116      */
117     public String getRel() {
118         return _rel;
119     }
120 
121     /***
122      * Sets the link rel.
123      * <p>
124      * @param rel the link rel,, <b>null</b> if none.
125      *
126      */
127     public void setRel(String rel) {
128         if (!RELS.contains(rel)) {
129             throw new IllegalArgumentException("Invalid rel ["+rel+"]");
130         }
131         _rel = rel;
132     }
133 
134     /***
135      * Returns the link type.
136      * <p>
137      * @return the link type, <b>null</b> if none.
138      *
139      */
140     public String getType() {
141         return _type;
142     }
143 
144     /***
145      * Sets the link type.
146      * <p>
147      * @param type the link type, <b>null</b> if none.
148      *
149      */
150     public void setType(String type) {
151         _type = type;
152     }
153 
154     /***
155      * Returns the link href.
156      * <p>
157      * @return the link href, <b>null</b> if none.
158      *
159      */
160     public String getHref() {
161         return _href;
162     }
163 
164     /***
165      * Sets the link href.
166      * <p>
167      * @param href the link href, <b>null</b> if none.
168      *
169      */
170     public void setHref(String href) {
171         _href = href;
172     }
173 
174     /***
175      * Returns the link title.
176      * <p>
177      * @return the link title, <b>null</b> if none.
178      *
179      */
180     public String getTitle() {
181         return _title;
182     }
183 
184     /***
185      * Sets the link title.
186      * <p>
187      * @param title the link title, <b>null</b> if none.
188      *
189      */
190     public void setTitle(String title) {
191         _title = title;
192     }
193 
194 }