Source code: com/k_int/codec/runtime/BitString_codec.java
1 /**
2 *
3 * bitstring_codec : A basic bitstring codec
4 *
5 * @author Ian Ibbotson ( ibbo@k-int.com )
6 * @version $Id: BitString_codec.java,v 1.2 2000/12/23 10:44:33 ianibbo Exp $
7 *
8 * Copyright: Copyright (C) 2000, Knowledge Integration Ltd.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1 of
13 * the license, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite
23 * 330, Boston, MA 02111-1307, USA.
24 *
25 *
26 */
27
28 package com.k_int.codec.runtime;
29
30 public class BitString_codec extends base_codec
31 {
32 private static BitString_codec me = null;
33
34 public static BitString_codec getCodec()
35 {
36 if ( null == me )
37 me = new BitString_codec();
38
39 return me;
40 }
41
42 public Object serialize(SerializationManager sm,
43 Object type_instance,
44 boolean is_optional,
45 String type_name) throws java.io.IOException
46 {
47 AsnBitString retval = (AsnBitString)type_instance;
48
49 boolean is_constructed = false;
50
51 if ( sm.getDirection() == SerializationManager.DIRECTION_ENCODE )
52 {
53 if ( null != retval )
54 {
55 sm.implicit_settag(SerializationManager.UNIVERSAL, SerializationManager.BITSTRING);
56 int len = sm.tag_codec(false);
57 if ( len >= 0 )
58 retval = sm.bitstring_codec(retval, is_constructed);
59 }
60 }
61 else if ( sm.getDirection() == SerializationManager.DIRECTION_DECODE )
62 {
63 sm.implicit_settag(SerializationManager.UNIVERSAL, SerializationManager.BITSTRING);
64 int len = sm.tag_codec(false);
65 if ( len >= 0 )
66 retval = sm.bitstring_codec(retval, is_constructed);
67 }
68
69 if ( ( null == retval ) && ( ! is_optional ) )
70 throw new java.io.IOException("Missing mandatory member: "+type_name);
71
72 return (Object)retval;
73 }
74 }