idltypesutil.java
来自「JAVA 所有包」· Java 代码 · 共 581 行 · 第 1/2 页
JAVA
581 行
} return foundIsProperty; } private boolean isHasCorrespondingReadProperty(Method readProperty, Class c) { if (!FOLLOW_RMIC) return false ; String readPropertyMethodName = readProperty.getName(); boolean foundIsProperty = false; try { // Look for a valid corresponding Read property String isPropertyMethodName = readPropertyMethodName.replaceFirst(IS_PROPERTY_PREFIX, GET_PROPERTY_PREFIX); Method isPropertyMethod = c.getMethod( isPropertyMethodName, new Class[] {}); foundIsProperty = isPropertyAccessorMethod(isPropertyMethod, c) ; } catch(Exception e) { // ignore. this means we didn't find a corresponding read property. } return foundIsProperty; } public String getAttributeNameForProperty(String propertyName) { String attributeName = null; String prefix = null; if( propertyName.startsWith(GET_PROPERTY_PREFIX) ) { prefix = GET_PROPERTY_PREFIX; } else if( propertyName.startsWith(SET_PROPERTY_PREFIX) ) { prefix = SET_PROPERTY_PREFIX; } else if( propertyName.startsWith(IS_PROPERTY_PREFIX) ) { prefix = IS_PROPERTY_PREFIX; } if( (prefix != null) && (prefix.length() < propertyName.length()) ) { String remainder = propertyName.substring(prefix.length()); if( (remainder.length() >= 2) && Character.isUpperCase(remainder.charAt(0)) && Character.isUpperCase(remainder.charAt(1)) ) { // don't set the first letter to lower-case if the // first two are upper-case attributeName = remainder; } else { attributeName = Character.toLowerCase(remainder.charAt(0)) + remainder.substring(1); } } return attributeName; } /** * Return IDL Type name for primitive types as defined in * Section 1.3.3 of Java2IDL spec or null if not a primitive type. */ public IDLType getPrimitiveIDLTypeMapping(Class c) { if( c == null ) { throw new IllegalArgumentException(); } if( c.isPrimitive() ) { if( c == Void.TYPE ) { return new IDLType( c, "void" ) ; } else if( c == Boolean.TYPE ) { return new IDLType( c, "boolean" ) ; } else if( c == Character.TYPE ) { return new IDLType( c, "wchar" ) ; } else if( c == Byte.TYPE ) { return new IDLType( c, "octet" ) ; } else if( c == Short.TYPE ) { return new IDLType( c, "short" ) ; } else if( c == Integer.TYPE ) { return new IDLType( c, "long" ) ; } else if( c == Long.TYPE ) { return new IDLType( c, "long_long" ) ; } else if( c == Float.TYPE ) { return new IDLType( c, "float" ) ; } else if( c == Double.TYPE ) { return new IDLType( c, "double" ) ; } } return null; } /** * Return IDL Type name for special case type mappings as defined in * Table 1-1 of Java2IDL spec or null if given class is not a special * type. */ public IDLType getSpecialCaseIDLTypeMapping(Class c) { if( c == null ) { throw new IllegalArgumentException(); } if( c == java.lang.Object.class ) { return new IDLType( c, new String[] { "java", "lang" }, "Object" ) ; } else if( c == java.lang.String.class ) { return new IDLType( c, new String[] { "CORBA" }, "WStringValue" ) ; } else if( c == java.lang.Class.class ) { return new IDLType( c, new String[] { "javax", "rmi", "CORBA" }, "ClassDesc" ) ; } else if( c == java.io.Serializable.class ) { return new IDLType( c, new String[] { "java", "io" }, "Serializable" ) ; } else if( c == java.io.Externalizable.class ) { return new IDLType( c, new String[] { "java", "io" }, "Externalizable" ) ; } else if( c == java.rmi.Remote.class ) { return new IDLType( c, new String[] { "java", "rmi" }, "Remote" ) ; } else if( c == org.omg.CORBA.Object.class ) { return new IDLType( c, "Object" ) ; } else { return null; } } /** * Implements 1.2.3 #2 and #4 */ private void validateExceptions(Method method) throws IDLTypeException { Class[] exceptions = method.getExceptionTypes(); boolean declaresRemoteExceptionOrSuperClass = false; // Section 1.2.3, #2 for(int eIndex = 0; eIndex < exceptions.length; eIndex++) { Class exception = exceptions[eIndex]; if( isRemoteExceptionOrSuperClass(exception) ) { declaresRemoteExceptionOrSuperClass = true; break; } } if( !declaresRemoteExceptionOrSuperClass ) { String msg = "Method '" + method + "' must throw at least one " + "exception of type java.rmi.RemoteException or one of its " + "super-classes"; throw new IDLTypeException(msg); } // Section 1.2.3, #4 // See also bug 4972402 // For all exceptions E in exceptions, // (isCheckedException(E) => (isValue(E) || RemoteException.isAssignableFrom( E ) ) for(int eIndex = 0; eIndex < exceptions.length; eIndex++) { Class exception = exceptions[eIndex]; if (isCheckedException(exception) && !isValue(exception) && !isRemoteException(exception)) { String msg = "Exception '" + exception + "' on method '" + method + "' is not a allowed RMI/IIOP exception type"; throw new IDLTypeException(msg); } } return; } /** * Returns true if the method's throw clause conforms to the exception * restrictions for properties as defined in Section 1.3.4.3 of * Java2IDL spec. This means that for all exceptions E declared on the * method, E isChecked => RemoteException.isAssignableFrom( E ). */ private boolean validPropertyExceptions(Method method) { Class[] exceptions = method.getExceptionTypes(); for(int eIndex = 0; eIndex < exceptions.length; eIndex++) { Class exception = exceptions[eIndex]; if (isCheckedException(exception) && !isRemoteException(exception)) return false ; } return true; } /** * Implements Section 1.2.3, #2. */ private boolean isRemoteExceptionOrSuperClass(Class c) { return ((c == java.rmi.RemoteException.class) || (c == java.io.IOException.class) || (c == java.lang.Exception.class) || (c == java.lang.Throwable.class)); } /** * Implements Section 1.2.3, #5. */ private void validateDirectInterfaces(Class c) throws IDLTypeException { Class[] directInterfaces = c.getInterfaces(); if( directInterfaces.length < 2 ) { return; } Set allMethodNames = new HashSet(); Set currentMethodNames = new HashSet(); for(int i = 0; i < directInterfaces.length; i++) { Class next = directInterfaces[i]; Method[] methods = next.getMethods(); // Comparison is based on method names only. First collect // all methods from current interface, eliminating duplicate // names. currentMethodNames.clear(); for(int m = 0; m < methods.length; m++) { currentMethodNames.add(methods[m].getName()); } // Now check each method against list of all unique method // names processed so far. for(Iterator iter=currentMethodNames.iterator(); iter.hasNext();) { String methodName = (String) iter.next(); if( allMethodNames.contains(methodName) ) { String msg = "Class " + c + " inherits method " + methodName + " from multiple direct interfaces."; throw new IDLTypeException(msg); } else { allMethodNames.add(methodName); } } } return; } /** * Implements 1.2.3 #6 */ private void validateConstants(final Class c) throws IDLTypeException { Field[] fields = null; try { fields = (Field[]) java.security.AccessController.doPrivileged (new java.security.PrivilegedExceptionAction() { public java.lang.Object run() throws Exception { return c.getFields(); } }); } catch(java.security.PrivilegedActionException pae) { IDLTypeException ite = new IDLTypeException(); ite.initCause(pae); throw ite; } for(int i = 0; i < fields.length; i++) { Field next = fields[i]; Class fieldType = next.getType(); if( (fieldType != java.lang.String.class) && !isPrimitive(fieldType) ) { String msg = "Constant field '" + next.getName() + "' in class '" + next.getDeclaringClass().getName() + "' has invalid type' " + next.getType() + "'. Constants" + " in RMI/IIOP interfaces can only have primitive" + " types and java.lang.String types."; throw new IDLTypeException(msg); } } return; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?