KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > structure > EditorDefinition


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.structure;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashMap JavaDoc;
34
35 import com.genimen.djeneric.repository.exceptions.DjenericException;
36 import com.genimen.djeneric.util.DjLogger;
37
38 public class EditorDefinition implements Cloneable JavaDoc
39 {
40
41   String JavaDoc _name;
42   ScriptDefinition _scriptDefinition = new ScriptDefinition();
43   ExtentUsage _usages;
44   boolean _markedForDelete = false;
45   String JavaDoc _customEditorClass = null;
46
47   public Object JavaDoc clone()
48   {
49     EditorDefinition result = null;
50     try
51     {
52       result = (EditorDefinition) super.clone();
53       result._scriptDefinition = (ScriptDefinition) _scriptDefinition.clone();
54       if (_usages != null) result._usages = (ExtentUsage) _usages.clone();
55     }
56     catch (CloneNotSupportedException JavaDoc e)
57     {
58       DjLogger.log(e);
59     }
60
61     return result;
62   }
63
64   public void copyFrom(EditorDefinition source)
65   {
66     _name = source._name;
67     _customEditorClass = source._customEditorClass;
68     _scriptDefinition = (ScriptDefinition) source.getScriptDefinition().clone();
69     _usages = (ExtentUsage) source._usages.clone();
70     _markedForDelete = source._markedForDelete;
71   }
72
73   public boolean equals(Object JavaDoc obj)
74   {
75     if (obj == this) return true;
76     if (!(obj instanceof EditorDefinition)) return false;
77     EditorDefinition other = (EditorDefinition) obj;
78
79     return safeCompare(_name, other._name) && safeCompare(_customEditorClass, other._customEditorClass)
80            && safeCompare(_scriptDefinition, other._scriptDefinition) && safeCompare(_usages, other._usages);
81   }
82
83   public int hashCode()
84   {
85     int result = 0;
86     if (_name != null) result += _name.hashCode();
87     if (_customEditorClass != null) result += _customEditorClass.hashCode();
88     if (_scriptDefinition != null) result += _scriptDefinition.hashCode();
89     return result;
90   }
91
92   private boolean safeCompare(Object JavaDoc one, Object JavaDoc two)
93   {
94     if (one == null && two == null) return true;
95     if (one == null || two == null) return false;
96
97     return one.equals(two);
98   }
99
100   public ScriptDefinition getScriptDefinition()
101   {
102     return _scriptDefinition;
103   }
104
105   /**
106    * @param scriptDefinition
107    */

108   public void setScriptDefinition(ScriptDefinition scriptDefinition)
109   {
110     _scriptDefinition = scriptDefinition;
111   }
112
113   public EditorDefinition()
114   {
115   }
116
117   public EditorDefinition(String JavaDoc name, ExtentUsage usages)
118   {
119     _usages = usages;
120     _name = name;
121   }
122
123   public String JavaDoc getName()
124   {
125     return _name;
126   }
127
128   public void setName(String JavaDoc name)
129   {
130     _name = name;
131   }
132
133   public void setUsages(ExtentUsage usages)
134   {
135     _usages = usages;
136   }
137
138   public ExtentUsage getUsages()
139   {
140     return _usages;
141   }
142
143   public String JavaDoc toString()
144   {
145     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
146     result.append(_name);
147
148     if (_usages != null)
149     {
150       result.append(" (");
151       result.append(_usages.getExtent().getName());
152       result.append(")");
153     }
154
155     return result.toString();
156   }
157
158   public boolean isMarkedForDelete()
159   {
160     return _markedForDelete;
161   }
162
163   public void setMarkedForDelete(boolean markedForDelete)
164   {
165     _markedForDelete = markedForDelete;
166   }
167
168   public String JavaDoc getCustomEditorClass()
169   {
170     return _customEditorClass;
171   }
172
173   public void setCustomEditorClass(String JavaDoc className)
174   {
175     if (className != null && className.trim().length() == 0) className = null;
176
177     _customEditorClass = className;
178   }
179
180   public void removeInvalidExtents()
181   {
182     ExtentUsage usages = getUsages();
183     if (usages != null) usages.deleteInvalidNodes();
184   }
185
186   public void validate() throws DjenericException
187   {
188     _usages.validate();
189   }
190
191   public void getUsageIdAndTypes(HashMap JavaDoc variables)
192   {
193     ExtentUsage usages = getUsages();
194     addUsages(variables, usages);
195   }
196
197   private void addUsages(HashMap JavaDoc variables, ExtentUsage usage)
198   {
199     variables.put(usage.getId(), usage.getExtent().getQualifiedObjectType());
200     ExtentUsage[] children = usage.getChildren();
201     for (int i = 0; i < children.length; i++)
202       addUsages(variables, children[i]);
203   }
204
205   public String JavaDoc[] getEvents()
206   {
207     ArrayList JavaDoc ev = new ArrayList JavaDoc();
208
209     ev.add("validate");
210     ev.add("accept");
211     ev.add("cancel");
212
213     addExtentEvents(getUsages(), ev);
214     return (String JavaDoc[]) ev.toArray(new String JavaDoc[0]);
215   }
216
217   protected void addExtentEvents(ExtentUsage usg, ArrayList JavaDoc ev)
218   {
219     ev.add(usg.getId() + ".aftercreate");
220     ev.add(usg.getId() + ".afterdelete");
221     ev.add(usg.getId() + ".afterpropertychanged");
222     ev.add(usg.getId() + ".beforecreate");
223     ev.add(usg.getId() + ".beforedelete");
224     ev.add(usg.getId() + ".beforepropertychanged");
225
226     ExtentUsage[] children = usg.getChildren();
227     for (int i = 0; i < children.length; i++)
228     {
229       addExtentEvents(children[i], ev);
230     }
231   }
232
233 }
Popular Tags