001    /* ValueHandler.java --
002       Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package javax.rmi.CORBA;
040    
041    import java.io.Serializable;
042    
043    import org.omg.CORBA.CustomMarshal;
044    import org.omg.CORBA.portable.InputStream;
045    import org.omg.CORBA.portable.OutputStream;
046    import org.omg.CORBA.portable.Streamable;
047    import org.omg.SendingContext.RunTime;
048    
049    /**
050     * Serializes Java objects to and from CDR (GIOP) streams. The working instance
051     * of the value handler is returned by {@link Util#createValueHandler} and can
052     * be altered by setting the system property "javax.rmi.CORBA.ValueHandlerClass"
053     * to the name of the alternative class that must implement ValueHandler.
054     * 
055     * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
056     */
057    public interface ValueHandler
058    {
059      /**
060       * Get CORBA repository Id for the given java class.
061       * 
062       * The syntax of the repository ID is the initial ?RMI:?, followed by the Java
063       * class name, followed by name, followed by a hash code string, followed
064       * optionally by a serialization version UID string.
065       * 
066       * For Java identifiers that contain illegal OMG IDL identifier characters
067       * such as ?$?, any such illegal characters are replaced by ?\U? followed by
068       * the 4 hexadecimal characters (in upper case) representing the Unicode
069       * value.
070       * 
071       * @param clz a class for that the repository Id is required.
072       * 
073       * @return the class repository id.
074       */
075      String getRMIRepositoryID(Class clz);
076    
077      /**
078       * Returns the CodeBase for this ValueHandler.
079       * 
080       * @return the codebase.
081       */
082      RunTime getRunTimeCodeBase();
083    
084      /**
085       * Indicates that the given class is responsible itself for writing its
086       * content to the stream. Such classes implement either {@link Streamable}
087       * (default marshalling, generated by IDL-to-java compiler) or
088       * {@link CustomMarshal} (the user-programmed marshalling).
089       * 
090       * @param clz the class being checked.
091       * @return true if the class supports custom or default marshalling, false
092       * otherwise.
093       */
094      boolean isCustomMarshaled(Class clz);
095    
096      /**
097       * Read value from the CORBA input stream in the case when the value is not
098       * Streamable or CustomMarshall'ed. The fields of the class being written will
099       * be accessed using reflection.
100       * 
101       * @param in a CORBA stream to read.
102       * @param offset the current position in the input stream.
103       * @param clz the type of value being read.
104       * @param repositoryID the repository Id of the value being read.
105       * @param sender the sending context that should provide data about the
106       * message originator.
107       * 
108       * @return the object, extracted from the stream.
109       */
110      Serializable readValue(InputStream in, int offset, Class clz,
111        String repositoryID, RunTime sender);
112    
113      /**
114       * When the value provides the writeReplace method, the result of this method
115       * is written. Otherwise, the value itself is written.
116       * 
117       * @param the value that should be written to the stream.
118       * 
119       * @return the value that will be actually written to the stream.
120       */
121      Serializable writeReplace(Serializable value);
122    
123      /**
124       * Write value to CORBA output stream using java senmatics.
125       * 
126       * @param out a stream to write into.
127       * @param value a java object to write.
128       */
129      void writeValue(OutputStream out, Serializable value);
130    }