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.util.ArrayList;
024    import java.util.HashSet;
025    import java.util.List;
026    import java.util.Set;
027    import java.util.TreeSet;
028    
029    import org.granite.generator.TemplateUri;
030    import org.granite.generator.as3.reflect.JavaType.Kind;
031    
032    import com.thoughtworks.xstream.annotations.XStreamAlias;
033    import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
034    import com.thoughtworks.xstream.annotations.XStreamImplicit;
035    
036    /**
037     * @author Franck WOLFF
038     */
039    @XStreamAlias(value="gas3")
040    public class Gas3 implements Validable {
041    
042            @XStreamAsAttribute
043            private String uid;
044    
045            @XStreamAsAttribute
046            private String as3TypeFactory;
047    
048            @XStreamAsAttribute
049            private String entityFactory;
050    
051            @XStreamAsAttribute
052            private String remoteDestinationFactory;
053    
054            @XStreamAsAttribute
055            private boolean debugEnabled;
056    
057            @XStreamAsAttribute
058            private boolean flexConfig;
059    
060            @XStreamAsAttribute
061            private boolean externalizeLong;
062    
063            @XStreamAsAttribute
064            private boolean externalizeBigInteger;
065    
066            @XStreamAsAttribute
067            private boolean externalizeBigDecimal;
068            
069            @XStreamImplicit(itemFieldName="source")
070            private TreeSet<Gas3Source> sources;
071            
072            @XStreamImplicit(itemFieldName="project")
073            private TreeSet<Gas3Project> projects;
074            
075            @XStreamImplicit(itemFieldName="classpath")
076            private List<Gas3Classpath> classpaths;
077            
078            @XStreamImplicit(itemFieldName="template")
079            private Set<Gas3Template> templates;
080            
081            @XStreamImplicit(itemFieldName="transformer")
082            private List<Gas3Transformer> transformers;
083            
084            @XStreamImplicit(itemFieldName="translator")
085            private Set<Gas3Translator> translators;
086    
087            public Gas3() {
088            }
089    
090            public Gas3(String uid, String as3TypeFactory, String entityFactory, String remoteDestinationFactory) {
091                    this.uid = uid;
092                    this.as3TypeFactory = as3TypeFactory;
093                    this.entityFactory = entityFactory;
094                    this.remoteDestinationFactory = remoteDestinationFactory;
095            }
096    
097            public String getUid() {
098                    return uid;
099            }
100    
101            public void setUid(String uid) {
102                    this.uid = uid;
103            }
104    
105            public String getAs3TypeFactory() {
106                    return as3TypeFactory;
107            }
108    
109            public void setAs3TypeFactory(String as3TypeFactory) {
110                    this.as3TypeFactory = as3TypeFactory;
111            }
112    
113            public String getEntityFactory() {
114                    return entityFactory;
115            }
116    
117            public void setEntityFactory(String entityFactory) {
118                    this.entityFactory = entityFactory;
119            }
120    
121            public String getRemoteDestinationFactory() {
122                    return remoteDestinationFactory;
123            }
124    
125            public void setRemoteDestinationFactory(String remoteDestinationFactory) {
126                    this.remoteDestinationFactory = remoteDestinationFactory;
127            }
128    
129            public boolean isDebugEnabled() {
130                    return debugEnabled;
131            }
132    
133            public void setDebugEnabled(boolean debugEnabled) {
134                    this.debugEnabled = debugEnabled;
135            }
136    
137            public boolean isFlexConfig() {
138                    return flexConfig;
139            }
140    
141            public void setFlexConfig(boolean flexConfig) {
142                    this.flexConfig = flexConfig;
143            }
144    
145            public boolean isExternalizeLong() {
146                    return externalizeLong;
147            }
148    
149            public void setExternalizeLong(boolean externalizeLong) {
150                    this.externalizeLong = externalizeLong;
151            }
152    
153            public boolean isExternalizeBigInteger() {
154                    return externalizeBigInteger;
155            }
156    
157            public void setExternalizeBigInteger(boolean externalizeBigInteger) {
158                    this.externalizeBigInteger = externalizeBigInteger;
159            }
160    
161            public boolean isExternalizeBigDecimal() {
162                    return externalizeBigDecimal;
163            }
164    
165            public void setExternalizeBigDecimal(boolean externalizeBigDecimal) {
166                    this.externalizeBigDecimal = externalizeBigDecimal;
167            }
168    
169            public TreeSet<Gas3Source> getSources() {
170                    if (sources == null)
171                            sources = new TreeSet<Gas3Source>();
172                    return sources;
173            }
174    
175            public void setSources(TreeSet<Gas3Source> sources) {
176                    this.sources = sources;
177            }
178            
179            public Gas3Source getMatchingSource(String path, String file) {
180                    if (sources != null) {
181                            for (Gas3Source source : sources) {
182                                    if (source.match(path, file))
183                                            return source;
184                            }
185                    }
186                    return null;
187            }
188    
189            public TreeSet<Gas3Project> getProjects() {
190                    if (projects == null)
191                            projects = new TreeSet<Gas3Project>();
192                    return projects;
193            }
194    
195            public void setProjects(TreeSet<Gas3Project> projects) {
196                    this.projects = projects;
197            }
198    
199            public List<Gas3Classpath> getClasspaths() {
200                    if (classpaths == null)
201                            classpaths = new ArrayList<Gas3Classpath>();
202                    return classpaths;
203            }
204    
205            public void setClasspaths(List<Gas3Classpath> classpaths) {
206                    this.classpaths = classpaths;
207            }
208    
209            public Set<Gas3Template> getTemplates() {
210                    if (templates == null)
211                            templates = new HashSet<Gas3Template>();
212                    return templates;
213            }
214    
215            public void setTemplates(Set<Gas3Template> templates) {
216                    this.templates = templates;
217            }
218    
219            public Gas3Template getTemplate(Kind kind) {
220                    for (Gas3Template template : getTemplates()) {
221                            if (kind.equals(template.getKind()))
222                                    return template;
223                    }
224                    return null;
225            }
226    
227            public TemplateUri[] getMatchingTemplateUris(Kind kind) {
228                    if (templates != null) {
229                            for (Gas3Template template : templates) {
230                                    if (kind.equals(template.getKind()))
231                                            return template.getTemplateUris();
232                            }
233                    }
234                    return null;
235            }
236    
237            public List<Gas3Transformer> getTransformers() {
238                    if (transformers == null)
239                            transformers = new ArrayList<Gas3Transformer>();
240                    return transformers;
241            }
242    
243            public Set<Gas3Translator> getTranslators() {
244                    if (translators == null)
245                            translators = new HashSet<Gas3Translator>();
246                    return translators;
247            }
248    
249            public void validate(ValidationResults results) {
250                    if (sources != null) {
251                            for (Validable validable : sources)
252                                    validable.validate(results);
253                    }
254                    if (classpaths != null) {
255                            for (Validable validable : classpaths)
256                                    validable.validate(results);
257                    }
258                    if (templates != null) {
259                            for (Validable validable : templates)
260                                    validable.validate(results);
261                    }
262                    if (transformers != null) {
263                            for (Validable validable : transformers)
264                                    validable.validate(results);
265                    }
266                    if (translators != null) {
267                            for (Validable validable : translators)
268                                    validable.validate(results);
269                    }
270            }
271    }