KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > coplets > basket > AbstractItem


1 /*
2  * Copyright 2004-2005 The Apache Software Foundation.
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 package org.apache.cocoon.portal.coplets.basket;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22
23
24 /**
25  * This is a possible base class for item implementations.
26  *
27  * It just adds attributes (or meta-data) functionality
28  *
29  * @version CVS $Id: AbstractItem.java 125056 2005-01-13 10:33:37Z cziegeler $
30  */

31 public class AbstractItem implements Serializable JavaDoc {
32     
33     protected static long currentId = System.currentTimeMillis();
34     
35     /** The attributes */
36     protected Map JavaDoc attributes = new HashMap JavaDoc();
37     
38     /** Unique id */
39     protected long id;
40     
41     public AbstractItem() {
42         synchronized ( this.getClass() ) {
43             currentId++;
44             this.id = currentId;
45         }
46     }
47
48     /** Return an attribute or null */
49     public Object JavaDoc getAttribute(String JavaDoc name) {
50         return this.attributes.get(name);
51     }
52     
53     /** Set an attribute */
54     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
55         this.attributes.put(name, value);
56     }
57     
58     /** Get all attribute names */
59     public Iterator JavaDoc getAttributeNames() {
60         return this.attributes.keySet().iterator();
61     }
62     
63     /** Remove one attribute */
64     public void removeAttribute(String JavaDoc name) {
65         this.attributes.remove(name);
66     }
67     
68     /** Check if an attribute is available */
69     public boolean hasAttribute(String JavaDoc name) {
70         return this.attributes.containsKey(name);
71     }
72     
73     public long getId() {
74         return this.id;
75     }
76 }
77
Popular Tags