KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > xml > idefix > serializer > SerializerHelper


1 package org.sapia.util.xml.idefix.serializer;
2
3
4 /**
5  * This class contains some static utility methods.
6  *
7  * @author <a HREF="mailto:jc@sapia-oss.org">Jean-Cedric Desrochers</a>
8  * <dl>
9  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
10  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
11  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
12  * </dl>
13  */

14 public class SerializerHelper {
15   /**
16    * Returns the local name of the class of the object passed in.
17    *
18    * @param anObject The object fom which to get the local name class.
19    * @return The local name of the class or empty string if the object is <code>null</code>.
20    */

21   public static String JavaDoc getLocalClassName(Object JavaDoc anObject) {
22     if (anObject == null) {
23       return "";
24     }
25
26     Class JavaDoc aClass = anObject.getClass();
27
28     String JavaDoc aQualifiedClassName = aClass.getName();
29     String JavaDoc aPackageName = aClass.getPackage().getName();
30     String JavaDoc aLocalClassName = aQualifiedClassName.substring(aPackageName.length() +
31         1);
32
33     return aLocalClassName;
34   }
35
36   /**
37    * This utility method will return a string with the first character beign
38    * lower case. The string return will be a substring of the passed in string
39    * starting at the specified position.
40    *
41    * @param aString The string to convert.
42    * @param aStartingIndex The starting index of the passed in string.
43    * @return The converted string.
44    * @exception IllegalArgumentException If the starting index is lower than zero.
45    */

46   public static String JavaDoc firstToLowerFromIndex(String JavaDoc aString, int aStartingIndex) {
47     if (aStartingIndex < 0) {
48       throw new IllegalArgumentException JavaDoc(
49         "The starting position is lower than zero");
50     }
51
52     char[] newChars = new char[aString.length() - aStartingIndex];
53     newChars[0] = Character.toLowerCase(aString.charAt(aStartingIndex));
54     aString.getChars(aStartingIndex + 1, aString.length(), newChars, 1);
55
56     return new String JavaDoc(newChars);
57   }
58
59   /**
60    * This utility method will return a string with the first character beign
61    * upper case. The string return will be a substring of the passed in string
62    * starting at the specified position.
63    *
64    * @param aString The string to convert.
65    * @param aStartingIndex The starting index of the passed in string.
66    * @return The converted string.
67    * @exception IllegalArgumentException If the starting index is lower than zero.
68    */

69   public static String JavaDoc firstToUpperFromIndex(String JavaDoc aString, int aStartingIndex) {
70     if (aStartingIndex < 0) {
71       throw new IllegalArgumentException JavaDoc(
72         "The starting position is lower than zero");
73     }
74
75     char[] newChars = new char[aString.length() - aStartingIndex];
76     newChars[0] = Character.toUpperCase(aString.charAt(aStartingIndex));
77     aString.getChars(aStartingIndex + 1, aString.length(), newChars, 1);
78
79     return new String JavaDoc(newChars);
80   }
81 }
82
Popular Tags