Changeset 135:a9339f5b493a
- Timestamp:
- 08/26/08 15:32:42 (5 years ago)
- Branch:
- default
- convert_revision:
- svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@136
- Location:
- org/w3c/unicorn
- Files:
-
- 2 modified
-
Framework.java (modified) (3 diffs)
-
UnicornCall.java (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
org/w3c/unicorn/Framework.java
r102 r135 1 // $Id: Framework.java,v 1.1 2 2008-07-02 17:34:47 jean-guiExp $1 // $Id: Framework.java,v 1.13 2008-08-26 15:32:42 fbatard Exp $ 2 2 // Author: Damien LEROY. 3 3 // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. … … 31 31 import org.w3c.unicorn.tasklist.RDFUnmarshallerJena; 32 32 import org.w3c.unicorn.tasklist.Task; 33 import org.w3c.unicorn.tasklist.TaskListUnmarshallerBeans; 33 34 import org.w3c.unicorn.tasklist.TasksListUnmarshaller; 34 import org.w3c.unicorn.tasklist.TasksListUnmarshallerJAXB;35 35 import org.w3c.unicorn.util.ListFiles; 36 36 import org.w3c.unicorn.util.LocalizedString; … … 214 214 .get("PATH_TO_TASKLIST"), "\\.xml"); 215 215 216 final TasksListUnmarshaller aTaskListUnmarshaller = new Task sListUnmarshallerJAXB(216 final TasksListUnmarshaller aTaskListUnmarshaller = new TaskListUnmarshallerBeans( 217 217 Framework.mapOfObserver); 218 218 for (final File aFile : tFileXML) { -
org/w3c/unicorn/UnicornCall.java
r116 r135 1 // $Id: UnicornCall.java,v 1.1 0 2008-07-24 09:51:53fbatard Exp $1 // $Id: UnicornCall.java,v 1.11 2008-08-26 15:32:42 fbatard Exp $ 2 2 // Author: Jean-Guilhem Rouel 3 3 // (c) COPYRIGHT MIT, ERCIM and Keio, 2006. … … 14 14 15 15 import javax.activation.MimeType; 16 import javax.xml.bind.JAXBException;17 16 18 17 import org.apache.commons.fileupload.FileItem; … … 25 24 import org.w3c.unicorn.exceptions.NoDocumentException; 26 25 import org.w3c.unicorn.exceptions.NoMimeTypeException; 27 import org.w3c.unicorn.exceptions.UnsupportedMimeTypeException;28 import org.w3c.unicorn.generated.tasklist.TPriority;29 26 import org.w3c.unicorn.input.InputFactory; 30 27 import org.w3c.unicorn.request.Request; … … 32 29 import org.w3c.unicorn.response.Response; 33 30 import org.w3c.unicorn.response.parser.ResponseParserFactory; 34 import org.w3c.unicorn.tasklist.Observation;35 31 import org.w3c.unicorn.tasklist.Task; 36 32 import org.w3c.unicorn.tasklist.parameters.Mapping; 37 33 import org.w3c.unicorn.tasklist.parameters.Parameter; 38 34 import org.w3c.unicorn.tasklist.parameters.Value; 35 import org.w3c.unicorn.tasklisttree.TLTCond; 36 import org.w3c.unicorn.tasklisttree.TLTExec; 37 import org.w3c.unicorn.tasklisttree.TLTIf; 38 import org.w3c.unicorn.tasklisttree.TLTNode; 39 39 import org.w3c.unicorn.util.Property; 40 40 … … 72 72 private Map<String, String[]> mapOfStringParameter = null; 73 73 74 // Results 75 /** 76 * Data Structure for the response with high priority 77 */ 78 private Map<String, Response> mapOfResponseHigh; 79 80 /** 81 * Data Structure for the response with medium priority 82 */ 83 private Map<String, Response> mapOfResponseMedium; 84 85 /** 86 * Data Structure for the response with low priority 87 */ 88 private Map<String, Response> mapOfResponseLow; 89 90 /** 91 * Tells if the high priority check passed 92 */ 93 private boolean bPassedHigh; 94 95 /** 96 * Tells if the medium priority check passed 97 */ 98 private boolean bPassedMedium; 99 100 /** 101 * Tells if the low priority check passed 102 */ 103 private boolean bPassedLow; 74 /** 75 * Data Structure for the response 76 */ 77 private Map<String, Response> mapOfResponse; 104 78 105 79 /** … … 121 95 this.mapOfStringParameter = new LinkedHashMap<String, String[]>(); 122 96 123 this.mapOfResponseHigh = new LinkedHashMap<String, Response>(); 124 this.mapOfResponseMedium = new LinkedHashMap<String, Response>(); 125 this.mapOfResponseLow = new LinkedHashMap<String, Response>(); 126 127 this.bPassedHigh = true; 128 this.bPassedMedium = true; 129 this.bPassedLow = true; 130 97 this.mapOfResponse = new LinkedHashMap<String, Response>(); 131 98 this.nbActiveThreads = 0; 132 99 } … … 200 167 .debug("MimeType : " + aMimeType.toString() + "."); 201 168 } 202 /* 203 * Check if the mimetype is handle by the asked task redirect 204 * automatically to another input method if this one does not support 205 * this mimetype 206 */ 207 if (!this.aTask.allowMimeType(aMimeType)) { 208 UnicornCall.logger.error("Task " + this.aTask.getID() 209 + " does not support the mimetype " + aMimeType.toString() 210 + "."); 211 throw new UnsupportedMimeTypeException(aMimeType.toString() + "."); 212 } 169 213 170 214 171 // Create input method … … 216 173 this.aEnumInputMethod, this.oInputParameterValue); 217 174 175 this.doNode(aInputFactory,this.aTask.getTree()); 176 177 178 aInputFactory.dispose(); 179 } 180 181 /** 182 * Main function called to do the recursion over the Task tree to launch the requests 183 * @param aInputFactory InputFactory used for the resquests 184 * @param node the current node that we're parsing in the Task tree 185 * @throws Exception raised from generateRequestList and doRequest 186 */ 187 private void doNode(InputFactory aInputFactory,TLTNode node) throws Exception{ 218 188 // Generate the list of request 189 UnicornCall.logger.trace("doNode."); 190 if (UnicornCall.logger.isDebugEnabled()) { 191 UnicornCall.logger.debug("InputFactory : " + aInputFactory 192 + "."); 193 UnicornCall.logger.debug("Current node : " 194 + node + "."); 195 } 196 if(node!=null){ 219 197 this.aRequestList = this.generateRequestList(aInputFactory, 220 this.mapOfStringParameter );198 this.mapOfStringParameter,node); 221 199 222 200 if (UnicornCall.logger.isDebugEnabled()) { … … 226 204 227 205 // send requests to observer 228 this.bPassedHigh = this.doRequests(TPriority.HIGH); 229 if (!this.bPassedHigh) 230 return; 231 this.bPassedMedium = this.doRequests(TPriority.MEDIUM); 232 if (!this.bPassedMedium) 233 return; 234 this.bPassedLow = this.doRequests(TPriority.LOW); 235 236 aInputFactory.dispose(); 237 } 238 206 this.doRequests(); 207 208 UnicornCall.logger.info("Check the condition of the Ifs"); 209 //browse the conditions to do the connection 210 for(TLTIf ifs: node.getIfList()){ 211 if(this.checkCond(ifs))this.doNode(aInputFactory,ifs.getIfOk()); 212 else this.doNode(aInputFactory,ifs.getIfNotOk()); 213 } 214 } 215 else{ 216 //Inform if the node is null 217 if (UnicornCall.logger.isDebugEnabled()) { 218 UnicornCall.logger 219 .debug("The node is null at this point."); 220 } 221 } 222 223 } 224 225 /** 226 * Check the conditions of the if branch it makes a OR between all conditions 227 * @param ifs the if branch to check 228 * @return whether or not the conditions are true 229 */ 230 private boolean checkCond(TLTIf ifs){ 231 UnicornCall.logger.trace("checkCond."); 232 if (UnicornCall.logger.isDebugEnabled()) { 233 UnicornCall.logger.debug("If node : " + ifs 234 + "."); 235 } 236 boolean conditionOK=true; 237 //TODO boolean to manage the OR in the conditions, if the donc is false we change the boolean to false , if not we don't care 238 //that will simulate the OR 239 for(TLTCond cond:ifs.getCondArray()){ 240 241 } 242 return conditionOK; 243 } 244 245 /** 246 * Creates the map of all the Observer to call in the current node 247 * @param node the current node of the Task tree we are parsing 248 */ 249 private Map<String,Observer> createExecList(TLTNode node){ 250 Map<String,Observer> mapOfCurrentNodeObserver=new LinkedHashMap<String, Observer>(); 251 for (TLTExec exec : node.getExecutionList()) { 252 mapOfCurrentNodeObserver.put(exec.getValue(),exec.getObserver()); 253 } 254 return mapOfCurrentNodeObserver; 255 } 256 257 239 258 /** 240 259 * Adds 1 to active threads number … … 280 299 * Input/Output error 281 300 */ 282 private boolean doRequests(final TPriority aTPriority) throws IOException, 283 JAXBException { 301 private boolean doRequests() throws IOException{ 284 302 UnicornCall.logger.trace("doRequest"); 285 if (UnicornCall.logger.isDebugEnabled()) {286 UnicornCall.logger.debug("Priority : " + aTPriority + ".");287 }288 303 289 304 bPassed = true; 290 291 final Map<String, Response> mapOfResponse; 292 switch (aTPriority) { 293 case HIGH: 294 mapOfResponse = this.mapOfResponseHigh; 295 break; 296 case LOW: 297 mapOfResponse = this.mapOfResponseLow; 298 break; 299 case MEDIUM: 300 mapOfResponse = this.mapOfResponseMedium; 301 break; 302 default: 303 mapOfResponse = null; 304 } 305 305 306 final Map<String, Request> requests = this.aRequestList 306 .getRequest (aTPriority);307 .getRequestMap(); 307 308 // Creation of the thread list 308 309 ArrayList<Thread> threadsList = new ArrayList<Thread>(); … … 339 340 * @param mapOfArrayUseParameter 340 341 * array of the parameter 342 * @param node the current node that we are parsing 341 343 * @return the list of the request for the call 342 344 * @throws Exception 343 345 * error occured during the process 344 346 */ 345 //TODO Changer la génération de la liste pour prendre en compte les level d'execution346 //Adapter la Map dans la RequestList347 //Dans le doTask on bouclera tant qu'on trouve des lvl d'execution superieur348 347 private RequestList generateRequestList(final InputFactory aInputFactory, 349 final Map<String, String[]> mapOfArrayUseParameter )348 final Map<String, String[]> mapOfArrayUseParameter,TLTNode node) 350 349 throws Exception { 351 350 … … 357 356 + mapOfArrayUseParameter + "."); 358 357 } 359 358 360 359 final MimeType aMimeType = aInputFactory.getMimeType(); 361 360 final EnumInputMethod aEnumInputMethod = aInputFactory … … 365 364 // Iterate over all observation of this task to build a basic 366 365 // request list with only the url of observator and input parameter 367 for (final Observation aObservation : this.aTask.getMapOfObservation() 368 .values()) { 369 final Observer aObserver = aObservation.getObserver(); 366 //Il faut creer une list avec tous les exec et toutes les rencardeur de ifs 367 //Une liste d'Observer 368 369 for (final Observer aObserver : this.createExecList(node).values()) { 370 370 final String sObserverID = aObserver.getID(); 371 371 // add only observer who handle the current mimetype … … 403 403 } 404 404 405 final InputMethod aInputMethod = aObserv ation.getObserver()405 final InputMethod aInputMethod = aObserver 406 406 .getInputMethod(aEIM); 407 407 // create a new request with input parameter … … 414 414 // add this request to request list 415 415 416 aRequestList.addRequest(aRequest, aObservation 417 .getPriority(aMimeType), sObserverID); 416 aRequestList.addRequest(aRequest,""+node.getID()); 418 417 // log debug information 419 418 if (UnicornCall.logger.isDebugEnabled()) { … … 461 460 462 461 // Get name of the lang parameter (defined in RDF file) 463 String observerParamLangName = aObserv ation.getObserver()462 String observerParamLangName = aObserver 464 463 .getParamLangName(); 465 464 … … 471 470 472 471 // Add this request to request list 473 aRequestList.addRequest(aRequest, aObservation 474 .getPriority(aMimeType), sObserverID); 472 aRequestList.addRequest(aRequest,""+node.getID()); 475 473 // Log debug information 476 474 if (UnicornCall.logger.isDebugEnabled()) { … … 513 511 UnicornCall.logger.warn("Parameter " + sTaskParameterName 514 512 + " has no value intput and no default value."); 515 // TODO check if this parameter is required516 513 continue; 517 514 } … … 540 537 final Map<String, List<Mapping>> mapOfMapping = aValue 541 538 .getMapOfMapping(); 539 542 540 for (final String sObserverName : mapOfMapping.keySet()) { 543 final Observation aObservation = this.aTask 544 .getMapOfObservation().get(sObserverName); 541 545 542 final Request aRequest = aRequestList 546 543 .getRequest(sObserverName); 547 final TPriority aTPriority = aObservation 548 .getPriority(aMimeType); 549 if (null == aTPriority) { 550 if (UnicornCall.logger.isDebugEnabled()) { 551 UnicornCall.logger.debug("Observator " 552 + sObserverName + " unhandle mimetype " 553 + aMimeType.getBaseType() + "."); 554 } 555 continue; 556 } 544 557 545 for (final Mapping aMapping : mapOfMapping 558 546 .get(sObserverName)) { … … 566 554 aRequest.addParameter(aMapping.getParam(), sValue); 567 555 } 556 568 557 } // foreach mapOfMapping.keySet() 558 569 559 continue; 570 560 } 561 571 562 for (final String sUseParameterValue : tStringUseParameterValue) { 572 563 final Value aValue = mapOfValue.get(sUseParameterValue); … … 574 565 .getMapOfMapping(); 575 566 for (final String sObserverName : mapOfMapping.keySet()) { 576 final Observation aObservation = this.aTask577 .getMapOfObservation().get(sObserverName);578 567 final Request aRequest = aRequestList 579 568 .getRequest(sObserverName); 580 final TPriority aTPriority = aObservation 581 .getPriority(aMimeType); 582 if (null == aTPriority) { 583 if (UnicornCall.logger.isDebugEnabled()) { 584 UnicornCall.logger.debug("Observator " 585 + sObserverName + " unhandle mimetype " 586 + aMimeType.getBaseType() + "."); 587 } 588 continue; 589 } 569 590 570 for (final Mapping aMapping : mapOfMapping 591 571 .get(sObserverName)) { … … 602 582 } // foreach mapOfMapping.keySet() 603 583 } // foreach sArrayParameterValue 584 604 585 } // foreach this.parameters.values() 586 605 587 return aRequestList; 606 588 } 607 589 608 590 /** 609 * Returns the responses of high priority observations.610 *611 * @return responses of high priority observations.612 */613 public Map<String, Response> getHighResponses() {614 return this.mapOfResponseHigh;615 }616 617 /**618 * Returns the responses of medium priority observations.619 *620 * @return Returns the responses of medium priority observations.621 */622 public Map<String, Response> getMediumResponses() {623 return this.mapOfResponseMedium;624 }625 626 /**627 591 * Returns the responses of low priority observations. 628 592 * 629 593 * @return responses of low priority observations. 630 594 */ 631 public Map<String, Response> getLowResponses() { 632 return this.mapOfResponseLow; 633 } 634 635 /** 636 * Return the boolean if high checks have passed 637 * 638 * @return Returns the highPassed. 639 */ 640 public boolean haveHighPassed() { 641 return this.bPassedHigh; 642 } 643 644 /** 645 * Return the boolean if low checks have passed 646 * 647 * @return Returns the lowPassed. 648 */ 649 public boolean haveLowPassed() { 650 return this.bPassedLow; 651 } 652 653 /** 654 * Return the boolean if medium checks have passed 655 * 656 * @return Returns the mediumPassed. 657 */ 658 public boolean haveMediumPassed() { 659 return this.bPassedMedium; 595 public Map<String, Response> getResponses() { 596 return this.mapOfResponse; 660 597 } 661 598 … … 715 652 */ 716 653 public Map<String, Response> getObservationList() { 717 final Map<String, Response> mapOfResponse;718 mapOfResponse = new LinkedHashMap<String, Response>();719 mapOfResponse.putAll(this.mapOfResponseHigh);720 mapOfResponse.putAll(this.mapOfResponseMedium);721 mapOfResponse.putAll(this.mapOfResponseLow);722 654 return mapOfResponse; 723 655 } … … 875 807 } 876 808 } 809 877 810 878 811 synchronized (mapOfResponse) {
