📄 anyimpl.java
字号:
/** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_octet(byte b) { //debug.log ("insert_octet"); typeCode = orb.get_primitive_tc(TCKind._tk_octet); value = b; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public byte extract_octet() { //debug.log ("extract_octet"); checkExtractBadOperation( TCKind._tk_octet ) ; return (byte)value; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_string(String s) { //debug.log ("insert_string"); // Make sure type code information for bounded strings is not erased if (typeCode.kind() == TCKind.tk_string) { int length = 0; try { length = typeCode.length(); } catch (BadKind bad) { throw wrapper.badkindCannotOccur() ; } // Check if bounded strings length is not exceeded if (length != 0 && s != null && s.length() > length) { throw wrapper.badStringBounds( new Integer(s.length()), new Integer(length) ) ; } } else { typeCode = orb.get_primitive_tc(TCKind._tk_string); } object = s; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public String extract_string() { //debug.log ("extract_string"); checkExtractBadOperation( TCKind._tk_string ) ; return (String)object; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_wstring(String s) { //debug.log ("insert_wstring"); // Make sure type code information for bounded strings is not erased if (typeCode.kind() == TCKind.tk_wstring) { int length = 0; try { length = typeCode.length(); } catch (BadKind bad) { throw wrapper.badkindCannotOccur() ; } // Check if bounded strings length is not exceeded if (length != 0 && s != null && s.length() > length) { throw wrapper.badStringBounds( new Integer(s.length()), new Integer(length) ) ; } } else { typeCode = orb.get_primitive_tc(TCKind._tk_wstring); } object = s; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public String extract_wstring() { //debug.log ("extract_wstring"); checkExtractBadOperation( TCKind._tk_wstring ) ; return (String)object; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_any(Any a) { //debug.log ("insert_any"); typeCode = orb.get_primitive_tc(TCKind._tk_any); object = a; stream = null; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public Any extract_any() { //debug.log ("extract_any"); checkExtractBadOperation( TCKind._tk_any ) ; return (Any)object; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_Object(org.omg.CORBA.Object o) { //debug.log ("insert_Object"); if ( o == null ) { typeCode = orb.get_primitive_tc(TCKind._tk_objref); } else { if (StubAdapter.isStub(o)) { String[] ids = StubAdapter.getTypeIds( o ) ; typeCode = new TypeCodeImpl(orb, TCKind._tk_objref, ids[0], ""); } else { throw wrapper.badInsertobjParam( CompletionStatus.COMPLETED_MAYBE, o.getClass().getName() ) ; } } object = o; isInitialized = true; } /** * A variant of the insertion operation that takes a typecode * argument as well. */ public void insert_Object(org.omg.CORBA.Object o, TypeCode tc) { //debug.log ("insert_Object2"); try { if ( tc.id().equals("IDL:omg.org/CORBA/Object:1.0") || o._is_a(tc.id()) ) { typeCode = TypeCodeImpl.convertToNative(orb, tc); object = o; } else { throw wrapper.insertObjectIncompatible() ; } } catch ( Exception ex ) { throw wrapper.insertObjectFailed(ex) ; } isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public org.omg.CORBA.Object extract_Object() { //debug.log ("extract_Object"); if (!isInitialized) throw wrapper.extractNotInitialized() ; // Check if the object contained here is of the type in typeCode org.omg.CORBA.Object obj = null; try { obj = (org.omg.CORBA.Object) object; if (typeCode.id().equals("IDL:omg.org/CORBA/Object:1.0") || obj._is_a(typeCode.id())) { return obj; } else { throw wrapper.extractObjectIncompatible() ; } } catch ( Exception ex ) { throw wrapper.extractObjectFailed(ex); } } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public void insert_TypeCode(TypeCode tc) { //debug.log ("insert_TypeCode"); typeCode = orb.get_primitive_tc(TCKind._tk_TypeCode); object = tc; isInitialized = true; } /** * See the description of the <a href="#anyOps">general Any operations.</a> */ public TypeCode extract_TypeCode() { //debug.log ("extract_TypeCode"); checkExtractBadOperation( TCKind._tk_TypeCode ) ; return (TypeCode)object; } /** * @deprecated */ @Deprecated public void insert_Principal(Principal p) { typeCode = orb.get_primitive_tc(TCKind._tk_Principal); object = p; isInitialized = true; } /** * @deprecated */ @Deprecated public Principal extract_Principal() { checkExtractBadOperation( TCKind._tk_Principal ) ; return (Principal)object; } /** * Note that the Serializable really should be an IDLEntity of * some kind. It shouldn't just be an RMI-IIOP type. Currently, * we accept and will produce RMI repIds with the latest * calculations if given a non-IDLEntity Serializable. */ public Serializable extract_Value() { //debug.log ("extract_Value"); checkExtractBadOperationList( new int[] { TCKind._tk_value, TCKind._tk_value_box, TCKind._tk_abstract_interface } ) ; return (Serializable)object; } public void insert_Value(Serializable v) { //debug.log ("insert_Value"); object = v; TypeCode tc; if ( v == null ) { tc = orb.get_primitive_tc (TCKind.tk_value); } else { // See note in getPrimitiveTypeCodeForClass. We // have to use the latest type code fixes in this // case since there is no way to know what ORB will // actually send this Any. In RMI-IIOP, when using // Util.writeAny, we can do the versioning correctly, // and use the insert_Value(Serializable, TypeCode) // method. // // The ORB singleton uses the latest version. tc = createTypeCodeForClass (v.getClass(), (ORB)ORB.init()); } typeCode = TypeCodeImpl.convertToNative(orb, tc); isInitialized = true; } public void insert_Value(Serializable v, org.omg.CORBA.TypeCode t) { //debug.log ("insert_Value2"); object = v; typeCode = TypeCodeImpl.convertToNative(orb, t); isInitialized = true; } public void insert_fixed(java.math.BigDecimal value) { typeCode = TypeCodeImpl.convertToNative(orb, orb.create_fixed_tc(TypeCodeImpl.digits(value), TypeCodeImpl.scale(value))); object = value; isInitialized = true; } public void insert_fixed(java.math.BigDecimal value, org.omg.CORBA.TypeCode type) { try { if (TypeCodeImpl.digits(value) > type.fixed_digits() || TypeCodeImpl.scale(value) > type.fixed_scale()) { throw wrapper.fixedNotMatch() ; } } catch (org.omg.CORBA.TypeCodePackage.BadKind bk) { // type isn't even of kind fixed throw wrapper.fixedBadTypecode( bk ) ; } typeCode = TypeCodeImpl.convertToNative(orb, type); object = value; isInitialized = true; } public java.math.BigDecimal extract_fixed() { checkExtractBadOperation( TCKind._tk_fixed ) ; return (BigDecimal)object; } /** * Utility method for insert_Value and Util.writeAny. * * The ORB passed in should have the desired ORBVersion. It * is used to generate the type codes. */ public TypeCode createTypeCodeForClass (java.lang.Class c, ORB tcORB) { // Look in the cache first TypeCodeImpl classTC = tcORB.getTypeCodeForClass(c); if (classTC != null) return classTC; // All cases need to be able to create repository IDs. // // See bug 4391648 for more info about the tcORB in this // case. RepositoryIdStrings repStrs = RepositoryIdFactory.getRepIdStringsFactory(tcORB); // Assertion: c instanceof Serializable? if ( c.isArray() ) { // Arrays - may recurse for multi-dimensional arrays Class componentClass = c.getComponentType(); TypeCode embeddedType; if ( componentClass.isPrimitive() ) { embeddedType = getPrimitiveTypeCodeForClass(componentClass, tcORB); } else { embeddedType = createTypeCodeForClass (componentClass, tcORB); } TypeCode t = tcORB.create_sequence_tc (0, embeddedType); String id = repStrs.createForJavaType(c); return tcORB.create_value_box_tc (id, "Sequence", t); } else if ( c == java.lang.String.class ) { // Strings TypeCode t = tcORB.create_string_tc (0); String id = repStrs.createForJavaType(c); return tcORB.create_value_box_tc (id, "StringValue", t); } // Anything else // We know that this is a TypeCodeImpl since it is our ORB classTC = (TypeCodeImpl)ValueUtility.createTypeCodeForClass( tcORB, c, ORBUtility.createValueHandler(tcORB)); // Intruct classTC to store its buffer classTC.setCaching(true); // Update the cache tcORB.setTypeCodeForClass(c, classTC); return classTC; } /** * It looks like this was copied from io.ValueUtility at some * point. * * It's used by createTypeCodeForClass. The tcORB passed in * should have the desired ORB version, and is used to * create the type codes. */ private TypeCode getPrimitiveTypeCodeForClass (Class c, ORB tcORB) { //debug.log ("getPrimitiveTypeCodeForClass"); if (c == Integer.TYPE) { return tcORB.get_primitive_tc (TCKind.tk_long); } else if (c == Byte.TYPE) { return tcORB.get_primitive_tc (TCKind.tk_octet); } else if (c == Long.TYPE) { return tcORB.get_primitive_tc (TCKind.tk_longlong); } else if (c == Float.TYPE) { return tcORB.get_primitive_tc (TCKind.tk_float); } else if (c == Double.TYPE) { return tcORB.get_primitive_tc (TCKind.tk_double); } else if (c == Short.TYPE) { return tcORB.get_primitive_tc (TCKind.tk_short); } else if (c == Character.TYPE) { // For Merlin or later JDKs, or for foreign ORBs, // we correctly say that a Java char maps to a // CORBA wchar. For backwards compatibility // with our older ORBs, we say it maps to a // CORBA char. This is only used in RMI-IIOP // in our javax.rmi.CORBA.Util delegate's // writeAny method. In Java IDL, there's no way // to know the ORB version that the Any will be // sent out with -- it could be different than // the one used to create the Any -- so we use the // most recent version (see insert_Value). if (ORBVersionFactory.getFOREIGN().compareTo(tcORB.getORBVersion()) == 0 || ORBVersionFactory.getNEWER().compareTo(tcORB.getORBVersion()) <= 0) return tcORB.get_primitive_tc(TCKind.tk_wchar); else return tcORB.get_primitive_tc(TCKind.tk_char); } else if (c == Boolean.TYPE) { return tcORB.get_primitive_tc (TCKind.tk_boolean); } else { // _REVISIT_ Not sure if this is right. return tcORB.get_primitive_tc (TCKind.tk_any); } } // Extracts a member value according to the given TypeCode from the given complex Any // (at the Anys current internal stream position, consuming the anys stream on the way) // and returns it wrapped into a new Any public Any extractAny(TypeCode memberType, ORB orb) { Any returnValue = orb.create_any(); OutputStream out = returnValue.create_output_stream(); TypeCodeImpl.convertToNative(orb, memberType).copy((InputStream)stream, out); returnValue.read_value(out.create_input_stream(), memberType); return returnValue; } // This method could very well be moved into TypeCodeImpl or a common utility class, // but is has to be in this package. static public Any extractAnyFromStream(TypeCode memberType, InputStream input, ORB orb) { Any returnValue = orb.create_any(); OutputStream out = returnValue.create_output_stream(); TypeCodeImpl.convertToNative(orb, memberType).copy(input, out); returnValue.read_value(out.create_input_stream(), memberType); return returnValue; } // There is no other way for DynAnys to find out whether the Any is initialized. public boolean isInitialized() { return isInitialized; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -