1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.security.authorization.testwikis.internal.parser

File AbstractEntityFactory.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

0
3
5
1
95
27
5
1.67
0.6
5
1

Classes

Class Line # Actions
AbstractEntityFactory 35 3 0% 5 2
0.7575%
 

Contributing tests

This file is covered by 15 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software 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 GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20   
21    package org.xwiki.security.authorization.testwikis.internal.parser;
22   
23    import org.xml.sax.Attributes;
24    import org.xml.sax.SAXException;
25    import org.xwiki.security.authorization.testwikis.TestEntity;
26   
27    /**
28    * Base factory for the creation of test entities based on an XML definition.
29    *
30    * @param <T> Specialized type of the entity created by this factory
31    *
32    * @version $Id: f99b3df3a971be11c956c5db8b7ba748e1ac37d5 $
33    * @since 5.0M2
34    */
 
35    public abstract class AbstractEntityFactory<T extends TestEntity> implements EntityFactory
36    {
37    /** Parent entity to be used for all entities created by this factory. */
38    private TestEntity parent;
39   
40    /** Create a factory for the root element (no parent). */
 
41  547 toggle AbstractEntityFactory() {
42    }
43   
44    /**
45    * Create a factory for some types children of the given parent.
46    * @param parent Parent entity to be used for all entities created by this factory.
47    */
 
48  0 toggle AbstractEntityFactory(TestEntity parent) {
49  0 setParent(parent);
50    }
51   
52    /**
53    * Set the parent entity to be used for all entities created by this factory. Overridden by subclasses to
54    * change their parent to another entity then the default behavior (which is taking the entity represented
55    * by the parent XML element).
56    * @param parent the entity that will hold any entities created by this factory.
57    */
 
58  532 toggle protected void setParent(TestEntity parent)
59    {
60  532 this.parent = parent;
61    }
62   
 
63  533 toggle @Override
64    public void newElement(ElementParser parser, String name, Attributes attributes) throws SAXException
65    {
66  533 registerFactories(parser, getNewInstance(parser, name, parent, attributes));
67    }
68   
69    /**
70    * Register factories for children of entity created by this factory.
71    *
72    * This needs to be overridden by subclasses to define possible child element of the XML element representing the
73    * current entity.
74    *
75    * @param parser the XML parser current parsing the XML definition.
76    * @param entity the entity created for representing the current element.
77    */
 
78  518 toggle protected void registerFactories(ElementParser parser, T entity)
79    {
80    }
81   
82    /**
83    * Abstract method to be overridden by subclasses to create a new instance of an test entity representing the
84    * currently parsed XML element.
85    *
86    * @param parser the XML parser current parsing the XML definition.
87    * @param name the name of the currently parsed element.
88    * @param parent the parent to be used for creating the entity.
89    * @param attributes the attribute of the XML element representing this entity.
90    * @return a new test entity.
91    * @throws SAXException on error.
92    */
93    abstract T getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes)
94    throws SAXException;
95    }