1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package org.jomc.sdk.model.support;
38
39 import org.w3c.dom.ls.LSResourceResolver;
40 import java.io.IOException;
41 import java.io.InputStream;
42 import java.io.Reader;
43 import java.net.URL;
44 import org.jomc.sdk.model.SchemaType;
45 import org.jomc.sdk.model.SchemasType;
46 import org.w3c.dom.ls.LSInput;
47 import static org.jomc.sdk.model.modlet.SdkModelProvider.XML_SCHEMA_JAVA_CLASSPATH_ID_ATTRIBUTE;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
71
72
73 public final class JaxpResourceResolverFactory implements LSResourceResolver
74 {
75
76
77 public LSInput resolveResource( final String type, final String namespaceURI, final String publicId,
78 final String systemId, final String baseURI )
79 {
80 LSInput input = null;
81 final SchemasType schemas = this.getSchemas();
82
83 if ( schemas.getLanguageId().equals( type ) )
84 {
85 SchemaType schema = null;
86
87 if ( namespaceURI != null )
88 {
89 schema = schemas.getSchemaByPublicId( namespaceURI );
90 }
91 if ( schema == null && publicId != null )
92 {
93 schema = schemas.getSchemaByPublicId( publicId );
94 }
95 if ( schema == null && systemId != null )
96 {
97 schema = schemas.getSchemaBySystemId( systemId );
98 }
99
100 if ( schema != null )
101 {
102 input = new SchemaTypeInput( schema );
103 }
104 }
105
106 return input;
107 }
108
109
110
111
112
113
114
115
116 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
117 public JaxpResourceResolverFactory()
118 {
119
120 super();
121
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
136 private org.jomc.sdk.model.SchemasType getSchemas()
137 {
138 final org.jomc.sdk.model.SchemasType _p = (org.jomc.sdk.model.SchemasType) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "schemas" );
139 assert _p != null : "'schemas' property not found.";
140 return _p;
141 }
142
143
144
145
146 }
147
148
149
150
151
152
153
154 class SchemaTypeInput implements LSInput
155 {
156
157
158 private final SchemaType schemaType;
159
160
161
162
163
164
165 SchemaTypeInput( final SchemaType schemaType )
166 {
167 this.schemaType = schemaType;
168 }
169
170 public Reader getCharacterStream()
171 {
172 return null;
173 }
174
175 public void setCharacterStream( final Reader characterStream )
176 {
177 }
178
179 public InputStream getByteStream()
180 {
181 try
182 {
183 final URL javaResource = this.getJavaResource();
184 if ( javaResource != null )
185 {
186 return javaResource.openStream();
187 }
188
189 return null;
190 }
191 catch ( final IOException e )
192 {
193 return null;
194 }
195 }
196
197 public void setByteStream( final InputStream byteStream )
198 {
199 }
200
201 public String getStringData()
202 {
203 return null;
204 }
205
206 public void setStringData( final String stringData )
207 {
208 }
209
210 public String getSystemId()
211 {
212 final URL javaResource = this.getJavaResource();
213 return javaResource != null ? javaResource.toExternalForm() : this.schemaType.getSystemId();
214 }
215
216 public void setSystemId( final String systemId )
217 {
218 }
219
220 public String getPublicId()
221 {
222 return this.schemaType.getPublicId();
223 }
224
225 public void setPublicId( final String publicId )
226 {
227 }
228
229 public String getBaseURI()
230 {
231 return null;
232 }
233
234 public void setBaseURI( final String baseURI )
235 {
236 }
237
238 public String getEncoding()
239 {
240 return null;
241 }
242
243 public void setEncoding( final String encoding )
244 {
245 }
246
247 public boolean getCertifiedText()
248 {
249 return false;
250 }
251
252 public void setCertifiedText( final boolean certifiedText )
253 {
254 }
255
256 private URL getJavaResource()
257 {
258 if ( this.schemaType.getOtherAttributes().containsKey( XML_SCHEMA_JAVA_CLASSPATH_ID_ATTRIBUTE ) )
259 {
260 String absoluteLocation =
261 this.schemaType.getOtherAttributes().get( XML_SCHEMA_JAVA_CLASSPATH_ID_ATTRIBUTE );
262
263 if ( !absoluteLocation.startsWith( "/" ) )
264 {
265 absoluteLocation = '/' + absoluteLocation;
266 }
267
268 return this.getClass().getResource( absoluteLocation );
269 }
270
271 return null;
272 }
273
274 }