Source code: jacomma/icm/io/imp/StringEncoder.java
1 /*
2 * $Source: /home/data/cvsroot/src/jacomma/icm/io/imp/StringEncoder.java,v $
3 * $Revision: 1.6 $
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.imp;
32
33 import jacomma.icm.io.EncObject;
34 import jacomma.icm.io.EncObjectType;
35 import jacomma.icm.io.ObjectEncoder;
36 import jacomma.icm.io.EncObjectSignature;
37
38 import jacomma.icm.type.Symbol;
39
40 /**
41 * TBA
42 **/
43 public class StringEncoder extends EncoderTemplate {
44
45 java.util.Map tmap_ = new java.util.HashMap( 4 );
46
47 public StringEncoder() {
48 all_.add( String.class );
49 tmap_.put( String.class, EncObjectType.String );
50 all_.add( Symbol.class );
51 tmap_.put( Symbol.class, EncObjectType.Symbol );
52 }
53
54 public EncObject encode( Object obj, Object hint, boolean s ) {
55
56 EncObject eo = null;
57 CacheKey key = new CacheKey( obj, hint );
58
59 if ( (eo = (EncObject)cache_.get( key )) == null ) {
60 EncObjectType t = (hint == null || !(hint instanceof EncObjectType))
61 ? (EncObjectType)tmap_.get( obj.getClass() ) : (EncObjectType)hint;
62
63 eo = (EncObject)cache_.try_put( key, new
64 EncObjectImp( t, obj.toString().getBytes() ) );
65 }
66
67 return s ? sign( eo ) : eo;
68 }
69
70 }