📄 gnuany.java
字号:
/* gnuAny.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;import gnu.CORBA.CDR.Vio;import gnu.CORBA.CDR.BufferredCdrInput;import gnu.CORBA.CDR.BufferedCdrOutput;import gnu.CORBA.typecodes.PrimitiveTypeCode;import gnu.CORBA.typecodes.StringTypeCode;import org.omg.CORBA.Any;import org.omg.CORBA.AnyHolder;import org.omg.CORBA.BAD_OPERATION;import org.omg.CORBA.BooleanHolder;import org.omg.CORBA.CharHolder;import org.omg.CORBA.DoubleHolder;import org.omg.CORBA.FixedHolder;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.ObjectHolder;import org.omg.CORBA.Principal;import org.omg.CORBA.PrincipalHolder;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.ValueBaseHolder;import org.omg.CORBA.portable.Streamable;import java.io.Serializable;import java.lang.reflect.Field;import java.math.BigDecimal;import java.util.Arrays;import java.util.zip.Adler32;/** * The implementation of {@link Any}. * * For performance reasonse, the inserted values are not cloned. * If the value object allows modifications (like {@link Streamable}), * these subsequent alterations are reflected by the instance of * this gnuAny, and the gnuAny alterations are reflected by the * returned value. If it is required to have the uncoupled value, * it must be requested from the copy of the current instance. * The {@link gnuAny} can be simply cloned by the provided * {@link Clone()} method. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */public class gnuAny extends Any{ /** * Use serialVersionUID for interoperability. */ private static final long serialVersionUID = 1; /** * The value, returned by {@link #type()} if the value has been * not intialized. */ protected static final TypeCode nullType = new PrimitiveTypeCode(TCKind.tk_null); /** * The Streamable, representing the value, held by this gnuAny. */ protected Streamable has; /** * The complete typecode of the Streamable, if explicitly set. */ protected TypeCode typecode; /** * The typecode kind of the Streamable, if explicitly set. */ protected int xKind = -1; /** * The associated ORB. */ private ORB orb; /** * Set the associated orb. */ public void setOrb(ORB an_orb) { orb = an_orb; } /** * Creates a deep copy of this gnuAny, writing to and subsequently * reading from from the byte buffer. * * @return the uncoupled gnuAny with all fields set to identical * values. */ public gnuAny Clone() { BufferedCdrOutput out = new BufferedCdrOutput(); out.setOrb(orb); out.write_any(this); BufferredCdrInput in = new BufferredCdrInput(out.buffer.toByteArray()); in.setOrb(orb); return (gnuAny) in.read_any(); } /** * Create the buffered CDR input stream, containing the * value, stored inside of this {@link Any}. */ public org.omg.CORBA.portable.InputStream create_input_stream() { if (has instanceof GeneralHolder) { GeneralHolder u = (GeneralHolder) has; return u.getInputStream(); } else { BufferedCdrOutput out = new BufferedCdrOutput(); out.setOrb(orb); write_value(out); BufferredCdrInput in = new BufferredCdrInput(out.buffer.toByteArray()); in.setOrb(orb); return in; } } /** * Create the buffered CDR output stream (empty). */ public org.omg.CORBA.portable.OutputStream create_output_stream() { BufferedCdrOutput stream = new BufferedCdrOutput(); stream.setOrb(orb); return stream; } /** * Compare two Any's for equality. * @param other the other Any to compare. */ public boolean equal(Any other) { if (other == this) return true; if (type().kind() != other.type().kind()) return false; if (has != null && other instanceof gnuAny) if (has.equals(((gnuAny) other).has)) return true; BufferedCdrOutput a = new BufferedCdrOutput(); a.setOrb(orb); write_value(a); BufferedCdrOutput b = new BufferedCdrOutput(); b.setOrb(orb); other.write_value(b); byte[] ba = a.buffer.toByteArray(); byte[] bb = b.buffer.toByteArray(); return Arrays.equals(ba, bb); } /** * Get the content - dependent hashcode. */ public int hashCode() { if (has == null) return type().kind().value(); else { Adler32 adler = new Adler32(); BufferedCdrOutput a = new BufferedCdrOutput(); a.setOrb(orb); write_value(a); adler.update(a.buffer.toByteArray()); adler.update(type().kind().value()); return (int) adler.getValue() & Integer.MAX_VALUE; } } /** * Delegates functionality to {@link #equal(Any)}. */ public boolean equals(java.lang.Object other) { if (other == this) return true; if (!(other instanceof Any)) return false; return equal((Any) other); } /** * Extract the previously stored object. */ public org.omg.CORBA.Object extract_Object() { try { return ((ObjectHolder) has).value; } catch (ClassCastException ex) { BAD_OPERATION bad = new BAD_OPERATION(); bad.initCause(ex); bad.minor = Minor.Any; throw bad; } } /** * Extract the previously inserted CORBA <code>Principal</code>/ * @return the previously inserted value. * * @throws org.omg.CORBA.BAD_OPERATION if the holder contains something * else than Principal. * * @deprecated by CORBA 2.2. */ public Principal extract_Principal() { check(TCKind._tk_Principal); return ((PrincipalHolder) has).value; } /** * Return the value, encapsulated in a suitable holder. * This implementation returns the direct reference, * so the alterations on the returned streamable are * directly reflected to the content of this {@link Any}. */ public Streamable extract_Streamable() { return has; } public TypeCode extract_TypeCode() throws BAD_OPERATION { check(TCKind._tk_TypeCode); return ((TypeCodeHolder) has).value; } /** * Extract the stored value type. * * @return the previously stored value type. * * @throws BAD_OPERATION if the Any contains something different. * * @see org.omg.CORBA.portable.ValueBase */ public Serializable extract_Value() throws BAD_OPERATION { try { if (has instanceof ValueBaseHolder) return ((ValueBaseHolder) has).value; else { // Normally, ValueBase holder must be an instance of the // ValueBaseHolder. However some IDL compilers probably // have a bug, do not deriving this way. The the only // way to access the wrapped value is via reflection. Field f = has.getClass().getField("value"); return (Serializable) f.get(has); } } catch (Exception ex) { BAD_OPERATION bad = new BAD_OPERATION("Value type expected"); bad.minor = Minor.Any; bad.initCause(ex); throw bad; } } /** {@inheritDoc} */ public Any extract_any() throws BAD_OPERATION { check(TCKind._tk_any); return ((AnyHolder) has).value; } /** {@inheritDoc} */ public boolean extract_boolean() throws BAD_OPERATION { check(TCKind._tk_boolean); return ((BooleanHolder) has).value; } /** {@inheritDoc} */ public char extract_char() throws BAD_OPERATION { check(TCKind._tk_char); return ((CharHolder) has).value; } /** {@inheritDoc} */ public double extract_double() throws BAD_OPERATION { check(TCKind._tk_double); return ((DoubleHolder) has).value; } /** * Extract the previously inserted CORBA <code>fixed</code>/ * @return the previously inserted value. * * @throws org.omg.CORBA.BAD_OPERATION if the holder contains something * else than BigDecimal. */ public BigDecimal extract_fixed() throws org.omg.CORBA.BAD_OPERATION { check(TCKind._tk_fixed); return ((FixedHolder) has).value; } /** {@inheritDoc} */ public float extract_float() throws BAD_OPERATION { check(TCKind._tk_float); return ((FloatHolder) has).value; } /** {@inheritDoc} */ public int extract_long() throws BAD_OPERATION { // CORBA long = java int. check(TCKind._tk_long); return ((IntHolder) has).value; } /** {@inheritDoc} */ public long extract_longlong() throws BAD_OPERATION { check(TCKind._tk_longlong); return ((LongHolder) has).value; } /** {@inheritDoc} */ public byte extract_octet() throws BAD_OPERATION { // ShortHolder holds also octets. check(TCKind._tk_octet); return (byte) ((OctetHolder) has).value; } /** {@inheritDoc} */ public short extract_short() throws BAD_OPERATION { check(TCKind._tk_short); return ((ShortHolder) has).value; } /** {@inheritDoc} */ public String extract_string() throws BAD_OPERATION { check(TCKind._tk_string); return ((StringHolder) has).value; } /** {@inheritDoc} */ public int extract_ulong() throws BAD_OPERATION { // IntHolder also holds ulongs. check(TCKind._tk_ulong); return ((IntHolder) has).value; } /** {@inheritDoc} */ public long extract_ulonglong() throws BAD_OPERATION { // LongHolder also holds ulonglong check(TCKind._tk_ulonglong); return ((LongHolder) has).value; } /** {@inheritDoc} */ public short extract_ushort() throws BAD_OPERATION { // ShortHolder also holds ushorts. check(TCKind._tk_ushort); return ((ShortHolder) has).value;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -