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.standalone.model.modlet;
38
39 import java.text.MessageFormat;
40 import java.util.ResourceBundle;
41 import java.util.logging.Level;
42 import javax.xml.bind.JAXBElement;
43 import org.jomc.model.Implementation;
44 import org.jomc.model.Module;
45 import org.jomc.model.Modules;
46 import org.jomc.model.ObjectFactory;
47 import org.jomc.model.modlet.ModelHelper;
48 import org.jomc.modlet.Model;
49 import org.jomc.modlet.ModelContext;
50 import org.jomc.modlet.ModelException;
51 import org.jomc.modlet.ModelValidationReport;
52 import org.jomc.modlet.ModelValidator;
53 import org.jomc.standalone.model.MethodType;
54 import org.jomc.standalone.model.MethodsType;
55
56
57
58
59
60
61
62
63
64
65
66
67
68 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
69
70
71 public final class StandaloneModelValidator implements ModelValidator
72 {
73
74
75 public ModelValidationReport validateModel( final ModelContext context, final Model model )
76 throws ModelException
77 {
78 if ( context == null )
79 {
80 throw new NullPointerException( "context" );
81 }
82 if ( model == null )
83 {
84 throw new NullPointerException( "model" );
85 }
86
87 final ModelValidationReport report = new ModelValidationReport();
88 final Modules modules = ModelHelper.getModules( model );
89
90 if ( modules != null )
91 {
92 if ( context.isLoggable( Level.FINE ) )
93 {
94 context.log( Level.FINE, getMessage(
95 "validatingModel", this.getClass().getName(), model.getIdentifier() ), null );
96
97 }
98
99 for ( Module m : modules.getModule() )
100 {
101 if ( m.getImplementations() != null )
102 {
103 for ( Implementation i : m.getImplementations().getImplementation() )
104 {
105 final JAXBElement<Implementation> detailElement = new ObjectFactory().createImplementation( i );
106
107 for ( MethodsType methodsType : i.getAnyObjects( MethodsType.class ) )
108 {
109 if ( methodsType.getExceptions() != null
110 && methodsType.getExceptions().getDefaultException() != null
111 && methodsType.getExceptions().getDefaultException().getTargetClass() != null )
112 {
113 report.getDetails().add( new ModelValidationReport.Detail(
114 "IMPLEMENTATION_METHODS_DEFAULT_EXCEPTION_TARGET_CLASS_CONSTRAINT", Level.SEVERE,
115 getMessage( "implementationMethodsDefaultExceptionTargetClassConstraint",
116 i.getIdentifier(),
117 methodsType.getExceptions().getDefaultException().getClazz(),
118 methodsType.getExceptions().getDefaultException().getTargetClass() ),
119 detailElement ) );
120
121 }
122
123 for ( MethodType methodType : methodsType.getMethod() )
124 {
125 if ( methodType.getExceptions() != null
126 && methodType.getExceptions().getDefaultException() != null
127 && methodType.getExceptions().getDefaultException().getTargetClass() != null )
128 {
129 report.getDetails().add( new ModelValidationReport.Detail(
130 "IMPLEMENTATION_METHOD_DEFAULT_EXCEPTION_TARGET_CLASS_CONSTRAINT", Level.SEVERE,
131 getMessage( "implementationMethodDefaultExceptionTargetClassConstraint",
132 i.getIdentifier(), methodType.getName(),
133 methodsType.getExceptions().getDefaultException().getClazz(),
134 methodsType.getExceptions().getDefaultException().getTargetClass() ),
135 detailElement ) );
136
137 }
138 }
139 }
140 }
141 }
142 }
143 }
144 else if ( context.isLoggable( Level.WARNING ) )
145 {
146 context.log( Level.WARNING, getMessage( "modulesNotFound", model.getIdentifier() ), null );
147 }
148
149 return report;
150 }
151
152 private static String getMessage( final String key, final Object... arguments )
153 {
154 return MessageFormat.format( ResourceBundle.getBundle(
155 StandaloneModelValidator.class.getName().replace( '.', '/' ) ).getString( key ), arguments );
156
157 }
158
159
160
161
162
163
164 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
165 public StandaloneModelValidator()
166 {
167
168 super();
169
170 }
171
172
173
174
175
176
177
178
179 }