Changeset 135:a9339f5b493a

Show
Ignore:
Timestamp:
08/26/08 15:32:42 (5 years ago)
Author:
fbatard
Branch:
default
convert_revision:
svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@136
Message:

Handling the new functionalities for the tasklist tree

Location:
org/w3c/unicorn
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • org/w3c/unicorn/Framework.java

    r102 r135  
    1 // $Id: Framework.java,v 1.12 2008-07-02 17:34:47 jean-gui Exp $ 
     1// $Id: Framework.java,v 1.13 2008-08-26 15:32:42 fbatard Exp $ 
    22// Author: Damien LEROY. 
    33// (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. 
     
    3131import org.w3c.unicorn.tasklist.RDFUnmarshallerJena; 
    3232import org.w3c.unicorn.tasklist.Task; 
     33import org.w3c.unicorn.tasklist.TaskListUnmarshallerBeans; 
    3334import org.w3c.unicorn.tasklist.TasksListUnmarshaller; 
    34 import org.w3c.unicorn.tasklist.TasksListUnmarshallerJAXB; 
    3535import org.w3c.unicorn.util.ListFiles; 
    3636import org.w3c.unicorn.util.LocalizedString; 
     
    214214                                        .get("PATH_TO_TASKLIST"), "\\.xml"); 
    215215 
    216                         final TasksListUnmarshaller aTaskListUnmarshaller = new TasksListUnmarshallerJAXB( 
     216                        final TasksListUnmarshaller aTaskListUnmarshaller = new TaskListUnmarshallerBeans( 
    217217                                        Framework.mapOfObserver); 
    218218                        for (final File aFile : tFileXML) { 
  • org/w3c/unicorn/UnicornCall.java

    r116 r135  
    1 // $Id: UnicornCall.java,v 1.10 2008-07-24 09:51:53 fbatard Exp $ 
     1// $Id: UnicornCall.java,v 1.11 2008-08-26 15:32:42 fbatard Exp $ 
    22// Author: Jean-Guilhem Rouel 
    33// (c) COPYRIGHT MIT, ERCIM and Keio, 2006. 
     
    1414 
    1515import javax.activation.MimeType; 
    16 import javax.xml.bind.JAXBException; 
    1716 
    1817import org.apache.commons.fileupload.FileItem; 
     
    2524import org.w3c.unicorn.exceptions.NoDocumentException; 
    2625import org.w3c.unicorn.exceptions.NoMimeTypeException; 
    27 import org.w3c.unicorn.exceptions.UnsupportedMimeTypeException; 
    28 import org.w3c.unicorn.generated.tasklist.TPriority; 
    2926import org.w3c.unicorn.input.InputFactory; 
    3027import org.w3c.unicorn.request.Request; 
     
    3229import org.w3c.unicorn.response.Response; 
    3330import org.w3c.unicorn.response.parser.ResponseParserFactory; 
    34 import org.w3c.unicorn.tasklist.Observation; 
    3531import org.w3c.unicorn.tasklist.Task; 
    3632import org.w3c.unicorn.tasklist.parameters.Mapping; 
    3733import org.w3c.unicorn.tasklist.parameters.Parameter; 
    3834import org.w3c.unicorn.tasklist.parameters.Value; 
     35import org.w3c.unicorn.tasklisttree.TLTCond; 
     36import org.w3c.unicorn.tasklisttree.TLTExec; 
     37import org.w3c.unicorn.tasklisttree.TLTIf; 
     38import org.w3c.unicorn.tasklisttree.TLTNode; 
    3939import org.w3c.unicorn.util.Property; 
    4040 
     
    7272        private Map<String, String[]> mapOfStringParameter = null; 
    7373 
    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; 
    10478 
    10579        /** 
     
    12195                this.mapOfStringParameter = new LinkedHashMap<String, String[]>(); 
    12296 
    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>(); 
    13198                this.nbActiveThreads = 0; 
    13299        } 
     
    200167                                        .debug("MimeType : " + aMimeType.toString() + "."); 
    201168                } 
    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 
    213170 
    214171                // Create input method 
     
    216173                                this.aEnumInputMethod, this.oInputParameterValue); 
    217174 
     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{ 
    218188                // 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){ 
    219197                this.aRequestList = this.generateRequestList(aInputFactory, 
    220                                 this.mapOfStringParameter); 
     198                                this.mapOfStringParameter,node); 
    221199 
    222200                if (UnicornCall.logger.isDebugEnabled()) { 
     
    226204 
    227205                // 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         
    239258        /** 
    240259         * Adds 1 to active threads number 
     
    280299         *             Input/Output error 
    281300         */ 
    282         private boolean doRequests(final TPriority aTPriority) throws IOException, 
    283                         JAXBException { 
     301        private boolean doRequests() throws IOException{ 
    284302                UnicornCall.logger.trace("doRequest"); 
    285                 if (UnicornCall.logger.isDebugEnabled()) { 
    286                         UnicornCall.logger.debug("Priority : " + aTPriority + "."); 
    287                 } 
    288303 
    289304                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                 
    305306                final Map<String, Request> requests = this.aRequestList 
    306                                 .getRequest(aTPriority); 
     307                                .getRequestMap(); 
    307308                // Creation of the thread list 
    308309                ArrayList<Thread> threadsList = new ArrayList<Thread>(); 
     
    339340         * @param mapOfArrayUseParameter 
    340341         *            array of the parameter 
     342         * @param node the current node that we are parsing            
    341343         * @return the list of the request for the call 
    342344         * @throws Exception 
    343345         *             error occured during the process 
    344346         */ 
    345         //TODO Changer la génération de la liste pour prendre en compte les level d'execution 
    346         //Adapter la Map dans la RequestList  
    347         //Dans le doTask on bouclera tant qu'on trouve des lvl d'execution superieur 
    348347        private RequestList generateRequestList(final InputFactory aInputFactory, 
    349                         final Map<String, String[]> mapOfArrayUseParameter) 
     348                        final Map<String, String[]> mapOfArrayUseParameter,TLTNode node) 
    350349                        throws Exception { 
    351350 
     
    357356                                        + mapOfArrayUseParameter + "."); 
    358357                } 
    359  
     358                  
    360359                final MimeType aMimeType = aInputFactory.getMimeType(); 
    361360                final EnumInputMethod aEnumInputMethod = aInputFactory 
     
    365364                // Iterate over all observation of this task to build a basic 
    366365                // 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()) { 
    370370                        final String sObserverID = aObserver.getID(); 
    371371                        // add only observer who handle the current mimetype 
     
    403403                                        } 
    404404 
    405                                         final InputMethod aInputMethod = aObservation.getObserver() 
     405                                        final InputMethod aInputMethod = aObserver 
    406406                                                        .getInputMethod(aEIM); 
    407407                                        // create a new request with input parameter 
     
    414414                                        // add this request to request list 
    415415 
    416                                         aRequestList.addRequest(aRequest, aObservation 
    417                                                         .getPriority(aMimeType), sObserverID); 
     416                                        aRequestList.addRequest(aRequest,""+node.getID()); 
    418417                                        // log debug information 
    419418                                        if (UnicornCall.logger.isDebugEnabled()) { 
     
    461460 
    462461                        // Get name of the lang parameter (defined in RDF file) 
    463                         String observerParamLangName = aObservation.getObserver() 
     462                        String observerParamLangName = aObserver 
    464463                                        .getParamLangName(); 
    465464 
     
    471470 
    472471                        // Add this request to request list 
    473                         aRequestList.addRequest(aRequest, aObservation 
    474                                         .getPriority(aMimeType), sObserverID); 
     472                        aRequestList.addRequest(aRequest,""+node.getID()); 
    475473                        // Log debug information 
    476474                        if (UnicornCall.logger.isDebugEnabled()) { 
     
    513511                                        UnicornCall.logger.warn("Parameter " + sTaskParameterName 
    514512                                                        + " has no value intput and no default value."); 
    515                                         // TODO check if this parameter is required 
    516513                                        continue; 
    517514                                } 
     
    540537                                final Map<String, List<Mapping>> mapOfMapping = aValue 
    541538                                                .getMapOfMapping(); 
     539                                 
    542540                                for (final String sObserverName : mapOfMapping.keySet()) { 
    543                                         final Observation aObservation = this.aTask 
    544                                                         .getMapOfObservation().get(sObserverName); 
     541                                         
    545542                                        final Request aRequest = aRequestList 
    546543                                                        .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                                         
    557545                                        for (final Mapping aMapping : mapOfMapping 
    558546                                                        .get(sObserverName)) { 
     
    566554                                                aRequest.addParameter(aMapping.getParam(), sValue); 
    567555                                        } 
     556                                         
    568557                                } // foreach mapOfMapping.keySet() 
     558                                 
    569559                                continue; 
    570560                        } 
     561                         
    571562                        for (final String sUseParameterValue : tStringUseParameterValue) { 
    572563                                final Value aValue = mapOfValue.get(sUseParameterValue); 
     
    574565                                                .getMapOfMapping(); 
    575566                                for (final String sObserverName : mapOfMapping.keySet()) { 
    576                                         final Observation aObservation = this.aTask 
    577                                                         .getMapOfObservation().get(sObserverName); 
    578567                                        final Request aRequest = aRequestList 
    579568                                                        .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                                         
    590570                                        for (final Mapping aMapping : mapOfMapping 
    591571                                                        .get(sObserverName)) { 
     
    602582                                } // foreach mapOfMapping.keySet() 
    603583                        } // foreach sArrayParameterValue 
     584                         
    604585                } // foreach this.parameters.values() 
     586         
    605587                return aRequestList; 
    606588        } 
    607589 
    608590        /** 
    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         /** 
    627591         * Returns the responses of low priority observations. 
    628592         *  
    629593         * @return responses of low priority observations. 
    630594         */ 
    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; 
    660597        } 
    661598 
     
    715652         */ 
    716653        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); 
    722654                return mapOfResponse; 
    723655        } 
     
    875807                        } 
    876808                } 
     809                 
    877810 
    878811                synchronized (mapOfResponse) {