Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / gnu / javax / rmi / CORBA / ValueHandlerDelegateImpl.java
blobdc3b3cd6ee8c8d2f5cd2d7f5922b37d717fde6ad
1 /* ValueHandlerDelegateImpl.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.javax.rmi.CORBA;
41 import gnu.CORBA.CDR.gnuRuntime;
43 import org.omg.CORBA.BAD_PARAM;
44 import org.omg.CORBA.CustomMarshal;
45 import org.omg.CORBA.portable.OutputStream;
46 import org.omg.CORBA.portable.Streamable;
47 import org.omg.SendingContext.RunTime;
49 import java.io.Externalizable;
50 import java.io.ObjectStreamClass;
51 import java.io.Serializable;
52 import java.rmi.Remote;
54 import javax.rmi.CORBA.ValueHandler;
55 import javax.rmi.CORBA.ValueHandlerMultiFormat;
57 /**
58 * Implementation of the ValueHandler.
60 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) (implementation)
62 public class ValueHandlerDelegateImpl
63 extends RmiUtilities
64 implements ValueHandler, ValueHandlerMultiFormat
66 /**
67 * Return the maximal supported stream format version. We currently
68 * support the version 1.
70 * TODO Support the version 2.
72 public byte getMaximumStreamFormatVersion()
74 return 1;
77 /**
78 * Write value using the given stream format version.
80 public void writeValue(OutputStream output, Serializable value, byte version)
82 if (version!=1)
83 throw new BAD_PARAM("Unsupported stream format version "+version);
84 else
85 writeValue(output, value);
88 /**
89 * This implementation associates RunTime with stream rather than with the
90 * value handler and this method is not used in the implementation. It is
91 * implemented just for the sake of compatibility.
93 public RunTime getRunTimeCodeBase()
95 return new gnuRuntime(null, null);
98 /**
99 * Checks if an instance of this class can write its fields itself.
101 public boolean isCustomMarshaled(Class clz)
103 return CustomMarshal.class.isAssignableFrom(clz)
104 || Streamable.class.isAssignableFrom(clz);
108 * No replacement, returns the passed parameter.
110 public Serializable writeReplace(Serializable value)
112 return value;
116 * Compute the repository id in the RMI hashed format.
118 public String getRMIRepositoryID(final Class cx)
120 long hash = 0;
121 Class of = cx.isArray() ? cx.getComponentType() : null;
123 if (cx.equals(String[].class))
124 return RMI_STRING_ARRAY_ID;
125 else if (cx.equals(String.class))
126 return RMI_STRING_ID;
127 else if (cx.equals(Class.class))
128 return RMI_CLASS_ID;
129 else if (Remote.class.isAssignableFrom(cx)
130 || !Serializable.class.isAssignableFrom(cx)
131 || cx.isInterface()
132 || (cx.isArray() && (!Serializable.class.isAssignableFrom(of)
133 || of.isPrimitive() || Remote.class.isAssignableFrom(of)))
136 // Some classes that have zero hash code and serial no version id
137 // included.
138 return "RMI:" + cx.getName() + ":" + toHex(hash);
139 else if (cx.isArray())
140 // Arrays have the same hashcode and uid as they components.
141 return "RMI:" + cx.getName() + ":" + toHex(getHashCode(of)) + ":"
142 + toHex(getSid(of));
143 else
145 if (Externalizable.class.isAssignableFrom(cx))
146 hash = 1;
147 else
148 hash = getHashCode(cx);
150 return "RMI:" + cx.getName() + ":" + toHex(hash) + ":"
151 + toHex(getSid(cx));
156 * Get the class serial version UID.
158 long getSid(Class cx)
160 ObjectStreamClass osc = ObjectStreamClass.lookup(cx);
161 return osc.getSerialVersionUID();