KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > data > AbstractPData


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: AbstractPData.java,v 1.3 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.data;
21
22 import java.io.*;
23 import java.util.*;
24
25 /**
26  * Abstract implementation of the basic PData methods.
27  */

28 public abstract class AbstractPData implements PData {
29
30     protected PData parent = null;
31     protected boolean inheritParents = true;
32     protected DefaultStateMap state = null;
33
34
35     //--------------- PData --------------------------------------
36
/**
37      * set the object's parent. May be some other PData object or
38      * null (indicating hierarchy root). May not be a reference to self.
39      *
40      * @param p the parent PData object
41      */

42     public void setParent(PData p) {
43         //don't ever allow an object to set itself as the parent...this
44
//is meaningless and would result in an endless loop in the case
45
//of getRootParent()
46
if (p==this) return;
47         parent = p;
48     }
49
50     /**
51      * get the objects parent (null if root)
52      *
53      * @return the PData object
54      */

55     public PData getParent() {
56         return parent;
57     }
58
59     /**
60      * get the root parent by chaining back up the heirarchy until we find
61      * the highest PData object in the heirarchy.
62      *
63      * @return the root PData object
64      */

65     public PData getRootParent() {
66         if ((parent!=null) || (parent instanceof PData)) return parent.getRootParent();
67         else return this;
68     }
69     
70     /**
71      * Do we want to inherit parents. Defaults to true. This indicates that
72      * when an object is added to this data collection, if it implements
73      * PData, it should automatically inherit the current object as its
74      * parent. You would typically set this to false if you were going
75      * to be storing PData "mini-hierarchies" within a larger PData
76      * hierarchy
77      *
78      * @param val true if we should inherit parents
79      */

80     public void setInheritParents(boolean val) {
81         inheritParents = val;
82     }
83     
84     /**
85      * Return true if we are inheriting parents.
86      *
87      * @return true if we are inheriting parents
88      */

89     public boolean isInheritParents() {
90         return inheritParents;
91     }
92
93
94     //--------------- StateMap -----------------------------------
95
/**
96      * set a property in this StateMap
97      *
98      * @param key the key object
99      * @param val the value object
100      */

101     public void putState(Object JavaDoc key, Object JavaDoc val) {
102         if (state==null) state = new DefaultStateMap();
103         state.putState(key, val);
104     }
105     
106     /**
107      * get a property in this StateMap
108      *
109      * @param key the key object
110      * @return the value for the given key
111      */

112     public Object JavaDoc getState(Object JavaDoc key) {
113         if (state==null) return null;
114         else return state.getState(key);
115     }
116     
117     /**
118      * remove a property in this StateMap
119      *
120      * @param key the key object
121      * @return the object which was removed
122      */

123     public Object JavaDoc removeState(Object JavaDoc key) {
124         if (state==null) return null;
125         else return state.removeState(key);
126     }
127     
128     /**
129      * get a List of the keys for this StateMap (implementation
130      * is an ArrayList)
131      *
132      * @return a List the keys for this StateMap
133      */

134     public List getStateKeys() {
135         if (state==null) return null;
136         else return state.getStateKeys();
137     }
138     
139     /**
140      * get a copy of the underlying Map that holds
141      * the state values
142      *
143      * @return a copy of the underlying state Map
144      */

145     public Map getStateValues() {
146         if (state==null) state = new DefaultStateMap();
147         return state.getStateValues();
148     }
149
150     //csc_052803_2 - added
151
/**
152      * clear all state information
153      */

154     public void clearState() {
155         if (state!=null) state.clearState();
156     }
157
158
159
160 }
161
Popular Tags