3030import com .ocpsoft .pretty .faces .annotation .URLActions ;
3131import com .ocpsoft .pretty .faces .annotation .URLBeanName ;
3232import com .ocpsoft .pretty .faces .annotation .URLMapping ;
33+ import com .ocpsoft .pretty .faces .annotation .URLMappings ;
3334import com .ocpsoft .pretty .faces .annotation .URLQueryParameter ;
3435import com .ocpsoft .pretty .faces .annotation .URLValidator ;
3536import com .ocpsoft .pretty .faces .config .PrettyConfigBuilder ;
@@ -105,21 +106,21 @@ public void processClass(Class clazz)
105106
106107 // scan for PrettyAnnotation class
107108 // returns the mapping ID, if an annotation was found
108- String classMappingId = processPrettyMappingAnnotation (clazz );
109+ String [] classMappingIds = processClassMappingAnnotations (clazz );
109110
110111 // scan for PrettyBean annotation
111112 processPrettyBeanAnnotation (clazz );
112113
113114 // process annotations on public methods
114115 for (Method method : clazz .getMethods ())
115116 {
116- processMethodAnnotations (method , new String [] { classMappingId } );
117+ processMethodAnnotations (method , classMappingIds );
117118 }
118119
119120 // loop over fields to find URLQueryParameter annotations
120121 for (Field field : clazz .getDeclaredFields ())
121122 {
122- processFieldAnnotations (field , new String [] { classMappingId } );
123+ processFieldAnnotations (field , classMappingIds );
123124 }
124125
125126 }
@@ -132,86 +133,119 @@ public void processClass(Class clazz)
132133 }
133134
134135 /**
135- * Checks the class for a {@link URLMapping} annotation.
136+ * Checks for PrettyFaces mapping annotations on a single class
136137 *
137- * @param clazz Class to scan
138- * @return The mapping ID or <code>null</code> if no mapping was found
138+ * @param clazz
139+ * Class to scan
140+ * @return The IDs of the mappings found on the class
139141 */
140- private String processPrettyMappingAnnotation (Class clazz )
142+ public String [] processClassMappingAnnotations (Class clazz )
141143 {
142144
145+ // list of all mapping IDs found on the class
146+ List <String > classMappingIds = new ArrayList <String >();
147+
143148 // get reference to @URLMapping annotation
144149 URLMapping mappingAnnotation = (URLMapping ) clazz .getAnnotation (URLMapping .class );
145150
146151 // process annotation if it exists
147152 if (mappingAnnotation != null )
148153 {
154+ String mappingId = processPrettyMappingAnnotation (clazz , mappingAnnotation );
155+ classMappingIds .add (mappingId );
156+ }
149157
150- // log class name
151- if (log .isTraceEnabled ())
158+ // container annotation
159+ URLMappings mappingsAnnotation = (URLMappings ) clazz .getAnnotation (URLMappings .class );
160+
161+ if (mappingsAnnotation != null )
162+ {
163+
164+ // process all contained @URLMapping annotations
165+ for (URLMapping child : mappingsAnnotation .mappings ())
152166 {
153- log .trace ("Found @URLMapping annotation on class: " + clazz .getName ());
167+ String mappingId = processPrettyMappingAnnotation (clazz , child );
168+ classMappingIds .add (mappingId );
154169 }
155170
156- // create UrlMapping from annotation
157- UrlMapping mapping = new UrlMapping ();
158- mapping .setId (mappingAnnotation .id ());
159- mapping .setParentId (mappingAnnotation .parentId ());
160- mapping .setPattern (mappingAnnotation .pattern ());
161- mapping .setViewId (mappingAnnotation .viewId ());
162- mapping .setOutbound (mappingAnnotation .outbound ());
163- mapping .setOnPostback (mappingAnnotation .onPostback ());
171+ }
164172
165- // register mapping
166- Object existingMapping = urlMappings . put ( mapping . getId (), mapping );
173+ // return list of mappings found
174+ return classMappingIds . toArray ( new String [ classMappingIds . size ()] );
167175
168- // fail if a mapping with this ID already existed
169- if (existingMapping != null )
170- {
171- throw new IllegalArgumentException ("Duplicated mapping id: " + mapping .getId ());
172- }
176+ }
177+
178+ /**
179+ * Process a single {@link URLMapping} annotation.
180+ *
181+ * @param clazz The class that the annotation was found on
182+ * @param mappingAnnotation The annotation to process
183+ * @return The mapping ID of the mapping found
184+ */
185+ private String processPrettyMappingAnnotation (Class clazz , URLMapping mappingAnnotation )
186+ {
173187
174- // At bean name to lookup map if it has been specified
175- if (( mappingAnnotation . beanName () != null ) && ( mappingAnnotation . beanName (). length () > 0 ))
176- {
177- beanNameMap . put ( clazz , mappingAnnotation . beanName ());
178- }
188+ // log class name
189+ if (log . isTraceEnabled ( ))
190+ {
191+ log . trace ( "Found @URLMapping annotation on class: " + clazz . getName ());
192+ }
179193
180- // process validations
181- for (URLValidator validationAnnotation : mappingAnnotation .validation ())
182- {
194+ // create UrlMapping from annotation
195+ UrlMapping mapping = new UrlMapping ();
196+ mapping .setId (mappingAnnotation .id ());
197+ mapping .setParentId (mappingAnnotation .parentId ());
198+ mapping .setPattern (mappingAnnotation .pattern ());
199+ mapping .setViewId (mappingAnnotation .viewId ());
200+ mapping .setOutbound (mappingAnnotation .outbound ());
201+ mapping .setOnPostback (mappingAnnotation .onPostback ());
183202
184- // index attribute is required in this case
185- if (validationAnnotation .index () < 0 )
186- {
187- throw new IllegalArgumentException (
188- "Please set the index of the path parameter you want to validate with the @URLValidator specified on mapping: " + mapping .getId ());
189- }
203+ // register mapping
204+ Object existingMapping = urlMappings .put (mapping .getId (), mapping );
190205
191- // prepare PathValidator
192- PathValidator pathValidator = new PathValidator ();
193- pathValidator . setIndex ( validationAnnotation . index ());
194- pathValidator . setOnError ( validationAnnotation . onError ());
195- pathValidator . setValidatorIds ( join ( validationAnnotation . validatorIds (), " " ));
206+ // fail if a mapping with this ID already existed
207+ if ( existingMapping != null )
208+ {
209+ throw new IllegalArgumentException ( "Duplicated mapping id: " + mapping . getId ());
210+ }
196211
197- // optional validator method
198- if (! isBlank ( validationAnnotation . validator () ))
199- {
200- pathValidator . setValidatorExpression ( new ConstantExpression ( validationAnnotation . validator () ));
201- }
212+ // At bean name to lookup map if it has been specified
213+ if (( mappingAnnotation . beanName () != null ) && ( mappingAnnotation . beanName (). length () > 0 ))
214+ {
215+ beanNameMap . put ( clazz , mappingAnnotation . beanName ( ));
216+ }
202217
203- // add PathValidator to the mapping
204- mapping .getPathValidators ().add (pathValidator );
218+ // process validations
219+ for (URLValidator validationAnnotation : mappingAnnotation .validation ())
220+ {
205221
222+ // index attribute is required in this case
223+ if (validationAnnotation .index () < 0 )
224+ {
225+ throw new IllegalArgumentException (
226+ "Please set the index of the path parameter you want to validate with the @URLValidator specified on mapping: " + mapping .getId ());
206227 }
207228
208- // return mapping id
209- return mapping .getId ();
229+ // prepare PathValidator
230+ PathValidator pathValidator = new PathValidator ();
231+ pathValidator .setIndex (validationAnnotation .index ());
232+ pathValidator .setOnError (validationAnnotation .onError ());
233+ pathValidator .setValidatorIds (join (validationAnnotation .validatorIds (), " " ));
234+
235+ // optional validator method
236+ if (!isBlank (validationAnnotation .validator ()))
237+ {
238+ pathValidator .setValidatorExpression (new ConstantExpression (validationAnnotation .validator ()));
239+ }
240+
241+ // add PathValidator to the mapping
242+ mapping .getPathValidators ().add (pathValidator );
210243
211244 }
212245
213- // we have not found a mapping
214- return null ;
246+ // return mapping id
247+ return mapping .getId ().trim ();
248+
215249 }
216250
217251 /**
0 commit comments