1 25 package org.ofbiz.workflow.definition; 26 27 import java.io.IOException ; 28 import java.net.URL ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.LinkedList ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 import javax.xml.parsers.ParserConfigurationException ; 36 37 import org.ofbiz.base.util.Debug; 38 import org.ofbiz.base.util.StringUtil; 39 import org.ofbiz.base.util.UtilDateTime; 40 import org.ofbiz.base.util.UtilMisc; 41 import org.ofbiz.base.util.UtilURL; 42 import org.ofbiz.base.util.UtilXml; 43 import org.ofbiz.entity.GenericDelegator; 44 import org.ofbiz.entity.GenericEntityException; 45 import org.ofbiz.entity.GenericValue; 46 import org.ofbiz.entity.transaction.GenericTransactionException; 47 import org.ofbiz.entity.transaction.TransactionUtil; 48 import org.w3c.dom.Document ; 49 import org.w3c.dom.Element ; 50 import org.xml.sax.SAXException ; 51 52 60 public class XpdlReader { 61 62 protected GenericDelegator delegator = null; 63 protected List values = null; 64 65 public static final String module = XpdlReader.class.getName(); 66 67 public XpdlReader(GenericDelegator delegator) { 68 this.delegator = delegator; 69 } 70 71 73 public static void importXpdl(URL location, GenericDelegator delegator) throws DefinitionParserException { 74 List values = readXpdl(location, delegator); 75 76 boolean beganTransaction = false; 78 try { 79 beganTransaction = TransactionUtil.begin(); 80 } catch (GenericTransactionException gte) { 81 Debug.logError(gte, "Unable to begin transaction", module); 82 } 83 84 try { 85 delegator.storeAll(values); 86 TransactionUtil.commit(beganTransaction); 87 } catch (GenericEntityException e) { 88 try { 89 TransactionUtil.rollback(beganTransaction, "Error importing XPDL", e); 91 } catch (GenericEntityException e2) { 92 Debug.logError(e2, "Problems rolling back transaction", module); 93 } 94 throw new DefinitionParserException("Could not store values", e); 95 } 96 } 97 98 101 public static List readXpdl(URL location, GenericDelegator delegator) throws DefinitionParserException { 102 if (Debug.infoOn()) Debug.logInfo("Beginning XPDL File Parse: " + location.toString(), module); 103 104 XpdlReader reader = new XpdlReader(delegator); 105 106 try { 107 Document document = UtilXml.readXmlDocument(location); 108 109 return reader.readAll(document); 110 } catch (ParserConfigurationException e) { 111 Debug.logError(e, module); 112 throw new DefinitionParserException("Could not configure XML reader", e); 113 } catch (SAXException e) { 114 Debug.logError(e, module); 115 throw new DefinitionParserException("Could not parse XML (invalid?)", e); 116 } catch (IOException e) { 117 Debug.logError(e, module); 118 throw new DefinitionParserException("Could not load file", e); 119 } 120 } 121 122 public List readAll(Document document) throws DefinitionParserException { 123 values = new LinkedList (); 124 Element docElement; 125 126 docElement = document.getDocumentElement(); 127 readPackage(docElement); 130 131 return (values); 132 } 133 134 138 protected void readPackage(Element packageElement) throws DefinitionParserException { 139 if (packageElement == null) 140 return; 141 if (!"Package".equals(packageElement.getTagName())) 142 throw new DefinitionParserException("Tried to make Package from element not named Package"); 143 144 GenericValue packageValue = delegator.makeValue("WorkflowPackage", null); 145 146 values.add(packageValue); 147 148 String packageId = packageElement.getAttribute("Id"); 149 150 packageValue.set("packageId", packageId); 151 packageValue.set("packageName", packageElement.getAttribute("Name")); 152 153 Element packageHeaderElement = UtilXml.firstChildElement(packageElement, "PackageHeader"); 155 156 if (packageHeaderElement != null) { 157 packageValue.set("specificationId", "XPDL"); 158 packageValue.set("specificationVersion", UtilXml.childElementValue(packageHeaderElement, "XPDLVersion")); 159 packageValue.set("sourceVendorInfo", UtilXml.childElementValue(packageHeaderElement, "Vendor")); 160 String createdStr = UtilXml.childElementValue(packageHeaderElement, "Created"); 161 162 if (createdStr != null) { 163 try { 164 packageValue.set("creationDateTime", java.sql.Timestamp.valueOf(createdStr)); 165 } catch (IllegalArgumentException e) { 166 throw new DefinitionParserException("Invalid Date-Time format in Package->Created: " + createdStr, e); 167 } 168 } 169 packageValue.set("description", UtilXml.childElementValue(packageHeaderElement, "Description")); 170 packageValue.set("documentationUrl", UtilXml.childElementValue(packageHeaderElement, "Documentation")); 171 packageValue.set("priorityUomId", UtilXml.childElementValue(packageHeaderElement, "PriorityUnit")); 172 packageValue.set("costUomId", UtilXml.childElementValue(packageHeaderElement, "CostUnit")); 173 } 174 175 Element redefinableHeaderElement = UtilXml.firstChildElement(packageElement, "RedefinableHeader"); 177 boolean packageOk = readRedefinableHeader(redefinableHeaderElement, packageValue, "package"); 178 String packageVersion = packageValue.getString("packageVersion"); 179 180 if (packageOk) { 182 Element conformanceClassElement = UtilXml.firstChildElement(packageElement, "ConformanceClass"); 184 185 if (conformanceClassElement != null) { 186 packageValue.set("graphConformanceEnumId", "WGC_" + conformanceClassElement.getAttribute("GraphConformance")); 187 } 188 189 Element participantsElement = UtilXml.firstChildElement(packageElement, "Participants"); 191 List participants = UtilXml.childElementList(participantsElement, "Participant"); 192 193 readParticipants(participants, packageId, packageVersion, "_NA_", "_NA_", packageValue); 194 195 Element externalPackagesElement = UtilXml.firstChildElement(packageElement, "ExternalPackages"); 197 List externalPackages = UtilXml.childElementList(externalPackagesElement, "ExternalPackage"); 198 199 readExternalPackages(externalPackages, packageId, packageVersion); 200 201 Element typeDeclarationsElement = UtilXml.firstChildElement(packageElement, "TypeDeclarations"); 203 List typeDeclarations = UtilXml.childElementList(typeDeclarationsElement, "TypeDeclaration"); 204 205 readTypeDeclarations(typeDeclarations, packageId, packageVersion); 206 207 Element applicationsElement = UtilXml.firstChildElement(packageElement, "Applications"); 209 List applications = UtilXml.childElementList(applicationsElement, "Application"); 210 211 readApplications(applications, packageId, packageVersion, "_NA_", "_NA_"); 212 213 Element dataFieldsElement = UtilXml.firstChildElement(packageElement, "DataFields"); 215 List dataFields = UtilXml.childElementList(dataFieldsElement, "DataField"); 216 217 readDataFields(dataFields, packageId, packageVersion, "_NA_", "_NA_"); 218 } else { 219 values = new LinkedList (); 220 } 221 222 Element workflowProcessesElement = UtilXml.firstChildElement(packageElement, "WorkflowProcesses"); 224 List workflowProcesses = UtilXml.childElementList(workflowProcessesElement, "WorkflowProcess"); 225 226 readWorkflowProcesses(workflowProcesses, packageId, packageVersion); 227 } 228 229 protected boolean readRedefinableHeader(Element redefinableHeaderElement, GenericValue valueObject, String prefix) throws DefinitionParserException { 230 if (redefinableHeaderElement == null) { 231 valueObject.set(prefix + "Version", UtilDateTime.nowDateString()); 232 return checkVersion(valueObject, prefix); 233 } 234 235 valueObject.set("author", UtilXml.childElementValue(redefinableHeaderElement, "Author")); 236 valueObject.set(prefix + "Version", UtilXml.childElementValue(redefinableHeaderElement, "Version", UtilDateTime.nowDateString())); 237 valueObject.set("codepage", UtilXml.childElementValue(redefinableHeaderElement, "Codepage")); 238 valueObject.set("countryGeoId", UtilXml.childElementValue(redefinableHeaderElement, "Countrykey")); 239 valueObject.set("publicationStatusId", "WPS_" + redefinableHeaderElement.getAttribute("PublicationStatus")); 240 241 if (!checkVersion(valueObject, prefix)) return false; 242 243 Element responsiblesElement = UtilXml.firstChildElement(redefinableHeaderElement, "Responsibles"); 245 List responsibles = UtilXml.childElementList(responsiblesElement, "Responsible"); 246 247 readResponsibles(responsibles, valueObject, prefix); 248 return true; 249 } 250 251 private boolean checkVersion(GenericValue valueObject, String prefix) { 252 try { 254 String message = new String (); 255 256 if (prefix.equals("package")) { 257 GenericValue gvCheck = valueObject.getDelegator().findByPrimaryKey("WorkflowPackage", 258 UtilMisc.toMap("packageId", valueObject.getString("packageId"), 259 "packageVersion", valueObject.getString("packageVersion"))); 260 261 if (gvCheck != null) { 262 message = "[xpdl] Package: " + valueObject.getString("packageId") + 263 " (ver " + valueObject.getString("packageVersion") + 264 ") has already been imported. Will not update/import."; 265 } 266 } else if (prefix.equals("process")) { 267 GenericValue gvCheck = valueObject.getDelegator().findByPrimaryKey("WorkflowProcess", 268 UtilMisc.toMap("packageId", valueObject.getString("packageId"), 269 "packageVersion", valueObject.getString("packageVersion"), 270 "processId", valueObject.getString("processId"), 271 "processVersion", valueObject.getString("processVersion"))); 272 273 if (gvCheck != null) { 274 message = "[xpdl] Process: " + valueObject.getString("processId") + 275 " (ver " + valueObject.getString("processVersion") + 276 ") has already been imported. Not importing."; 277 } 278 } 279 if (message.length() > 0) { 280 StringBuffer lines = new StringBuffer (); 281 282 for (int i = 0; i < message.length(); i++) { 283 lines.append("-"); 284 } 285 Debug.logWarning(lines.toString(), module); 286 Debug.logWarning(message, module); 287 Debug.logWarning(lines.toString(), module); 288 return false; 289 } 290 } catch (GenericEntityException e) { 291 return false; 292 } 293 return true; 294 } 295 296 protected void readResponsibles(List responsibles, GenericValue valueObject, String prefix) throws DefinitionParserException { 297 if (responsibles == null || responsibles.size() == 0) { 298 return; 299 } 300 301 String responsibleListId = delegator.getNextSeqId("WorkflowParticipantList"); 302 valueObject.set("responsibleListId", responsibleListId); 303 304 Iterator responsibleIter = responsibles.iterator(); 305 int responsibleIndex = 1; 306 307 while (responsibleIter.hasNext()) { 308 Element responsibleElement = (Element ) responsibleIter.next(); 309 String responsibleId = UtilXml.elementValue(responsibleElement); 310 GenericValue participantListValue = delegator.makeValue("WorkflowParticipantList", null); 311 312 participantListValue.set("packageId", valueObject.getString("packageId")); 313 participantListValue.set("packageVersion", valueObject.getString("packageVersion")); 314 participantListValue.set("participantListId", responsibleListId); 315 participantListValue.set("participantId", responsibleId); 316 participantListValue.set("participantIndex", new Long (responsibleIndex)); 317 if (prefix.equals("process")) { 318 participantListValue.set("processId", valueObject.getString("processId")); 319 participantListValue.set("processVersion", valueObject.getString("processVersion")); 320 } else { 321 participantListValue.set("processId", "_NA_"); 322 participantListValue.set("processVersion", "_NA_"); 323 } 324 values.add(participantListValue); 325 responsibleIndex++; 326 } 327 } 328 329 protected void readExternalPackages(List externalPackages, String packageId, String packageVersion) { 330 if (externalPackages == null || externalPackages.size() == 0) 331 return; 332 Iterator externalPackageIter = externalPackages.iterator(); 333 334 while (externalPackageIter.hasNext()) { 335 Element externalPackageElement = (Element ) externalPackageIter.next(); 336 GenericValue externalPackageValue = delegator.makeValue("WorkflowPackageExternal", null); 337 338 values.add(externalPackageValue); 339 externalPackageValue.set("packageId", packageId); 340 externalPackageValue.set("packageVersion", packageVersion); 341 externalPackageValue.set("externalPackageId", externalPackageElement.getAttribute("href")); 342 } 343 } 344 345 protected void readTypeDeclarations(List typeDeclarations, String packageId, String packageVersion) throws DefinitionParserException { 346 if (typeDeclarations == null || typeDeclarations.size() == 0) 347 return; 348 Iterator typeDeclarationsIter = typeDeclarations.iterator(); 349 350 while (typeDeclarationsIter.hasNext()) { 351 Element typeDeclarationElement = (Element ) typeDeclarationsIter.next(); 352 GenericValue typeDeclarationValue = delegator.makeValue("WorkflowTypeDeclaration", null); 353 354 values.add(typeDeclarationValue); 355 356 typeDeclarationValue.set("packageId", packageId); 357 typeDeclarationValue.set("packageVersion", packageVersion); 358 typeDeclarationValue.set("typeId", typeDeclarationElement.getAttribute("Id")); 359 typeDeclarationValue.set("typeName", typeDeclarationElement.getAttribute("Name")); 360 361 readType(typeDeclarationElement, typeDeclarationValue); 363 364 typeDeclarationValue.set("description", UtilXml.childElementValue(typeDeclarationElement, "Description")); 366 } 367 } 368 369 373 protected void readWorkflowProcesses(List workflowProcesses, String packageId, String packageVersion) throws DefinitionParserException { 374 if (workflowProcesses == null || workflowProcesses.size() == 0) 375 return; 376 Iterator workflowProcessIter = workflowProcesses.iterator(); 377 378 while (workflowProcessIter.hasNext()) { 379 Element workflowProcessElement = (Element ) workflowProcessIter.next(); 380 381 readWorkflowProcess(workflowProcessElement, packageId, packageVersion); 382 } 383 } 384 385 protected void readWorkflowProcess(Element workflowProcessElement, String packageId, String packageVersion) throws DefinitionParserException { 386 GenericValue workflowProcessValue = delegator.makeValue("WorkflowProcess", null); 387 388 values.add(workflowProcessValue); 389 390 String processId = workflowProcessElement.getAttribute("Id"); 391 392 workflowProcessValue.set("packageId", packageId); 393 workflowProcessValue.set("packageVersion", packageVersion); 394 workflowProcessValue.set("processId", processId); 395 workflowProcessValue.set("objectName", workflowProcessElement.getAttribute("Name")); 396 397 Element processHeaderElement = UtilXml.firstChildElement(workflowProcessElement, "ProcessHeader"); 399 400 if (processHeaderElement != null) { 401 workflowProcessValue.set("durationUomId", processHeaderElement.getAttribute("DurationUnit")); 403 String createdStr = UtilXml.childElementValue(processHeaderElement, "Created"); 404 405 if (createdStr != null) { 406 try { 407 workflowProcessValue.set("creationDateTime", java.sql.Timestamp.valueOf(createdStr)); 408 } catch (IllegalArgumentException e) { 409 throw new DefinitionParserException("Invalid Date-Time format in WorkflowProcess->ProcessHeader->Created: " + createdStr, e); 410 } 411 } 412 workflowProcessValue.set("description", UtilXml.childElementValue(processHeaderElement, "Description")); 413 414 String priorityStr = UtilXml.childElementValue(processHeaderElement, "Priority"); 415 416 if (priorityStr != null) { 417 try { 418 workflowProcessValue.set("objectPriority", Long.valueOf(priorityStr)); 419 } catch (NumberFormatException e) { 420 throw new DefinitionParserException("Invalid whole number format in WorkflowProcess->ProcessHeader->Priority: " + priorityStr, e); 421 } 422 } 423 String limitStr = UtilXml.childElementValue(processHeaderElement, "Limit"); 424 425 if (limitStr != null) { 426 try { 427 workflowProcessValue.set("timeLimit", Double.valueOf(limitStr)); 428 } catch (NumberFormatException e) { 429 throw new DefinitionParserException("Invalid decimal number format in WorkflowProcess->ProcessHeader->Limit: " + limitStr, e); 430 } 431 } 432 433 String validFromStr = UtilXml.childElementValue(processHeaderElement, "ValidFrom"); 434 435 if (validFromStr != null) { 436 try { 437 workflowProcessValue.set("validFromDate", java.sql.Timestamp.valueOf(validFromStr)); 438 } catch (IllegalArgumentException e) { 439 throw new DefinitionParserException("Invalid Date-Time format in WorkflowProcess->ProcessHeader->ValidFrom: " + validFromStr, e); 440 } 441 } 442 String validToStr = UtilXml.childElementValue(processHeaderElement, "ValidTo"); 443 444 if (validToStr != null) { 445 try { 446 workflowProcessValue.set("validToDate", java.sql.Timestamp.valueOf(validToStr)); 447 } catch (IllegalArgumentException e) { 448 throw new DefinitionParserException("Invalid Date-Time format in WorkflowProcess->ProcessHeader->ValidTo: " + validToStr, e); 449 } 450 } 451 452 Element timeEstimationElement = UtilXml.firstChildElement(processHeaderElement, "TimeEstimation"); 454 455 if (timeEstimationElement != null) { 456 String waitingTimeStr = UtilXml.childElementValue(timeEstimationElement, "WaitingTime"); 457 458 if (waitingTimeStr != null) { 459 try { 460 workflowProcessValue.set("waitingTime", Double.valueOf(waitingTimeStr)); 461 } catch (NumberFormatException e) { 462 throw new DefinitionParserException("Invalid decimal number format in WorkflowProcess->ProcessHeader->TimeEstimation->WaitingTime: " + waitingTimeStr, e); 463 } 464 } 465 String workingTimeStr = UtilXml.childElementValue(timeEstimationElement, "WorkingTime"); 466 467 if (workingTimeStr != null) { 468 try { 469 workflowProcessValue.set("waitingTime", Double.valueOf(workingTimeStr)); 470 } catch (NumberFormatException e) { 471 throw new DefinitionParserException("Invalid decimal number format in WorkflowProcess->ProcessHeader->TimeEstimation->WorkingTime: " + workingTimeStr, e); 472 } 473 } 474 String durationStr = UtilXml.childElementValue(timeEstimationElement, "Duration"); 475 476 if (durationStr != null) { 477 try { 478 workflowProcessValue.set("duration", Double.valueOf(durationStr)); 479 } catch (NumberFormatException e) { 480 throw new DefinitionParserException("Invalid decimal number format in WorkflowProcess->ProcessHeader->TimeEstimation->Duration: " + durationStr, e); 481 } 482 } 483 } 484 } 485 486 Element redefinableHeaderElement = UtilXml.firstChildElement(workflowProcessElement, "RedefinableHeader"); 488 boolean processOk = readRedefinableHeader(redefinableHeaderElement, workflowProcessValue, "process"); 489 String processVersion = workflowProcessValue.getString("processVersion"); 490 491 if (!processOk) { 492 values.remove(workflowProcessValue); 493 return; 494 } 495 496 Element formalParametersElement = UtilXml.firstChildElement(workflowProcessElement, "FormalParameters"); 498 List formalParameters = UtilXml.childElementList(formalParametersElement, "FormalParameter"); 499 500 readFormalParameters(formalParameters, packageId, packageVersion, processId, processVersion, "_NA_"); 501 502 504 Element dataFieldsElement = UtilXml.firstChildElement(workflowProcessElement, "DataFields"); 506 List dataFields = UtilXml.childElementList(dataFieldsElement, "DataField"); 507 508 readDataFields(dataFields, packageId, packageVersion, processId, processVersion); 509 510 Element participantsElement = UtilXml.firstChildElement(workflowProcessElement, "Participants"); 512 List participants = UtilXml.childElementList(participantsElement, "Participant"); 513 514 readParticipants(participants, packageId, packageVersion, processId, processVersion, workflowProcessValue); 515 516 Element applicationsElement = UtilXml.firstChildElement(workflowProcessElement, "Applications"); 518 List applications = UtilXml.childElementList(applicationsElement, "Application"); 519 520 readApplications(applications, packageId, packageVersion, processId, processVersion); 521 522 Element activitiesElement = UtilXml.firstChildElement(workflowProcessElement, "Activities"); 524 List activities = UtilXml.childElementList(activitiesElement, "Activity"); 525 526 readActivities(activities, packageId, packageVersion, processId, processVersion, workflowProcessValue); 527 528 Element transitionsElement = UtilXml.firstChildElement(workflowProcessElement, "Transitions"); 530 List transitions = UtilXml.childElementList(transitionsElement, "Transition"); 531 532 readTransitions(transitions, packageId, packageVersion, processId, processVersion); 533 534 workflowProcessValue.set("defaultStartActivityId", getExtendedAttributeValue(workflowProcessElement, "defaultStartActivityId", workflowProcessValue.getString("defaultStartActivityId"))); 536 workflowProcessValue.set("sourceReferenceField", getExtendedAttributeValue(workflowProcessElement, "sourceReferenceField", "sourceReferenceId")); 537 } 538 539 543 protected void readActivities(List activities, String packageId, String packageVersion, String processId, 544 String processVersion, GenericValue processValue) throws DefinitionParserException { 545 if (activities == null || activities.size() == 0) 546 return; 547 Iterator activitiesIter = activities.iterator(); 548 549 if (activitiesIter.hasNext()) { 551 Element activityElement = (Element ) activitiesIter.next(); 552 String activityId = activityElement.getAttribute("Id"); 553 554 processValue.set("defaultStartActivityId", activityId); 555 readActivity(activityElement, packageId, packageVersion, processId, processVersion); 556 } 557 558 while (activitiesIter.hasNext()) { 559 Element activityElement = (Element ) activitiesIter.next(); 560 561 readActivity(activityElement, packageId, packageVersion, processId, processVersion); 562 } 563 } 564 565 protected void readActivity(Element activityElement, String packageId, String packageVersion, String processId, 566 String processVersion) throws DefinitionParserException { 567 if (activityElement == null) 568 return; 569 570 GenericValue activityValue = delegator.makeValue("WorkflowActivity", null); 571 572 values.add(activityValue); 573 574 String activityId = activityElement.getAttribute("Id"); 575 576 activityValue.set("packageId", packageId); 577 activityValue.set("packageVersion", packageVersion); 578 activityValue.set("processId", processId); 579 activityValue.set("processVersion", processVersion); 580 activityValue.set("activityId", activityId); 581 activityValue.set("objectName", activityElement.getAttribute("Name")); 582 583 activityValue.set("description", UtilXml.childElementValue(activityElement, "Description")); 584 String limitStr = UtilXml.childElementValue(activityElement, "Limit"); 585 586 if (limitStr != null) { 587 try { 588 activityValue.set("timeLimit", Double.valueOf(limitStr)); 589 } catch (NumberFormatException e) { 590 throw new DefinitionParserException("Invalid decimal number format in Activity->Limit: " + limitStr, e); 591 } 592 } 593 594 Element routeElement = UtilXml.firstChildElement(activityElement, "Route"); 596 Element implementationElement = UtilXml.firstChildElement(activityElement, "Implementation"); 597 598 if (routeElement != null) { 599 activityValue.set("activityTypeEnumId", "WAT_ROUTE"); 600 } else if (implementationElement != null) { 601 Element noElement = UtilXml.firstChildElement(implementationElement, "No"); 602 Element subFlowElement = UtilXml.firstChildElement(implementationElement, "SubFlow"); 603 Element loopElement = UtilXml.firstChildElement(implementationElement, "Loop"); 604 List tools = UtilXml.childElementList(implementationElement, "Tool"); 605 606 if (noElement != null) { 607 activityValue.set("activityTypeEnumId", "WAT_NO"); 608 } else if (subFlowElement != null) { 609 activityValue.set("activityTypeEnumId", "WAT_SUBFLOW"); 610 readSubFlow(subFlowElement, packageId, packageVersion, processId, processVersion, activityId); 611 } else if (loopElement != null) { 612 activityValue.set("activityTypeEnumId", "WAT_LOOP"); 613 readLoop(loopElement, packageId, packageVersion, processId, processVersion, activityId); 614 } else if (tools != null && tools.size() > 0) { 615 activityValue.set("activityTypeEnumId", "WAT_TOOL"); 616 readTools(tools, packageId, packageVersion, processId, processVersion, activityId); 617 } else { 618 throw new DefinitionParserException( 619 "No, SubFlow, Loop or one or more Tool elements must exist under the Implementation element of Activity with ID " + activityId + 620 " in Process with ID " + processId); 621 } 622 } else { 623 throw new DefinitionParserException("Route or Implementation must exist for Activity with ID " + activityId + " in Process with ID " + processId); 624 } 625 626 activityValue.set("performerParticipantId", UtilXml.childElementValue(activityElement, "Performer")); 628 629 Element startModeElement = UtilXml.firstChildElement(activityElement, "StartMode"); 631 632 if (startModeElement != null) { 633 if (UtilXml.firstChildElement(startModeElement, "Automatic") != null) 634 activityValue.set("startModeEnumId", "WAM_AUTOMATIC"); 635 else if (UtilXml.firstChildElement(startModeElement, "Manual") != null) 636 activityValue.set("startModeEnumId", "WAM_MANUAL"); 637 else 638 throw new DefinitionParserException("Could not find Mode under StartMode"); 639 } 640 641 Element finishModeElement = UtilXml.firstChildElement(activityElement, "FinishMode"); 643 644 if (finishModeElement != null) { 645 if (UtilXml.firstChildElement(finishModeElement, "Automatic") != null) 646 activityValue.set("finishModeEnumId", "WAM_AUTOMATIC"); 647 else if (UtilXml.firstChildElement(finishModeElement, "Manual") != null) 648 activityValue.set("finishModeEnumId", "WAM_MANUAL"); 649 else 650 throw new DefinitionParserException("Could not find Mode under FinishMode"); 651 } 652 653 String priorityStr = UtilXml.childElementValue(activityElement, "Priority"); 655 656 if (priorityStr != null) { 657 try { 658 activityValue.set("objectPriority", Long.valueOf(priorityStr)); 659 } catch (NumberFormatException e) { 660 throw new DefinitionParserException("Invalid whole number format in Activity->Priority: " + priorityStr, e); 661 } 662 } 663 664 Element simulationInformationElement = UtilXml.firstChildElement(activityElement, "SimulationInformation"); 666 667 if (simulationInformationElement != null) { 668 if (simulationInformationElement.getAttribute("Instantiation") != null) 669 activityValue.set("instantiationLimitEnumId", "WFI_" + simulationInformationElement.getAttribute("Instantiation")); 670 String costStr = UtilXml.childElementValue(simulationInformationElement, "Cost"); 671 672 if (costStr != null) { 673 try { 674 activityValue.set("cost", Double.valueOf(costStr)); 675 } catch (NumberFormatException e) { 676 throw new DefinitionParserException("Invalid decimal number format in Activity->SimulationInformation->Cost: " + costStr, e); 677 } 678 } 679 680 Element timeEstimationElement = UtilXml.firstChildElement(simulationInformationElement, "TimeEstimation"); 682 683 if (timeEstimationElement != null) { 684 String waitingTimeStr = UtilXml.childElementValue(timeEstimationElement, "WaitingTime"); 685 686 if (waitingTimeStr != null) { 687 try { 688 activityValue.set("waitingTime", Double.valueOf(waitingTimeStr)); 689 } catch (NumberFormatException e) { 690 throw new DefinitionParserException("Invalid decimal number format in Activity->SimulationInformation->TimeEstimation->WaitingTime: " + waitingTimeStr, e); 691 } 692 } 693 String workingTimeStr = UtilXml.childElementValue(timeEstimationElement, "WorkingTime"); 694 695 if (workingTimeStr != null) { 696 try { 697 activityValue.set("waitingTime", Double.valueOf(workingTimeStr)); 698 } catch (NumberFormatException e) { 699 throw new DefinitionParserException("Invalid decimal number format in Activity->SimulationInformation->TimeEstimation->WorkingTime: " + workingTimeStr, e); 700 } 701 } 702 String durationStr = UtilXml.childElementValue(timeEstimationElement, "Duration"); 703 704 if (durationStr != null) { 705 try { 706 activityValue.set("duration", Double.valueOf(durationStr)); 707 } catch (NumberFormatException e) { 708 throw new DefinitionParserException("Invalid decimal number format in Activity->SimulationInformation->TimeEstimation->Duration: " + durationStr, e); 709 } 710 } 711 } 712 } 713 714 activityValue.set("iconUrl", UtilXml.childElementValue(activityElement, "Icon")); 715 activityValue.set("documentationUrl", UtilXml.childElementValue(activityElement, "Documentation")); 716 717 Element transitionRestrictionsElement = UtilXml.firstChildElement(activityElement, "TransitionRestrictions"); 719 List transitionRestrictions = UtilXml.childElementList(transitionRestrictionsElement, "TransitionRestriction"); 720 721 readTransitionRestrictions(transitionRestrictions, activityValue); 722 723 activityValue.set("acceptAllAssignments", getExtendedAttributeValue(activityElement, "acceptAllAssignments", "N")); 725 activityValue.set("completeAllAssignments", getExtendedAttributeValue(activityElement, "completeAllAssignments", "N")); 726 activityValue.set("limitService", getExtendedAttributeValue(activityElement, "limitService", null), false); 727 activityValue.set("limitAfterStart", getExtendedAttributeValue(activityElement, "limitAfterStart", "Y")); 728 activityValue.set("restartOnDelegate", getExtendedAttributeValue(activityElement, "restartOnDelegate", "N")); 729 activityValue.set("delegateAfterStart", getExtendedAttributeValue(activityElement, "delegateAfterStart", "Y")); 730 activityValue.set("inheritPriority", getExtendedAttributeValue(activityElement, "inheritPriority", "N")); 731 activityValue.set("canStart", getExtendedAttributeValue(activityElement, "canStart", "Y")); 732 } 733 734 protected void readSubFlow(Element subFlowElement, String packageId, String packageVersion, String processId, 735 String processVersion, String activityId) throws DefinitionParserException { 736 if (subFlowElement == null) 737 return; 738 739 GenericValue subFlowValue = delegator.makeValue("WorkflowActivitySubFlow", null); 740 741 values.add(subFlowValue); 742 743 subFlowValue.set("packageId", packageId); 744 subFlowValue.set("packageVersion", packageVersion); 745 subFlowValue.set("processId", processId); 746 subFlowValue.set("processVersion", processVersion); 747 subFlowValue.set("activityId", activityId); 748 subFlowValue.set("subFlowProcessId", subFlowElement.getAttribute("Id")); 749 750 if (subFlowElement.getAttribute("Execution") != null) 751 subFlowValue.set("executionEnumId", "WSE_" + subFlowElement.getAttribute("Execution")); 752 else 753 subFlowValue.set("executionEnumId", "WSE_ASYNCHR"); 754 755 Element actualParametersElement = UtilXml.firstChildElement(subFlowElement, "ActualParameters"); 757 List actualParameters = UtilXml.childElementList(actualParametersElement, "ActualParameter"); 758 759 subFlowValue.set("actualParameters", readActualParameters(actualParameters), false); 760 } 761 762 protected void readLoop(Element loopElement, String packageId, String packageVersion, String processId, 763 String processVersion, String activityId) throws DefinitionParserException { 764 if (loopElement == null) 765 return; 766 767 GenericValue loopValue = delegator.makeValue("WorkflowActivityLoop", null); 768 769 values.add(loopValue); 770 771 loopValue.set("packageId", packageId); 772 loopValue.set("packageVersion", packageVersion); 773 loopValue.set("processId", processId); 774 loopValue.set("processVersion", processVersion); 775 loopValue.set("activityId", activityId); 776 777 if (loopElement.getAttribute("Kind") != null) 778 loopValue.set("loopKindEnumId", "WLK_" + loopElement.getAttribute("Kind")); 779 else 780 loopValue.set("loopKindEnumId", "WLK_WHILE"); 781 782 loopValue.set("conditionExpr", UtilXml.childElementValue(loopElement, "Condition")); 784 } 785 786 protected void readTools(List tools, String packageId, String packageVersion, String processId, 787 String processVersion, String activityId) throws DefinitionParserException { 788 if (tools == null || tools.size() == 0) 789 return; 790 Iterator toolsIter = tools.iterator(); 791 792 while (toolsIter.hasNext()) { 793 Element toolElement = (Element ) toolsIter.next(); 794 795 readTool(toolElement, packageId, packageVersion, processId, processVersion, activityId); 796 } 797 } 798 799 protected void readTool(Element toolElement, String packageId, String packageVersion, String processId, 800 String processVersion, String activityId) throws DefinitionParserException { 801 if (toolElement == null) 802 return; 803 804 GenericValue toolValue = delegator.makeValue("WorkflowActivityTool", null); 805 806 values.add(toolValue); 807 808 toolValue.set("packageId", packageId); 809 toolValue.set("packageVersion", packageVersion); 810 toolValue.set("processId", processId); 811 toolValue.set("processVersion", processVersion); 812 toolValue.set("activityId", activityId); 813 toolValue.set("toolId", toolElement.getAttribute("Id")); 814 815 if (toolElement.getAttribute("Type") != null) 816 toolValue.set("toolTypeEnumId", "WTT_" + toolElement.getAttribute("Type")); 817 else 818 toolValue.set("toolTypeEnumId", "WTT_PROCEDURE"); 819 820 toolValue.set("description", UtilXml.childElementValue(toolElement, "Description")); 822 823 Element actualParametersElement = UtilXml.firstChildElement(toolElement, "ActualParameters"); 825 Element extendedAttributesElement = UtilXml.firstChildElement(toolElement, "ExtendedAttributes"); 826 List actualParameters = UtilXml.childElementList(actualParametersElement, "ActualParameter"); 827 List extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); 828 829 toolValue.set("actualParameters", readActualParameters(actualParameters), false); 830 toolValue.set("extendedAttributes", readExtendedAttributes(extendedAttributes), false); 831 } 832 833 protected String readActualParameters(List actualParameters) { 834 if (actualParameters == null || actualParameters.size() == 0) return null; 835 StringBuffer actualParametersBuf = new StringBuffer (); 836 Iterator actualParametersIter = actualParameters.iterator(); 837 838 while (actualParametersIter.hasNext()) { 839 Element actualParameterElement = (Element ) actualParametersIter.next(); 840 841 actualParametersBuf.append(UtilXml.elementValue(actualParameterElement)); 842 if (actualParametersIter.hasNext()) 843 actualParametersBuf.append(','); 844 } 845 return actualParametersBuf.toString(); 846 } 847 848 protected String readExtendedAttributes(List extendedAttributes) { 849 if (extendedAttributes == null || extendedAttributes.size() == 0) return null; 850 Map ea = new HashMap (); 851 Iterator i = extendedAttributes.iterator(); 852 853 while (i.hasNext()) { 854 Element e = (Element ) i.next(); 855 856 ea.put(e.getAttribute("Name"), e.getAttribute("Value")); 857 } 858 return StringUtil.mapToStr(ea); 859 } 860 861 865 protected void readTransitions(List transitions, String packageId, String packageVersion, String processId, 866 String processVersion) throws DefinitionParserException { 867 if (transitions == null || transitions.size() == 0) 868 return; 869 Iterator transitionsIter = transitions.iterator(); 870 871 while (transitionsIter.hasNext()) { 872 Element transitionElement = (Element ) transitionsIter.next(); 873 874 readTransition(transitionElement, packageId, packageVersion, processId, processVersion); 875 } 876 } 877 878 protected void readTransition(Element transitionElement, String packageId, String packageVersion, 879 String processId, String processVersion) throws DefinitionParserException { 880 if (transitionElement == null) 881 return; 882 883 GenericValue transitionValue = delegator.makeValue("WorkflowTransition", null); 884 885 values.add(transitionValue); 886 887 String transitionId = transitionElement.getAttribute("Id"); 888 889 transitionValue.set("packageId", packageId); 890 transitionValue.set("packageVersion", packageVersion); 891 transitionValue.set("processId", processId); 892 transitionValue.set("processVersion", processVersion); 893 transitionValue.set("transitionId", transitionId); 894 transitionValue.set("fromActivityId", transitionElement.getAttribute("From")); 895 transitionValue.set("toActivityId", transitionElement.getAttribute("To")); 896 897 if (transitionElement.getAttribute("Loop") != null && transitionElement.getAttribute("Loop").length() > 0) 898 transitionValue.set("loopTypeEnumId", "WTL_" + transitionElement.getAttribute("Loop")); 899 else 900 transitionValue.set("loopTypeEnumId", "WTL_NOLOOP"); 901 902 transitionValue.set("transitionName", transitionElement.getAttribute("Name")); 903 904 Element conditionElement = UtilXml.firstChildElement(transitionElement, "Condition"); 906 907 if (conditionElement != null) { 908 if (conditionElement.getAttribute("Type") != null) 909 transitionValue.set("conditionTypeEnumId", "WTC_" + conditionElement.getAttribute("Type")); 910 else 911 transitionValue.set("conditionTypeEnumId", "WTC_CONDITION"); 912 913 List xPressions = UtilXml.childElementList(conditionElement, "XPression"); 915 916 if (xPressions != null && xPressions.size() > 0) { 917 throw new DefinitionParserException("XPression elements under Condition not yet supported, just use text inside Condition with the expression"); 918 } else { 919 transitionValue.set("conditionExpr", UtilXml.elementValue(conditionElement)); 920 } 921 } 922 923 transitionValue.set("description", UtilXml.childElementValue(transitionElement, "Description")); 925 926 Element extendedAttributesElement = UtilXml.firstChildElement(transitionElement, "ExtendedAttributes"); 928 List extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); 929 transitionValue.set("extendedAttributes", readExtendedAttributes(extendedAttributes), false); 930 } 931 932 protected void readTransitionRestrictions(List transitionRestrictions, GenericValue activityValue) throws DefinitionParserException { 933 if (transitionRestrictions == null || transitionRestrictions.size() == 0) 934 return; 935 Iterator transitionRestrictionsIter = transitionRestrictions.iterator(); 936 937 if (transitionRestrictionsIter.hasNext()) { 938 Element transitionRestrictionElement = (Element ) transitionRestrictionsIter.next(); 939 940 readTransitionRestriction(transitionRestrictionElement, activityValue); 941 } 942 if (transitionRestrictionsIter.hasNext()) { 943 throw new DefinitionParserException("Multiple TransitionRestriction elements found, this is not currently supported. Please remove extras."); 944 } 945 } 946 947 protected void readTransitionRestriction(Element transitionRestrictionElement, GenericValue activityValue) throws DefinitionParserException { 948 String packageId = activityValue.getString("packageId"); 949 String packageVersion = activityValue.getString("packageVersion"); 950 String processId = activityValue.getString("processId"); 951 String processVersion = activityValue.getString("processVersion"); 952 String activityId = activityValue.getString("activityId"); 953 954 Element inlineBlockElement = UtilXml.firstChildElement(transitionRestrictionElement, "InlineBlock"); 956 957 if (inlineBlockElement != null) { 958 activityValue.set("isInlineBlock", "Y"); 959 activityValue.set("blockName", UtilXml.childElementValue(inlineBlockElement, "BlockName")); 960 activityValue.set("blockDescription", UtilXml.childElementValue(inlineBlockElement, "Description")); 961 activityValue.set("blockIconUrl", UtilXml.childElementValue(inlineBlockElement, "Icon")); 962 activityValue.set("blockDocumentationUrl", UtilXml.childElementValue(inlineBlockElement, "Documentation")); 963 964 activityValue.set("blockBeginActivityId", inlineBlockElement.getAttribute("Begin")); 965 activityValue.set("blockEndActivityId", inlineBlockElement.getAttribute("End")); 966 } 967 968 Element joinElement = UtilXml.firstChildElement(transitionRestrictionElement, "Join"); 970 971 if (joinElement != null) { 972 String joinType = joinElement.getAttribute("Type"); 973 974 if (joinType != null && joinType.length() > 0) { 975 activityValue.set("joinTypeEnumId", "WJT_" + joinType); 976 } 977 } 978 979 Element splitElement = UtilXml.firstChildElement(transitionRestrictionElement, "Split"); 981 982 if (splitElement != null) { 983 String splitType = splitElement.getAttribute("Type"); 984 985 if (splitType != null && splitType.length() > 0) { 986 activityValue.set("splitTypeEnumId", "WST_" + splitType); 987 } 988 989 Element transitionRefsElement = UtilXml.firstChildElement(splitElement, "TransitionRefs"); 991 List transitionRefs = UtilXml.childElementList(transitionRefsElement, "TransitionRef"); 992 993 readTransitionRefs(transitionRefs, packageId, packageVersion, processId, processVersion, activityId); 994 } 995 } 996 997 protected void readTransitionRefs(List transitionRefs, String packageId, String packageVersion, String processId, String processVersion, String activityId) throws DefinitionParserException { 998 if (transitionRefs == null || transitionRefs.size() == 0) 999 return; 1000 Iterator transitionRefsIter = transitionRefs.iterator(); 1001 1002 while (transitionRefsIter.hasNext()) { 1003 Element transitionRefElement = (Element ) transitionRefsIter.next(); 1004 GenericValue transitionRefValue = delegator.makeValue("WorkflowTransitionRef", null); 1005 1006 values.add(transitionRefValue); 1007 1008 transitionRefValue.set("packageId", packageId); 1009 transitionRefValue.set("packageVersion", packageVersion); 1010 transitionRefValue.set("processId", processId); 1011 transitionRefValue.set("processVersion", processVersion); 1012 transitionRefValue.set("activityId", activityId); 1013 transitionRefValue.set("transitionId", transitionRefElement.getAttribute("Id")); 1014 } 1015 } 1016 1017 1021 protected void readParticipants(List participants, String packageId, String packageVersion, String processId, String processVersion, GenericValue valueObject) throws DefinitionParserException { 1022 if (participants == null || participants.size() == 0) 1023 return; 1024 Iterator participantsIter = participants.iterator(); 1025 1026 while (participantsIter.hasNext()) { 1027 Element participantElement = (Element ) participantsIter.next(); 1028 String participantId = participantElement.getAttribute("Id"); 1029 GenericValue participantValue = delegator.makeValue("WorkflowParticipant", null); 1030 1031 values.add(participantValue); 1032 1033 participantValue.set("packageId", packageId); 1034 participantValue.set("packageVersion", packageVersion); 1035 participantValue.set("processId", processId); 1036 participantValue.set("processVersion", processVersion); 1037 participantValue.set("participantId", participantId); 1038 participantValue.set("participantName", participantElement.getAttribute("Name")); 1039 1040 Element participantTypeElement = UtilXml.firstChildElement(participantElement, "ParticipantType"); 1042 1043 if (participantTypeElement != null) { 1044 participantValue.set("participantTypeId", participantTypeElement.getAttribute("Type")); 1045 } 1046 1047 participantValue.set("description", UtilXml.childElementValue(participantElement, "Description")); 1049 1050 participantValue.set("partyId", getExtendedAttributeValue(participantElement, "partyId", null), false); 1052 participantValue.set("roleTypeId", getExtendedAttributeValue(participantElement, "roleTypeId", null), false); 1053 } 1054 } 1055 1056 1121 1122 protected void readApplications(List applications, String packageId, String packageVersion, String processId, 1123 String processVersion) throws DefinitionParserException { 1124 if (applications == null || applications.size() == 0) 1125 return; 1126 Iterator applicationsIter = applications.iterator(); 1127 1128 while (applicationsIter.hasNext()) { 1129 Element applicationElement = (Element ) applicationsIter.next(); 1130 GenericValue applicationValue = delegator.makeValue("WorkflowApplication", null); 1131 1132 values.add(applicationValue); 1133 1134 String applicationId = applicationElement.getAttribute("Id"); 1135 1136 applicationValue.set("packageId", packageId); 1137 applicationValue.set("packageVersion", packageVersion); 1138 applicationValue.set("processId", processId); 1139 applicationValue.set("processVersion", processVersion); 1140 applicationValue.set("applicationId", applicationId); 1141 applicationValue.set("applicationName", applicationElement.getAttribute("Name")); 1142 1143 applicationValue.set("description", UtilXml.childElementValue(applicationElement, "Description")); 1145 1146 Element formalParametersElement = UtilXml.firstChildElement(applicationElement, "FormalParameters"); 1148 List formalParameters = UtilXml.childElementList(formalParametersElement, "FormalParameter"); 1149 1150 readFormalParameters(formalParameters, packageId, packageVersion, processId, processVersion, applicationId); 1151 } 1152 } 1153 1154 protected void readDataFields(List dataFields, String packageId, String packageVersion, String processId, 1155 String processVersion) throws DefinitionParserException { 1156 if (dataFields == null || dataFields.size() == 0) 1157 return; 1158 Iterator dataFieldsIter = dataFields.iterator(); 1159 1160 while (dataFieldsIter.hasNext()) { 1161 Element dataFieldElement = (Element ) dataFieldsIter.next(); 1162 GenericValue dataFieldValue = delegator.makeValue("WorkflowDataField", null); 1163 1164 values.add(dataFieldValue); 1165 1166 String dataFieldId = dataFieldElement.getAttribute("Id"); 1167 String dataFieldName = dataFieldElement.getAttribute("Name"); 1168 if (dataFieldName == null || dataFieldName.length() == 0) 1169 dataFieldName = dataFieldId; 1170 1171 dataFieldValue.set("packageId", packageId); 1172 dataFieldValue.set("packageVersion", packageVersion); 1173 dataFieldValue.set("processId", processId); 1174 dataFieldValue.set("processVersion", processVersion); 1175 dataFieldValue.set("dataFieldId", dataFieldId); 1176 dataFieldValue.set("dataFieldName", dataFieldName); 1177 1178 dataFieldValue.set("isArray", ("TRUE".equals(dataFieldElement.getAttribute("IsArray")) ? "Y" : "N")); 1180 1181 Element dataTypeElement = UtilXml.firstChildElement(dataFieldElement, "DataType"); 1183 1184 if (dataTypeElement != null) { 1185 readType(dataTypeElement, dataFieldValue); 1187 } 1188 1189 dataFieldValue.set("initialValue", UtilXml.childElementValue(dataFieldElement, "InitialValue")); 1191 1192 String lengthStr = UtilXml.childElementValue(dataFieldElement, "Length"); 1194 1195 if (lengthStr != null && lengthStr.length() > 0) { 1196 try { 1197 dataFieldValue.set("lengthBytes", Long.valueOf(lengthStr)); 1198 } catch (NumberFormatException e) { 1199 throw new DefinitionParserException("Invalid whole number format in DataField->Length: " + lengthStr, e); 1200 } 1201 } 1202 1203 dataFieldValue.set("description", UtilXml.childElementValue(dataFieldElement, "Description")); 1205 } 1206 } 1207 1208 protected void readFormalParameters(List formalParameters, String packageId, String packageVersion, 1209 String processId, String processVersion, String applicationId) throws DefinitionParserException { 1210 if (formalParameters == null || formalParameters.size() == 0) 1211 return; 1212 Iterator formalParametersIter = formalParameters.iterator(); 1213 long index = 1; 1214 1215 while (formalParametersIter.hasNext()) { 1216 Element formalParameterElement = (Element ) formalParametersIter.next(); 1217 GenericValue formalParameterValue = delegator.makeValue("WorkflowFormalParam", null); 1218 1219 values.add(formalParameterValue); 1220 1221 String formalParamId = formalParameterElement.getAttribute("Id"); 1222 1223 formalParameterValue.set("packageId", packageId); 1224 formalParameterValue.set("packageVersion", packageVersion); 1225 formalParameterValue.set("processId", processId); 1226 formalParameterValue.set("processVersion", processVersion); 1227 formalParameterValue.set("applicationId", applicationId); 1228 formalParameterValue.set("formalParamId", formalParamId); 1229 formalParameterValue.set("modeEnumId", "WPM_" + formalParameterElement.getAttribute("Mode")); 1230 1231 String indexStr = formalParameterElement.getAttribute("Index"); 1232 1233 if (indexStr != null && indexStr.length() > 0) { 1234 try { 1235 formalParameterValue.set("indexNumber", Long.valueOf(indexStr)); 1236 } catch (NumberFormatException e) { 1237 throw new DefinitionParserException("Invalid decimal number format in FormalParameter->Index: " + indexStr, e); 1238 } 1239 } else 1240 formalParameterValue.set("indexNumber", new Long (index)); 1241 index++; 1242 1243 Element dataTypeElement = UtilXml.firstChildElement(formalParameterElement, "DataType"); 1245 1246 if (dataTypeElement != null) { 1247 readType(dataTypeElement, formalParameterValue); 1249 } 1250 1251 formalParameterValue.set("description", UtilXml.childElementValue(formalParameterElement, "Description")); 1253 } 1254 } 1255 1256 1260 protected void readType(Element element, GenericValue value) { 1261 Element typeElement = null; 1263 1264 if ((typeElement = UtilXml.firstChildElement(element, "RecordType")) != null) { } else if ((typeElement = UtilXml.firstChildElement(element, "UnionType")) != null) { } else if ((typeElement = UtilXml.firstChildElement(element, "EnumerationType")) != null) { } else if ((typeElement = UtilXml.firstChildElement(element, "ArrayType")) != null) { } else if ((typeElement = UtilXml.firstChildElement(element, "ListType")) != null) { } else if ((typeElement = UtilXml.firstChildElement(element, "BasicType")) != null) { 1270 value.set("dataTypeEnumId", "WDT_" + typeElement.getAttribute("Type")); 1271 } else if ((typeElement = UtilXml.firstChildElement(element, "PlainType")) != null) { 1272 value.set("dataTypeEnumId", "WDT_" + typeElement.getAttribute("Type")); 1273 } else if ((typeElement = UtilXml.firstChildElement(element, "DeclaredType")) != null) { 1274 value.set("dataTypeEnumId", "WDT_DECLARED"); 1276 value.set("complexTypeInfoId", typeElement.getAttribute("Id")); 1277 } 1278 1279 1288 } 1289 1290 protected String getExtendedAttributeValue(Element element, String name, String defaultValue) { 1291 if (element == null || name == null) 1292 return defaultValue; 1293 1294 Element extendedAttributesElement = UtilXml.firstChildElement(element, "ExtendedAttributes"); 1295 1296 if (extendedAttributesElement == null) 1297 return defaultValue; 1298 List extendedAttributes = UtilXml.childElementList(extendedAttributesElement, "ExtendedAttribute"); 1299 1300 if (extendedAttributes == null || extendedAttributes.size() == 0) 1301 return defaultValue; 1302 1303 Iterator iter = extendedAttributes.iterator(); 1304 1305 while (iter.hasNext()) { 1306 Element extendedAttribute = (Element ) iter.next(); 1307 String elementName = extendedAttribute.getAttribute("Name"); 1308 1309 if (name.equals(elementName)) { 1310 return extendedAttribute.getAttribute("Value"); 1311 } 1312 } 1313 return defaultValue; 1314 } 1315 1316 1320 public static void main(String [] args) throws Exception { 1321 String sampleFileName = "../../docs/examples/sample.xpdl"; 1322 1323 if (args.length > 0) 1324 sampleFileName = args[0]; 1325 List values = readXpdl(UtilURL.fromFilename(sampleFileName), GenericDelegator.getGenericDelegator("default")); 1326 Iterator viter = values.iterator(); 1327 1328 while (viter.hasNext()) 1329 System.out.println(viter.next().toString()); 1330 } 1331} 1332 1333 | Popular Tags |