View Javadoc

1   // $Id: XsAnalyzerApplicationModel.java 165 2009-05-28 21:46:38Z agony $
2   /*
3    * xsAnalyzer - XML schema analyzing tool. Copyright (C) 2008 Michael Engelhardt
4    * 
5    * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6    * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7    * version.
8    * 
9    * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11   * 
12   * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
13   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14   */
15  /**
16   * 
17   */
18  package de.mindcrimeilab.xsanalyzer.model;
19  
20  import java.io.File;
21  import java.util.Map;
22  import java.util.Set;
23  
24  import javax.xml.namespace.QName;
25  
26  import org.apache.xerces.xs.XSModel;
27  import org.apache.xerces.xs.XSNamespaceItem;
28  import org.apache.xerces.xs.XSObject;
29  import org.apache.xerces.xs.XSObjectList;
30  import org.apache.xerces.xs.XSTypeDefinition;
31  
32  import de.mindcrimeilab.xsanalyzer.util.XSModelHelper;
33  
34  /**
35   * @author Michael Engelhardt<me@mindcrime-ilab.de>
36   * @author $Author: agony $
37   * @version $Revision: 165 $
38   * 
39   */
40  public class XsAnalyzerApplicationModel {
41  
42      private File schemaFile;
43  
44      private XSModel schemaModel;
45  
46      private XSNamespaceItem targetNamespace = null;
47  
48      private Map<XSObject, ? extends XSObjectList> usedTypes;
49  
50      private Set<XSTypeDefinition> unusedTypes;
51  
52      private Map<String, XSObjectList> similarTypes;
53  
54      private Map<QName, XSObjectList> sameNamesDifferentTypes;
55  
56      public XsAnalyzerApplicationModel() {
57          schemaFile = null;
58          usedTypes = null;
59          unusedTypes = null;
60          similarTypes = null;
61          sameNamesDifferentTypes = null;
62      }
63  
64      /**
65       * @return the schemaFile
66       */
67      public File getSchemaFile() {
68          return schemaFile;
69      }
70  
71      /**
72       * @param schemaFile
73       *            the schemaFile to set
74       */
75      public void setSchemaFile(File schemaFile) {
76          this.schemaFile = schemaFile;
77      }
78  
79      /**
80       * @return the schemaModel
81       */
82      public XSModel getSchemaModel() {
83          return schemaModel;
84      }
85  
86      /**
87       * @param schemaModel
88       *            the schemaModel to set
89       */
90      public void setSchemaModel(XSModel schemaModel) {
91          this.schemaModel = schemaModel;
92          updateTargetNamespace();
93      }
94  
95      /**
96       * @return the usedTypes
97       */
98      public Map<XSObject, ? extends XSObjectList> getUsedTypes() {
99          return usedTypes;
100     }
101 
102     /**
103      * @param usedTypes
104      *            the usedTypes to set
105      */
106     public void setUsedTypes(Map<XSObject, ? extends XSObjectList> usedTypes) {
107         this.usedTypes = usedTypes;
108     }
109 
110     /**
111      * 
112      * @return the unusedTypes
113      */
114     public Set<XSTypeDefinition> getUnusedTypes() {
115         return unusedTypes;
116     }
117 
118     /**
119      * @param unusedTypes
120      *            the unusedTypes to set
121      */
122     public void setUnusedTypes(Set<XSTypeDefinition> unusedTypes) {
123         this.unusedTypes = unusedTypes;
124     }
125 
126     /**
127      * @return the similarTypes
128      */
129     public Map<String, XSObjectList> getSimilarTypes() {
130         return similarTypes;
131     }
132 
133     public void setSimilarTypes(Map<String, XSObjectList> similarTypes) {
134         this.similarTypes = similarTypes;
135     }
136 
137     /**
138      * @return the sameNamesDifferentTypes
139      */
140     public Map<QName, XSObjectList> getSameNamesDifferentTypes() {
141         return sameNamesDifferentTypes;
142     }
143 
144     public void setSameNamesDifferentTypes(Map<QName, XSObjectList> sameNames) {
145         this.sameNamesDifferentTypes = sameNames;
146     }
147 
148     public XSNamespaceItem getTargetNamespace() {
149         if (null == targetNamespace) {
150             updateTargetNamespace();
151         }
152         return targetNamespace;
153     }
154 
155     /**
156      * @param schemaModel
157      */
158     private void updateTargetNamespace() {
159         targetNamespace = XSModelHelper.getTargetNamespace(schemaModel, schemaFile);
160     }
161 }