Coverage Report - org.jtheque.primary.utils.web.analyzers.generic.value.IteratorValueGetterFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
IteratorValueGetterFactory
0 %
0/16
0 %
0/10
2.333
 
 1  
 package org.jtheque.primary.utils.web.analyzers.generic.value;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *            
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License. 
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jdom.Element;
 20  
 import org.jtheque.core.utils.file.XMLException;
 21  
 import org.jtheque.core.utils.file.XMLReader;
 22  
 import org.jtheque.primary.utils.web.analyzers.generic.Factory;
 23  
 import org.jtheque.primary.utils.web.analyzers.generic.condition.ConditionUtils;
 24  
 import org.jtheque.primary.utils.web.analyzers.generic.operation.iterator.IteratorOperation;
 25  
 import org.jtheque.primary.utils.web.analyzers.generic.operation.iterator.IteratorOperationFactory;
 26  
 
 27  
 import java.util.ArrayList;
 28  
 import java.util.Collection;
 29  
 
 30  
 /**
 31  
  * @author Baptiste Wicht
 32  
  */
 33  0
 public final class IteratorValueGetterFactory implements Factory<ValueGetter> {
 34  
         @Override
 35  
         public boolean canFactor(Element element, XMLReader reader) throws XMLException{
 36  0
                 return !reader.getNodes("iterator", element).isEmpty();
 37  
         }
 38  
 
 39  
         @Override
 40  
         public ValueGetter factor(Element element, XMLReader reader) throws XMLException{
 41  0
                 Element n = reader.getNode("iterator", element);
 42  
 
 43  0
                 IteratorValue value = new IteratorValue(ValueGetterFactory.getScannerPossessor());
 44  
 
 45  0
                 for (IteratorOperation operation : getIteratorOperations(n, "before", reader)){
 46  0
                         value.addOperationsBefore(operation);
 47  
                 }
 48  
 
 49  0
                 for (IteratorOperation operation : getIteratorOperations(n, "after", reader)){
 50  0
                         value.addOperationsAfter(operation);
 51  
                 }
 52  
 
 53  0
                 for (IteratorOperation operation : getIteratorOperations(n, "operations", reader)){
 54  0
                         value.addOperations(operation);
 55  
                 }
 56  
 
 57  0
                 value.setCondition(ConditionUtils.getCondition(n, "condition", reader));
 58  
 
 59  0
                 return value;
 60  
         }
 61  
 
 62  
         /**
 63  
          * Return the iterator operations in a specific location of node.
 64  
          *
 65  
          * @param node The node to search in.
 66  
          * @param location The location to search in.
 67  
          * @param reader The XML reader.
 68  
          *
 69  
          * @return A List containing all the IteratorOperation found in the specific location of the node.
 70  
          *
 71  
          * @throws XMLException If an errors occurs during the parse of the XML Elements.
 72  
          */
 73  
         private static Iterable<IteratorOperation> getIteratorOperations(Object node, String location, XMLReader reader) throws XMLException{
 74  0
                 Collection<IteratorOperation> operations = new ArrayList<IteratorOperation>(8);
 75  
 
 76  0
                 for (Element n : reader.getNodes(location + "/*", node)){
 77  0
                         operations.add(IteratorOperationFactory.getPosition(n, reader));
 78  
                 }
 79  
 
 80  0
                 return operations;
 81  
         }
 82  
 }