View Javadoc

1   package org.xmlhammer.gui.util;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.xmlhammer.model.jaxp.Activatable;
7   import org.xmlhammer.model.jaxp.Attribute;
8   import org.xmlhammer.model.jaxp.Feature;
9   import org.xmlhammer.model.jaxp.JAXPDocumentBuilderFactory;
10  import org.xmlhammer.model.jaxp.JAXPSAXParserFactory;
11  import org.xmlhammer.model.jaxp.JAXPSchemaFactory;
12  import org.xmlhammer.model.jaxp.JAXPTransformerFactory;
13  import org.xmlhammer.model.jaxp.JAXPXPathFactory;
14  import org.xmlhammer.model.jaxp.Mapping;
15  import org.xmlhammer.model.jaxp.Property;
16  import org.xmlhammer.model.jaxp.SchemaFactoryProperty;
17  import org.xmlhammer.model.jaxp.Settings;
18  
19  public class JAXPSettings {
20      private Settings project = null;
21      private Settings preferences = null;
22  
23      public JAXPSettings(Settings preferences, Settings project) {
24          super();
25          
26          this.preferences = preferences;
27          this.project = project;
28      }
29      
30      /***
31       * @return the JAXPXPathFactory.Settings, project specific if defined, otherwise from global preferences.
32       */
33      public JAXPXPathFactory.Settings getXPathFactorySettings() {
34          if ( project.getJAXPXPathFactory().getSettings() == null) {
35              return preferences.getJAXPXPathFactory().getSettings();
36          }
37  
38          return project.getJAXPXPathFactory().getSettings();
39      }
40  
41      /***
42       * @return the JAXPXPathFactory.Settings, project specific if defined, otherwise from global preferences.
43       */
44      public List<Feature> getXPathFactoryFeatures() {
45          ActiveFilter<Feature> filter = new ActiveFilter<Feature>();
46          
47          if (project.getJAXPXPathFactory().getFeatures() == null) {
48              return filter.filter(preferences.getJAXPXPathFactory().getFeatures().getFeature());
49          }
50  
51          return filter.filter(project.getJAXPXPathFactory().getFeatures().getFeature());
52      }
53  
54      /***
55       * @return the JAXPXPathFactory.Mappings, project specific if defined, otherwise from global preferences.
56       */
57      public final List<Mapping> getXPathFactoryMappings() {
58          ActiveFilter<Mapping> filter = new ActiveFilter<Mapping>();
59  
60          if (project.getJAXPXPathFactory().getMappings() == null) {
61              return filter.filter(preferences.getJAXPXPathFactory().getMappings().getMapping());
62          }
63  
64          return filter.filter(project.getJAXPXPathFactory().getMappings().getMapping());
65      }
66  
67      /***
68       * @return the JAXPSAXParserFactory.Settings, project specific if defined, otherwise from global preferences.
69       */
70      public final JAXPSAXParserFactory.Settings getSAXParserSettings() {
71          if ( project.getJAXPSAXParserFactory().getSettings() == null) {
72              return preferences.getJAXPSAXParserFactory().getSettings();
73          }
74  
75          return project.getJAXPSAXParserFactory().getSettings();
76      }
77  
78      /***
79       * @return the JAXPSAXParserFactory.Features, project specific if defined, otherwise from global preferences.
80       */
81      public final List<Feature> getSAXParserFactoryFeatures() {
82          ActiveFilter<Feature> filter = new ActiveFilter<Feature>();
83  
84          if (project.getJAXPSAXParserFactory().getFeatures() == null) {
85              return filter.filter(preferences.getJAXPSAXParserFactory().getFeatures().getFeature());
86          }
87  
88          return filter.filter(project.getJAXPSAXParserFactory().getFeatures().getFeature());
89      }
90  
91      /***
92       * @return the JAXPSAXParserFactory.Properties, project specific if defined, otherwise from global preferences.
93       */
94      public final List<Property> getSAXParserFactoryProperties() {
95          ActiveFilter<Property> filter = new ActiveFilter<Property>();
96  
97          if (project.getJAXPSAXParserFactory().getProperties() == null) {
98              return filter.filter(preferences.getJAXPSAXParserFactory().getProperties().getProperty());
99          }
100 
101         return filter.filter(project.getJAXPSAXParserFactory().getProperties().getProperty());
102     }
103 
104     /***
105      * @return the JAXPDocumentBuilderFactory.Settings, project specific if defined, otherwise from global preferences.
106      */
107     public final JAXPDocumentBuilderFactory.Settings getDocumentBuilderFactorySettings() {
108         if (project.getJAXPDocumentBuilderFactory().getSettings() == null) {
109             return preferences.getJAXPDocumentBuilderFactory().getSettings();
110         }
111 
112         return project.getJAXPDocumentBuilderFactory().getSettings();
113     }
114 
115     /***
116      * @return the JAXPDocumentBuilderFactory.Features, project specific if defined, otherwise from global preferences.
117      */
118     public final List<Feature> getDocumentBuilderFactoryFeatures() {
119         ActiveFilter<Feature> filter = new ActiveFilter<Feature>();
120 
121         if (project.getJAXPDocumentBuilderFactory().getFeatures() == null) {
122             return filter.filter(preferences.getJAXPDocumentBuilderFactory().getFeatures().getFeature());
123         }
124 
125         return filter.filter(project.getJAXPDocumentBuilderFactory().getFeatures().getFeature());
126     }
127 
128     /***
129      * @return the JAXPDocumentBuilderFactory.Attributes, project specific if defined, otherwise from global preferences.
130      */
131     public final List<Attribute> getDocumentBuilderFactoryAttributes() {
132         ActiveFilter<Attribute> filter = new ActiveFilter<Attribute>();
133 
134         if (project.getJAXPDocumentBuilderFactory().getAttributes() == null) {
135             return filter.filter(preferences.getJAXPDocumentBuilderFactory().getAttributes().getAttribute());
136         }
137 
138         return filter.filter(project.getJAXPDocumentBuilderFactory().getAttributes().getAttribute());
139     }
140 
141     /***
142      * @return the JAXPSchemaFactory.Settings, project specific if defined, otherwise from global preferences.
143      */
144     public final JAXPSchemaFactory.Settings getSchemaFactorySettings() {
145         if (project.getJAXPSchemaFactory().getSettings() == null) {
146             return preferences.getJAXPSchemaFactory().getSettings();
147         }
148 
149         return project.getJAXPSchemaFactory().getSettings();
150     }
151 
152     /***
153      * @return the JAXPSchemaFactory.Settings, project specific if defined, otherwise from global preferences.
154      */
155     public final List<SchemaFactoryProperty> getSchemaFactoryLanguageProperties() {
156         if (project.getJAXPSchemaFactory().getSchemaFactoryProperties() == null) {
157             return preferences.getJAXPSchemaFactory().getSchemaFactoryProperties().getSchemaFactoryProperty();
158         }
159 
160         return project.getJAXPSchemaFactory().getSchemaFactoryProperties().getSchemaFactoryProperty();
161     }
162 
163     /***
164      * @return the JAXPSchemaFactory.Features, project specific if defined, otherwise from global preferences.
165      */
166     public final List<Feature> getSchemaFactoryFeatures() {
167         ActiveFilter<Feature> filter = new ActiveFilter<Feature>();
168 
169         if (project.getJAXPSchemaFactory().getFeatures() == null) {
170             return filter.filter(preferences.getJAXPSchemaFactory().getFeatures().getFeature());
171         }
172 
173         return filter.filter(project.getJAXPSchemaFactory().getFeatures().getFeature());
174     }
175 
176     /***
177      * @return the JAXPSchemaFactory.Properties, project specific if defined, otherwise from global preferences.
178      */
179     public final List<Property> getSchemaFactoryProperties() {
180         ActiveFilter<Property> filter = new ActiveFilter<Property>();
181 
182         if (project.getJAXPSchemaFactory().getProperties() == null) {
183             return filter.filter(preferences.getJAXPSchemaFactory().getProperties().getProperty());
184         }
185 
186         return filter.filter(project.getJAXPSchemaFactory().getProperties().getProperty());
187     }
188 
189     /***
190      * @return the JAXPTransformerFactory.Settings, project specific if defined, otherwise from global preferences.
191      */
192     public final JAXPTransformerFactory.Settings getTransformerFactorySettings() {
193         if (project.getJAXPTransformerFactory().getSettings() == null) {
194             return preferences.getJAXPTransformerFactory().getSettings();
195         }
196 
197         return project.getJAXPTransformerFactory().getSettings();
198     }
199 
200     /***
201      * @return the JAXPTransformerFactory.Features, project specific if defined, otherwise from global preferences.
202      */
203     public final List<Feature> getTransformerFactoryFeatures() {
204         ActiveFilter<Feature> filter = new ActiveFilter<Feature>();
205 
206         if (project.getJAXPTransformerFactory().getFeatures() == null) {
207             return filter.filter(preferences.getJAXPTransformerFactory().getFeatures().getFeature());
208         }
209 
210         return filter.filter(project.getJAXPTransformerFactory().getFeatures().getFeature());
211     }
212 
213     /***
214      * @return the JAXPTransformerFactory.Attributes, project specific if defined, otherwise from global preferences.
215      */
216     public final List<Attribute> getTransformerFactoryAttributes() {
217         ActiveFilter<Attribute> filter = new ActiveFilter<Attribute>();
218 
219         if (project.getJAXPTransformerFactory().getAttributes() == null) {
220             return filter.filter(preferences.getJAXPTransformerFactory().getAttributes().getAttribute());
221         }
222 
223         return filter.filter(project.getJAXPTransformerFactory().getAttributes().getAttribute());
224     }
225     
226     private class ActiveFilter<T extends Activatable> {
227         public List<T> filter(List<T> objects) {
228             List<T> activeObjects = new ArrayList<T>(objects);
229             
230             for (T object : objects) {
231                 if (!object.isActive()) {
232                     activeObjects.remove(object);
233                 }
234             }
235             
236             return activeObjects;
237         }
238     }
239 }