Changeset 567 for DCWoRMS/trunk/src/test/DEBBTranslator
- Timestamp:
- 11/07/12 11:17:40 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DCWoRMS/trunk/src/test/DEBBTranslator/src/DEBB2DCWoRMSTranslator.java
r566 r567 42 42 // 3) 43 43 44 private static final String DEFAULT_OUTPUT_FILE_NAME = "xml/DCWORMS_TEST.xml"; 45 // private static final String DEFAULT_INPUT_FILE_NAME = "xml/PLMXML_PSNCRECS.xml"; 46 private static final String DEFAULT_INPUT_FILE_NAME = "xml/PLMXML_HLRSSmallServerRoom.xml"; 44 private static final String DEFAULT_DCWORMS_OUTPUT_FILE_NAME = "xml/DCWORMS_TEST.xml"; 45 // private static final String DEFAULT_INPUT_FILE_NAME = 46 // "xml/PLMXML_PSNCRECS.xml"; 47 private static final String DEFAULT_PLMXML_INPUT_FILE_NAME = "xml/PLMXML_HLRSSmallServerRoom.xml"; 48 private static final String DEFAULT_DEBB_COMPONENT_INPUT_FILE_NAME = "xml/DEBBComponents.xml"; 47 49 private static DocumentBuilder xmlDocumentBuilder; 48 50 private static DocumentBuilderFactory domFactory; … … 61 63 */ 62 64 public static void main(String[] args) { 63 String inputFileName = DEFAULT_ INPUT_FILE_NAME;64 String outputFileName = DEFAULT_ OUTPUT_FILE_NAME;65 String inputFileName = DEFAULT_PLMXML_INPUT_FILE_NAME; 66 String outputFileName = DEFAULT_DCWORMS_OUTPUT_FILE_NAME; 65 67 66 68 if (args != null && args.length > 0) { 67 69 inputFileName = args[0]; 68 70 if (inputFileName != null && inputFileName.isEmpty() == false) { 69 inputFileName = DEFAULT_ INPUT_FILE_NAME;71 inputFileName = DEFAULT_PLMXML_INPUT_FILE_NAME; 70 72 } 71 73 72 74 outputFileName = args[1]; 73 75 if (outputFileName != null && outputFileName.isEmpty() == false) { 74 outputFileName = DEFAULT_ OUTPUT_FILE_NAME;76 outputFileName = DEFAULT_DCWORMS_OUTPUT_FILE_NAME; 75 77 } 76 78 } … … 80 82 81 83 // Open and read content of the input file (i.e. PLM XML document) 82 Document plmxmlDocument = read InputFile(inputFileName);84 Document plmxmlDocument = readPLMXMLInputFile(inputFileName); 83 85 84 86 XPathFactory xpathFactory = XPathFactory.newInstance(); … … 91 93 .compile("//plm:ProductDef/plm:InstanceGraph/@rootRefs"); 92 94 Object result = expr.evaluate(plmxmlDocument, XPathConstants.NODE); 93 Node rootId = (Node) result;94 System.out.println(rootId .getNodeName());95 System.out.println(rootId .getNodeValue());95 Node rootIdNode = (Node) result; 96 System.out.println(rootIdNode.getNodeName()); 97 System.out.println(rootIdNode.getNodeValue()); 96 98 97 99 // Creating destination, dcworms document … … 109 111 rootElement.appendChild(resourcesElement); 110 112 111 // *****************************************************************113 // ***************************************************************** 112 114 // Creating (main) scheduler element 113 115 // TODO: Fill scheduler with reasonable data! … … 118 120 resourcesElement.appendChild(schedulerElement); 119 121 120 // *****************************************************************122 // ***************************************************************** 121 123 // Transform top level DEBB and all nested DEBBs 122 124 transformDEBB(plmxmlDocument, dcwormsDocument, resourcesElement, 123 xpath, rootId .getNodeValue());125 xpath, rootIdNode.getNodeValue()); 124 126 125 127 // write the content into xml file 126 save OutputFile(outputFileName, dcwormsDocument);128 saveDCWoRMSOutputFile(outputFileName, dcwormsDocument); 127 129 128 130 } catch (ParserConfigurationException e) { … … 165 167 } 166 168 167 private static Document read InputFile(String inputFileName) {169 private static Document readPLMXMLInputFile(String inputFileName) { 168 170 Document plmxmlDocument; 169 171 try { … … 180 182 } 181 183 182 private static void saveOutputFile(String outputFileName, 184 private static Document readDEBBComponentInputFile(String inputFileName) { 185 Document debbComponentDocument; 186 try { 187 debbComponentDocument = xmlDocumentBuilder.parse(inputFileName); 188 return debbComponentDocument; 189 } catch (SAXException e) { 190 // TODO Auto-generated catch block 191 e.printStackTrace(); 192 } catch (IOException e) { 193 // TODO Auto-generated catch block 194 e.printStackTrace(); 195 } 196 return null; 197 } 198 199 private static void saveDCWoRMSOutputFile(String outputFileName, 183 200 Document dcwormsDocument) { 184 201 … … 238 255 239 256 // Find DEBB with given id and transform it 240 // *****************************************************************257 // ***************************************************************** 241 258 // 1) ProductInstance - 242 259 XPathExpression expr = xpath … … 244 261 + instanceId + "']"); 245 262 Object result = expr.evaluate(plmxmlDocument, XPathConstants.NODE); 246 Node productInstance = (Node) result; 247 Node debbName = productInstance.getAttributes().getNamedItem("name"); 248 System.out.println("name=" + debbName.getNodeValue()); 249 Node partRef = productInstance.getAttributes().getNamedItem("partRef"); 250 System.out.println("partRef=" + partRef.getNodeValue()); 251 String partId = partRef.getNodeValue().substring(1); // Get rid of # at 252 // the beginning 263 Node productInstanceNode = (Node) result; 264 Node debbNameNode = productInstanceNode.getAttributes().getNamedItem( 265 "name"); 266 System.out.println("name=" + debbNameNode.getNodeValue()); 267 Node partRefNode = productInstanceNode.getAttributes().getNamedItem( 268 "partRef"); 269 System.out.println("partRef=" + partRefNode.getNodeValue()); 270 String partId = partRefNode.getNodeValue().substring(1); // Get rid of # 271 // at 272 // the 273 // beginning 253 274 // UserData - hostname 254 275 expr = xpath 255 276 .compile("plm:UserData/plm:UserValue[@title='hostname']/@value"); 256 result = expr.evaluate(productInstance , XPathConstants.NODE);257 Node debbHostName = (Node) result;258 259 // 277 result = expr.evaluate(productInstanceNode, XPathConstants.NODE); 278 Node debbHostNameNode = (Node) result; 279 280 // UserData - sequence 260 281 expr = xpath 261 282 .compile("plm:UserData/plm:UserValue[@title='sequence']/@value"); 262 result = expr.evaluate(productInstance , XPathConstants.NODE);263 Node debbSequence = (Node) result;264 265 // 283 result = expr.evaluate(productInstanceNode, XPathConstants.NODE); 284 Node debbSequenceNode = (Node) result; 285 286 // UserData - label 266 287 expr = xpath 267 288 .compile("plm:UserData/plm:UserValue[@title='label']/@value"); 268 result = expr.evaluate(productInstance , XPathConstants.NODE);269 Node debbLabel = (Node) result;270 271 // 289 result = expr.evaluate(productInstanceNode, XPathConstants.NODE); 290 Node debbLabelNode = (Node) result; 291 292 // UserData - location 272 293 expr = xpath 273 294 .compile("plm:UserData/plm:UserValue[@title='location']/@value"); 274 result = expr.evaluate(productInstance , XPathConstants.NODE);275 Node debbLocation = (Node) result;276 277 // *****************************************************************295 result = expr.evaluate(productInstanceNode, XPathConstants.NODE); 296 Node debbLocationNode = (Node) result; 297 298 // ***************************************************************** 278 299 // 2) ProductRevisionView 279 300 expr = xpath … … 281 302 + partId + "']"); 282 303 result = expr.evaluate(plmxmlDocument, XPathConstants.NODE); 283 Node productRevisionView = (Node) result;304 Node productRevisionViewNode = (Node) result; 284 305 // debbName = productRevisionView.getAttributes().getNamedItem("name"); 285 306 // System.out.println("name=" + debbName.getNodeValue()); … … 289 310 expr = xpath 290 311 .compile("plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value"); 291 result = expr.evaluate(productRevisionView , XPathConstants.NODE);292 Node debbComponentId = (Node) result;293 if (debbComponentId != null) {312 result = expr.evaluate(productRevisionViewNode, XPathConstants.NODE); 313 Node debbComponentIdNode = (Node) result; 314 if (debbComponentIdNode != null) { 294 315 System.out.println("debbComponentId=" 295 + debbComponentId .getNodeValue());316 + debbComponentIdNode.getNodeValue()); 296 317 } 297 318 … … 299 320 expr = xpath 300 321 .compile("plm:UserData/plm:UserValue[@title='DEBBLevel']/@value"); 301 result = expr.evaluate(productRevisionView , XPathConstants.NODE);302 Node debbLevel = (Node) result;303 if (debbLevel != null) {304 System.out.println("debbLevel=" + debbLevel .getNodeValue());322 result = expr.evaluate(productRevisionViewNode, XPathConstants.NODE); 323 Node debbLevelNode = (Node) result; 324 if (debbLevelNode != null) { 325 System.out.println("debbLevel=" + debbLevelNode.getNodeValue()); 305 326 } 306 327 … … 308 329 expr = xpath 309 330 .compile("plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value"); 310 result = expr.evaluate(productRevisionView, XPathConstants.NODE); 311 Node debbComponentFileName = (Node) result; 312 if (debbComponentFileName == null) { 331 result = expr.evaluate(productRevisionViewNode, XPathConstants.NODE); 332 Node debbComponentFileNameNode = (Node) result; 333 String debbComponentFileName = null; 334 if (debbComponentFileNameNode != null) { 313 335 // Default DEBBComponent file is assumed 314 315 } 316 System.out.println("debbComponentFileName=" + debbComponentFileName); 317 318 //***************************************************************** 336 debbComponentFileName = debbComponentFileNameNode.getNodeValue(); 337 } else { 338 debbComponentFileName = DEFAULT_DEBB_COMPONENT_INPUT_FILE_NAME; 339 } 340 System.out.println("debbComponentFileToOpen=" + debbComponentFileName); 341 342 // ***************************************************************** 319 343 // Add computingResource element for the DEBB 320 if (debbLevel != null) {344 if (debbLevelNode != null) { 321 345 Element computingResourceElement = dcwormsDocument 322 346 .createElement("computingResource"); 323 347 Attr nameAttribute = dcwormsDocument.createAttribute("name"); 324 nameAttribute.setValue(debbName .getNodeValue());348 nameAttribute.setValue(debbNameNode.getNodeValue()); 325 349 computingResourceElement.setAttributeNode(nameAttribute); 326 350 327 351 Attr classAttribute = dcwormsDocument.createAttribute("class"); 328 String dcwormsClass = computingResourceClasses.get(debbLevel 352 String dcwormsClass = computingResourceClasses.get(debbLevelNode 329 353 .getNodeValue()); 330 354 classAttribute.setValue(dcwormsClass); 331 355 computingResourceElement.setAttributeNode(classAttribute); 332 356 333 if (debbHostName != null) { 334 Element parameterElement =dcwormsDocument.createElement("parameter"); 335 Attr parameterNameAttribute = dcwormsDocument.createAttribute("name"); 357 if (debbHostNameNode != null) { 358 Element parameterElement = dcwormsDocument 359 .createElement("parameter"); 360 Attr parameterNameAttribute = dcwormsDocument 361 .createAttribute("name"); 336 362 parameterNameAttribute.setValue("hostname"); 337 363 parameterElement.setAttributeNode(parameterNameAttribute); 338 364 Element valueElement = dcwormsDocument.createElement("value"); 339 valueElement.appendChild(dcwormsDocument.createTextNode(debbHostName.getNodeValue())); 365 valueElement.appendChild(dcwormsDocument 366 .createTextNode(debbHostNameNode.getNodeValue())); 340 367 parameterElement.appendChild(valueElement); 341 368 computingResourceElement.appendChild(parameterElement); 342 369 } 343 370 344 if (debbSequence != null) {371 if (debbSequenceNode != null) { 345 372 // TODO: Sequence is described unclearly in the deliverable, not 346 373 // used in any example. Not sure what to do with it. 347 Element parameterElement =dcwormsDocument.createElement("parameter"); 348 Attr parameterNameAttribute = dcwormsDocument.createAttribute("name"); 374 Element parameterElement = dcwormsDocument 375 .createElement("parameter"); 376 Attr parameterNameAttribute = dcwormsDocument 377 .createAttribute("name"); 349 378 parameterNameAttribute.setValue("sequence"); 350 379 parameterElement.setAttributeNode(parameterNameAttribute); 351 380 Element valueElement = dcwormsDocument.createElement("value"); 352 valueElement.appendChild(dcwormsDocument.createTextNode(debbSequence.getNodeValue())); 381 valueElement.appendChild(dcwormsDocument 382 .createTextNode(debbSequenceNode.getNodeValue())); 353 383 parameterElement.appendChild(valueElement); 354 computingResourceElement.appendChild(parameterElement); 384 computingResourceElement.appendChild(parameterElement); 355 385 } 356 386 debbParentElement.appendChild(computingResourceElement); 357 387 358 if (debbLabel != null) { 359 Element parameterElement =dcwormsDocument.createElement("parameter"); 360 Attr parameterNameAttribute = dcwormsDocument.createAttribute("name"); 388 if (debbLabelNode != null) { 389 Element parameterElement = dcwormsDocument 390 .createElement("parameter"); 391 Attr parameterNameAttribute = dcwormsDocument 392 .createAttribute("name"); 361 393 parameterNameAttribute.setValue("label"); 362 394 parameterElement.setAttributeNode(parameterNameAttribute); 363 395 Element valueElement = dcwormsDocument.createElement("value"); 364 valueElement.appendChild(dcwormsDocument.createTextNode(debbLabel.getNodeValue())); 396 valueElement.appendChild(dcwormsDocument 397 .createTextNode(debbLabelNode.getNodeValue())); 365 398 parameterElement.appendChild(valueElement); 366 399 computingResourceElement.appendChild(parameterElement); 367 368 } 369 370 if (debbLocation != null) { 371 Element parameterElement =dcwormsDocument.createElement("parameter"); 372 Attr parameterNameAttribute = dcwormsDocument.createAttribute("name"); 400 401 } 402 403 if (debbLocationNode != null) { 404 Element parameterElement = dcwormsDocument 405 .createElement("parameter"); 406 Attr parameterNameAttribute = dcwormsDocument 407 .createAttribute("name"); 373 408 parameterNameAttribute.setValue("location"); 374 409 parameterElement.setAttributeNode(parameterNameAttribute); 375 410 Element valueElement = dcwormsDocument.createElement("value"); 376 valueElement.appendChild(dcwormsDocument.createTextNode(debbLocation.getNodeValue())); 411 valueElement.appendChild(dcwormsDocument 412 .createTextNode(debbLocationNode.getNodeValue())); 377 413 parameterElement.appendChild(valueElement); 378 414 computingResourceElement.appendChild(parameterElement); 379 380 } 381 382 //***************************************************************** 415 416 } 417 418 // ***************************************************************** 419 // Read data from DEBBComponent file(s) 420 Document debbComponentDocument = readDEBBComponentInputFile(debbComponentFileName); 421 422 // Find component 423 424 // ***************************************************************** 383 425 // Get nested instances - nested DEBBs and ask them to transform 384 426 // themselves 385 Node instanceRefs = productRevisionView.getAttributes()427 Node instanceRefsNode = productRevisionViewNode.getAttributes() 386 428 .getNamedItem("instanceRefs"); 387 429 // Check if anything is nested at all 388 if (instanceRefs != null) {389 String instances = instanceRefs .getNodeValue();430 if (instanceRefsNode != null) { 431 String instances = instanceRefsNode.getNodeValue(); 390 432 System.out.println("instances=" + instances); 391 433 // Separate instance ids
Note: See TracChangeset
for help on using the changeset viewer.