001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021:
022: package org.jacorb.orb.portableInterceptor;
023:
024: import org.omg.IOP.CodecPackage.*;
025: import org.omg.IOP.Codec;
026: import org.omg.CORBA.*;
027:
028: import org.jacorb.orb.CDRInputStream;
029: import org.jacorb.orb.CDROutputStream;
030:
031: /**
032: * This class represents a codec for encoding ENCODING_CDR_ENCAPS 1.0.
033: *
034: * See PI SPec p.10-77ff
035: *
036: * @author Nicolas Noffke
037: * @version $Id: Codec_CDR_1_0_Impl.java,v 1.13 2006/07/07 10:55:57 alphonse.bendt Exp $
038: */
039:
040: public class Codec_CDR_1_0_Impl extends org.omg.CORBA.LocalObject
041: implements Codec {
042: private final ORB orb;
043:
044: public Codec_CDR_1_0_Impl(ORB orb) {
045: this .orb = orb;
046: }
047:
048: // implementation of org.omg.IOP.CodecOperations interface
049:
050: public Any decode(byte[] data) throws FormatMismatch {
051: final CDRInputStream in = new CDRInputStream(orb, data);
052:
053: try {
054: in.openEncapsulatedArray();
055: Any result = in.read_any();
056:
057: // not necessary to end encapsulation, since stream is never used again
058:
059: return result;
060: } finally {
061: in.close();
062: }
063: }
064:
065: public Any decode_value(byte[] data, TypeCode tc)
066: throws FormatMismatch, TypeMismatch {
067: final CDRInputStream in = new CDRInputStream(orb, data);
068:
069: try {
070: in.openEncapsulatedArray();
071: Any result = orb.create_any();
072: result.read_value(in, tc);
073:
074: // not necessary to end encapsulation, since stream is never used again
075:
076: return result;
077: } finally {
078: in.close();
079: }
080: }
081:
082: public byte[] encode(Any data) throws InvalidTypeForEncoding {
083: final CDROutputStream out = new CDROutputStream(orb);
084:
085: try {
086: out.beginEncapsulatedArray();
087: out.write_any(data);
088:
089: // do not end encapsulation since it will patch the
090: // array with a size!
091:
092: return out.getBufferCopy();
093: } finally {
094: out.close();
095: }
096: }
097:
098: public byte[] encode_value(Any data) throws InvalidTypeForEncoding {
099: final CDROutputStream out = new CDROutputStream(orb);
100:
101: try {
102:
103: out.beginEncapsulatedArray();
104: data.write_value(out);
105:
106: // do not end encapsulation since it will patch the
107: // array with a size!
108:
109: return out.getBufferCopy();
110: } finally {
111: out.close();
112: }
113: }
114: }
|