📄 gnudynany.java
字号:
/* gnuDynAny.java -- Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.CORBA.DynAn;import gnu.CORBA.CDR.BufferedCdrOutput;import gnu.CORBA.OctetHolder;import gnu.CORBA.Unexpected;import gnu.CORBA.WCharHolder;import gnu.CORBA.WStringHolder;import gnu.CORBA.HolderLocator;import gnu.CORBA.TypeKindNamer;import gnu.CORBA.GeneralHolder;import org.omg.CORBA.Any;import org.omg.CORBA.AnyHolder;import org.omg.CORBA.BooleanHolder;import org.omg.CORBA.CharHolder;import org.omg.CORBA.DoubleHolder;import org.omg.CORBA.FloatHolder;import org.omg.CORBA.IntHolder;import org.omg.CORBA.LongHolder;import org.omg.CORBA.MARSHAL;import org.omg.CORBA.ORB;import org.omg.CORBA.Object;import org.omg.CORBA.ObjectHolder;import org.omg.CORBA.ShortHolder;import org.omg.CORBA.StringHolder;import org.omg.CORBA.TCKind;import org.omg.CORBA.TypeCode;import org.omg.CORBA.TypeCodeHolder;import org.omg.CORBA.TypeCodePackage.BadKind;import org.omg.CORBA.ValueBaseHolder;import org.omg.CORBA.portable.InputStream;import org.omg.CORBA.portable.OutputStream;import org.omg.CORBA.portable.Streamable;import org.omg.DynamicAny.DynAny;import org.omg.DynamicAny.DynAnyPackage.InvalidValue;import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;import java.io.IOException;import java.io.Serializable;import java.util.Arrays;/** * The primitive dynamic Any holds the value basic final_type that cannot be * traversed. * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */public class gnuDynAny extends AbstractAny implements DynAny, Serializable{ /** * Use serialVersionUID for interoperability. */ private static final long serialVersionUID = 1; /** * The enclosed Streamable, holding the actual value. */ protected Streamable holder; /** * 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; } /** * Assign the contents of the given {@link DynAny} to this DynAny. * * @param from the source to assign from. */ public void assign(DynAny from) throws TypeMismatch { checkType(official_type, from.type()); if (from instanceof gnuDynAny) holder = ((gnuDynAny) from).holder; else holder = from.to_any().extract_Streamable(); valueChanged(); } /** * 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); } } /** * Always returns <code>null</code>. * * @return <code>null</code>, always. */ public DynAny current_component() throws TypeMismatch { throw new TypeMismatch("Not applicable for " + TypeKindNamer.nameIt(final_type) ); } /** * Returns without action, leaving all work to the garbage collector. */ public void destroy() { } /** * Takes the passed parameter as the enclosed {@link Any} reference. * * @param an_any the {@link Any} that will be used as an enclosed reference. * * @throws TypeMismatch if the final_type of the passed Any is not the same as * the final_type, currently stored in this Any. */ public void from_any(Any an_any) throws TypeMismatch, InvalidValue { checkType(official_type, an_any.type()); Streamable a_holder = an_any.extract_Streamable(); if (a_holder == null) { throw new InvalidValue(ISNULL); } else if (a_holder instanceof GeneralHolder) { holder = HolderLocator.createHolder(official_type); if (holder == null) holder = HolderLocator.createHolder(final_type); if (holder == null) holder = ((GeneralHolder) a_holder).Clone(); else { InputStream in = an_any.create_input_stream(); holder._read(in); try { in.close(); } catch (IOException ex) { throw new Unexpected(ex); } } } else { try { InputStream in = an_any.create_input_stream(); holder = (Streamable) a_holder.getClass().newInstance(); holder._read(in); in.close(); } catch (Exception ex) { TypeMismatch t = new TypeMismatch(); t.initCause(ex); throw t; } } valueChanged(); } /** * Return the second (enclosed any) that is stored in the wrapped Any. */ public Any get_any() throws TypeMismatch { try { return ((AnyHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public boolean get_boolean() throws TypeMismatch { try { return ((BooleanHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public char get_char() throws TypeMismatch { try { return ((CharHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public double get_double() throws TypeMismatch { try { return ((DoubleHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public float get_float() throws TypeMismatch { try { return ((FloatHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public int get_long() throws TypeMismatch { try { return ((IntHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public long get_longlong() throws TypeMismatch { try { return ((LongHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public byte get_octet() throws TypeMismatch { try { return ((OctetHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public Object get_reference() throws TypeMismatch { try { return ((ObjectHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public short get_short() throws TypeMismatch { try { return ((ShortHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public String get_string() throws TypeMismatch { try { return ((StringHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public TypeCode get_typecode() throws TypeMismatch { try { return ((TypeCodeHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public int get_ulong() throws TypeMismatch { check(TCKind.tk_ulong); return get_long(); } /** {@inheritDoc} */ public long get_ulonglong() throws TypeMismatch { check(TCKind.tk_ulonglong); return get_longlong(); } /** {@inheritDoc} */ public short get_ushort() throws TypeMismatch { check(TCKind.tk_ushort); return get_short(); } /** {@inheritDoc} */ public Serializable get_val() throws TypeMismatch { try { return ((ValueBaseHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public char get_wchar() throws TypeMismatch { try { return ((WCharHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } } /** {@inheritDoc} */ public String get_wstring() throws TypeMismatch { try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -