001: package com.bostechcorp.cbesb.console.help;
002:
003: import java.io.File;
004: import java.util.HashMap;
005: import java.util.Map;
006:
007: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
008: import com.bostechcorp.cbesb.console.jmxclient.ServerUtil;
009:
010: public class DeployInfo {
011:
012: //key<->name value<->DeployObject
013: private Map<String, DeployObject> mapBCComponent = new HashMap<String, DeployObject>();
014: private Map<String, DeployObject> mapSEComponent = new HashMap<String, DeployObject>();
015: private Map<String, DeployObject> mapSharedLibrary = new HashMap<String, DeployObject>();
016: private Map<String, DeployObject> mapServiceAssembly = new HashMap<String, DeployObject>();
017:
018: //private Map<String, String> mapCheck=new HashMap<String, String>();
019:
020: private static DeployInfo deploy = null;
021:
022: public static DeployInfo getInstance() {
023: if (deploy == null)
024: deploy = new DeployInfo();
025: return deploy;
026: }
027:
028: private DeployInfo() {
029:
030: }
031:
032: public Map getDeployBCComponents() {
033:
034: return mapBCComponent;
035: }
036:
037: public Map getDeploySEComponents() {
038: return mapSEComponent;
039: }
040:
041: public Map getDeploySharedLibraries() {
042:
043: return mapSharedLibrary;
044: }
045:
046: public Map getServiceAssemblies() {
047:
048: return mapServiceAssembly;
049: }
050:
051: public String getAssemblyJarByName(String assemblyName) {
052: DeployObject deployObj = mapServiceAssembly.get(assemblyName);
053: return deployObj.getJarName();
054: }
055:
056: public void parseCustomCompontentsJar() {
057: mapBCComponent.clear();
058: mapSEComponent.clear();
059: mapSharedLibrary.clear();
060:
061: try {
062: //runtimes/console/components
063: String path = ServerUtil.getComponentFolder();
064: parseJarResource(path, 0);
065: } catch (Exception ex) {
066: System.err.println(ex.toString());
067: }
068: }
069:
070: public void parseCompontentsJar() {
071: mapBCComponent.clear();
072: mapSEComponent.clear();
073: mapSharedLibrary.clear();
074:
075: String path = EsbPathHelper.getCbesbHomeDir() + "/components/";
076: parseJarResource(path, 0);
077:
078: try {
079: ////runtimes/console/components
080: path = ServerUtil.getComponentFolder();
081: parseJarResource(path, 0);
082: } catch (Exception ex) {
083: System.err.println(ex.toString());
084: }
085: }
086:
087: public void parseAssebliesJar() {
088: mapServiceAssembly.clear();
089:
090: try {
091: ////runtimes/console/sa
092: String path = ServerUtil.getAssemblyFolder();
093: parseJarResource(path, 1);
094: } catch (Exception ex) {
095: System.err.println(ex.toString());
096: }
097: }
098:
099: private void parseJarResource(String path, int type) {
100:
101: File dir = new File(path);
102: if (!dir.exists()) {
103: System.err.println("Path can not be found :"
104: + dir.getAbsolutePath());
105: return;
106: }
107: if (!dir.isDirectory()) {
108: System.err.println(dir.toString() + "is not a directory.");
109: return;
110: }
111:
112: // parse jar file
113: String jarPath;
114:
115: File[] fe = dir.listFiles();
116: for (int i = 0; i < fe.length; i++) {
117: jarPath = fe[i].toString();
118: //System.out.println(jarPath);
119: ParseJarFile JR = new ParseJarFile(jarPath);
120: // byte[] buff = JR.getResource("META-INF/jbi.xml");
121: String buff = JR.getResource("META-INF/jbi.xml");
122:
123: if (buff == null) {
124: System.err
125: .println("META-INF/jdb.xml could not be found");
126: continue;
127: }
128:
129: try {
130: // String newStrGB = new String(buff, "GB2312");//GB2312 char encoding
131: // system default char encoding
132: // String newStrDefault = new String(buff);
133: String newStrDefault = buff;
134:
135: //System.out.println(fe[i].toString() + "/META-INF/jbi.xml");
136: //System.out.print(newStrDefault);// prit jbi.xml content
137:
138: DeployObject deployObj = new DeployObject();
139: deployObj.setJarName(fe[i].getName());
140:
141: if (type == 0)
142: parseComponentContent(newStrDefault, deployObj);
143: else if (type == 1)
144: parseAssembleyContent(newStrDefault, deployObj);
145:
146: //System.out
147: // .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
148: } catch (Exception ex) {
149: System.err.println(ex.toString());
150: }
151: //break;
152: }
153: }
154:
155: private void parseComponentContent(String jbiXml,
156: DeployObject deployObj) {
157: String name;
158: if (jbiXml.indexOf("component type") > 0) {
159: //jbiXml.indexOf("component type="+"service-engine"+");
160: name = getNameByJbiXml(jbiXml);
161: deployObj.setName(name);
162: int found = jbiXml
163: .indexOf("component type=\"service-engine\"");
164: if (found > 0) {
165: //deployObj.setType(DeployObject.TYPE_SERVICE_ENGINE_COMPONENT);
166: mapSEComponent.put(name, deployObj);
167: }
168: found = jbiXml
169: .indexOf("component type=\"binding-component\"");
170: if (found > 0) {
171: //deployObj.setType(DeployObject.TYPE_BINDING_COMPONENT);
172: mapBCComponent.put(name, deployObj);
173: }
174: } else if (jbiXml.indexOf("<shared-library>") > 0) {
175: //deployObj.setType(DeployObject.TYPE_SHARED_LIBRARY);
176: name = getNameByJbiXml(jbiXml);
177: deployObj.setName(name);
178: mapSharedLibrary.put(name, deployObj);
179: }
180: //<component type="service-engine">
181: //<name>ChainBuilderESB-SE-Sequencing</name>
182:
183: //<shared-library>
184: //<identification>
185: //<name>CCSL</name>
186:
187: //<service-assembly>
188: //<name>JBISA1</name>
189: }
190:
191: private void parseAssembleyContent(String jbiXml,
192: DeployObject deployObj) {
193: String name;
194: if (jbiXml.indexOf("<service-assembly>") > 0) {
195: //deployObj.setType(DeployObject.TYPE_SERVICE_ASSEMBLY);
196: name = getNameByJbiXml(jbiXml);
197: deployObj.setName(name);
198: mapServiceAssembly.put(name, deployObj);
199: }
200: //<component type="service-engine">
201: //<name>ChainBuilderESB-SE-Sequencing</name>
202:
203: //<shared-library>
204: //<identification>
205: //<name>CCSL</name>
206:
207: //<service-assembly>
208: //<name>JBISA1</name>
209: }
210:
211: private String getNameByJbiXml(String jbiXml) {
212: String name = "";
213:
214: /* Pattern pattern = Pattern.compile("<name>*</name>");
215: Matcher matcher = pattern.matcher(jbiXml);
216: */
217: int startPos = jbiXml.indexOf("<name>");
218: int endPos = jbiXml.indexOf("</name>");
219:
220: name = jbiXml.substring(startPos + 6, endPos);
221: //System.out.println(name);
222: /*
223: if(matcher.matches()==false)
224: return name;
225:
226: for(int i=1;i<=matcher.groupCount();i++){
227: name=matcher.group(i);
228: System.out.println(name);
229: }
230: */return name;
231: }
232: }
|