001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object.loaders;
006:
007: /**
008: * Manage classloader namespaces
009: */
010: public class Namespace {
011:
012: // The separator is . coz classes are generated in the server with these as a part of the package name
013: private static final String SEP = ".";
014:
015: // this should never be found in className or loaderDescription
016: private static final String CLASS_NAME_LOADER_SEPARATOR = ":://::";
017:
018: private static final String LOGICAL_CLASS_EXTENDS_SEPARATOR = "::";
019:
020: // top level loader namespaces
021: public static final String STANDARD_NAMESPACE = "Standard" + SEP;
022: public static final String TOMCAT_NAMESPACE = "Tomcat" + SEP;
023: public static final String GERONIMO_NAMESPACE = "Geronimo" + SEP;
024: public static final String WEBLOGIC_NAMESPACE = "Weblogic" + SEP;
025: public static final String JBOSS_NAMESPACE = "JBoss" + SEP;
026: public static final String MODULES_NAMESPACE = "Modules" + SEP;
027: public static final String JETTY_NAMESPACE = "Jetty" + SEP;
028: public static final String WEBSPHERE_NAMESPACE = "Websphere" + SEP;
029:
030: private static final String SYSTEM_LOADER_NAME = STANDARD_NAMESPACE
031: + "system";
032: private static final String EXT_LOADER_NAME = STANDARD_NAMESPACE
033: + "ext";
034: private static final String BOOT_LOADER_NAME = STANDARD_NAMESPACE
035: + "bootstrap";
036:
037: /**
038: * @return Normal system class loader name
039: */
040: public static String getStandardSystemLoaderName() {
041: return SYSTEM_LOADER_NAME;
042: }
043:
044: /**
045: * @return Extensions class loader name
046: */
047: public static String getStandardExtensionsLoaderName() {
048: return EXT_LOADER_NAME;
049: }
050:
051: /**
052: * @return Boot class loader name
053: */
054: public static String getStandardBootstrapLoaderName() {
055: return BOOT_LOADER_NAME;
056: }
057:
058: /**
059: * @return Separator between loader and class name
060: */
061: public static String getClassNameAndLoaderSeparator() {
062: return CLASS_NAME_LOADER_SEPARATOR;
063: }
064:
065: /**
066: * @return Separator in logical class extension
067: */
068: public static String getLogicalClassExtendsSeparator() {
069: return LOGICAL_CLASS_EXTENDS_SEPARATOR;
070: }
071:
072: /**
073: * Create logical extending class name by combining class names
074: * @param className Class name
075: * @param superClassName Logical super class name
076: */
077: public static String createLogicalExtendingClassName(
078: String className, String super ClassName) {
079: return className + LOGICAL_CLASS_EXTENDS_SEPARATOR
080: + super ClassName;
081: }
082:
083: /**
084: * Parse class name out of logical extending class name
085: * @param className Logical extending name, as returned by {@link #createLogicalExtendingClassName(String, String)}
086: * @return Extending class name
087: */
088: public static String parseClassNameIfNecessary(String className) {
089: int separatorIndex = className
090: .indexOf(LOGICAL_CLASS_EXTENDS_SEPARATOR);
091: if (separatorIndex == -1) {
092: return className;
093: }
094: return className.substring(0, separatorIndex);
095: }
096:
097: /**
098: * Parse super class name out of logical extending class name
099: * @param className Logical extending name, as returned by {@link #createLogicalExtendingClassName(String, String)}
100: * @return Logical super class name
101: */
102: public static String parseLogicalNameIfNeceesary(String className) {
103: int separatorIndex = className
104: .indexOf(LOGICAL_CLASS_EXTENDS_SEPARATOR);
105: if (separatorIndex == -1) {
106: return null;
107: }
108: return className.substring(separatorIndex
109: + LOGICAL_CLASS_EXTENDS_SEPARATOR.length());
110: }
111:
112: /**
113: * Create a loader name based on a toplevel loader name and a subname
114: * @param topLevel Top level name
115: * @param subName Sub level name
116: * @return Classloader name
117: */
118: public static String createLoaderName(String topLevel,
119: String subName) {
120: if (topLevel == null) {
121: throw new IllegalArgumentException("topLevel space is null");
122: }
123: if (subName == null) {
124: throw new IllegalArgumentException("subName is null");
125: }
126:
127: if (topLevel.equals(TOMCAT_NAMESPACE)
128: || topLevel.equals(WEBLOGIC_NAMESPACE)
129: || topLevel.equals(GERONIMO_NAMESPACE)
130: || topLevel.equals(JBOSS_NAMESPACE)
131: || topLevel.equals(MODULES_NAMESPACE)
132: || topLevel.equals(JETTY_NAMESPACE)
133: || topLevel.equals(WEBSPHERE_NAMESPACE)) {
134: // this check will probably need to evolve over time, it's obviously not fancy enough yet
135: return new StringBuffer(topLevel).append(subName)
136: .toString();
137: }
138:
139: throw new IllegalArgumentException(
140: "Invalid top level namespace: " + topLevel);
141: }
142:
143: private Namespace() {
144: //
145: }
146: }
|