View Javadoc

1   /* #####################################################################
2    * #                        REFLEXIVE FRAMEWORK                        #
3    * #                        ___________________                        #
4    * #                                                                   #
5    * # Reflexive Framework, Copyright (C) 2007 Andries Inze              #
6    * #                                                                   #
7    * # This library  is free software; you can redistribute it and/or    #
8    * # modify it under the terms of the GNU Lesser General Public        #
9    * # License as published by the Free Software Foundation; either      #
10   * # version 2.1 of the License, or (at your option) any later version.#
11   * #                                                                   #
12   * # This library  is distributed in the hope that it will be useful,  #
13   * # but WITHOUT ANY WARRANTY; without even the implied warranty of    #
14   * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     #
15   * # GNU Lesser General Public License for more details.               #
16   * #                                                                   #
17   * # You should have received a copy of the GNU Lesser General Public  #
18   * # License along with this program; if not, write to the Free        #
19   * # Software Foundation, Inc., 51 Franklin Street, Fifth Floor,       #
20   * # Boston, MA  02110-1301  USA                                       #
21   * #                                                                   #
22   * #####################################################################
23   */
24  package org.reflexiveframework.proxy;
25  
26  import org.apache.commons.lang.Validate;
27  
28  /***
29   * Common static utility class.
30   * To be used internally only
31   * 
32   * @author Andries Inze
33   *
34   */
35  final class ReflexiveUtils {
36  
37      /***
38       * Utility methods need private constructors.
39       */
40      private ReflexiveUtils() {
41          
42      }
43      
44      /***
45       * Converts a getter into the property name.
46       * e.g.
47       * 'getNickName' will be converted into 'nickName'
48       * 
49       * @param methodName the full methodName
50       * @return the propertyName
51       */
52      public static String convertMethodNameToPropertyName(
53              final String methodName) {
54      	Validate.notNull(methodName, "The methodName can not be null");
55      	Validate.isTrue(methodName.startsWith("get") 
56      			|| methodName.startsWith("is"), "Only getters are supported");
57      	
58      	StringBuilder sb = new StringBuilder(methodName);
59      	if (methodName.startsWith("get")) {
60      		sb.delete(0, 3);
61      	} else {
62      		sb.delete(0, 2);
63      	}
64      	sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
65      	return sb.toString();    		
66      	
67      }
68  
69      /***
70       * @return
71       */
72      public static String createRandomString() {
73          return "" + System.currentTimeMillis();
74      }
75  
76  	public static String makeNestedPath(String[] propertyNames) {
77  		StringBuilder sb = new StringBuilder();
78  		
79  		for (int i = 0; i < propertyNames.length; i++) {
80  			sb.append(propertyNames[i]);
81  			if(i < propertyNames.length-1) {
82  				sb.append(".");
83  			}
84  		}
85  		
86  		return sb.toString();
87  	}
88  	
89  	public static String makeNestedPath(String propertyName) {
90  		return makeNestedPath(new String[] { propertyName });
91  	}
92  }