|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DefaultStoreVisitor.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* EJTools, the Enterprise Java Tools
|
|
| 3 |
*
|
|
| 4 |
* Distributable under LGPL license.
|
|
| 5 |
* See terms of license at www.gnu.org.
|
|
| 6 |
*/
|
|
| 7 |
package org.ejtools.util.state;
|
|
| 8 |
|
|
| 9 |
import java.lang.reflect.Method;
|
|
| 10 |
import java.util.HashMap;
|
|
| 11 |
import java.util.Iterator;
|
|
| 12 |
import java.util.Map;
|
|
| 13 |
import java.util.Stack;
|
|
| 14 |
import org.w3c.dom.Node;
|
|
| 15 |
|
|
| 16 |
import org.apache.log4j.Logger;
|
|
| 17 |
import org.ejtools.beans.Sort;
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
/**
|
|
| 21 |
* @author Laurent Etiemble
|
|
| 22 |
* @version $Revision: 1.2 $
|
|
| 23 |
*/
|
|
| 24 |
public class DefaultStoreVisitor implements StoreVisitor |
|
| 25 |
{
|
|
| 26 |
/** Description of the Field */
|
|
| 27 |
private Stack nodes = new Stack(); |
|
| 28 |
/** Description of the Field */
|
|
| 29 |
private Map persistMappings = new HashMap(); |
|
| 30 |
/** Description of the Field */
|
|
| 31 |
private static Logger logger = Logger.getLogger(DefaultStoreVisitor.class); |
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
/**Constructor for the ReflectivePersistenceStore object */
|
|
| 36 | 0 |
public DefaultStoreVisitor() { }
|
| 37 |
|
|
| 38 |
|
|
| 39 |
/**
|
|
| 40 |
* Description of the Method
|
|
| 41 |
*
|
|
| 42 |
* @param iterator Description of the Parameter
|
|
| 43 |
*/
|
|
| 44 | 0 |
public void persist(Iterator iterator) |
| 45 |
{
|
|
| 46 | 0 |
Iterator it = Sort.getChildrenByClass(iterator, Storable.class);
|
| 47 | 0 |
for (; it.hasNext(); )
|
| 48 |
{
|
|
| 49 | 0 |
Storable p = (Storable) it.next(); |
| 50 | 0 |
p.accept(this);
|
| 51 |
} |
|
| 52 |
} |
|
| 53 |
|
|
| 54 |
|
|
| 55 |
/**
|
|
| 56 |
* Description of the Method
|
|
| 57 |
*
|
|
| 58 |
* @param o Description of the Parameter
|
|
| 59 |
*/
|
|
| 60 | 0 |
public void persist(Object o) |
| 61 |
{
|
|
| 62 | 0 |
Class clazz = o.getClass(); |
| 63 | 0 |
Method m = (Method) this.persistMappings.get(clazz);
|
| 64 | 0 |
try
|
| 65 |
{
|
|
| 66 | 0 |
m.invoke(this, new Object[]{o}); |
| 67 |
} |
|
| 68 |
catch (Exception e)
|
|
| 69 |
{
|
|
| 70 | 0 |
logger.debug("Object of type " + o.getClass().getName() + " will not be persist"); |
| 71 |
} |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
|
|
| 75 |
/**
|
|
| 76 |
* Description of the Method
|
|
| 77 |
*
|
|
| 78 |
* @return Description of the Return Value
|
|
| 79 |
*/
|
|
| 80 | 0 |
protected Node peekCurrentNode()
|
| 81 |
{
|
|
| 82 | 0 |
return (Node) this.nodes.peek(); |
| 83 |
} |
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
/**
|
|
| 88 |
* Description of the Method
|
|
| 89 |
*
|
|
| 90 |
* @return Description of the Return Value
|
|
| 91 |
*/
|
|
| 92 | 0 |
protected Node popCurrentNode()
|
| 93 |
{
|
|
| 94 | 0 |
return (Node) this.nodes.pop(); |
| 95 |
} |
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
/**
|
|
| 100 |
* Description of the Method
|
|
| 101 |
*
|
|
| 102 |
* @param node Description of the Parameter
|
|
| 103 |
*/
|
|
| 104 | 0 |
protected void pushCurrentNode(Node node) |
| 105 |
{
|
|
| 106 | 0 |
this.nodes.push(node);
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
|
|
| 110 |
/**
|
|
| 111 |
* Description of the Method
|
|
| 112 |
*
|
|
| 113 |
* @param clazz Description of the Parameter
|
|
| 114 |
*/
|
|
| 115 | 0 |
public final void registerForPersistence(Class clazz) |
| 116 |
{
|
|
| 117 | 0 |
try
|
| 118 |
{
|
|
| 119 | 0 |
Method m = this.getClass().getMethod("persist", new Class[]{clazz}); |
| 120 | 0 |
this.persistMappings.put(clazz, m);
|
| 121 |
} |
|
| 122 |
catch (NoSuchMethodException nsme)
|
|
| 123 |
{
|
|
| 124 | 0 |
logger.warn("Can't register for persistence class " + clazz.getName());
|
| 125 |
} |
|
| 126 |
} |
|
| 127 |
} |
|
| 128 |
|
|
||||||||||