KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > loaders > Namespace


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.object.loaders;
6
7 public class Namespace {
8
9   // The separator is . coz classes are generated in the server with these as a part of the package name
10
private static final String JavaDoc SEP = ".";
11
12   // this should never be found in className or loaderDescription
13
private static final String JavaDoc CLASS_NAME_LOADER_SEPARATOR = ":://::";
14
15   private static final String JavaDoc LOGICAL_CLASS_EXTENDS_SEPARATOR = "::";
16
17   // top level loader namespaces
18
public static final String JavaDoc STANDARD_NAMESPACE = "Standard" + SEP;
19   public static final String JavaDoc TOMCAT_NAMESPACE = "Tomcat" + SEP;
20   public static final String JavaDoc GERONIMO_NAMESPACE = "Geronimo" + SEP;
21   public static final String JavaDoc WEBLOGIC_NAMESPACE = "Weblogic" + SEP;
22   public static final String JavaDoc JBOSS_NAMESPACE = "JBoss" + SEP;
23   public static final String JavaDoc MODULES_NAMESPACE = "Modules" + SEP;
24
25   private static final String JavaDoc SYSTEM_LOADER_NAME = STANDARD_NAMESPACE + "system";
26   private static final String JavaDoc EXT_LOADER_NAME = STANDARD_NAMESPACE + "ext";
27   private static final String JavaDoc BOOT_LOADER_NAME = STANDARD_NAMESPACE + "bootstrap";
28
29   public static String JavaDoc getStandardSystemLoaderName() {
30     return SYSTEM_LOADER_NAME;
31   }
32
33   public static String JavaDoc getStandardExtensionsLoaderName() {
34     return EXT_LOADER_NAME;
35   }
36
37   public static String JavaDoc getStandardBootstrapLoaderName() {
38     return BOOT_LOADER_NAME;
39   }
40
41   public static String JavaDoc getClassNameAndLoaderSeparator() {
42     return CLASS_NAME_LOADER_SEPARATOR;
43   }
44
45   public static String JavaDoc getLogicalClassExtendsSeparator() {
46     return LOGICAL_CLASS_EXTENDS_SEPARATOR;
47   }
48   
49   public static String JavaDoc createLogicalExtendingClassName(String JavaDoc className, String JavaDoc superClassName) {
50     return className + LOGICAL_CLASS_EXTENDS_SEPARATOR + superClassName;
51   }
52
53   public static String JavaDoc parseClassNameIfNecessary(String JavaDoc className) {
54     int separatorIndex = className.indexOf(LOGICAL_CLASS_EXTENDS_SEPARATOR);
55     if (separatorIndex == -1) { return className; }
56     return className.substring(0, separatorIndex);
57   }
58
59   public static String JavaDoc parseLogicalNameIfNeceesary(String JavaDoc className) {
60     int separatorIndex = className.indexOf(LOGICAL_CLASS_EXTENDS_SEPARATOR);
61     if (separatorIndex == -1) { return null; }
62     return className.substring(separatorIndex + LOGICAL_CLASS_EXTENDS_SEPARATOR.length());
63   }
64
65   public static String JavaDoc createLoaderName(String JavaDoc topLevel, String JavaDoc subName) {
66     if (topLevel == null) { throw new IllegalArgumentException JavaDoc("topLevel space is null"); }
67     if (subName == null) { throw new IllegalArgumentException JavaDoc("subName is null"); }
68
69     if (topLevel.equals(TOMCAT_NAMESPACE) || topLevel.equals(WEBLOGIC_NAMESPACE) || topLevel.equals(GERONIMO_NAMESPACE)
70         || topLevel.equals(JBOSS_NAMESPACE) || topLevel.equals(MODULES_NAMESPACE)) {
71       // this check will probably need to evolve over time, it's obviously not fancy enough yet
72
return new StringBuffer JavaDoc(topLevel).append(subName).toString();
73     }
74
75     throw new IllegalArgumentException JavaDoc("Invalid top level namespace: " + topLevel);
76   }
77
78   private Namespace() {
79     //
80
}
81 }
82
Popular Tags