KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > boot > DefaultPropertyDefinitionCategory


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.boot;
21
22 import java.io.Serializable JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.List JavaDoc;
27
28
29 /**
30  * Default implementation of a {@link PropertyDefinitionCategory}.
31  *
32  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
33  */

34 public class DefaultPropertyDefinitionCategory implements PropertyDefinitionCategory, Serializable JavaDoc {
35
36     // Private instance variables
37

38     private int id;
39     private String JavaDoc imagePath;
40     private String JavaDoc bundle;
41     private List JavaDoc<PropertyDefinitionCategory> children;
42     private PropertyDefinitionCategory parent;
43     private boolean enabled = true;
44     private transient PropertyClass propertyClass;
45
46     /**
47      * Constructor.
48      *
49      * @param id category id
50      * @param bundle bundle
51      * @param imagePath path for image
52      */

53     public DefaultPropertyDefinitionCategory(int id, String JavaDoc bundle, String JavaDoc imagePath) {
54         this.id = id;
55         this.imagePath = imagePath;
56         this.bundle = bundle;
57         children = new ArrayList JavaDoc<PropertyDefinitionCategory>();
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see java.lang.Object#equals(java.lang.Object)
64      */

65     public boolean equals(Object JavaDoc o) {
66         return o instanceof PropertyDefinitionCategory && ((PropertyDefinitionCategory) o).getId() == getId();
67     }
68
69     /*
70      * (non-Javadoc)
71      *
72      * @see com.sslexplorer.properties.PropertyDefinitionCategory#getParent()
73      */

74     public PropertyDefinitionCategory getParent() {
75         return parent;
76     }
77
78     /*
79      * (non-Javadoc)
80      *
81      * @see com.sslexplorer.properties.PropertyDefinitionCategory#getId()
82      */

83     public int getId() {
84         return id;
85     }
86
87     /*
88      * (non-Javadoc)
89      *
90      * @see com.sslexplorer.properties.PropertyDefinitionCategory#getBundle()
91      */

92     public String JavaDoc getBundle() {
93         return bundle;
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see com.sslexplorer.properties.PropertyDefinitionCategory#getImagePath()
100      */

101     public String JavaDoc getImagePath() {
102         return imagePath;
103     }
104
105     /*
106      * (non-Javadoc)
107      *
108      * @see com.sslexplorer.properties.PropertyDefinitionCategory#addCategory(com.sslexplorer.properties.PropertyDefinitionCategory)
109      */

110     public PropertyDefinitionCategory addCategory(PropertyDefinitionCategory category) {
111         children.add(category);
112         return this;
113     }
114
115     /*
116      * (non-Javadoc)
117      *
118      * @see com.sslexplorer.properties.PropertyDefinitionCategory#removeCategory(com.sslexplorer.properties.PropertyDefinitionCategory)
119      */

120     public PropertyDefinitionCategory removeCategory(PropertyDefinitionCategory category) {
121         children.remove(category);
122         return this;
123     }
124
125     /*
126      * (non-Javadoc)
127      *
128      * @see com.sslexplorer.properties.PropertyDefinitionCategory#setParent(com.sslexplorer.properties.PropertyDefinitionCategory)
129      */

130     public void setParent(PropertyDefinitionCategory parent) {
131         this.parent = parent;
132     }
133
134     /*
135      * (non-Javadoc)
136      *
137      * @see com.sslexplorer.properties.PropertyDefinitionCategory#size()
138      */

139     public int size() {
140         return children.size();
141     }
142
143     /*
144      * (non-Javadoc)
145      *
146      * @see com.sslexplorer.properties.PropertyDefinitionCategory#getCategories()
147      */

148     public List JavaDoc<PropertyDefinitionCategory> getCategories() {
149         return children;
150     }
151
152     /*
153      * (non-Javadoc)
154      *
155      * @see com.sslexplorer.properties.PropertyDefinitionCategory#contains(com.sslexplorer.properties.PropertyDefinitionCategory)
156      */

157     public boolean contains(PropertyDefinitionCategory category) {
158         return children.contains(category);
159     }
160
161     /*
162      * (non-Javadoc)
163      *
164      * @see com.sslexplorer.properties.PropertyDefinitionCategory#isEnabled()
165      */

166     public boolean isEnabled() {
167         return enabled;
168     }
169
170     /*
171      * (non-Javadoc)
172      *
173      * @see com.sslexplorer.properties.PropertyDefinitionCategory#setEnabled(boolean)
174      */

175     public void setEnabled(boolean enabled) {
176         this.enabled = enabled;
177         for(PropertyDefinitionCategory cat : children) {
178             cat.setEnabled(enabled);
179         }
180     }
181
182     /*
183      * (non-Javadoc)
184      *
185      * @see com.sslexplorer.properties.PropertyDefinitionCategory#getPropertyClass()
186      */

187     public PropertyClass getPropertyClass() {
188         return propertyClass;
189     }
190
191     /*
192      * (non-Javadoc)
193      *
194      * @see com.sslexplorer.properties.PropertyDefinitionCategory#setPropertyClass(com.sslexplorer.boot.PropertyClass)
195      */

196     public void setPropertyClass(PropertyClass propertyClass) {
197         this.propertyClass = propertyClass;
198     }
199
200     /* (non-Javadoc)
201      * @see com.sslexplorer.boot.PropertyDefinitionCategory#getDefinitions()
202      */

203     public Collection JavaDoc<PropertyDefinition> getDefinitions() {
204         List JavaDoc<PropertyDefinition> l = new ArrayList JavaDoc<PropertyDefinition>();
205         if(propertyClass == null) {
206             return l;
207         }
208         for(PropertyDefinition def : propertyClass.getDefinitions()) {
209             if(def.getCategory() == getId()) {
210                 l.add(def);
211             }
212         }
213         Collections.sort(l);
214         return l;
215     }
216     
217     /* (non-Javadoc)
218      * @see java.lang.Object#toString()
219      */

220     public String JavaDoc toString() {
221         return "[parent=" + getParent() + ", id=" + getId() + ", bundle=" + getBundle() + ", image=" + getImagePath() + "]";
222     }
223 }
224
Popular Tags