1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class CCSDParser 38 extends org.xml.sax.helpers.DefaultHandler 39 { 40 static final private String _class_name = "CCSDParser"; 42 private ORBService _orbservice; 43 44 private boolean _serviceid_found; 46 private boolean _reqcorbaservice_found; 47 private boolean _corbaserviceref_found; 48 49 private String _service_id; 51 private org.omg.CORBA.Object _csref_ref; 52 private String _csref_type; 53 private String _csref_regname; 54 55 public 57 CCSDParser(ORBService orbs) 58 { 59 _orbservice = orbs; 61 62 _serviceid_found = false; 64 _reqcorbaservice_found = false; 65 _corbaserviceref_found = false; 66 67 _service_id = null; 69 _csref_ref = null; 70 _csref_type = null; 71 _csref_regname = null; 72 } 73 74 78 static private void 79 parseAsSAXDoc(String fname, String dtdloc, 80 org.xml.sax.helpers.DefaultHandler handler) 81 { 82 final String opname = "parseAsSAXDoc"; 83 org.xml.sax.InputSource isource = null; 85 try { 86 isource = new org.xml.sax.InputSource (new java.io.FileInputStream (fname)); 87 } catch (java.io.FileNotFoundException ex) { 88 final String msg = "FAILED (file not found: "+fname+")"; 89 TheLogger.error(_class_name, opname, msg, ex); 90 return ; 91 } 92 93 String loc = isource.getSystemId(); 95 isource.setSystemId(dtdloc+"/"+loc); 96 97 javax.xml.parsers.SAXParserFactory fact = javax.xml.parsers.SAXParserFactory.newInstance(); 100 fact.setNamespaceAware(false); 101 fact.setValidating(false); 102 103 try { 105 javax.xml.parsers.SAXParser parser = fact.newSAXParser(); 106 parser.parse(isource, handler); 107 } catch (Exception ex) { 108 TheLogger.error(_class_name, opname, "FAILED", ex); 109 return ; 110 } 111 } 112 113 117 static public CCSDParser 118 parse(String fname, String dtdloc, ORBService orbs) 119 { 120 CCSDParser parser = new CCSDParser(orbs); 121 parseAsSAXDoc(fname, dtdloc, parser); 122 123 return parser; 124 } 125 126 130 final public String 131 getServiceId() 132 { 133 return _service_id; 134 } 135 136 final public org.coach.ECM.CORBAServiceRef 137 getCORBAServiceRef() 138 { 139 final String opname = "getCORBAServiceRef"; 140 if (_csref_ref==null) { 141 final String msg = "no CORBAServiceRef element defined"; 142 TheLogger.debug(_class_name, opname, msg); 143 return null; 144 } 145 146 org.coach.ECM.CORBAServiceRef csref = new org.coach.ECM.CORBAServiceRef(); 147 if (_csref_type==null) { 148 final String msg = "type attribute of requirescorbaservice element must be specified"; 149 TheLogger.error(_class_name, opname, msg); 150 } 151 152 if (_csref_regname==null) { 153 final String msg = "registerwithorb element must be specified"; 154 TheLogger.error(_class_name, opname, msg); 155 } 156 157 csref.corba_type = _csref_type; 158 csref.orb_registration_name = _csref_regname; 159 csref.initial_reference = _csref_ref; 160 161 return csref; 162 } 163 164 168 final public void 169 startDocument() 170 throws org.xml.sax.SAXException 171 { 172 } 175 176 final public void 177 endDocument() 178 throws org.xml.sax.SAXException 179 { 180 } 183 184 final public void 185 startElement(String nsuri, String lname, String qname, 186 org.xml.sax.Attributes attrs) 187 throws org.xml.sax.SAXException 188 { 189 if (qname.equals("serviceid")) { 191 _serviceid_found = true; 192 return ; 193 } 194 195 if (qname.equals("requirescorbaservice")) { 198 _reqcorbaservice_found = true; 199 _csref_type = attrs.getValue("type"); 200 return ; 201 } 202 203 if (_reqcorbaservice_found && (qname.equals("corbaserviceref"))) { 205 _corbaserviceref_found = true; 206 return ; 207 } 208 209 if (_reqcorbaservice_found && (qname.equals("registerwithorb"))) { 211 _csref_regname = attrs.getValue("name"); 212 return ; 213 } 214 215 if (_corbaserviceref_found && (qname.equals("objref"))) { 217 String ior = attrs.getValue("string"); 218 _csref_ref = _orbservice.string_to_object(ior); 219 return ; 220 } 221 if (_corbaserviceref_found && (qname.equals("link"))) { 223 return ; 225 } 226 if (_corbaserviceref_found && (qname.equals("ins"))) { 228 String insname = attrs.getValue("name"); 229 RegistrationService regs = org.objectweb.corba.runtime.Runtime.getRegistrationService(); 230 INSRegistrationScheme scheme = (INSRegistrationScheme)regs.get_scheme(INSRegistrationScheme.SCHEME_ID); 231 232 _csref_ref = scheme.lookup(insname, _orbservice); 233 return ; 234 } 235 236 } 237 238 final public void 239 endElement(String nsuri, String lname, String qname) 240 throws org.xml.sax.SAXException 241 { 242 if (qname.equals("serviceid")) { 244 _serviceid_found = false; 245 return ; 246 } 247 248 if (qname.equals("requirescorbaservice")) { 250 _reqcorbaservice_found = false; 251 return ; 252 } 253 254 if (_reqcorbaservice_found && (qname.equals("corbaserviceref"))) { 256 _corbaserviceref_found = false; 257 return ; 258 } 259 } 260 261 final public void 262 characters(char[] ch, int start, int length) 263 throws org.xml.sax.SAXException 264 { 265 if (_serviceid_found) { 267 _service_id = new String (ch, start, length); 268 return ; 272 } 273 } 274 } 275 | Popular Tags |