59
59
import org .springframework .beans .factory .config .BeanExpressionResolver ;
60
60
import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
61
61
import org .springframework .core .LocalVariableTableParameterNameDiscoverer ;
62
+ import org .springframework .core .Ordered ;
62
63
import org .springframework .core .ParameterNameDiscoverer ;
63
64
import org .springframework .core .annotation .AnnotationUtils ;
64
65
import org .springframework .core .style .StylerUtils ;
117
118
* @see #setWebBindingInitializer
118
119
* @see #setSessionAttributeStore
119
120
*/
120
- public class AnnotationMethodHandlerAdapter extends PortletContentGenerator implements HandlerAdapter , BeanFactoryAware {
121
+ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
122
+ implements HandlerAdapter , Ordered , BeanFactoryAware {
121
123
122
124
private static final String IMPLICIT_MODEL_ATTRIBUTE = "org.springframework.web.portlet.mvc.ImplicitModel" ;
123
125
@@ -136,6 +138,8 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator impl
136
138
137
139
private ModelAndViewResolver [] customModelAndViewResolvers ;
138
140
141
+ private int order = Ordered .LOWEST_PRECEDENCE ;
142
+
139
143
private ConfigurableBeanFactory beanFactory ;
140
144
141
145
private BeanExpressionContext expressionContext ;
@@ -242,6 +246,19 @@ public void setCustomModelAndViewResolvers(ModelAndViewResolver[] customModelAnd
242
246
this .customModelAndViewResolvers = customModelAndViewResolvers ;
243
247
}
244
248
249
+ /**
250
+ * Specify the order value for this HandlerAdapter bean.
251
+ * <p>Default value is <code>Integer.MAX_VALUE</code>, meaning that it's non-ordered.
252
+ * @see org.springframework.core.Ordered#getOrder()
253
+ */
254
+ public void setOrder (int order ) {
255
+ this .order = order ;
256
+ }
257
+
258
+ public int getOrder () {
259
+ return this .order ;
260
+ }
261
+
245
262
public void setBeanFactory (BeanFactory beanFactory ) {
246
263
if (beanFactory instanceof ConfigurableBeanFactory ) {
247
264
this .beanFactory = (ConfigurableBeanFactory ) beanFactory ;
@@ -362,6 +379,9 @@ private PortletHandlerMethodResolver getMethodResolver(Object handler) {
362
379
}
363
380
364
381
382
+ /**
383
+ * Portlet-specific subclass of {@link HandlerMethodResolver}.
384
+ */
365
385
private static class PortletHandlerMethodResolver extends HandlerMethodResolver {
366
386
367
387
private final Map <Method , RequestMappingInfo > mappings = new HashMap <Method , RequestMappingInfo >();
@@ -467,100 +487,9 @@ else if (EventRequest.class.isAssignableFrom(argType) || EventResponse.class.isA
467
487
}
468
488
469
489
470
- private static class RequestMappingInfo {
471
-
472
- public final Set <PortletMode > modes = new HashSet <PortletMode >();
473
-
474
- public String phase ;
475
-
476
- public String value ;
477
-
478
- public final Set <String > methods = new HashSet <String >();
479
-
480
- public String [] params = new String [0 ];
481
-
482
- public String [] headers = new String [0 ];
483
-
484
- public void initStandardMapping (String [] modes , RequestMethod [] methods , String [] params , String [] headers ) {
485
- for (String mode : modes ) {
486
- this .modes .add (new PortletMode (mode ));
487
- }
488
- for (RequestMethod method : methods ) {
489
- this .methods .add (method .name ());
490
- }
491
- this .params = StringUtils .mergeStringArrays (this .params , params );
492
- this .headers = StringUtils .mergeStringArrays (this .headers , headers );
493
- }
494
-
495
- public void initPhaseMapping (String phase , String value , String [] params ) {
496
- if (this .phase != null ) {
497
- throw new IllegalStateException (
498
- "Invalid mapping - more than one phase specified: '" + this .phase + "', '" + phase + "'" );
499
- }
500
- this .phase = phase ;
501
- this .value = value ;
502
- this .params = StringUtils .mergeStringArrays (this .params , params );
503
- }
504
-
505
- public boolean match (PortletRequest request ) {
506
- if (!this .modes .isEmpty () && !this .modes .contains (request .getPortletMode ())) {
507
- return false ;
508
- }
509
- if (StringUtils .hasLength (this .phase ) &&
510
- !this .phase .equals (request .getAttribute (PortletRequest .LIFECYCLE_PHASE ))) {
511
- return false ;
512
- }
513
- if (StringUtils .hasLength (this .value )) {
514
- if (this .phase .equals (PortletRequest .ACTION_PHASE ) &&
515
- !this .value .equals (request .getParameter (ActionRequest .ACTION_NAME ))) {
516
- return false ;
517
- }
518
- else if (this .phase .equals (PortletRequest .RENDER_PHASE ) &&
519
- !(new WindowState (this .value )).equals (request .getWindowState ())) {
520
- return false ;
521
- }
522
- else if (this .phase .equals (PortletRequest .RESOURCE_PHASE ) &&
523
- !this .value .equals (((ResourceRequest ) request ).getResourceID ())) {
524
- return false ;
525
- }
526
- else if (this .phase .equals (PortletRequest .EVENT_PHASE )) {
527
- Event event = ((EventRequest ) request ).getEvent ();
528
- if (!this .value .equals (event .getName ()) && !this .value .equals (event .getQName ().toString ())) {
529
- return false ;
530
- }
531
- }
532
- }
533
- return PortletAnnotationMappingUtils .checkRequestMethod (this .methods , request ) &&
534
- PortletAnnotationMappingUtils .checkParameters (this .params , request ) &&
535
- PortletAnnotationMappingUtils .checkHeaders (this .headers , request );
536
- }
537
-
538
- public boolean isBetterMatchThan (RequestMappingInfo other ) {
539
- return ((!this .modes .isEmpty () && other .modes .isEmpty ()) ||
540
- (StringUtils .hasLength (this .phase ) && !StringUtils .hasLength (other .phase )) ||
541
- (StringUtils .hasLength (this .value ) && !StringUtils .hasLength (other .value )) ||
542
- (!this .methods .isEmpty () && other .methods .isEmpty ()) ||
543
- this .params .length > other .params .length );
544
- }
545
-
546
- @ Override
547
- public boolean equals (Object obj ) {
548
- RequestMappingInfo other = (RequestMappingInfo ) obj ;
549
- return (this .modes .equals (other .modes ) &&
550
- ObjectUtils .nullSafeEquals (this .phase , other .phase ) &&
551
- ObjectUtils .nullSafeEquals (this .value , other .value ) &&
552
- this .methods .equals (other .methods ) &&
553
- Arrays .equals (this .params , other .params ) &&
554
- Arrays .equals (this .headers , other .headers ));
555
- }
556
-
557
- @ Override
558
- public int hashCode () {
559
- return (ObjectUtils .nullSafeHashCode (this .modes ) * 29 + this .phase .hashCode ());
560
- }
561
- }
562
-
563
-
490
+ /**
491
+ * Portlet-specific subclass of {@link HandlerMethodInvoker}.
492
+ */
564
493
private class PortletHandlerMethodInvoker extends HandlerMethodInvoker {
565
494
566
495
public PortletHandlerMethodInvoker (HandlerMethodResolver resolver ) {
@@ -735,4 +664,101 @@ else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
735
664
}
736
665
}
737
666
667
+
668
+ /**
669
+ * Holder for request mapping metadata. Allows for finding a best matching candidate.
670
+ */
671
+ private static class RequestMappingInfo {
672
+
673
+ public final Set <PortletMode > modes = new HashSet <PortletMode >();
674
+
675
+ public String phase ;
676
+
677
+ public String value ;
678
+
679
+ public final Set <String > methods = new HashSet <String >();
680
+
681
+ public String [] params = new String [0 ];
682
+
683
+ public String [] headers = new String [0 ];
684
+
685
+ public void initStandardMapping (String [] modes , RequestMethod [] methods , String [] params , String [] headers ) {
686
+ for (String mode : modes ) {
687
+ this .modes .add (new PortletMode (mode ));
688
+ }
689
+ for (RequestMethod method : methods ) {
690
+ this .methods .add (method .name ());
691
+ }
692
+ this .params = StringUtils .mergeStringArrays (this .params , params );
693
+ this .headers = StringUtils .mergeStringArrays (this .headers , headers );
694
+ }
695
+
696
+ public void initPhaseMapping (String phase , String value , String [] params ) {
697
+ if (this .phase != null ) {
698
+ throw new IllegalStateException (
699
+ "Invalid mapping - more than one phase specified: '" + this .phase + "', '" + phase + "'" );
700
+ }
701
+ this .phase = phase ;
702
+ this .value = value ;
703
+ this .params = StringUtils .mergeStringArrays (this .params , params );
704
+ }
705
+
706
+ public boolean match (PortletRequest request ) {
707
+ if (!this .modes .isEmpty () && !this .modes .contains (request .getPortletMode ())) {
708
+ return false ;
709
+ }
710
+ if (StringUtils .hasLength (this .phase ) &&
711
+ !this .phase .equals (request .getAttribute (PortletRequest .LIFECYCLE_PHASE ))) {
712
+ return false ;
713
+ }
714
+ if (StringUtils .hasLength (this .value )) {
715
+ if (this .phase .equals (PortletRequest .ACTION_PHASE ) &&
716
+ !this .value .equals (request .getParameter (ActionRequest .ACTION_NAME ))) {
717
+ return false ;
718
+ }
719
+ else if (this .phase .equals (PortletRequest .RENDER_PHASE ) &&
720
+ !(new WindowState (this .value )).equals (request .getWindowState ())) {
721
+ return false ;
722
+ }
723
+ else if (this .phase .equals (PortletRequest .RESOURCE_PHASE ) &&
724
+ !this .value .equals (((ResourceRequest ) request ).getResourceID ())) {
725
+ return false ;
726
+ }
727
+ else if (this .phase .equals (PortletRequest .EVENT_PHASE )) {
728
+ Event event = ((EventRequest ) request ).getEvent ();
729
+ if (!this .value .equals (event .getName ()) && !this .value .equals (event .getQName ().toString ())) {
730
+ return false ;
731
+ }
732
+ }
733
+ }
734
+ return PortletAnnotationMappingUtils .checkRequestMethod (this .methods , request ) &&
735
+ PortletAnnotationMappingUtils .checkParameters (this .params , request ) &&
736
+ PortletAnnotationMappingUtils .checkHeaders (this .headers , request );
737
+ }
738
+
739
+ public boolean isBetterMatchThan (RequestMappingInfo other ) {
740
+ return ((!this .modes .isEmpty () && other .modes .isEmpty ()) ||
741
+ (StringUtils .hasLength (this .phase ) && !StringUtils .hasLength (other .phase )) ||
742
+ (StringUtils .hasLength (this .value ) && !StringUtils .hasLength (other .value )) ||
743
+ (!this .methods .isEmpty () && other .methods .isEmpty ()) ||
744
+ this .params .length > other .params .length );
745
+ }
746
+
747
+ @ Override
748
+ public boolean equals (Object obj ) {
749
+ RequestMappingInfo other = (RequestMappingInfo ) obj ;
750
+ return (this .modes .equals (other .modes ) &&
751
+ ObjectUtils .nullSafeEquals (this .phase , other .phase ) &&
752
+ ObjectUtils .nullSafeEquals (this .value , other .value ) &&
753
+ this .methods .equals (other .methods ) &&
754
+ Arrays .equals (this .params , other .params ) &&
755
+ Arrays .equals (this .headers , other .headers ));
756
+ }
757
+
758
+ @ Override
759
+ public int hashCode () {
760
+ return (ObjectUtils .nullSafeHashCode (this .modes ) * 29 + this .phase .hashCode ());
761
+ }
762
+ }
763
+
738
764
}
0 commit comments