7777import org .springframework .beans .factory .DisposableBean ;
7878import org .springframework .beans .factory .InitializingBean ;
7979import org .springframework .context .ApplicationContextAware ;
80- import org .springframework .core .LocalVariableTableParameterNameDiscoverer ;
8180import org .springframework .core .ParameterNameDiscoverer ;
8281import org .springframework .extensions .surf .util .I18NUtil ;
8382import org .springframework .extensions .webscripts .Cache ;
9493public class AlfrescoScriptAPITernGet extends DeclarativeWebScript implements InitializingBean
9594{
9695
96+ private static final Logger LOGGER = LoggerFactory .getLogger (AlfrescoScriptAPITernGet .class );
97+
9798 private static final Collection <Class <?>> PRIMITIVE_NUMBER_CLASSES = Collections
9899 .unmodifiableList (Arrays .<Class <?>> asList (byte .class , short .class , int .class , long .class , float .class , double .class ));
99100
@@ -108,9 +109,42 @@ public class AlfrescoScriptAPITernGet extends DeclarativeWebScript implements In
108109 private static final Collection <String > INIT_METHOD_NAMES = Collections
109110 .unmodifiableSet (new HashSet <String >(Arrays .<String > asList ("init" , "register" )));
110111
111- private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER = new LocalVariableTableParameterNameDiscoverer ();
112+ private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER ;
113+ static
114+ {
115+ // Alfresco 5.0.d (earliest version we want to try to support) contains Spring 3.x
116+ // StandardReflectionParameterNameDiscoverer is only available from Spring 4.x on
117+ Class <?> cls = null ;
118+ try
119+ {
120+ cls = Class .forName ("org.springframework.core.StandardReflectionParameterNameDiscoverer" );
121+ }
122+ catch (final ClassNotFoundException ex )
123+ {
124+ try
125+ {
126+ cls = Class .forName ("org.springframework.core.LocalVariableTableParameterNameDiscoverer" );
127+ }
128+ catch (final ClassNotFoundException ex2 )
129+ {
130+ LOGGER .info ("No valid Spring parameter name discoverer class found" );
131+ }
132+ }
112133
113- private static final Logger LOGGER = LoggerFactory .getLogger (AlfrescoScriptAPITernGet .class );
134+ ParameterNameDiscoverer pnd = null ;
135+ if (cls != null )
136+ {
137+ try
138+ {
139+ pnd = (ParameterNameDiscoverer ) cls .newInstance ();
140+ }
141+ catch (final InstantiationException | IllegalAccessException ex )
142+ {
143+ LOGGER .warn ("Failed to instantiate Spring paramater name discoverer" , ex );
144+ }
145+ }
146+ PARAMETER_NAME_DISCOVERER = pnd ;
147+ }
114148
115149 protected NamespaceService namespaceService ;
116150
@@ -320,7 +354,7 @@ protected List<Map<String, Object>> prepareJavaTypeDefinitions(final Map<String,
320354
321355 while (classesToDescribe .size () > classesDescribed .size ())
322356 {
323- final Collection <Class <?>> remainingClasses = new HashSet <Class <?> >(classesToDescribe );
357+ final Collection <Class <?>> remainingClasses = new HashSet <>(classesToDescribe );
324358 remainingClasses .removeAll (classesDescribed );
325359
326360 for (final Class <?> cls : remainingClasses )
@@ -333,7 +367,7 @@ protected List<Map<String, Object>> prepareJavaTypeDefinitions(final Map<String,
333367
334368 if (skip == null || skip .isEmpty () || !Boolean .parseBoolean (skip ))
335369 {
336- final Map <String , Object > typeDefinition = new HashMap <String , Object >();
370+ final Map <String , Object > typeDefinition = new HashMap <>();
337371 final Collection <Class <?>> relatedClasses = this .fillClassTypeDefinition (cls , typeDefinition );
338372 classesToDescribe .addAll (relatedClasses );
339373 typeDefinitions .add (typeDefinition );
@@ -401,7 +435,7 @@ protected List<Map<String, Object>> prepareGlobalDefinitions(final Map<String, O
401435 }
402436 }
403437
404- final Collection <Class <?>> dummyClasses = new HashSet <Class <?> >();
438+ final Collection <Class <?>> dummyClasses = new HashSet <>();
405439
406440 for (final Entry <String , Object > globalEntry : model .entrySet ())
407441 {
@@ -509,18 +543,18 @@ protected Collection<Class<?>> fillClassTypeDefinition(final Class<?> cls, final
509543 final String nameOnly = this .properties .getProperty (commonPrefix + ".nameOnly" );
510544 if (nameOnly == null || nameOnly .isEmpty () || !Boolean .parseBoolean (nameOnly ))
511545 {
512- this .fillClassTypeMemberDefinitions (cls , typeDefinition , relatedClasses , commonPrefix , superclass );
546+ this .fillClassTypeMemberDefinitions (cls , typeDefinition , relatedClasses , commonPrefix );
513547 }
514548
515549 return relatedClasses ;
516550 }
517551
518552 protected void fillClassTypeMemberDefinitions (final Class <?> cls , final Map <String , Object > typeDefinition ,
519- final Collection <Class <?>> relatedClasses , final String commonPrefix , final Class <?> superclass )
553+ final Collection <Class <?>> relatedClasses , final String commonPrefix )
520554 {
521- final List <Map <String , Object >> memberDefinitions = new ArrayList <Map < String , Object > >();
522- final Map <String , AtomicInteger > usedMemberNames = new HashMap <String , AtomicInteger >();
523- final Collection <String > handledProperties = new HashSet <String >();
555+ final List <Map <String , Object >> memberDefinitions = new ArrayList <>();
556+ final Map <String , AtomicInteger > usedMemberNames = new HashMap <>();
557+ final Collection <String > handledProperties = new HashSet <>();
524558
525559 final List <Method > methods = this .collectDocumentableMethods (cls );
526560
@@ -1014,7 +1048,7 @@ protected String buildMethodTypeDescription(final Method method, final Class<?>
10141048 typeBuilder .append ("fn(" );
10151049 if (parameterTypes .length > 0 )
10161050 {
1017- final String [] parameterNames = PARAMETER_NAME_DISCOVERER .getParameterNames (method );
1051+ final String [] parameterNames = PARAMETER_NAME_DISCOVERER != null ? PARAMETER_NAME_DISCOVERER .getParameterNames (method ) : null ;
10181052
10191053 for (int idx = 0 ; idx < parameterTypes .length ; idx ++)
10201054 {
@@ -1047,7 +1081,12 @@ else if (Boolean.class.equals(parameterTypes[idx]))
10471081 typeName = "bool" ;
10481082 }
10491083
1050- final String parameterTypeTernName = this .properties .getProperty (methodPrefix + ".arg" + idx + ".typeTernName" );
1084+ String parameterTypeTernName = this .properties .getProperty (methodPrefix + "." + parameterName + ".typeTernName" );
1085+ if ((parameterTypeTernName == null || parameterTypeTernName .isEmpty ()) && !parameterName .equals ("arg" + idx ))
1086+ {
1087+ parameterTypeTernName = this .properties .getProperty (methodPrefix + ".arg" + idx + ".typeTernName" );
1088+ }
1089+
10511090 if (parameterTypeTernName != null && !parameterTypeTernName .isEmpty ())
10521091 {
10531092 typeName = parameterTypeTernName ;
0 commit comments