View Javadoc

1   
2   package org.catacomb.serial;
3   
4   
5   import org.catacomb.interlish.structure.ElementFactory;
6   import org.catacomb.serial.om.OmElementFactory;
7   
8   
9   import java.util.HashMap;
10  
11  
12  public class SerializationContext {
13  
14  
15      HashMap<String, Object> referentHM;
16  
17      String currentPackage;
18  
19      // values for recurse;
20      final static int PRIMITIVES_ONLY = 1;
21      final static int ALL = 2;
22  
23      int recurse = ALL;
24  
25      OmElementFactory eltfac;
26  
27  
28  
29      public SerializationContext() {
30          referentHM = new HashMap<String, Object>();
31          recurse = ALL;
32      }
33  
34  
35      public void setPrimitivesOnly() {
36          recurse = PRIMITIVES_ONLY;
37      }
38  
39  
40      public ElementFactory getElementFactory() {
41          if (eltfac == null) {
42              eltfac = new OmElementFactory();
43          }
44          return eltfac;
45      }
46  
47  
48      public boolean acceptsReferents() {
49          return true;
50      }
51  
52  
53      public void addReferent(String hcode, Object val) {
54          if (referentHM == null) {
55              referentHM = new HashMap<String, Object>();
56          }
57          referentHM.put(hcode, val);
58      }
59  
60  
61  
62      public boolean recurseAll() {
63          return (recurse == ALL);
64      }
65  
66  
67      public HashMap<String, Object> getHashMap() {
68          return referentHM;
69      }
70  
71  
72      public boolean shouldWritePackage(String s) {
73          boolean ret = false;
74          if (currentPackage != null && currentPackage.equals(s)) {
75              // leave as is;
76  
77          } else {
78              currentPackage = s;
79              ret = true;
80          }
81          return ret;
82      }
83  
84  }