1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class CSDParser 38 { 39 static final private String _class_name = "CSDParser"; 41 private org.w3c.dom.Document _doc; 42 private String _uuid; 44 public String descriptor_location; public String code_entrypoint; public String code_location; public java.util.ArrayList valuetype_factories; 50 51 public 53 CSDParser(org.w3c.dom.Document doc, 54 String uuid) 55 { 56 _doc = doc; 58 _uuid = uuid; 59 60 descriptor_location = null; 62 code_entrypoint = null; 63 code_location = null; 64 valuetype_factories = new java.util.ArrayList (); 65 } 66 67 71 static private org.w3c.dom.Document 72 openAsDocument(String fname, String dtdloc) 73 { 74 final String opname = "openAsDocument"; 75 org.xml.sax.InputSource isource = null; 77 try { 78 isource = new org.xml.sax.InputSource (new java.io.FileInputStream (fname)); 79 } catch (java.io.FileNotFoundException ex) { 80 final String msg = "FAILED (file not found: "+fname+")"; 81 TheLogger.error(_class_name, opname, msg, ex); 82 return null; 83 } 84 85 String loc = isource.getSystemId(); 87 isource.setSystemId(dtdloc+"/"+loc); 88 89 javax.xml.parsers.DocumentBuilderFactory fact = javax.xml.parsers.DocumentBuilderFactory.newInstance(); 92 fact.setNamespaceAware(false); 93 fact.setValidating(false); 94 95 try { 97 javax.xml.parsers.DocumentBuilder parser = fact.newDocumentBuilder(); 98 return parser.parse(isource); 99 } catch (Exception ex) { 100 TheLogger.error(_class_name, opname, "FAILED", ex); 101 return null; 102 } 103 } 104 105 final private void 106 parseDocument() 107 { 108 org.w3c.dom.Element root = _doc.getDocumentElement(); 109 org.w3c.dom.NodeList childs = root.getChildNodes(); 110 org.w3c.dom.Node node = null; 111 for (int i=0;i<childs.getLength();i++) { 112 node = childs.item(i); 113 switch (node.getNodeType()) { 114 case org.w3c.dom.Node.ELEMENT_NODE: 115 org.w3c.dom.Element element = (org.w3c.dom.Element )node; 116 String tagname = element.getTagName(); 117 118 if (tagname.equals("implementation")) { 119 String id = element.getAttribute("id"); 121 if (_uuid.equals(id)) { 122 parseImplementation(element); 123 } 124 } 125 126 break; 127 default: 128 break; 129 } 130 } 131 } 132 133 final private void 134 parseImplementation(org.w3c.dom.Element impl) 135 { 136 final String opname = "parseImplementation"; 137 138 org.w3c.dom.NodeList codes = impl.getElementsByTagName("code"); 141 if (codes.getLength()==0) { 142 TheLogger.error(_class_name, opname, "FAILED (missing code element, UUID="+_uuid+")"); 143 } 144 145 org.w3c.dom.Element code = (org.w3c.dom.Element )codes.item(0); 147 parseCode(code); 148 149 org.w3c.dom.NodeList dependencies = impl.getElementsByTagName("dependency"); 152 org.w3c.dom.Element dep = null; 153 for (int i=0;i<dependencies.getLength();i++) { 154 dep = (org.w3c.dom.Element )dependencies.item(i); 155 parseDependency(dep); 156 } 157 158 org.w3c.dom.NodeList descriptors = impl.getElementsByTagName("descriptor"); 161 if (descriptors.getLength()==0) { 162 TheLogger.error(_class_name, opname, "FAILED (missing descriptor element, UUID="+_uuid+")"); 163 } 164 165 org.w3c.dom.Element desc = (org.w3c.dom.Element )descriptors.item(0); 167 parseDescriptor(desc); 168 } 169 170 final private void 171 parseCode(org.w3c.dom.Element code) 172 { 173 final String opname = "parseCode"; 174 175 org.w3c.dom.NodeList entrypoints = code.getElementsByTagName("entrypoint"); 178 if (entrypoints.getLength()==0) { 179 TheLogger.error(_class_name, opname, "FAILED (missing entrypoint element, UUID="+_uuid+")"); 180 } 181 182 org.w3c.dom.Element entrypoint = (org.w3c.dom.Element )entrypoints.item(0); 184 org.w3c.dom.NodeList datas = entrypoint.getChildNodes(); 185 for (int i=0;i<datas.getLength();i++) { 186 org.w3c.dom.Node node = datas.item(i); 187 if ((node.getNodeName().equals("#cdata-section")) || 188 (node.getNodeName().equals("#text"))) { 189 org.w3c.dom.CharacterData data = (org.w3c.dom.CharacterData )node; 190 code_entrypoint = data.getData(); 191 } 192 } 193 194 if (code_entrypoint==null) { 195 TheLogger.error(_class_name, opname, "FAILED (missing entrypoint value, UUID="+_uuid+")"); 196 } 197 198 org.w3c.dom.NodeList fileinarchives = code.getElementsByTagName("fileinarchive"); 202 if (fileinarchives.getLength()==0) { 203 TheLogger.error(_class_name, opname, "FAILED (missing fileinarchive element, UUID="+_uuid+")"); 204 } 205 206 org.w3c.dom.Element fileinarchive = (org.w3c.dom.Element )fileinarchives.item(0); 208 code_location = fileinarchive.getAttribute("name"); 210 } 211 212 final private void 213 parseDependency(org.w3c.dom.Element dep) 214 { 215 final String opname = "parseDependency"; 216 217 org.w3c.dom.NodeList valuetypefactorys = dep.getElementsByTagName("valuetypefactory"); 221 if (valuetypefactorys.getLength()==0) { 222 return ; 223 } 224 225 org.w3c.dom.Element valuetypefactory = (org.w3c.dom.Element )valuetypefactorys.item(0); 227 org.coach.ECM.ValuetypeFactoryDependency vfdep = new org.coach.ECM.ValuetypeFactoryDependency(); 228 vfdep.repid = valuetypefactory.getAttribute("repid"); 229 vfdep.value_entrypoint = valuetypefactory.getAttribute("valueentrypoint"); 230 vfdep.factory_entrypoint = valuetypefactory.getAttribute("factoryentrypoint"); 231 232 org.w3c.dom.NodeList fileinarchives = valuetypefactory.getElementsByTagName("fileinarchive"); 236 if (fileinarchives.getLength()==0) { 237 TheLogger.error(_class_name, opname, "FAILED (missing fileinarchive element, UUID="+_uuid+")"); 238 } 239 240 org.w3c.dom.Element fileinarchive = (org.w3c.dom.Element )fileinarchives.item(0); 242 vfdep.code_location = fileinarchive.getAttribute("name"); 243 244 valuetype_factories.add(vfdep); 246 } 247 248 249 final private void 250 parseDescriptor(org.w3c.dom.Element desc) 251 { 252 final String opname = "parseDescriptor"; 253 254 org.w3c.dom.NodeList fileinarchives = desc.getElementsByTagName("fileinarchive"); 258 if (fileinarchives.getLength()==0) { 259 TheLogger.error(_class_name, opname, "FAILED (missing fileinarchive element, UUID="+_uuid+")"); 260 } 261 262 org.w3c.dom.Element fileinarchive = (org.w3c.dom.Element )fileinarchives.item(0); 264 descriptor_location = fileinarchive.getAttribute("name"); 265 } 266 267 271 static public CSDParser 272 parse(String fname, String dtdloc, String uuid) 273 { 274 CSDParser parser = null; 275 try { 276 org.w3c.dom.Document doc = openAsDocument(fname, dtdloc); 277 parser = new CSDParser(doc, uuid); 278 parser.parseDocument(); 279 } catch (Exception ex) { 280 final String opname = "parse"; 281 TheLogger.error(_class_name, opname, "FAILED", ex); 282 return null; 283 } 284 285 return parser; 286 } 287 } 288 | Popular Tags |