Thread: [Ejtools-cvs] libraries/common/src/main/org/ejtools/util/state DefaultRule.java,NONE,1.1 DefaultStor
Brought to you by:
letiemble
Update of /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util/state In directory sc8-pr-cvs1:/tmp/cvs-serv20661/common/src/main/org/ejtools/util/state Added Files: DefaultRule.java DefaultStoreVisitor.java LoadHandler.java Rule.java Storable.java StoreVisitor.java Log Message: Adjust Eclipse build files Adjust some Javadoc Integrate Persistence framework Integrate Image export as PNG --- NEW FILE: DefaultRule.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.util.state; import java.util.Map; /** * @author Laurent Etiemble * @version $Revision: 1.1 $ */ public class DefaultRule implements Rule { /** * Description of the Method * * @param context Description of the Parameter */ public void loadBody(Map context) { } /** * Description of the Method * * @param context Description of the Parameter */ public void loadEnter(Map context) { } /** * Description of the Method * * @param context Description of the Parameter */ public void loadExit(Map context) { } } --- NEW FILE: DefaultStoreVisitor.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.util.state; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Stack; import org.w3c.dom.Node; import org.apache.log4j.Logger; import org.ejtools.beans.Sort; /** * @author Laurent Etiemble * @version $Revision: 1.1 $ */ public class DefaultStoreVisitor implements StoreVisitor { /** Description of the Field */ private Stack nodes = new Stack(); /** Description of the Field */ private Map persistMappings = new HashMap(); /** Description of the Field */ private static Logger logger = Logger.getLogger(DefaultStoreVisitor.class); /**Constructor for the ReflectivePersistenceStore object */ public DefaultStoreVisitor() { } /** * Description of the Method * * @param iterator Description of the Parameter */ public void persist(Iterator iterator) { Iterator it = Sort.getChildrenByClass(iterator, Storable.class); for (; it.hasNext(); ) { Storable p = (Storable) it.next(); p.accept(this); } } /** * Description of the Method * * @param o Description of the Parameter */ public void persist(Object o) { Class clazz = o.getClass(); Method m = (Method) this.persistMappings.get(clazz); try { m.invoke(this, new Object[]{o}); } catch (Exception e) { logger.debug("Object of type " + o.getClass().getName() + " will not be persist"); } } /** * Description of the Method * * @return Description of the Return Value */ protected Node peekCurrentNode() { return (Node) this.nodes.peek(); } /** * Description of the Method * * @return Description of the Return Value */ protected Node popCurrentNode() { return (Node) this.nodes.pop(); } /** * Description of the Method * * @param node Description of the Parameter */ protected void pushCurrentNode(Node node) { this.nodes.push(node); } /** * Description of the Method * * @param clazz Description of the Parameter */ public final void registerForPersistence(Class clazz) { try { Method m = this.getClass().getMethod("persist", new Class[]{clazz}); this.persistMappings.put(clazz, m); } catch (NoSuchMethodException nsme) { logger.warn("Can't register for persistence class " + clazz.getName()); } } } --- NEW FILE: LoadHandler.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.util.state; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** * @author Laurent Etiemble * @version $Revision: 1.1 $ */ public class LoadHandler extends DefaultHandler { /** Description of the Field */ private Map context = new HashMap(); /** Description of the Field */ private String path = ""; /** Description of the Field */ private Map rules = new Hashtable(); /** Description of the Field */ public final static String ATTRIBUTES = "ATTRIBUTES"; /** Description of the Field */ public final static String ELEMENT = "ELEMENT"; /** Description of the Field */ public final static String TEXT = "TEXT"; /**Constructor for the WorkbenchHandler object */ public LoadHandler() { } /** * Adds a feature to the Rule attribute of the WorkbenchHandler object * * @param path The feature to be added to the Rule attribute * @param rule The feature to be added to the Rule attribute */ public void addRule(String path, Rule rule) { this.rules.put(path, rule); } /** * Description of the Method * * @param ch Description of the Parameter * @param start Description of the Parameter * @param length Description of the Parameter * @exception SAXException Description of the Exception */ public void characters(char[] ch, int start, int length) throws SAXException { String text = new String(ch, start, length); this.context.put("TEXT", text); Rule rule = (Rule) this.rules.get(this.path); if (rule != null) { rule.loadBody(this.context); } } /** * Description of the Method * * @param uri Description of the Parameter * @param localName Description of the Parameter * @param qName Description of the Parameter * @exception SAXException Description of the Exception */ public void endElement(String uri, String localName, String qName) throws SAXException { this.context.put("ELEMENT", qName); Rule rule = (Rule) this.rules.get(this.path); if (rule != null) { rule.loadExit(this.context); } this.path = this.path.substring(0, this.path.length() - qName.length() - 1); } /** * Gets the context attribute of the LoadHandler object * * @return The context value */ public Map getContext() { return this.context; } /** * Description of the Method * * @param uri Description of the Parameter * @param localName Description of the Parameter * @param qName Description of the Parameter * @param attributes Description of the Parameter * @exception SAXException Description of the Exception */ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { this.context.put("ELEMENT", qName); this.context.put("ATTRIBUTES", attributes); this.path = path + "/" + qName; Rule rule = (Rule) this.rules.get(this.path); if (rule != null) { rule.loadEnter(this.context); } } } --- NEW FILE: Rule.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.util.state; import java.util.Map; /** * @author Laurent Etiemble * @version $Revision: 1.1 $ */ public interface Rule { /** * Description of the Method * * @param context Description of the Parameter */ public void loadEnter(Map context); /** * Description of the Method * * @param context Description of the Parameter */ public void loadBody(Map context); /** * Description of the Method * * @param context Description of the Parameter */ public void loadExit(Map context); } --- NEW FILE: Storable.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.util.state; /** * @author Laurent Etiemble * @version $Revision: 1.1 $ */ public interface Storable { /** * Description of the Method * * @param visitor Description of the Parameter */ void accept(StoreVisitor visitor); } --- NEW FILE: StoreVisitor.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.util.state; import java.util.Iterator; /** * @author Laurent Etiemble * @version $Revision: 1.1 $ */ public interface StoreVisitor { /** * Description of the Method * * @param iterator Description of the Parameter */ void persist(Iterator iterator); /** * Description of the Method * * @param o Description of the Parameter */ void persist(Object o); /** * Description of the Method * * @param clazz Description of the Parameter */ void registerForPersistence(Class clazz); } |