1 package cve.esecutori.components.specificaSem; 2 3 4 import java.io.*; 5 import java.util.*; 6 7 import org.jdom.*; 8 9 import org.jdom.input.SAXBuilder; 10 import org.jdom.output.XMLOutputter; 11 12 import cve.staticLayout.*; 13 14 import org.apache.log4j.Logger; 15 16 22 public class Associations { 23 24 27 private HashMap associations; 28 private Document docAssSem, docSem; 29 30 public Associations(){ 31 Cve.errLog.debug(""); 32 associations=new HashMap(); 33 } 34 35 public void addAss(String idSint, Association ass){ 36 Cve.errLog.debug(""); 37 System.out.println(" #E @specificaSem.Associations.addAss: idSint: "+ idSint + " idSem: " + ass.getIdSem()); 38 associations.put(idSint, ass); 39 } 40 41 public HashMap getAllAss(){ 42 Cve.errLog.debug(""); 43 return associations; 44 } 45 46 public Association getAss(String idSint){ 47 Cve.errLog.debug(""); 48 return (Association)associations.get(idSint); 49 } 50 51 54 public void loadAssociations(String fileSem, String fileAssSem){ 55 Cve.errLog.debug(""); 56 System.out.println(" #E @specificaSem.Associations.loadAss: fileSem: "+ fileSem); 57 System.out.println(" #E @specificaSem.Associations.loadAss: fileAssSem: "+ fileAssSem); 58 59 Association appo_ass; 61 String appo_idSint, appo_idSem, appo_idAss, appo_NameResource; 62 Vector appo_parameter; 63 65 appo_idSint = new String (); 66 appo_idSem = new String (); 67 appo_idAss = new String (); 68 appo_NameResource = new String (); 69 70 try { 72 SAXBuilder builder = new SAXBuilder(false); 74 docAssSem = builder.build(new File(fileAssSem)); 75 docSem = builder.build(new File(fileSem)); 76 77 } catch (JDOMException e) { 78 Cve.errLog.error(e.toString()); 79 } catch (Exception e) { 80 Cve.errLog.error(e.toString()); 81 } 82 Element rootAssSem=docAssSem.getRootElement(); 83 Element rootSem=docSem.getRootElement(); 84 85 java.util.List setElement = rootAssSem.getChildren(); 88 for (int j=0; j<setElement.size();j++){ 89 Element elementFind=(Element)(setElement.get(j)); 90 91 String nomeElement = elementFind.getName(); 92 nomeElement = nomeElement.trim(); 93 if( nomeElement.equals("Association")){ 95 96 appo_ass = new Association(); 98 java.util.List attList = elementFind.getAttributes(); 100 101 for (int i=0; i<attList.size();i++){ 103 Attribute appoAttr = (Attribute)attList.get(i); 104 String appoAttrName = appoAttr.getName(); 106 appoAttrName = appoAttrName.trim(); 107 108 String appoAttrValue = appoAttr.getValue(); 110 appoAttrValue = appoAttrValue.trim(); 111 112 if (appoAttrName.equals("idAss")){ 115 116 appo_idAss = appoAttrValue; 118 } 119 } 121 if (appo_idAss.equals("")==false){ 123 java.util.List setElementFind = elementFind.getChildren(); 125 for (int k=0; k<setElementFind.size();k++){ 126 127 Element elementFindAss=(Element)(setElementFind.get(k)); 128 String nomeElementAss = elementFindAss.getName(); 129 nomeElementAss = nomeElementAss.trim(); 130 131 if( nomeElementAss.equals("SyntaxRule")){ 133 java.util.List attListFind = elementFindAss.getAttributes(); 135 for (int z=0; z<attListFind.size();z++){ 137 Attribute appoAttrFind = (Attribute)attListFind.get(z); 138 139 String appoAttrNameFind = appoAttrFind.getName(); 141 appoAttrNameFind = appoAttrNameFind.trim(); 142 143 String appoAttrValueFind = appoAttrFind.getValue(); 145 appoAttrValueFind = appoAttrValueFind.trim(); 146 147 if (appoAttrNameFind.equals("idRule")){ 149 appo_idSint = appoAttrValueFind; 151 152 } } } 156 if( nomeElementAss.equals("SemanticRule")){ 158 java.util.List attListFind2 = elementFindAss.getAttributes(); 160 for (int z1=0; z1<attListFind2.size();z1++){ 162 Attribute appoAttrFind2 = (Attribute)attListFind2.get(z1); 163 164 String appoAttrNameFind2 = appoAttrFind2.getName(); 166 appoAttrNameFind2 = appoAttrNameFind2.trim(); 167 168 String appoAttrValueFind2 = appoAttrFind2.getValue(); 170 appoAttrValueFind2 = appoAttrValueFind2.trim(); 171 172 if (appoAttrNameFind2.equals("idRule")){ 174 appo_idSem = appoAttrValueFind2; 176 178 java.util.List setElementSem = rootSem.getChildren(); 180 for (int j1=0; j1<setElementSem.size();j1++){ 181 Element elementFindSem = (Element)(setElementSem.get(j1)); 182 183 String nomeElementSem = elementFindSem.getName(); 184 nomeElementSem = nomeElementSem.trim(); 185 186 if( nomeElementSem.equals("Transition")){ 188 189 java.util.List attListFindSem = elementFindSem.getAttributes(); 190 for (int z2=0; z2<attListFindSem.size();z2++){ 192 Attribute appoAttrFindSem = (Attribute)attListFindSem.get(z2); 193 194 String appoAttrNameFindSem = appoAttrFindSem.getName(); 196 appoAttrNameFindSem = appoAttrNameFindSem.trim(); 197 198 String appoAttrValueFindSem = appoAttrFindSem.getValue(); 200 appoAttrValueFindSem = appoAttrValueFindSem.trim(); 201 202 if (appoAttrNameFindSem.equals("id") && appoAttrValueFindSem.equals(appo_idSem)){ 204 205 207 java.util.List setElementSemTra = elementFindSem.getChildren(); 210 for (int j2=0; j2<setElementSemTra.size();j2++){ 211 Element elementFindSemTra = (Element)(setElementSemTra.get(j2)); 212 213 String nomeElementSemTra = elementFindSemTra.getName(); 214 nomeElementSemTra = nomeElementSemTra.trim(); 215 216 if( nomeElementSemTra.equals("Get")){ 218 219 java.util.List setElementSemGet = elementFindSemTra.getChildren(); 221 for (int j3=0; j3<setElementSemGet.size();j3++){ 222 Element elementFindSemGet = (Element)(setElementSemGet.get(j3)); 223 224 String nomeElementSemGet = elementFindSemGet.getName(); 225 nomeElementSemGet = nomeElementSemGet.trim(); 226 227 if( nomeElementSemGet.equals("Item")){ 229 230 java.util.List attListFindSemItem = elementFindSemGet.getAttributes(); 231 for (int z3=0; z3<attListFindSemItem.size();z3++){ 233 Attribute appoAttrFindSemItem = (Attribute)attListFindSemItem.get(z3); 234 235 String appoAttrNameFindSemItem = appoAttrFindSemItem.getName(); 237 appoAttrNameFindSemItem = appoAttrNameFindSemItem.trim(); 238 239 String appoAttrValueFindSemItem = appoAttrFindSemItem.getValue(); 241 appoAttrValueFindSemItem = appoAttrValueFindSemItem.trim(); 242 243 if (appoAttrNameFindSemItem.equals("typeName")){ 245 appo_NameResource = appoAttrValueFindSemItem; 246 248 } } 251 appo_parameter = new Vector(); 253 java.util.List setElementSemPar = elementFindSemGet.getChildren(); 254 for (int j4=0; j4<setElementSemPar.size();j4++){ 255 Element elementFindSemPar = (Element)(setElementSemPar.get(j4)); 256 257 String nomeElementSemPar = elementFindSemPar.getName(); 258 nomeElementSemPar = nomeElementSemPar.trim(); 259 260 if( nomeElementSemPar.equals("Parameter")){ 262 263 java.util.List attListFindSemPar = elementFindSemPar.getAttributes(); 264 266 for (int z4=0; z4<attListFindSemPar.size();z4++){ 267 Attribute appoAttrFindSemPar = (Attribute)attListFindSemPar.get(z4); 268 269 271 String appoAttrValueFindSemPar = appoAttrFindSemPar.getValue(); 273 appoAttrValueFindSemPar = appoAttrValueFindSemPar.trim(); 274 275 appo_parameter.add(appoAttrValueFindSemPar); 278 appo_parameter.add(null); 279 280 } 282 } } 285 appo_ass.putResource(appo_NameResource,appo_parameter); 287 } 289 } } 292 } 294 } } 297 } 299 } 301 302 } } } } } 308 appo_ass.setIdAss(appo_idAss); 310 appo_ass.setIdSem(appo_idSem); 311 313 addAss(appo_idSint, appo_ass); 315 316 } } 319 } 320 321 public String getResource(String idSint){ 323 324 String appo_res; 325 Cve.errLog.debug(""); 326 Set setKey = associations.keySet(); 328 329 Association appo_ass; 330 appo_ass = (Association)getAss(idSint); 331 332 appo_res = new String (); 333 334 Set setResource = appo_ass.getResource().keySet(); 336 Iterator resIt = setResource.iterator(); 337 String res; 338 Vector parameter = new Vector(); 339 while (resIt.hasNext()){ 340 res = (String )resIt.next(); 341 parameter = (Vector)appo_ass.getResource().get(res); 342 appo_res = res +" "; 343 344 if (parameter.size()>0){ 346 int i=0; 347 appo_res = appo_res + "("; 348 while (i < parameter.size()-1){ 349 appo_res = appo_res + parameter.get(i)+ "="; 350 i = i+1; 351 appo_res = appo_res + parameter.get(i) +";"; 352 i = i+1; 353 } 354 appo_res = appo_res.substring(0, appo_res.length()-1) ; 356 357 appo_res = appo_res + ")"; 358 } 359 } 360 return appo_res; 361 } 362 363 public String toString(){ 365 366 Cve.errLog.debug(""); 367 String appo = new String (); 368 Set setKey = associations.keySet(); 370 System.out.println("Numero Associazioni registrate : " + setKey.size()); 371 Iterator assIt = setKey.iterator(); 373 String idSint; 374 Association appo_ass; 375 while (assIt.hasNext()){ 376 idSint = (String )assIt.next(); 378 appo_ass = (Association)getAss(idSint); 379 380 appo = appo + "ASSOCIAZIONE:"+ appo_ass.getIdAss() +"\r\n"; 381 appo = appo + " idSint: " + idSint +"\r\n"; 382 appo = appo + " idSem : " + appo_ass.getIdSem() +"\r\n"; 383 appo = appo + " Resources "+"\r\n"; 384 385 Set setResource = appo_ass.getResource().keySet(); 387 Iterator resIt = setResource.iterator(); 388 String res; 389 Vector parameter = new Vector(); 390 while (resIt.hasNext()){ 391 res = (String )resIt.next(); 392 parameter = (Vector)appo_ass.getResource().get(res); 393 appo = appo + " resource : "+ res +" Numero Parametri: "+parameter.size()/2 +"\r\n"; 394 395 int i=0; 397 while (i < parameter.size()-1){ 398 appo = appo + " parameter : "+ parameter.get(i) +"\r\n"; 399 i = i+1; 400 appo = appo + " value : "+ parameter.get(i) +"\r\n"; 401 i = i+1; 402 } 403 } 404 appo = appo + " Risorsa in Semantica: " + getResource(idSint) + "\r\n"; 405 } 406 return appo; 407 } 408 409 public void clear(){ 410 Cve.errLog.debug(""); 411 associations.clear(); 412 } 413 414 public static void main(String [] args){ 416 417 Associations appo_a = new Associations(); 418 String fileS, fileA; 419 420 fileS = new String ("D:\\CVE_HOME\\VisualLanguage\\SpecificheWippog//Sent_PetriLanguageSem.xml"); 421 fileA = new String ("D:\\CVE_HOME\\VisualLanguage\\SpecificheWippog//Sent_PetriLanguageSemASS.xml"); 422 423 appo_a.loadAssociations(fileS, fileA); 424 System.out.println(appo_a.toString()); 425 } 426 427 } | Popular Tags |