📄 valueutility.java
字号:
/* * @(#)ValueUtility.java 1.27 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * Licensed Materials - Property of IBM * RMI-IIOP v1.0 * Copyright IBM Corp. 1998 1999 All Rights Reserved * * US Government Users Restricted Rights - Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */package com.sun.corba.se.internal.io;import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;import com.sun.org.omg.CORBA.OperationDescription;import com.sun.org.omg.CORBA.AttributeDescription;import org.omg.CORBA.ValueMember;import com.sun.org.omg.CORBA.Initializer;import org.omg.CORBA.IDLType;import com.sun.org.omg.CORBA._IDLTypeStub;import org.omg.CORBA.ORB;import org.omg.CORBA.TypeCodePackage.*;import org.omg.CORBA.TypeCode;import org.omg.CORBA.TCKind;import java.lang.reflect.*;import com.sun.corba.se.internal.util.RepositoryId;import java.util.*;import javax.rmi.CORBA.Util;import javax.rmi.CORBA.ValueHandler;/** * Holds utility methods for converting from ObjectStreamClass to * FullValueDescription and generating typecodes from ObjectStreamClass. **/public class ValueUtility { public static final short PRIVATE_MEMBER = 0; public static final short PUBLIC_MEMBER = 1; private static final String primitiveConstants[] = { null, // tk_null 0 null, // tk_void 1 "S", // tk_short 2 "I", // tk_long 3 "S", // tk_ushort 4 "I", // tk_ulong 5 "F", // tk_float 6 "D", // tk_double 7 "Z", // tk_boolean 8 "C", // tk_char 9 "B", // tk_octet 10 null, // tk_any 11 null, // tk_typecode 12 null, // tk_principal 13 null, // tk_objref 14 null, // tk_struct 15 null, // tk_union 16 null, // tk_enum 17 null, // tk_string 18 null, // tk_sequence 19 null, // tk_array 20 null, // tk_alias 21 null, // tk_except 22 "J", // tk_longlong 23 "J", // tk_ulonglong 24 "D", // tk_longdouble 25 "C", // tk_wchar 26 null, // tk_wstring 27 null, // tk_fixed 28 null, // tk_value 29 null, // tk_value_box 30 null, // tk_native 31 null, // tk_abstract_interface 32 }; public static String getSignature(ValueMember member) throws ClassNotFoundException { // REVISIT. Can the type be something that is // non-primitive yet not a value_box, value, or objref? // If so, should use ObjectStreamClass or throw // exception. if (member.type.kind().value() == TCKind._tk_value_box || member.type.kind().value() == TCKind._tk_value || member.type.kind().value() == TCKind._tk_objref) { Class c = RepositoryId.cache.getId(member.id).getClassFromType(); return ObjectStreamClass.getSignature(c); } else { return primitiveConstants[member.type.kind().value()]; } } public static FullValueDescription translate(ORB orb, ObjectStreamClass osc, ValueHandler vh){ // Create FullValueDescription FullValueDescription result = new FullValueDescription(); Class className = osc.forClass(); ValueHandlerImpl vhandler = (com.sun.corba.se.internal.io.ValueHandlerImpl) vh; String repId = vhandler.createForAnyType(className); // Set FVD name result.name = vhandler.getUnqualifiedName(repId); if (result.name == null) result.name = ""; // Set FVD id _REVISIT_ : Manglings result.id = vhandler.getRMIRepositoryID(className); if (result.id == null) result.id = ""; // Set FVD is_abstract result.is_abstract = ObjectStreamClassCorbaExt.isAbstractInterface(className); // Set FVD is_custom result.is_custom = osc.isCustomMarshaled(); // Set FVD defined_in _REVISIT_ : Manglings result.defined_in = vhandler.getDefinedInId(repId); if (result.defined_in == null) result.defined_in = ""; // Set FVD version result.version = vhandler.getSerialVersionUID(repId); if (result.version == null) result.version = ""; // Skip FVD operations - N/A result.operations = new OperationDescription[0]; // Skip FVD attributed - N/A result.attributes = new AttributeDescription[0]; // Set FVD members // Maps classes to repositoryIDs strings. This is used to detect recursive types. IdentityKeyValueStack createdIDs = new IdentityKeyValueStack(); // Stores all types created for resolving indirect types at the end. result.members = translateMembers(orb, osc, vh, createdIDs); // Skip FVD initializers - N/A result.initializers = new Initializer[0]; Class interfaces[] = osc.forClass().getInterfaces(); int abstractCount = 0; // Skip FVD supported_interfaces result.supported_interfaces = new String[interfaces.length]; for (int interfaceIndex = 0; interfaceIndex < interfaces.length; interfaceIndex++) { result.supported_interfaces[interfaceIndex] = vhandler.createForAnyType(interfaces[interfaceIndex]); if ((!(java.rmi.Remote.class.isAssignableFrom(interfaces[interfaceIndex]))) || (!Modifier.isPublic(interfaces[interfaceIndex].getModifiers()))) abstractCount++; } // Skip FVD abstract_base_values - N/A result.abstract_base_values = new String[abstractCount]; for (int interfaceIndex = 0; interfaceIndex < interfaces.length; interfaceIndex++) { if ((!(java.rmi.Remote.class.isAssignableFrom(interfaces[interfaceIndex]))) || (!Modifier.isPublic(interfaces[interfaceIndex].getModifiers()))) result.abstract_base_values[interfaceIndex] = vhandler.createForAnyType(interfaces[interfaceIndex]); } result.is_truncatable = false; // Set FVD base_value Class superClass = osc.forClass().getSuperclass(); if (java.io.Serializable.class.isAssignableFrom(superClass)) result.base_value = vhandler.getRMIRepositoryID(superClass); else result.base_value = ""; // Set FVD type //result.type = createTypeCodeForClass(orb, osc.forClass()); result.type = orb.get_primitive_tc(TCKind.tk_value); //11638 return result; } private static ValueMember[] translateMembers (ORB orb, ObjectStreamClass osc, ValueHandler vh, IdentityKeyValueStack createdIDs) { ValueHandlerImpl vhandler = (com.sun.corba.se.internal.io.ValueHandlerImpl) vh; ObjectStreamField fields[] = osc.getFields(); int fieldsLength = fields.length; ValueMember[] members = new ValueMember[fieldsLength]; // Note : fields come out of ObjectStreamClass in correct order for // writing. So, we will create the same order in the members array. for (int i = 0; i < fieldsLength; i++) { String valRepId = vhandler.getRMIRepositoryID(fields[i].getClazz()); members[i] = new ValueMember(); members[i].name = fields[i].getName(); members[i].id = valRepId; // _REVISIT_ : Manglings members[i].defined_in = vhandler.getDefinedInId(valRepId);// _REVISIT_ : Manglings members[i].version = "1.0"; members[i].type_def = new _IDLTypeStub(); // _REVISIT_ : IDLType implementation missing if (fields[i].getField() == null) { // When using serialPersistentFields, the class may // no longer have an actual Field that corresponds // to one of the items. The Java to IDL spec // ptc-00-01-06 1.3.5.6 says that the IDL field // should be private in this case. members[i].access = PRIVATE_MEMBER; } else { int m = fields[i].getField().getModifiers(); if (Modifier.isPublic(m)) members[i].access = PUBLIC_MEMBER; else members[i].access = PRIVATE_MEMBER;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -