001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.builder.properties;
022
023 import java.beans.PropertyChangeListener;
024 import java.beans.PropertyChangeSupport;
025 import java.util.ArrayList;
026 import java.util.HashSet;
027 import java.util.List;
028 import java.util.Set;
029 import java.util.TreeSet;
030
031 import org.granite.generator.TemplateUri;
032 import org.granite.generator.as3.reflect.JavaType.Kind;
033
034 import com.thoughtworks.xstream.annotations.XStreamAlias;
035 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
036 import com.thoughtworks.xstream.annotations.XStreamImplicit;
037 import com.thoughtworks.xstream.annotations.XStreamOmitField;
038
039 /**
040 * @author Franck WOLFF
041 */
042 @XStreamAlias(value="gas3")
043 public class Gas3 implements Validable {
044
045 @XStreamOmitField
046 private PropertyChangeSupport _pcs = null;
047
048 @XStreamAsAttribute
049 private String uid;
050
051 @XStreamAsAttribute
052 private String as3TypeFactory;
053
054 @XStreamAsAttribute
055 private String entityFactory;
056
057 @XStreamAsAttribute
058 private String remoteDestinationFactory;
059
060 @XStreamAsAttribute
061 private boolean debugEnabled;
062
063 @XStreamAsAttribute
064 private boolean flexConfig;
065
066 @XStreamAsAttribute
067 private boolean externalizeLong;
068
069 @XStreamAsAttribute
070 private boolean externalizeBigInteger;
071
072 @XStreamAsAttribute
073 private boolean externalizeBigDecimal;
074
075 @XStreamImplicit(itemFieldName="source")
076 private TreeSet<Gas3Source> sources;
077
078 @XStreamImplicit(itemFieldName="project")
079 private TreeSet<Gas3Project> projects;
080
081 @XStreamImplicit(itemFieldName="classpath")
082 private List<Gas3Classpath> classpaths;
083
084 @XStreamImplicit(itemFieldName="template")
085 private Set<Gas3Template> templates;
086
087 @XStreamImplicit(itemFieldName="transformer")
088 private List<Gas3Transformer> transformers;
089
090 @XStreamImplicit(itemFieldName="translator")
091 private Set<Gas3Translator> translators;
092
093 public Gas3() {
094 _pcs = new PropertyChangeSupport(this);
095 }
096
097 public Gas3(String uid, String as3TypeFactory, String entityFactory, String remoteDestinationFactory) {
098 this.uid = uid;
099 this.as3TypeFactory = as3TypeFactory;
100 this.entityFactory = entityFactory;
101 this.remoteDestinationFactory = remoteDestinationFactory;
102
103 _pcs = new PropertyChangeSupport(this);
104 }
105
106 public String getUid() {
107 return uid;
108 }
109
110 public void setUid(String uid) {
111 this.uid = uid;
112 }
113
114 public String getAs3TypeFactory() {
115 return as3TypeFactory;
116 }
117
118 public void setAs3TypeFactory(String as3TypeFactory) {
119 String old = this.as3TypeFactory;
120 this.as3TypeFactory = as3TypeFactory;
121 if (_pcs != null)
122 _pcs.firePropertyChange("as3TypeFactory", old, as3TypeFactory);
123 }
124
125 public String getEntityFactory() {
126 return entityFactory;
127 }
128
129 public void setEntityFactory(String entityFactory) {
130 this.entityFactory = entityFactory;
131 }
132
133 public String getRemoteDestinationFactory() {
134 return remoteDestinationFactory;
135 }
136
137 public void setRemoteDestinationFactory(String remoteDestinationFactory) {
138 this.remoteDestinationFactory = remoteDestinationFactory;
139 }
140
141 public boolean isDebugEnabled() {
142 return debugEnabled;
143 }
144
145 public void setDebugEnabled(boolean debugEnabled) {
146 this.debugEnabled = debugEnabled;
147 }
148
149 public boolean isFlexConfig() {
150 return flexConfig;
151 }
152
153 public void setFlexConfig(boolean flexConfig) {
154 this.flexConfig = flexConfig;
155 }
156
157 public boolean isExternalizeLong() {
158 return externalizeLong;
159 }
160
161 public void setExternalizeLong(boolean externalizeLong) {
162 this.externalizeLong = externalizeLong;
163 }
164
165 public boolean isExternalizeBigInteger() {
166 return externalizeBigInteger;
167 }
168
169 public void setExternalizeBigInteger(boolean externalizeBigInteger) {
170 this.externalizeBigInteger = externalizeBigInteger;
171 }
172
173 public boolean isExternalizeBigDecimal() {
174 return externalizeBigDecimal;
175 }
176
177 public void setExternalizeBigDecimal(boolean externalizeBigDecimal) {
178 this.externalizeBigDecimal = externalizeBigDecimal;
179 }
180
181 public TreeSet<Gas3Source> getSources() {
182 if (sources == null)
183 sources = new TreeSet<Gas3Source>();
184 return sources;
185 }
186
187 public void setSources(TreeSet<Gas3Source> sources) {
188 this.sources = sources;
189 }
190
191 public Gas3Source getMatchingSource(String path, String file) {
192 if (sources != null) {
193 for (Gas3Source source : sources) {
194 if (source.match(path, file))
195 return source;
196 }
197 }
198 return null;
199 }
200
201 public TreeSet<Gas3Project> getProjects() {
202 if (projects == null)
203 projects = new TreeSet<Gas3Project>();
204 return projects;
205 }
206
207 public void setProjects(TreeSet<Gas3Project> projects) {
208 this.projects = projects;
209 }
210
211 public List<Gas3Classpath> getClasspaths() {
212 if (classpaths == null)
213 classpaths = new ArrayList<Gas3Classpath>();
214 return classpaths;
215 }
216
217 public void setClasspaths(List<Gas3Classpath> classpaths) {
218 this.classpaths = classpaths;
219 }
220
221 public Set<Gas3Template> getTemplates() {
222 if (templates == null)
223 templates = new HashSet<Gas3Template>();
224 return templates;
225 }
226
227 public void setTemplates(Set<Gas3Template> templates) {
228 this.templates = templates;
229 }
230
231 public Gas3Template getTemplate(Kind kind) {
232 for (Gas3Template template : getTemplates()) {
233 if (kind.equals(template.getKind()))
234 return template;
235 }
236 return null;
237 }
238
239 public TemplateUri[] getMatchingTemplateUris(Kind kind) {
240 if (templates != null) {
241 for (Gas3Template template : templates) {
242 if (kind.equals(template.getKind()))
243 return template.getTemplateUris();
244 }
245 }
246 return null;
247 }
248
249 public List<Gas3Transformer> getTransformers() {
250 if (transformers == null)
251 transformers = new ArrayList<Gas3Transformer>();
252 return transformers;
253 }
254
255 public Set<Gas3Translator> getTranslators() {
256 if (translators == null)
257 translators = new HashSet<Gas3Translator>();
258 return translators;
259 }
260
261 @Override
262 public void validate(ValidationResults results) {
263 if (sources != null) {
264 for (Validable validable : sources)
265 validable.validate(results);
266 }
267 if (classpaths != null) {
268 for (Validable validable : classpaths)
269 validable.validate(results);
270 }
271 if (templates != null) {
272 for (Validable validable : templates)
273 validable.validate(results);
274 }
275 if (transformers != null) {
276 for (Validable validable : transformers)
277 validable.validate(results);
278 }
279 if (translators != null) {
280 for (Validable validable : translators)
281 validable.validate(results);
282 }
283 }
284
285 public void addPropertyChangeListener(String name, PropertyChangeListener listener) {
286 if (_pcs == null)
287 _pcs = new PropertyChangeSupport(this);
288 _pcs.addPropertyChangeListener(name, listener);
289 }
290
291 public void addPropertyChangeListener(PropertyChangeListener listener) {
292 if (_pcs == null)
293 _pcs = new PropertyChangeSupport(this);
294 _pcs.addPropertyChangeListener(listener);
295 }
296
297 public void removePropertyChangeListener(String name, PropertyChangeListener listener) {
298 if (_pcs == null)
299 _pcs = new PropertyChangeSupport(this);
300 _pcs.removePropertyChangeListener(name, listener);
301 }
302
303 public void removePropertyChangeListener(PropertyChangeListener listener) {
304 if (_pcs == null)
305 _pcs = new PropertyChangeSupport(this);
306 _pcs.removePropertyChangeListener(listener);
307 }
308 }