1 package org.enhydra.shark; 2 import java.util.Iterator ; 3 import java.util.List ; 4 import java.util.Map ; 5 import java.util.Set ; 6 7 import org.enhydra.shark.api.SharkTransaction; 8 import org.enhydra.shark.api.client.wfbase.BaseException; 9 import org.enhydra.shark.util.ResourceManager; 10 import org.enhydra.shark.xpdl.PackageValidator; 11 import org.enhydra.shark.xpdl.XMLCollectionElement; 12 import org.enhydra.shark.xpdl.XMLComplexElement; 13 import org.enhydra.shark.xpdl.XMLElement; 14 import org.enhydra.shark.xpdl.XMLInterface; 15 import org.enhydra.shark.xpdl.XMLUtil; 16 import org.enhydra.shark.xpdl.XPDLConstants; 17 import org.enhydra.shark.xpdl.elements.Activity; 18 import org.enhydra.shark.xpdl.elements.ApplicationTypes; 19 import org.enhydra.shark.xpdl.elements.BasicType; 20 import org.enhydra.shark.xpdl.elements.DataField; 21 import org.enhydra.shark.xpdl.elements.DataType; 22 import org.enhydra.shark.xpdl.elements.DeclaredType; 23 import org.enhydra.shark.xpdl.elements.ExternalReference; 24 import org.enhydra.shark.xpdl.elements.Package; 25 import org.enhydra.shark.xpdl.elements.Participant; 26 import org.enhydra.shark.xpdl.elements.Script; 27 import org.enhydra.shark.xpdl.elements.TypeDeclaration; 28 import org.enhydra.shark.xpdl.elements.WorkflowProcess; 29 import org.enhydra.shark.xpdl.elements.WorkflowProcesses; 30 31 37 public class SharkPackageValidator extends PackageValidator { 38 private XMLInterface xpdlManager; 39 40 public SharkPackageValidator (Package p,XMLInterface xpdlManager,boolean checkExternalPackages) { 41 super(xpdlManager,p,true,checkExternalPackages,true,true); 42 this.xpdlManager=xpdlManager; 43 } 44 45 46 public boolean checkScript (boolean fullCheck) { 47 boolean isValid=true; 48 Script s=pkg.getScript(); 49 String sType=s.getType().trim(); 50 boolean isScriptInvalid=false; 51 SharkTransaction t=null; 52 try { 53 t=SharkUtilities.createTransaction(); 54 isScriptInvalid=SharkEngineManager. 55 getInstance(). 56 getScriptingManager(). 57 getEvaluator(t,sType)==null; 58 } catch (Exception ex) { 60 isScriptInvalid=true; 62 } finally { 63 try { SharkUtilities.releaseTransaction(t);} catch (BaseException e) {} 64 } 65 if (isScriptInvalid) { 66 isValid=false; 67 Map les=getLogicErrors(pkg); 68 if (les!=null) { 69 les.put(pkg,ResourceManager.getLanguageDependentString("ErrorUnsupportedScriptLanguage")); 70 } 71 } 72 73 return isValid; 74 } 75 76 public boolean checkDataType (XMLCollectionElement dfOrFp,boolean fullCheck) { 77 boolean isValid=super.checkDataType(dfOrFp,fullCheck); 78 79 if (isValid || fullCheck) { 80 DataType xpdlType=(DataType)dfOrFp.get("DataType"); 81 Object type=xpdlType.getDataTypes().getChoosen(); 82 if (type instanceof DeclaredType) { 83 TypeDeclaration td=pkg.getTypeDeclaration(((DeclaredType)type).getId()); 84 isValid=checkTypeDeclaration(td,false); 85 } else if (!((type instanceof BasicType)|| (type instanceof ExternalReference))) { 86 isValid=false; 87 } 88 if (!isValid) { 89 Map les; 90 XMLElement firstOwner=dfOrFp.getParent().getParent(); 91 if (dfOrFp instanceof DataField) { 92 les=getLogicErrors((XMLComplexElement)firstOwner); 93 } else { 94 if (firstOwner instanceof ApplicationTypes) { 95 les=getLogicErrors((XMLComplexElement)((ApplicationTypes)firstOwner).getParent().getParent().getParent()); 96 } else { 97 les=getLogicErrors((XMLComplexElement)firstOwner); 98 } 99 } 100 String msg=(String )les.get(dfOrFp); 101 msg=prepareMessageString(msg); 102 msg=msg+ResourceManager.getLanguageDependentString("ErrorUnsupportedDataType"); 103 les.put(dfOrFp,msg); 104 } 105 } 106 return isValid; 107 } 108 109 public boolean checkTypeDeclaration(TypeDeclaration td,boolean fullCheck) { 110 boolean isValid=true; 111 Object choosenType=td.getDataTypes().getChoosen(); 112 if (!((choosenType instanceof BasicType) || (choosenType instanceof ExternalReference))) { 113 isValid=false; 114 } 115 if (choosenType instanceof DeclaredType) { 116 TypeDeclaration td2=pkg.getTypeDeclaration(((DeclaredType)choosenType).getId()); 117 isValid=checkTypeDeclaration(td2,fullCheck); 118 } 119 if (!isValid) { 120 Map les=getLogicErrors(pkg); 121 String msg=ResourceManager.getLanguageDependentString("ErrorUnsupportedTypeDeclaration"); 122 les.put(td,msg); 123 124 } 125 return isValid; 126 } 127 128 public boolean validateAgainstXPDLSchema () { 129 xpdlSchemaValidationErrors=xpdlManager.getParsingErrorMessages(); 130 if (xpdlSchemaValidationErrors.size()>0) { 131 return false; 132 } else { 133 return true; 134 } 135 } 136 137 public boolean checkExternalPackages(boolean fullCheck) { 138 boolean isValid=true; 139 Map les=getLogicErrors(pkg); 140 141 Iterator it=pkg.getExternalPackageIds().iterator(); 142 while (it.hasNext() && (fullCheck || isValid)) { 143 Package p=(Package )xmlInterface.getPackageById((String )it.next()); 144 PackageValidator pv=new SharkPackageValidator(p,xpdlManager,false); 145 if (!pv.validateAll(false)) { 146 isValid=false; 147 if (les!=null) { 148 les.put(p,ResourceManager.getLanguageDependentString("ErrorInvalidExternalPackage")); 149 } 150 } 151 } 152 153 return isValid; 154 } 155 156 public boolean isExternalPackageError () { 157 List bgces=getBasicGraphConformanceErrors(pkg); 158 String bgce=getBasicGraphConnectionError(pkg); 159 String ble=getBasicLogicError(pkg); 160 String myPkgXmlFile=xpdlManager.getAbsoluteFilePath(pkg); 161 Map scherrs=getXPDLSchemaValidationErrors(); 162 if (((bgces!=null && bgces.size()>0) || bgce!=null || ble!=null) && 163 ((scherrs.size()>0 && scherrs.containsKey(myPkgXmlFile)) || scherrs.size()==0)) { 164 return false; 165 } else { 166 return true; 167 } 168 } 169 170 public boolean checkActivity (Activity act,boolean fullCheck) { 171 boolean isValid=super.checkActivity(act,fullCheck); 172 int type=act.getActivityType(); 173 if (type==XPDLConstants.ACTIVITY_TYPE_TOOL && act.getActivityTypes().getImplementation().getImplementationTypes().getTools().size()>0) { 174 isValid=checkStartMode(act) && isValid; 175 } 177 return isValid; 178 } 179 180 protected boolean checkStartMode (Activity toolAct) { 181 boolean isValid=true; 182 int startMode=toolAct.getActivityStartMode(); 183 String performer=toolAct.getPerformer().trim(); 184 boolean isSystemOrEmptyExpressionPerformer=false; 185 Participant p=null; 186 p=XMLUtil.getWorkflowProcess(toolAct).getParticipant(performer); 187 if (p==null) { 188 p=pkg.getParticipant(performer); 189 if (p==null) { 190 List l=XMLUtil.getAllExternalPackageIds(xmlInterface, pkg); 191 Iterator ita=l.iterator(); 192 while (ita.hasNext()) { 193 Package pk=xmlInterface.getPackageById((String )ita.next()); 194 if (pk!=null) { 195 p=pk.getParticipant(performer); 196 if (p!=null) { 197 break; 198 } 199 } 200 } 201 202 } 203 } 204 if (p!=null) { 205 String participantType=p.getParticipantType().getType(); 206 if (participantType.equals(XPDLConstants.PARTICIPANT_TYPE_SYSTEM)) { 207 isSystemOrEmptyExpressionPerformer=true; 208 } 209 } else { 210 if (performer.length()==0) { 211 isSystemOrEmptyExpressionPerformer=true; 212 } 213 } 214 if (isSystemOrEmptyExpressionPerformer && startMode==XPDLConstants.ACTIVITY_MODE_MANUAL) { 215 isValid=false; 216 Map les=getLogicErrors((XMLComplexElement)toolAct.getParent().getParent()); 217 String msg=(String )les.get(toolAct); 218 msg=prepareMessageString(msg); 219 msg=msg+ResourceManager.getLanguageDependentString("ErrorMANUALStartModeNotAllowedForToolActivitiesWithSystemParticipantOrEmptyExpressionPerformer"); 220 les.put(toolAct,msg); 221 } 222 if (!isSystemOrEmptyExpressionPerformer && startMode==XPDLConstants.ACTIVITY_MODE_AUTOMATIC) { 223 isValid=false; 224 Map les=getLogicErrors((XMLComplexElement)toolAct.getParent().getParent()); 225 String msg=(String )les.get(toolAct); 226 msg=prepareMessageString(msg); 227 msg=msg+ResourceManager.getLanguageDependentString("ErrorAUTOMATICStartModeNotAllowedForToolActivitiesWithPerformerOtherThenSystemParticipantOrEmptyExpression"); 228 les.put(toolAct,msg); 229 } 230 return isValid; 231 } 232 233 247 248 public boolean checkActivityPerformer (Activity act,boolean fullCheck) { 249 boolean isValid=super.checkActivityPerformer(act,fullCheck); 250 String performer=act.getPerformer().trim(); 252 int type=act.getActivityType(); 253 if (type==XPDLConstants.ACTIVITY_TYPE_NO || (type==XPDLConstants.ACTIVITY_TYPE_TOOL && act.getActivityTypes().getImplementation().getImplementationTypes().getTools().size()==0)) { 254 Participant p=null; 255 WorkflowProcess wp=XMLUtil.getWorkflowProcess(act); 256 p=wp.getParticipant(performer); 257 if (p==null) { 258 p=pkg.getParticipant(performer); 259 } 260 if (p!=null) { 261 String participantType=p.getParticipantType().getType(); 262 if (participantType.equals(XPDLConstants.PARTICIPANT_TYPE_SYSTEM)) { 263 isValid=false; 264 Map les=getLogicErrors((XMLComplexElement)act.getParent().getParent()); 265 String msg=(String )les.get(act); 266 msg=prepareMessageString(msg); 267 msg=msg+ResourceManager.getLanguageDependentString("ErrorNoImplementationActivityCannotHaveSystemParticipantPerformer"); 268 les.put(act,msg); 269 } 270 } 271 } 272 return isValid; 273 } 274 275 public void printDebug () { 276 System.err.println("SVEs="+xpdlSchemaValidationErrors); 277 System.err.println("GCEs="+graphsConnectionErrors); 278 System.err.println("BGCEs="+basicGraphConnectionErrors); 279 System.err.println("GCFEs="+graphsConformanceErrors); 280 System.err.println("BGCFEs="+basicGraphsConformanceErrors); 281 System.err.println("LEs="+logicErrors); 282 System.err.println("BLEs="+basicLogicErrors); 283 291 } 292 293 public String createXPDLValidationErrorsString () { 294 String errMsg="<html>"; 295 try { 296 errMsg=processErrors(xpdlSchemaValidationErrors,getGraphsConnectionErrors(pkg), 297 getBasicGraphConformanceErrors(pkg),getGraphConformanceErrors(pkg), 298 getLogicErrors(pkg),errMsg,pkg); 299 WorkflowProcesses wps=pkg.getWorkflowProcesses(); 300 Iterator it=wps.toElements().iterator(); 301 while (it.hasNext()) { 302 WorkflowProcess wp=(WorkflowProcess)it.next(); 303 errMsg=processErrors(null,getGraphsConnectionErrors(wp), 304 getBasicGraphConformanceErrors(wp),getGraphConformanceErrors(wp), 305 getLogicErrors(wp),errMsg,wp); 306 } 307 } catch (Exception ex) { 308 ex.printStackTrace(); 309 } 310 errMsg+="</html>"; 311 return errMsg; 312 } 313 314 315 318 protected String processErrors(Map parsingErrors,Map connectionErrors, 319 java.util.List basicGraphConformanceErrors,Map graphConformanceErrors, 320 Map logicErrors,String errMsg,XMLComplexElement pkgOrWpOrAs) { 321 boolean packageLevelProcessing=(pkgOrWpOrAs instanceof Package ); 322 String subtitle=""; 324 if (packageLevelProcessing) { 325 subtitle=XMLUtil.getLanguageDependentString("XPDLSchemaKey"); 326 errMsg+="<font size=6 face=\"sans-serif\" color=\"green\"><b><i><u>"+subtitle+"</u></i></b></font><br><br>"; 327 328 if (parsingErrors!=null && parsingErrors.size()>0) { 329 Iterator it=parsingErrors.entrySet().iterator(); 330 while (it.hasNext()) { 331 Map.Entry me=(Map.Entry )it.next(); 332 String pkgFile=(String )me.getKey(); 333 Set errorsForPkg=(Set )me.getValue(); 334 if (pkgFile.length()>0) { 335 errMsg+="<font size=5 face=\"sans-serif\" color=\"blue\"><b><i><u>"+ 336 pkgFile+"</u></i></b></font><br><br>"; 337 } 338 errMsg+="<font size=4 face=\"sans-serif\" color=\"#FF0000\"><i>"; 339 340 Iterator it2=errorsForPkg.iterator(); 341 while (it2.hasNext()) { 342 String msg=it2.next().toString(); 343 errMsg+=msg+"<br>"; 344 } 345 346 errMsg+="</i></font><br><br>"; 347 } 348 } 349 if (parsingErrors==null || parsingErrors.size()==0) { 350 String msg=XMLUtil. 351 getLanguageDependentString("MessageThereAreNoXPDLSchemaValidationErrors"); 352 errMsg+="<br><font size=4 face=\"sans-serif\" color=\"#0033CC\">"+msg+"</font><br><br>"; 353 } 354 355 } else { 356 errMsg+="<p>"; 357 } 358 359 if (packageLevelProcessing) { 360 subtitle=XMLUtil.getLanguageDependentString("PackageKey"); 361 } else if (pkgOrWpOrAs instanceof WorkflowProcess) { 362 subtitle=XMLUtil.getLanguageDependentString("WorkflowProcessKey"); 363 } 364 errMsg+="<font size=6 face=\"sans-serif\" color=\"black\"><b><i><u>"+subtitle+":"+pkgOrWpOrAs.get("Id").toValue()+"</u></i></b></font><br><br>"; 365 errMsg+="<p>"; 366 367 subtitle=XMLUtil.getLanguageDependentString("ConnectionsKey"); 369 errMsg+="<font size=5 face=\"sans-serif\" color=\"green\"><b><i><u>"+subtitle+"</u></i></b></font><br><br>"; 370 371 if (connectionErrors!=null) { 372 Iterator it=connectionErrors.entrySet().iterator(); 373 while (it.hasNext()) { 374 Map.Entry me=(Map.Entry )it.next(); 375 Object obj=me.getKey(); 376 String msg=me.getValue().toString(); 377 errMsg+="<font size=4 face=\"sans-serif\" color=\"#0033CC\">"; 378 errMsg=appendErrorMessage(obj,errMsg,packageLevelProcessing); 379 errMsg+="<blockquote>"; 381 errMsg+="<font size=\"4\" face=\"sans-serif\">"; 382 errMsg+="<em>"+msg+"</em><br>"; 383 errMsg+="</font></p></blockquote>"; 384 } 385 } 386 if (connectionErrors==null || connectionErrors.size()==0) { 387 String msg=XMLUtil. 388 getLanguageDependentString("MessageAllElementsAreProperlyConnected"); 389 errMsg+="<br><font size=4 face=\"sans-serif\" color=\"#0033CC\">"+msg+"</font><br><br>"; 390 } 391 392 subtitle=XMLUtil.getLanguageDependentString("GraphConformanceKey"); 394 errMsg+="<font size=5 face=\"sans-serif\" color=\"green\"><b><i><u>"+subtitle+"</u></i></b></font><br>"; 395 396 if (basicGraphConformanceErrors!=null) { 397 Iterator it=basicGraphConformanceErrors.iterator(); 398 while (it.hasNext()) { 399 String msg=(String )it.next(); 400 errMsg+="<font size=4 face=\"sans-serif\" color=\"#FF0000\">"+msg+"</font>"; 401 errMsg+="<br>"; 402 } 403 } 404 405 if (graphConformanceErrors!=null && graphConformanceErrors.size()>0) { 406 if (basicGraphConformanceErrors!=null && basicGraphConformanceErrors.size()>0) { 407 errMsg+="<br><br>"; 408 } else { 409 errMsg+="<br>"; 410 } 411 } 412 413 if (graphConformanceErrors!=null) { 414 Iterator it=graphConformanceErrors.entrySet().iterator(); 415 while (it.hasNext()) { 416 Map.Entry me=(Map.Entry )it.next(); 417 Object obj=me.getKey(); 418 String msg=me.getValue().toString(); 419 errMsg+="<font size=4 face=\"sans-serif\" color=\"#0033CC\">"; 420 errMsg=appendErrorMessage(obj,errMsg,packageLevelProcessing); 421 errMsg+="<blockquote>"; 423 errMsg+="<font size=\"4\" face=\"sans-serif\">"; 424 errMsg+="<em>"+msg+"</em><br>"; 425 errMsg+="</font></p></blockquote>"; 426 } 427 } 428 429 if ((basicGraphConformanceErrors==null || basicGraphConformanceErrors.size()==0) && 430 (graphConformanceErrors==null || graphConformanceErrors.size()==0)) { 431 String msg; 432 if (packageLevelProcessing) { 433 msg=XMLUtil. 434 getLanguageDependentString("MessagePackageGraphsConformsToTheGivenGraphConformanceClass"); 435 } else { 436 msg=XMLUtil. 437 getLanguageDependentString("MessageProcessGraphConformsToTheGivenGraphConformanceClass"); 438 } 439 errMsg+="<br><font size=4 face=\"sans-serif\" color=\"#0033CC\">"+msg+"</font><br><br>"; 440 } 441 442 if (basicGraphConformanceErrors!=null && basicGraphConformanceErrors.size()>0 && 443 (graphConformanceErrors==null || graphConformanceErrors.size()==0)) { 444 errMsg+="<br>"; 445 } 446 447 subtitle=XMLUtil.getLanguageDependentString("LogicKey"); 449 errMsg+="<font size=5 face=\"sans-serif\" color=\"green\"><b><i><u>"+subtitle+"</u></i></b></font><br><br>"; 450 451 if (logicErrors!=null) { 452 Iterator it=logicErrors.entrySet().iterator(); 453 while (it.hasNext()) { 454 Map.Entry me=(Map.Entry )it.next(); 455 Object obj=me.getKey(); 456 String msg=me.getValue().toString(); 457 errMsg+="<font size=4 face=\"sans-serif\" color=\"#0033CC\">"; 458 errMsg=appendErrorMessage(obj,errMsg,packageLevelProcessing); 459 errMsg+="<blockquote>"; 461 errMsg+="<font size=\"4\" face=\"sans-serif\">"; 462 errMsg+="<em>"+msg+"</em><br>"; 463 errMsg+="</font></p></blockquote>"; 464 } 465 } 466 if (logicErrors==null || logicErrors.size()==0) { 467 String msg=XMLUtil. 468 getLanguageDependentString("MessageThereAreNoLogicErrors"); 469 errMsg+="<br><font size=4 face=\"sans-serif\" color=\"#0033CC\">"+msg+"</font><br><br>"; 470 } 471 472 return errMsg; 473 } 474 475 private String appendErrorMessage (Object obj,String errMsg,boolean packageLevelProcessing) { 476 if ((obj instanceof XMLCollectionElement) || (obj instanceof Package )) { 477 XMLComplexElement xmlCe=(XMLComplexElement)obj; 478 if (obj instanceof WorkflowProcess) { 479 if(!packageLevelProcessing) return errMsg; 480 errMsg+="<u><strong>"+XMLUtil. 481 getLanguageDependentString("ProcessKey")+":</strong></u> </font>"; 482 } else if (obj instanceof Activity) { 483 Activity act=(Activity)obj; 484 if (act.getActivityType()==XPDLConstants.ACTIVITY_TYPE_SUBFLOW) { 485 errMsg+="<u><strong>"+XMLUtil. 486 getLanguageDependentString("SubFlowKey")+":</strong></u> </font>"; 487 } else if (act.getActivityType()==XPDLConstants.ACTIVITY_TYPE_BLOCK) { 488 errMsg+="<u><strong>"+XMLUtil. 489 getLanguageDependentString("BlockActivityKey")+":</strong></u> </font>"; 490 } else if (act.getActivityType()==XPDLConstants.ACTIVITY_TYPE_TOOL) { 491 errMsg+="<u><strong>"+XMLUtil. 492 getLanguageDependentString("GenericKey")+":</strong></u> </font>"; 493 } else { 494 errMsg+="<u><strong>"+XMLUtil. 495 getLanguageDependentString("RouteKey")+":</strong></u> </font>"; 496 } 497 } else { 498 errMsg+="<u><strong>"+XMLUtil.getLanguageDependentString(((XMLElement)obj).toName()+"Key")+":</strong></u> </font>"; 499 } 500 try { 501 errMsg+="<font size=\"4\" face=\"sans-serif\">" 502 +XMLUtil.getLanguageDependentString("IdKey")+"= <font color=\"#FF0000\">" 503 +xmlCe.get("Id").toValue()+"</font>, "; 504 errMsg+=XMLUtil.getLanguageDependentString("NameKey")+ 505 "= <font color=\"#FF0000\">"+xmlCe.get("Name").toValue()+"</font></font>"; 506 } catch (Exception ex) {} 507 } else if (obj instanceof XMLElement) { 508 errMsg+="<u><strong>"+XMLUtil.getLanguageDependentString(((XMLElement)obj).toName()+"Key")+":</strong></u> </font>"; 509 } else { 510 } 511 return errMsg; 512 } 513 514 515 } 516 | Popular Tags |