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

Quick Search    Search Deep

Source code: jacomma/icm/io/EncObjectType.java


1   /*
2    * $Source: /home/data/cvsroot/src/jacomma/icm/io/EncObjectType.java,v $
3    * $Revision: 1.9 $
4    * $Date: 2000/10/28 20:09:07 $
5    *
6    * This file is part of the jacomma framework
7    * Copyright (c) 2000   Dimitrios Vyzovitis
8    *      mailto:dviz@egnatia.ee.auth.gr
9    *      
10   *
11   *      
12   *      
13   *      
14   *
15   *  This library is free software; you can redistribute it and/or modify
16   *  it under the terms of the GNU Library General Public License as published by
17   *  the Free Software Foundation; either version 2 of the License, or
18   *  (at your option) any later version.
19   *
20   *  This library is distributed in the hope that it will be useful,
21   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23   *  GNU Library General Public License for more details.
24   *
25   *  You should have received a copy of the GNU Library General Public License
26   *  along with this library; if not, write to the Free Software
27   *  Foundation, Inc., 59 Temple Place, Suite 330, 
28   *  Boston, MA  02111-1307  USA
29   */
30  
31  package jacomma.icm.io;
32  
33  /**
34   * TBA
35   **/
36  public class EncObjectType {
37  
38    public final byte getByteCode() { return bc_; }
39    public final String toString() { return string_; }
40    public final boolean isComposite() { return comp_; }
41  
42    private final byte bc_;
43    private final String string_;
44    private final boolean comp_;
45  
46    private EncObjectType( byte bc, String string, boolean comp ) {
47      bc_ = bc;
48      string_ = string;
49      comp_ = comp;
50    }
51  
52    // factory method for type look-up
53    public static final EncObjectType typeOf( int b ) {
54      return typeOf( (byte)(0xff & b) );
55    }
56    
57    public static final EncObjectType typeOf( byte b ){
58      
59      switch ( (byte)0xf0 & b ) {
60      case (byte)0x00: return Any;
61      case (byte)0x10: return Int;
62      case (byte)0x20: return PosFloat;
63      case (byte)0x30: return NegFloat;
64      case (byte)0x40: return Symbol;
65      case (byte)0x50: return Handle;
66      case (byte)0x60: return String;
67      case (byte)0x70: return Code;
68      case (byte)0x80: return List;
69      case (byte)0x90: return Tuple;
70      case (byte)0xa0: return Tag;
71      case (byte)0xb0: return Ref;
72      case (byte)0xc0: return Short;
73      case (byte)0xd0: return Signed;
74      case (byte)0xe0: return Opaque;
75      default: 
76        throw new IOException( "Bad Type: " + ((byte)0xf0 & b));
77      }
78    }
79  
80    // factory method for parsing (case sensitive!!!)
81    public static final EncObjectType typeOf( String s ) {
82      try {
83        return (EncObjectType)EncObjectType.class.getField( s ).get( null );
84      } catch ( Exception exc ) {
85        throw new IOException( "No such type: " 
86                     + s + " [" + exc.getMessage() +"]" );
87      }
88    }
89  
90    // Generic Type
91    public static final EncObjectType 
92      Any = new EncObjectType( (byte)0x00, "Any", true );
93  
94    // standard types
95    public static final EncObjectType 
96      Int = new EncObjectType( (byte)0x10, "Int[0x10]", false );
97    public static final EncObjectType 
98      PosFloat = new EncObjectType( (byte)0x20, "PosFloat[0x20]", false );
99    public static final EncObjectType 
100     NegFloat = new EncObjectType( (byte)0x30, "NegFloat[0x30]", false );
101   public static final EncObjectType 
102     Symbol = new EncObjectType( (byte)0x40, "Symbol[0x40]", false );
103   public static final EncObjectType 
104     Handle = new EncObjectType( (byte)0x50, "Handle[0x50]", false );
105   public static final EncObjectType 
106     String = new EncObjectType( (byte)0x60, "String[0x60]", false );
107   public static final EncObjectType 
108     Code = new EncObjectType( (byte)0x70, "Code[0x70]", false );
109   public static final EncObjectType 
110     List = new EncObjectType( (byte)0x80, "List[0x80]", true );
111   public static final EncObjectType 
112     Tuple = new EncObjectType( (byte)0x90, "Tuple[0x90]", true );
113   public static final EncObjectType 
114     Tag = new EncObjectType( (byte)0xa0, "Tag[0xa0]", true );
115   public static final EncObjectType 
116     Ref = new EncObjectType( (byte)0xb0, "Ref[0xb0]", false );
117   public static final EncObjectType 
118     Short = new EncObjectType( (byte)0xc0, "Short[0xc0]", false );
119   public static final EncObjectType 
120     Signed = new EncObjectType( (byte)0xd0, "Signed[0xd0]", true );
121   public static final EncObjectType 
122     Opaque = new EncObjectType( (byte)0xe0, "Opaque[0xe0]", true );
123 
124 }