Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/k_int/codec/runtime/BOOL_codec.java


1   /**
2    *
3    * bool_codec
4    *
5    * @author Ian Ibbotson ( ibbo@k-int.com )
6    * @version $Id: BOOL_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  package com.k_int.codec.runtime;
28  
29  public class BOOL_codec extends base_codec
30  {
31    private static BOOL_codec me = null;
32  
33    public static BOOL_codec getCodec()
34    {
35      if ( null == me )
36        me = new BOOL_codec();
37  
38      return me;
39    }
40  
41    public Object serialize(SerializationManager sm,
42                            Object type_instance,
43                            boolean is_optional,
44                            String type_name) throws java.io.IOException
45    {
46      Boolean retval = (Boolean)type_instance;
47      boolean is_constructed = false;     
48   
49      if ( sm.getDirection() == SerializationManager.DIRECTION_ENCODE )
50      {
51        if ( null != retval )
52        {
53          sm.implicit_settag(SerializationManager.UNIVERSAL, SerializationManager.BOOLEAN);
54          int len = sm.tag_codec(false);
55          if ( len >= 0 )
56            retval = sm.boolean_codec(retval, is_constructed);
57        }
58      }
59      else if ( sm.getDirection() == SerializationManager.DIRECTION_DECODE )
60      {
61        sm.implicit_settag(SerializationManager.UNIVERSAL, SerializationManager.BOOLEAN);
62        int len = sm.tag_codec(false);
63        if ( len >= 0 )
64          retval = sm.boolean_codec(retval, is_constructed);
65      }
66   
67      if ( ( null == retval ) && ( ! is_optional ) )
68        throw new java.io.IOException("Missing mandatory member: "+type_name);
69   
70      return (Object)retval;
71    }
72  }