/** * Try to write value supposing that it implements self-streamable interfaces. * Return false if it does not or true on success. */ static boolean writeSelf(OutputStream output, Serializable value) { // User defined write method is present. if (value instanceof CustomMarshal) { ((CustomMarshal) value).marshal((DataOutputStream) output); return true; } else if (value instanceof Streamable) { ((Streamable) value)._write(output); return true; } return false; }
public void _write(org.omg.CORBA.portable.OutputStream out) { if (m_destroyed) throw new OBJECT_NOT_EXIST("DynAny destroyed", 0, CompletionStatus.COMPLETED_NO); if (m_component_count == 1) throw new BAD_OPERATION("Uncompleted union."); try { ((Streamable) get_discriminator())._write(out); ((Streamable) member())._write(out); } catch (InvalidValue iv) { throw new INTERNAL(iv.toString()); } }
/** * takes a streamable and inserts its reference into the any * * @param s the streamable to insert */ public void insert_Streamable(Streamable s) { //debug.log ("insert_Streamable"); typeCode = TypeCodeImpl.convertToNative(orb, s._type()); object = s; isInitialized = true; }
/** * The obsolete invocation using server request. Implemented for * compatibility reasons, but is it more effectinve to use * {@link #_invoke}. * * @param request a server request. */ public void invoke(ServerRequest request) { // "destroy" has a void return type, the two other methods - boolean. Streamable result = request.operation().equals("destroy") ? null : new BooleanHolder(); gnu.CORBA.ServiceRequestAdapter.invoke(request, this, result); }
/** * Done via reflection. */ public Any to_any() { try { Streamable sHolder = HolderLocator.createHolder(official_type); Class sHolderClass = sHolder.getClass(); Field sHolderValue = sHolderClass.getField("value"); Class sClass = sHolderValue.getType(); Object structure = sClass.newInstance(); Object member; Any am; Field vread; Field vwrite; Streamable memberHolder; for (int i = 0; i < array.length; i++) { am = array [ i ].to_any(); memberHolder = am.extract_Streamable(); vwrite = structure.getClass().getField(final_type.member_name(i)); vread = memberHolder.getClass().getField("value"); member = vread.get(memberHolder); vwrite.set(structure, member); } Any g = createAny(); sHolderValue.set(sHolder, structure); g.insert_Streamable(sHolder); g.type(official_type); return g; } catch (Exception e) { throw new Unexpected(e); } }
/** * Create DynAny providing the holder. * * @param a_holder */ public gnuDynAny(Streamable aHolder, TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory, ORB anOrb ) { super(oType, aType, aFactory, anOrb); holder = aHolder; }
/** * Create a copy of this {@link DynAny} via buffer read/write. */ public DynAny copy() { if (holder != null) { BufferedCdrOutput buffer = new BufferedCdrOutput(); holder._write(buffer); gnuDynAny other; try { other = new gnuDynAny((Streamable) (holder.getClass().newInstance()), official_type, final_type, factory, orb ); } catch (Exception e) { // Holder must have parameterless constructor. throw new Unexpected(e); } other.holder._read(buffer.create_input_stream()); return other; } else { return new gnuDynAny(null, official_type, final_type, factory, orb); } }
/** @inheritDoc */ public void from_any(Any an_any) throws TypeMismatch, InvalidValue { checkType(official_type, an_any.type()); try { if (!an_any.type().content_type().equal(content)) throw new InvalidValue(CONTENT); } catch (BadKind e) { TypeMismatch t = new TypeMismatch("Not a box"); t.initCause(e); throw t; } Serializable s = an_any.extract_Value(); if (s == null) set_to_null(); else { try { Streamable holder = HolderLocator.createHolder(content); Field v = holder.getClass().getField("value"); v.set(holder, s); Any cont = createAny(); cont.insert_Streamable(holder); array = new DynAny[] { factory.create_dyn_any(cont) }; } catch (Exception ex) { throw new Unexpected(ex); } } valueChanged(); }
/** @inheritDoc */ public Any to_any() { Any a = createAny(); if (!is_null()) { try { Streamable holder; if (array [ 0 ] instanceof gnuDynAny) holder = ((gnuDynAny) array [ 0 ]).holder; else { Any uan = array [ 0 ].to_any(); holder = uan.extract_Streamable(); } Field v = holder.getClass().getField("value"); Serializable value = (Serializable) v.get(holder); a.type(official_type); a.insert_Value(value, content); } catch (Exception ex) { throw new Unexpected(ex); } } else a.type(orb.get_primitive_tc(TCKind.tk_null)); return a; }
/** * Writes an instance of the CORBA {@link Any}. * This method writes the typecode, followed * by value itself. In Any contains null * (value not set), the {@link TCKind#tk_null} * is written. * * @param x the {@link Any} to write. */ public void write_any(Any x) { Streamable value = x.extract_Streamable(); if (value != null) { write_TypeCode(x.type()); value._write(this); } else { PrimitiveTypeCode p = new PrimitiveTypeCode(TCKind.tk_null); write_TypeCode(p); } }