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.modlet;
38
39 import java.text.MessageFormat;
40 import java.util.List;
41 import java.util.Locale;
42 import java.util.ResourceBundle;
43 import java.util.logging.Level;
44 import javax.xml.namespace.QName;
45 import org.jomc.model.Dependencies;
46 import org.jomc.model.Dependency;
47 import org.jomc.model.Implementation;
48 import org.jomc.model.ImplementationReference;
49 import org.jomc.model.Implementations;
50 import org.jomc.model.Module;
51 import org.jomc.model.Modules;
52 import org.jomc.model.Text;
53 import org.jomc.model.Texts;
54 import org.jomc.model.modlet.ModelHelper;
55 import org.jomc.modlet.Model;
56 import org.jomc.modlet.ModelContext;
57 import org.jomc.modlet.ModelException;
58 import org.jomc.modlet.ModelProvider;
59 import org.jomc.sdk.model.support.JaxbBinderFactory;
60 import org.jomc.sdk.model.support.JaxbContextFactory;
61 import org.jomc.sdk.model.support.JaxbIntrospectorFactory;
62 import org.jomc.sdk.model.support.JaxbMarshallerFactory;
63 import org.jomc.sdk.model.support.JaxbUnmarshallerFactory;
64 import org.jomc.sdk.model.support.JaxpEntityResolverFactory;
65 import org.jomc.sdk.model.support.JaxpResourceResolverFactory;
66 import org.jomc.sdk.model.support.JaxpSchemaFactory;
67 import org.jomc.sdk.model.support.JaxpValidatorFactory;
68 import org.jomc.sdk.model.support.JaxpValidatorHandlerFactory;
69 import static javax.xml.XMLConstants.NULL_NS_URI;
70
71
72
73
74
75
76
77
78
79
80
81
82
83 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
84
85
86 public final class SdkModelProvider implements ModelProvider
87 {
88
89
90
91 public static final QName XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE = new QName( NULL_NS_URI, "java-context-id" );
92
93
94 public static final QName XML_SCHEMA_JAVA_CLASSPATH_ID_ATTRIBUTE = new QName( NULL_NS_URI, "java-classpath-id" );
95
96
97 private static final String XML_SCHEMA_SET_SPECIFICATION_IDENTIFIER = "XML Schema Set";
98
99 public Model findModel( final ModelContext context, final Model model ) throws ModelException
100 {
101 if ( context == null )
102 {
103 throw new NullPointerException( "context" );
104 }
105 if ( model == null )
106 {
107 throw new NullPointerException( "model" );
108 }
109
110 Model found = null;
111 Modules modules = ModelHelper.getModules( model );
112
113 if ( modules != null )
114 {
115 if ( context.isLoggable( Level.FINE ) )
116 {
117 context.log( Level.FINE, getMessage(
118 "providingModel", this.getClass().getName(), model.getIdentifier() ), null );
119
120 }
121
122 found = new Model( model );
123 modules = ModelHelper.getModules( found );
124
125 final Implementations schemaSets =
126 modules.getImplementations( XML_SCHEMA_SET_SPECIFICATION_IDENTIFIER );
127
128 if ( schemaSets != null )
129 {
130 for ( Implementation schemaSet : schemaSets.getImplementation() )
131 {
132 final Module schemaSetModule = this.createSchemaSetModule( modules, schemaSet );
133
134 if ( modules.getModule( schemaSetModule.getName() ) == null )
135 {
136 modules.getModule().add( schemaSetModule );
137 }
138 }
139 }
140 }
141 else if ( context.isLoggable( Level.WARNING ) )
142 {
143 context.log( Level.WARNING, getMessage( "modulesNotFound", model.getIdentifier() ), null );
144 }
145
146 return found;
147 }
148
149 private Module createSchemaSetModule( final Modules modules, final Implementation schemaSet )
150 {
151 final Module m = new Module();
152 m.setName( getMessage( "schemaSetModuleName", schemaSet.getIdentifier() ) );
153 m.setVendor( schemaSet.getVendor() );
154 m.setVersion( schemaSet.getVersion() );
155 m.setDocumentation( getTexts( "modelProviderInfo" ) );
156 m.setImplementations( new Implementations() );
157 m.getImplementations().setDocumentation( getTexts( "modelProviderInfo" ) );
158
159 final List<Implementation> impls = m.getImplementations().getImplementation();
160 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxbContextFactory.class ) );
161 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxbBinderFactory.class ) );
162 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxbIntrospectorFactory.class ) );
163 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxbMarshallerFactory.class ) );
164 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxbUnmarshallerFactory.class ) );
165 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxpSchemaFactory.class ) );
166 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxpValidatorFactory.class ) );
167 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxpValidatorHandlerFactory.class ) );
168 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxpEntityResolverFactory.class ) );
169 impls.add( this.createJavaSchemaSetImplementation( modules, schemaSet, JaxpResourceResolverFactory.class ) );
170 return m;
171 }
172
173 private Implementation createJavaSchemaSetImplementation(
174 final Modules modules, final Implementation schemaSet, final Class factoryClazz )
175 {
176 final Implementation i = new Implementation();
177 i.setIdentifier( getMessage( "schemaSetImplementationIdenifier", schemaSet.getIdentifier(),
178 factoryClazz.getSimpleName() ) );
179
180 i.setName( schemaSet.getName() );
181 i.setDocumentation( getTexts( "modelProviderInfo" ) );
182 i.setClazz( factoryClazz.getName() );
183 i.setFinal( true );
184 i.setStateless( true );
185 i.setVendor( schemaSet.getVendor() );
186 i.setVersion( schemaSet.getVersion() );
187 i.setProperties( schemaSet.getProperties() );
188 i.setDependencies( schemaSet.getDependencies() );
189 i.setMessages( schemaSet.getMessages() );
190
191 final Implementation factoryDeclaration = modules.getImplementation( factoryClazz );
192
193 if ( factoryDeclaration != null )
194 {
195 final Implementations implementationReferences = new Implementations();
196 final ImplementationReference implementationReference = new ImplementationReference();
197 i.setImplementations( implementationReferences );
198 implementationReferences.getReference().add( implementationReference );
199 implementationReference.setIdentifier( factoryDeclaration.getIdentifier() );
200 implementationReference.setVersion( factoryDeclaration.getVersion() );
201
202 final Dependencies dependencyDeclarations = modules.getDependencies( factoryDeclaration.getIdentifier() );
203 if ( dependencyDeclarations != null )
204 {
205 for ( Dependency dependencyDeclaration : dependencyDeclarations.getDependency() )
206 {
207 if ( dependencyDeclaration.getImplementationName() != null
208 && dependencyDeclaration.getImplementationName().equals( factoryDeclaration.getName() )
209 && !dependencyDeclaration.isFinal() )
210 {
211 if ( i.getDependencies() == null )
212 {
213 i.setDependencies( new Dependencies() );
214 }
215
216 final Dependency d = new Dependency( dependencyDeclaration );
217 d.setImplementationName( i.getName() );
218 d.setFinal( true );
219 d.setOverride( true );
220 i.getDependencies().getDependency().add( d );
221 }
222 }
223 }
224 }
225
226 return i;
227 }
228
229 private static Texts getTexts( final String key, final Object... arguments )
230 {
231 final Texts texts = new Texts();
232 final Text text = new Text();
233 texts.getText().add( text );
234 texts.setDefaultLanguage( Locale.getDefault().getLanguage() );
235 text.setLanguage( texts.getDefaultLanguage() );
236 text.setValue( getMessage( key, arguments ) );
237 return texts;
238 }
239
240 private static String getMessage( final String key, final Object... arguments )
241 {
242 return MessageFormat.format( ResourceBundle.getBundle( SdkModelProvider.class.getName().replace( '.', '/' ) ).
243 getString( key ), arguments );
244
245 }
246
247
248
249
250
251
252 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
253 public SdkModelProvider()
254 {
255
256 super();
257
258 }
259
260
261
262
263
264
265
266
267 }