001/* CodecOperations.java --
002   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package org.omg.IOP;
040
041import org.omg.CORBA.Any;
042import org.omg.CORBA.TypeCode;
043import org.omg.IOP.CodecPackage.FormatMismatch;
044import org.omg.IOP.CodecPackage.InvalidTypeForEncoding;
045import org.omg.IOP.CodecPackage.TypeMismatch;
046
047/**
048 * Defines the operations, applicable to
049 * the Codec.
050 *
051 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
052 */
053public interface CodecOperations
054{
055  /**
056   * Encode the value, stored inside the given {@link Any}, into array of
057   * bytes. The returned byte array contains the data structure typecode,
058   * followed by the data structure itself.
059   *
060   * @param that the {@link Any}, containing the data structure, required to
061   * encode.
062   *
063   * @return the array of bytes, containing the encoded data structure.
064   *
065   * @throws InvalidTypeForEncoding if the data structure is not supported
066   * by this {@link Codec} (wide char and wide string are not supported
067   * by ENCODING_CDR_ENCAPS v 1.0).
068   *
069   * @see #decode(byte[])
070   */
071  byte[] encode(Any that)
072         throws InvalidTypeForEncoding;
073
074  /**
075   * Decode the given array of bytes and return the decoded value, inserted
076   * into {@link Any}. This methods expects that the byte array contains
077   * the CDR-encoded data structure {@link TypeCode}, followed by the data
078   * structure itself.
079   *
080   * @param them an array of bytes to decode.
081   * @return the {@link Any}, containing the decoded structure. The structure
082   * can be extracted from the Any with the appropriate helper.
083   *
084   * @throws FormatMismatch on the invalid structure of the byte array.
085   *
086   * @see #encode(Any)
087   */
088  Any decode(byte[] them)
089      throws FormatMismatch;
090
091  /**
092  * Encode the value (without the typecode), stored in the passed {@link Any},
093  * into the given byte array.
094  *
095  * @param that_value the {@link Any}, holding the value to encode.
096  * @return the array, containing the encoded value alone (no preceeding
097  * typecode).
098  *
099  * @see #decode_value(byte[], TypeCode)
100  */
101  byte[] encode_value(Any that_value)
102               throws InvalidTypeForEncoding;
103
104  /**
105   * Decode the given array of bytes, supposing that they contain the
106   * given data structure, and return the decoded value.
107   *
108   * @param them the array of bytes to decode. Should contain the data type,
109   * matching the structure, defined in the <code>type</code> parameter.
110   * Does not contain the typecode itself.
111   *
112   * @param type the typecode of the data structure, stored in the byte
113   * array.
114   *
115   * @return the {@link Any}, containing the decoded structure. The
116   * structure can be extracted from the Any with the appropriate helper.
117   *
118   * @throws FormatMismatch on the invalid structure of the byte array.
119   * @throws TypeMismatch if discovered that the the byte array defines a
120   * different structure.
121   *
122   * @see #encode_value(Any)
123   */
124  Any decode_value(byte[] them, TypeCode type)
125            throws FormatMismatch, TypeMismatch;
126}