idlnametranslatorimpl.java

来自「JAVA 所有包」· Java 代码 · 共 911 行 · 第 1/3 页

JAVA
911
字号
            }    private static boolean isIDLIdentifierChar(char c) {        return (isIDLAlphabeticChar(c) ||                 isIDLDecimalDigit(c)   ||                isUnderscore(c));    }    /**     * True if character is one of 114 Alphabetic characters as     * specified in Table 2 of Chapter 3 in CORBA spec.     */     private static boolean isIDLAlphabeticChar(char c) {        // NOTE that we can't use the java.lang.Character        // isUpperCase, isLowerCase, etc. methods since they        // include many characters other than the Alphabetic list in        // the CORBA spec.  Instead, we test for inclusion in the        // Unicode value ranges for the corresponding legal characters.        boolean alphaChar =             (             // A - Z             ((c >= 0x0041) && (c <= 0x005A))              ||                          // a - z             ((c >= 0x0061) && (c <= 0x007A))                           ||                          // other letter uppercase, other letter lowercase, which is             // the entire upper half of C1 Controls except X and /             ((c >= 0x00C0) && (c <= 0x00FF)              && (c != 0x00D7) && (c != 0x00F7)));                return alphaChar;    }    /**     * True if character is one of 10 Decimal Digits      * specified in Table 3 of Chapter 3 in CORBA spec.     */     private static boolean isIDLDecimalDigit(char c) {        return ( (c >= 0x0030) && (c <= 0x0039) );    }    private static boolean isUnderscore(char c) {        return ( c == 0x005F );    }        /**     * Mangle an overloaded method name as defined in Section 1.3.2.6 of     * Java2IDL spec.  Current value of method name is passed in as argument.     * We can't start from original method name since the name might have     * been partially mangled as a result of the other rules.       */    private static String mangleOverloadedMethod(String mangledName, Method m) {        IDLTypesUtil idlTypesUtil = new IDLTypesUtil();        // Start by appending the separator string        String newMangledName = mangledName + OVERLOADED_TYPE_SEPARATOR;                Class[] parameterTypes = m.getParameterTypes();                for(int i = 0; i < parameterTypes.length; i++) {            Class nextParamType = parameterTypes[i];                        if( i > 0 ) {                newMangledName = newMangledName + OVERLOADED_TYPE_SEPARATOR;            }                        IDLType idlType = classToIDLType(nextParamType);            String moduleName = idlType.getModuleName();            String memberName = idlType.getMemberName();            String typeName = (moduleName.length() > 0) ?                moduleName + UNDERSCORE + memberName : memberName;                                               if( !idlTypesUtil.isPrimitive(nextParamType) &&                 (idlTypesUtil.getSpecialCaseIDLTypeMapping(nextParamType)                  == null) &&                               isIDLKeyword(typeName) ) {                typeName = mangleIDLKeywordClash(typeName);            }            typeName = mangleUnicodeChars(typeName);            newMangledName = newMangledName + typeName;        }                return newMangledName;            }    private static IDLType classToIDLType(Class c) {                       IDLType idlType = null;        IDLTypesUtil idlTypesUtil = new IDLTypesUtil();        if( idlTypesUtil.isPrimitive(c) ) {            idlType = idlTypesUtil.getPrimitiveIDLTypeMapping(c);        } else if( c.isArray() ) {                        // Calculate array depth, as well as base element type.            Class componentType = c.getComponentType();            int numArrayDimensions = 1;            while(componentType.isArray()) {                componentType = componentType.getComponentType();                numArrayDimensions++;            }            IDLType componentIdlType = classToIDLType(componentType);                        String[] modules = BASE_IDL_ARRAY_MODULE_TYPE;            if( componentIdlType.hasModule() ) {                modules = (String[])ObjectUtility.concatenateArrays( modules,                     componentIdlType.getModules() ) ;            }            String memberName = BASE_IDL_ARRAY_ELEMENT_TYPE +                 numArrayDimensions + UNDERSCORE +                 componentIdlType.getMemberName();                                        idlType = new IDLType(c, modules, memberName);                       } else {            idlType = idlTypesUtil.getSpecialCaseIDLTypeMapping(c);            if (idlType == null) {                // Section 1.3.2.5 of Java2IDL spec defines mangling rules for                // inner classes.                String memberName = getUnmappedContainerName(c);                // replace inner class separator with double underscore                memberName = memberName.replaceAll("\\$",                                                    INNER_CLASS_SEPARATOR);                                                if( hasLeadingUnderscore(memberName) ) {                    memberName = mangleLeadingUnderscore(memberName);                }                                    // Get raw package name.  If there is a package, it                // will still have the "." separators and none of the                // mangling rules will have been applied.                String packageName = getPackageName(c);                                                 if (packageName == null) {		    idlType = new IDLType( c, memberName ) ;		} else {		    // If this is a generated IDL Entity Type we need to		    // prepend org_omg_boxedIDL per sections 1.3.5 and 1.3.9		    if (idlTypesUtil.isEntity(c)) {			packageName = "org.omg.boxedIDL." + packageName ;		    }		    		    // Section 1.3.2.1 and 1.3.2.6 of Java2IDL spec defines 		    // rules for mapping java packages to IDL modules and for 		    // mangling module name portion of type name.  NOTE that		    // of the individual identifier mangling rules, 		    // only the leading underscore test is done here.  		    // The other two(IDL Keyword, Illegal Unicode chars) are		    // done in mangleOverloadedMethodName.                      StringTokenizer tokenizer =                         new StringTokenizer(packageName, ".");		    		    String[] modules = new String[ tokenizer.countTokens() ] ;		    int index = 0 ;                    while (tokenizer.hasMoreElements()) {                        String next = tokenizer.nextToken();                        String moreMangled = hasLeadingUnderscore( next ) ?                            mangleLeadingUnderscore( next ) : next;			modules[index++] = moreMangled ;                    }                                                          		    idlType = new IDLType(c, modules, memberName);                }            }        }        return idlType;    }    /**     * Return Class' package name or null if there is no package.     */    private static String getPackageName(Class c) {        Package thePackage = c.getPackage();        String packageName = null;        // Try to get package name by introspection.  Some classloaders might        // not provide this information, so check for null.        if( thePackage != null ) {            packageName = thePackage.getName();        } else {            // brute force method            String fullyQualifiedClassName = c.getName();            int lastDot = fullyQualifiedClassName.indexOf('.');            packageName = (lastDot == -1) ? null :                fullyQualifiedClassName.substring(0, lastDot);        }        return packageName;    }        private static String getMappedContainerName(Class c) {        String unmappedName = getUnmappedContainerName(c);        return mangleIdentifier(unmappedName);    }    /**     * Return portion of class name excluding package name.     */    private static String getUnmappedContainerName(Class c) {        String memberName  = null;        String packageName = getPackageName(c);        String fullyQualifiedClassName = c.getName();                       if( packageName != null ) {            int packageLength = packageName.length();            memberName = fullyQualifiedClassName.substring(packageLength + 1);        } else {            memberName = fullyQualifiedClassName;        }        return memberName;    }    /**     * Internal helper class for tracking information related to each     * interface method while we're building the name translation table.     */    private static class IDLMethodInfo     {        public Method method;        public boolean isProperty;                // If this is a property, originalName holds the original         // attribute name. Otherwise, it holds the original method name.        public String originalName;        // If this is a property, mangledName holds the mangled attribute         // name. Otherwise, it holds the mangled method name.         public String mangledName;            }    public String toString() {        StringBuffer contents = new StringBuffer();        contents.append("IDLNameTranslator[" );	for( int ctr=0; ctr<interf_.length; ctr++) {	    if (ctr != 0)		contents.append( " " ) ;	    contents.append( interf_[ctr].getName() ) ;	}        contents.append("]\n");        for(Iterator iter = methodToIDLNameMap_.keySet().iterator();            iter.hasNext();) {            Method method  = (Method) iter.next();            String idlName = (String) methodToIDLNameMap_.get(method);            contents.append(idlName + ":" + method + "\n");        }        return contents.toString();    }    public static void main(String[] args) {                Class remoteInterface = java.rmi.Remote.class;                if( args.length > 0 ) {            String className = args[0];            try {                remoteInterface = Class.forName(className);            } catch(Exception e) {                e.printStackTrace();                System.exit(-1);            }                    }                System.out.println("Building name translation for " + remoteInterface);        try {            IDLNameTranslator nameTranslator =                 IDLNameTranslatorImpl.get(remoteInterface);            System.out.println(nameTranslator);        } catch(IllegalStateException ise) {            ise.printStackTrace();        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?