01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.portal.coplets.basket;
18:
19: import java.io.Serializable;
20: import java.util.HashMap;
21: import java.util.Iterator;
22: import java.util.Map;
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 433543 2006-08-22 06:22:54Z crossley $
30: */
31: public class AbstractItem implements Serializable {
32:
33: protected static long currentId = System.currentTimeMillis();
34:
35: /** The attributes */
36: protected Map attributes = new HashMap();
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 getAttribute(String name) {
50: return this .attributes.get(name);
51: }
52:
53: /** Set an attribute */
54: public void setAttribute(String name, Object value) {
55: this .attributes.put(name, value);
56: }
57:
58: /** Get all attribute names */
59: public Iterator getAttributeNames() {
60: return this .attributes.keySet().iterator();
61: }
62:
63: /** Remove one attribute */
64: public void removeAttribute(String name) {
65: this .attributes.remove(name);
66: }
67:
68: /** Check if an attribute is available */
69: public boolean hasAttribute(String name) {
70: return this .attributes.containsKey(name);
71: }
72:
73: public long getId() {
74: return this.id;
75: }
76: }
|