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/NULL_codec.java


1   /**
2    *
3    * NULL_codec
4    *
5    * @author Ian Ibbotson ( ibbo@k-int.com )
6    * @version $Id: NULL_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 NULL_codec extends base_codec
31  {
32    private static NULL_codec me = null;
33  
34    public static NULL_codec getCodec()
35    {
36      if ( null == me )
37        me = new NULL_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      AsnNull retval = (AsnNull)type_instance;
48      boolean is_constructed = false;     
49   
50      if ( sm.getDirection() == SerializationManager.DIRECTION_ENCODE )
51      {
52        if ( null != retval )
53        {
54          sm.implicit_settag(SerializationManager.UNIVERSAL, SerializationManager.NULL);
55          int len = sm.tag_codec(false);
56          if ( len >= 0 )
57            retval = sm.null_codec(retval, is_constructed);
58        }
59      }
60      else if ( sm.getDirection() == SerializationManager.DIRECTION_DECODE )
61      {
62        sm.implicit_settag(SerializationManager.UNIVERSAL, SerializationManager.NULL);
63        int len = sm.tag_codec(false);
64        if ( len >= 0 )
65          retval = sm.null_codec(retval, is_constructed);
66      }
67   
68      if ( ( null == retval ) && ( ! is_optional ) )
69        throw new java.io.IOException("Missing mandatory member: "+type_name);
70   
71      return (Object)retval;
72    }
73  }