Source code: jacomma/icm/io/EncObjectSignature.java
1 /*
2 * $Source: /home/data/cvsroot/src/jacomma/icm/io/EncObjectSignature.java,v $
3 * $Revision: 1.4 $
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 final class EncObjectSignature {
37
38 public static final String signatureOf( EncObject obj ) {
39 if ( obj.getSignature() == null )
40 switch ( obj.getType().getByteCode() ) {
41 case (byte)0x80: { // List
42 EncObject[] elements = (EncObject[])obj.getValue();
43 return (elements.length == 0) ?
44 EmptyList : List + signatureOf( elements[0] );
45 } case (byte)0x90: { // Tuple
46 EncObject[] elements = (EncObject[])obj.getValue();
47 String sig = Tuple + new String( new byte[]{(byte)(elements.length)} );
48 for ( int i = 0; i < elements.length; i++ )
49 sig += signatureOf( elements[i] );
50 return sig;
51 }
52 default: return signatureOf( obj.getType() );
53 }
54 else
55 return obj.getSignature();
56 }
57
58 public static final String signatureOf( EncObjectType t ){
59
60 switch ( t.getByteCode() ) {
61 case (byte)0x10:
62 case (byte)0x20:
63 case (byte)0x30: return Number;
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)0xd0: return Any;
71 case (byte)0xe0: return Opaque;
72 default:
73 throw new IOException( "No signature associated with: " + t);
74 }
75 }
76
77 public static final String Any = "A";
78 public static final String Number = "N";
79 public static final String String = "S";
80 public static final String Symbol = "s";
81 public static final String Handle = "h";
82 public static final String Tuple = "T";
83 public static final String List = "L";
84 public static final String Opaque = "O";
85 public static final String Logical = "l";
86 public static final String Variable = "$";
87 public static final String EmptyList = List + Variable + "\000";
88 public static final String Code = "P" + Tuple + "\000";
89 public static final String Choice = "|";
90 public static final String Abstract = ".";
91 public static final String SymbolMarker = "#";
92 public static final String Label = "R";
93 public static final String Field = "?";
94
95 }