replaced all StringBuffers with StringBuilder to improve performance
[Bob.git] / src / com / interrupt / bob / base / BobSystem.java
blob309acdda41f881cb9d527036cae3170bb1bfe085
2 package com.interrupt.bob.base;
4 import java.util.ArrayList;
5 import java.util.Iterator;
6 import java.util.Map;
7 import java.util.HashMap;
8 import java.util.List;
10 import org.apache.log4j.Logger;
12 import com.interrupt.bob.FindFiles;
13 import com.interrupt.bob.core.Memory;
14 import com.interrupt.bob.core.MemoryField;
15 import com.interrupt.bob.core.Queue;
16 import com.interrupt.bob.handler.DefinitionHandler;
17 import com.interrupt.bob.handler.BobHandler;
18 import com.interrupt.bob.handler.HandlerField;
19 import com.interrupt.bob.handler.IHandlerField;
20 import com.interrupt.bob.handler.XMLHandler;
21 import com.interrupt.bob.processor.DocumentProcessor;
22 import com.interrupt.bob.processor.ProcessorException;
23 import com.interrupt.bob.util.Util;
25 public class BobSystem {
28 private Logger logger = Logger.getLogger(BobSystem.class);
30 // Name stuff
31 public static String DEFINITIONS = "definition.list";
32 public static String SYSTEM = "bob.system";
34 private List definitions = null;
35 private IBob system = null;
36 private Map _messageMap = null;
37 //private boolean _initialised = false;
38 private BobSystem() {
39 _messageMap = new HashMap();
42 /* Singleton stuff
44 private static BobSystem _instance = null;
45 public static BobSystem getInstance() {
47 if(_instance == null) {
48 _instance = new BobSystem();
50 return _instance;
53 /* Message
55 public void setMessage(String _name, Object _val) {
56 _messageMap.put(_name,_val);
58 public Object getMessage(String _name) {
59 return _messageMap.get(_name);
62 /* Definitions
64 public List getDefinitions() {
65 return definitions;
67 public void setDefinitions(List defs) {
68 definitions = defs;
71 /* System
73 public IBob getSystem() {
74 return system;
76 public void setSystem(IBob sys) {
77 system = sys;
81 public void buildSystem( List plist ) {
84 StringBuilder fileString_b = new StringBuilder();
85 Iterator fileIter = plist.iterator();
86 while( fileIter.hasNext() ) {
88 fileString_b.append( " " );
89 fileString_b.append( (String)fileIter.next() );
92 String fileString_s = fileString_b.toString();
95 logger.debug( "INPUT List["+ fileString_s +"]" );
97 // definitions
98 DocumentProcessor dprocessor = null;
99 try {
101 DefinitionHandler dhandler = new DefinitionHandler();
102 dhandler.setFiles( fileString_s );
103 dhandler.setOut( Util.DEF );
105 IHandlerField hfield = new HandlerField();
106 hfield.setName("tagList");
107 hfield.setValue("${"+ Util.DEF +"}");
109 BobHandler bhandler = new BobHandler();
110 bhandler.setFiles( fileString_s );
111 bhandler.setOut( Util.SYS );
112 bhandler.addHandlerField(hfield);
114 dprocessor = new DocumentProcessor();
115 dprocessor.addHandler(dhandler);
116 dprocessor.addHandler(bhandler);
117 dprocessor.process();
120 Queue queue = dprocessor.getQueue();
121 logger.debug( "HERE 1 / Queue["+ queue +"]" );
123 Memory memory = (Memory)queue.getMemory();
125 MemoryField defField = (MemoryField)memory.findMemoryFieldByName( Util.DEF );
126 logger.debug( "HERE 2 / defField["+ defField +"]" );
127 definitions = (List)defField.getValue(defField);
129 MemoryField sysField = (MemoryField)memory.findMemoryFieldByName( Util.SYS );
130 logger.debug( "HERE 3 / sysField["+ sysField +"]" );
131 system = (IBob)sysField.getValue(sysField);
133 logger.debug("============== END ==================");
134 system.toXML( System.out );
135 logger.debug("\n\n\n");
138 catch(ProcessorException e) {
139 e.printStackTrace();