Author: glandais Date: 2008-02-22 16:48:16 +0000 (Fri, 22 Feb 2008) New Revision: 1195 Removed: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/CodeFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ComponentFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ConstantFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ConstantValueFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ExplorationApplicationFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ExplorationDataFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LibraryFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/RepositoryFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ResultFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/StructureFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/XmlConstants.java Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ContentTypeFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/XMLStreamEncoder.java Log: Usage of XStream for XML serialization Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -17,389 +17,377 @@ * ##% */ package fr.cemagref.simexplorer.is.factories; -import java.io.InputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.thoughtworks.xstream.XStream; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.dom.DOMSource; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; - import fr.cemagref.simexplorer.is.entities.BaseEntity; -import fr.cemagref.simexplorer.is.entities.data.DataEntity; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerTechnicalException; /** * A factory for creating BaseEntity objects. * * @param <E> Entity type */ -public abstract class BaseEntityFactory<E extends BaseEntity> implements XmlConstants { +public abstract class BaseEntityFactory<E extends BaseEntity> { - /** The document builder. */ - private static DocumentBuilder documentBuilder = null; + private static XStream xstream = new XStream(); - /** The factories. */ - private static Map<String, BaseEntityFactory<? extends DataEntity>> factories = new HashMap<String, BaseEntityFactory<? extends DataEntity>>(); - - /* - * Static methods - Retrieve factories, get XML document builder - */ - - /** - * Retrieve instance of the factory. - * - * @param <E> Entity type - * - * @param entityClass Class wanted - * - * @return Factory - * - * @throws SimExplorerException the exception - */ - @SuppressWarnings("unchecked") - public static <E extends DataEntity> BaseEntityFactory<E> getFactory(Class entityClass) throws SimExplorerException { - BaseEntityFactory<E> result = (BaseEntityFactory<E>) factories.get(entityClass.getSimpleName()); - if (result == null) { - String elementFactoryClassName = BaseEntityFactory.class.getPackage().getName() + "." - + entityClass.getSimpleName() + FACTORY_SUFFIX; - - Class<? extends BaseEntityFactory<E>> factoryClass; - try { - factoryClass = (Class<? extends BaseEntityFactory<E>>) Class.forName(elementFactoryClassName) - .asSubclass(BaseEntityFactory.class); - result = factoryClass.newInstance(); - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); - } - - factories.put(entityClass.getSimpleName(), result); - } - return result; + public static XStream getXstream() { + return xstream; } + +// /** The document builder. */ +// private static DocumentBuilder documentBuilder = null; +// +// /** The factories. */ +// private static Map<String, BaseEntityFactory<? extends DataEntity>> factories = new HashMap<String, BaseEntityFactory<? extends DataEntity>>(); +// +// /* +// * Static methods - Retrieve factories, get XML document builder +// */ +// +// /** +// * Retrieve instance of the factory. +// * +// * @param <E> Entity type +// * +// * @param entityClass Class wanted +// * +// * @return Factory +// * +// * @throws SimExplorerException the exception +// */ +// @SuppressWarnings("unchecked") +// public static <E extends DataEntity> BaseEntityFactory<E> getFactory(Class entityClass) throws SimExplorerException { +// BaseEntityFactory<E> result = (BaseEntityFactory<E>) factories.get(entityClass.getSimpleName()); +// if (result == null) { +// String elementFactoryClassName = BaseEntityFactory.class.getPackage().getName() + "." +// + entityClass.getSimpleName() + FACTORY_SUFFIX; +// +// Class<? extends BaseEntityFactory<E>> factoryClass; +// try { +// factoryClass = (Class<? extends BaseEntityFactory<E>>) Class.forName(elementFactoryClassName) +// .asSubclass(BaseEntityFactory.class); +// result = factoryClass.newInstance(); +// } catch (Exception e) { +// throw new SimExplorerTechnicalException(e); +// } +// +// factories.put(entityClass.getSimpleName(), result); +// } +// return result; +// } +// +// /** +// * Retrieve a factory with class name. +// * +// * @param entityClassName the entity class name +// * +// * @return the factory +// * +// * @throws SimExplorerException the exception +// */ +// public static BaseEntityFactory<? extends DataEntity> getFactory(String entityClassName) +// throws SimExplorerException { +// Class<? extends DataEntity> entityClass; +// try { +// entityClass = Class.forName(entityClassName).asSubclass(DataEntity.class); +// } catch (ClassNotFoundException e) { +// throw new SimExplorerTechnicalException(e); +// } +// return getFactory(entityClass); +// } +// +// /** +// * Retrieve an instance of document builder. +// * +// * @return XML document builder +// * @throws ParserConfigurationException +// * +// */ +// public static synchronized DocumentBuilder getXMLBuilder() throws ParserConfigurationException { +// if (documentBuilder == null) { +// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); +// documentBuilder = factory.newDocumentBuilder(); +// return documentBuilder; +// } +// return documentBuilder; +// } +// +// /* +// * Entity methods - Instanciate, load and save to XML/streams +// */ +// +// /** +// * Instanciate an element. +// * +// * @return Element +// */ +// public abstract E createInstance(); +// +// /** +// * Load an element from an XML node. +// * +// * @param xmlElement the xml element +// * +// * @return the E +// * +// * @throws SimExplorerException the exception +// */ +// public E loadElement(Element xmlElement) throws SimExplorerException { +// E element = createInstance(); +// return element; +// } +// +// /** +// * Load an element from a XML stream. +// * +// * @param stream the stream +// * +// * @return the E +// * +// * @throws SimExplorerException the exception +// */ +// public E loadElement(InputStream stream) throws SimExplorerException { +// Element rootElement; +// try { +// Document document = getXMLBuilder().parse(stream); +// rootElement = (Element) document.getFirstChild(); +// } catch (Exception e) { +// throw new SimExplorerTechnicalException(e); +// } +// E element = loadElement(rootElement); +// return element; +// } +// +// /** +// * Save an element to a XML node. +// * +// * @param document XML document +// * @param xmlElement XML node storing the element (not null) +// * @param element Element to save +// * +// * @throws SimExplorerException the exception +// */ +// public abstract void saveElement(Document document, Element xmlElement, E element) throws SimExplorerException; +// +// /** +// * Save an element to a XML stream. +// * +// * @param rootNodeName the root node name +// * @param element the element +// * +// * @return the input stream +// * +// * @throws SimExplorerException the exception +// */ +// public InputStream saveElement(String rootNodeName, E element) throws SimExplorerException { +// Document xmlDocument; +// Element rootNode; +// try { +// xmlDocument = getXMLBuilder().newDocument(); +// // DOM properties +// xmlDocument.setXmlVersion("1.0"); +// xmlDocument.setXmlStandalone(true); +// // DOM tree +// rootNode = xmlDocument.createElement(rootNodeName); +// } catch (Exception e) { +// throw new SimExplorerTechnicalException(e); +// } +// saveElement(xmlDocument, rootNode, element); +// try { +// xmlDocument.appendChild(rootNode); +// DOMSource domSource = new DOMSource(xmlDocument); +// +// PipedOutputStream os = new PipedOutputStream(); +// PipedInputStream is = new PipedInputStream(os); +// +// XMLStreamEncoder xse = new XMLStreamEncoder(domSource, os); +// xse.start(); +// +// return is; +// } catch (Exception e) { +// throw new SimExplorerTechnicalException(e); +// } +// } +// +// /* +// * Collection methods : Help load/save of inner collections +// */ +// +// /** +// * Load a collection inside a node. +// * +// * @param <T> Entity type +// * +// * @param tagSetName Tag of the node of the collection +// * @param tagName Tag of the node containing an item +// * @param clazz Class type +// * @param xmlElement Node containing the collection +// * @param parentData Element holding the collection +// * +// * @return the set< t> +// * +// * @throws SimExplorerException the exception +// */ +// public <T extends DataEntity> List<T> loadCollection(String tagSetName, String tagName, Class<T> clazz, +// Element xmlElement, DataEntity parentData) throws SimExplorerException { +// List<T> entities = new ArrayList<T>(); +// +// // Retrieve XML node containing the collection +// Element xmlCollection = getXMLElementByTagName(xmlElement, tagSetName); +// if (xmlCollection != null) { +// // Retrieve element factory +// BaseEntityFactory<T> elementFactory = getFactory(clazz); +// +// // Retrieve all XML elements +// List<Element> list = getXMLElementsByTagName(xmlCollection, tagName); +// for (Element element : list) { +// // Convert the XML node to entity +// T entity = elementFactory.loadElement(element); +// entity.setParentData(parentData); +// entities.add(entity); +// } +// } +// +// return entities; +// } +// +// /** +// * Save a collection of elements to XML node. +// * +// * @param <T> Entity type +// * +// * @param entities the entities +// * @param tagSetName the tag set name +// * @param tagName the tag name +// * @param clazz the clazz +// * @param document the document +// * @param xmlElement the xml element +// * +// * @throws SimExplorerException the exception +// */ +// public <T extends DataEntity> void saveCollection(List<T> entities, String tagSetName, String tagName, +// Class<T> clazz, Document document, Element xmlElement) throws SimExplorerException { +// if (entities != null && entities.size() > 0) { +// Element xmlCollection = document.createElement(tagSetName); +// BaseEntityFactory<T> elementFactory = getFactory(clazz); +// for (T entity : entities) { +// Element childElement = document.createElement(tagName); +// elementFactory.saveElement(document, childElement, entity); +// xmlCollection.appendChild(childElement); +// } +// xmlElement.appendChild(xmlCollection); +// } +// } +// +// /** +// * Save an element as a XML stream. +// * +// * @param node the node +// * +// * @return the input stream +// * +// * @throws SimExplorerException the exception +// */ +// public static InputStream serializeElement(Node node) throws SimExplorerException { +// try { +// Document xmlDocument = getXMLBuilder().newDocument(); +// // DOM properties +// xmlDocument.setXmlVersion("1.0"); +// xmlDocument.setXmlStandalone(true); +// // DOM tree +// xmlDocument.appendChild(xmlDocument.importNode(node, true)); +// DOMSource domSource = new DOMSource(xmlDocument); +// +// PipedOutputStream os = new PipedOutputStream(); +// PipedInputStream is = new PipedInputStream(os); +// +// XMLStreamEncoder xse = new XMLStreamEncoder(domSource, os); +// xse.start(); +// +// return is; +// } catch (Exception e) { +// throw new SimExplorerTechnicalException(e); +// } +// } +// +// /* +// * XML methods : set, get properties +// */ +// +// /** +// * Set a property in XML. +// * +// * @param document XML document +// * @param xmlElement Node to modify +// * @param tagName Tag of created node +// * @param value Value of node +// */ +// protected void setXMLProperty(Document document, Element xmlElement, String tagName, Object value) { +// if (value != null) { +// Element xmlProperty = document.createElement(tagName); +// Text xmlDescriptionText = document.createTextNode(value.toString()); +// xmlProperty.appendChild(xmlDescriptionText); +// xmlElement.appendChild(xmlProperty); +// } +// } +// +// /** +// * Get a property in XML. +// * +// * @param xmlElement Source node +// * @param tagName Tag name of property +// * +// * @return Property value +// */ +// public String getXMLProperty(Element xmlElement, String tagName) { +// Element element = getXMLElementByTagName(xmlElement, tagName); +// if (element != null) { +// return element.getFirstChild().getNodeValue(); +// } +// return null; +// } +// +// /* +// * XML methods : retrieve nodes +// */ +// +// /** +// * Retrieve XML element just under with specified tag name. +// * +// * @param xmlElement the xml element +// * @param tagName the tag name +// * +// * @return First child element with tagName +// */ +// public Element getXMLElementByTagName(Element xmlElement, String tagName) { +// List<Element> elements = getXMLElementsByTagName(xmlElement, tagName); +// if (elements.size() > 0) { +// return elements.iterator().next(); +// } +// return null; +// } +// +// /** +// * Retrieve all XML elements just under with specified tag name. +// * +// * @param xmlElement the xml element +// * @param tagName the tag name +// * +// * @return Children with tagName +// */ +// public List<Element> getXMLElementsByTagName(Element xmlElement, String tagName) { +// List<Element> elements = new ArrayList<Element>(); +// +// NodeList nodes = xmlElement.getChildNodes(); +// for (int i = 0; i < nodes.getLength(); i++) { +// Node node = nodes.item(i); +// if (node instanceof Element && tagName.equals(((Element) node).getTagName())) { +// elements.add((Element) node); +// } +// } +// return elements; +// } - /** - * Retrieve a factory with class name. - * - * @param entityClassName the entity class name - * - * @return the factory - * - * @throws SimExplorerException the exception - */ - public static BaseEntityFactory<? extends DataEntity> getFactory(String entityClassName) - throws SimExplorerException { - Class<? extends DataEntity> entityClass; - try { - entityClass = Class.forName(entityClassName).asSubclass(DataEntity.class); - } catch (ClassNotFoundException e) { - throw new SimExplorerTechnicalException(e); - } - return getFactory(entityClass); - } - /** - * Retrieve an instance of document builder. - * - * @return XML document builder - * @throws ParserConfigurationException - * - */ - public static synchronized DocumentBuilder getXMLBuilder() throws ParserConfigurationException { - if (documentBuilder == null) { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - documentBuilder = factory.newDocumentBuilder(); - return documentBuilder; - } - return documentBuilder; - } - /* - * Entity methods - Instanciate, load and save to XML/streams - */ - - /** - * Instanciate an element. - * - * @return Element - */ - public abstract E createInstance(); - - /** - * Load an element from an XML node. - * - * @param xmlElement the xml element - * - * @return the E - * - * @throws SimExplorerException the exception - */ - public E loadElement(Element xmlElement) throws SimExplorerException { - E element = createInstance(); - return element; - } - - /** - * Load an element from a XML stream. - * - * @param stream the stream - * - * @return the E - * - * @throws SimExplorerException the exception - */ - public E loadElement(InputStream stream) throws SimExplorerException { - Element rootElement; - try { - Document document = getXMLBuilder().parse(stream); - rootElement = (Element) document.getFirstChild(); - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); - } - E element = loadElement(rootElement); - return element; - } - - /** - * Save an element to a XML node. - * - * @param document XML document - * @param xmlElement XML node storing the element (not null) - * @param element Element to save - * - * @throws SimExplorerException the exception - */ - public abstract void saveElement(Document document, Element xmlElement, E element) throws SimExplorerException; - - /** - * Save an element to a XML stream. - * - * @param rootNodeName the root node name - * @param element the element - * - * @return the input stream - * - * @throws SimExplorerException the exception - */ - public InputStream saveElement(String rootNodeName, E element) throws SimExplorerException { - Document xmlDocument; - Element rootNode; - try { - xmlDocument = getXMLBuilder().newDocument(); - // DOM properties - xmlDocument.setXmlVersion("1.0"); - xmlDocument.setXmlStandalone(true); - // DOM tree - rootNode = xmlDocument.createElement(rootNodeName); - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); - } - saveElement(xmlDocument, rootNode, element); - try { - xmlDocument.appendChild(rootNode); - DOMSource domSource = new DOMSource(xmlDocument); - - PipedOutputStream os = new PipedOutputStream(); - PipedInputStream is = new PipedInputStream(os); - - XMLStreamEncoder xse = new XMLStreamEncoder(domSource, os); - xse.start(); - - return is; - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); - } - } - - /* - * Collection methods : Help load/save of inner collections - */ - - /** - * Load a collection inside a node. - * - * @param <T> Entity type - * - * @param tagSetName Tag of the node of the collection - * @param tagName Tag of the node containing an item - * @param clazz Class type - * @param xmlElement Node containing the collection - * @param parentData Element holding the collection - * - * @return the set< t> - * - * @throws SimExplorerException the exception - */ - public <T extends DataEntity> List<T> loadCollection(String tagSetName, String tagName, Class<T> clazz, - Element xmlElement, DataEntity parentData) throws SimExplorerException { - List<T> entities = new ArrayList<T>(); - - // Retrieve XML node containing the collection - Element xmlCollection = getXMLElementByTagName(xmlElement, tagSetName); - if (xmlCollection != null) { - // Retrieve element factory - BaseEntityFactory<T> elementFactory = getFactory(clazz); - - // Retrieve all XML elements - List<Element> list = getXMLElementsByTagName(xmlCollection, tagName); - for (Element element : list) { - // Convert the XML node to entity - T entity = elementFactory.loadElement(element); - entity.setParentData(parentData); - entities.add(entity); - } - } - - return entities; - } - - /** - * Save a collection of elements to XML node. - * - * @param <T> Entity type - * - * @param entities the entities - * @param tagSetName the tag set name - * @param tagName the tag name - * @param clazz the clazz - * @param document the document - * @param xmlElement the xml element - * - * @throws SimExplorerException the exception - */ - public <T extends DataEntity> void saveCollection(List<T> entities, String tagSetName, String tagName, - Class<T> clazz, Document document, Element xmlElement) throws SimExplorerException { - if (entities != null && entities.size() > 0) { - Element xmlCollection = document.createElement(tagSetName); - BaseEntityFactory<T> elementFactory = getFactory(clazz); - for (T entity : entities) { - Element childElement = document.createElement(tagName); - elementFactory.saveElement(document, childElement, entity); - xmlCollection.appendChild(childElement); - } - xmlElement.appendChild(xmlCollection); - } - } - - /** - * Save an element as a XML stream. - * - * @param node the node - * - * @return the input stream - * - * @throws SimExplorerException the exception - */ - public static InputStream serializeElement(Node node) throws SimExplorerException { - try { - Document xmlDocument = getXMLBuilder().newDocument(); - // DOM properties - xmlDocument.setXmlVersion("1.0"); - xmlDocument.setXmlStandalone(true); - // DOM tree - xmlDocument.appendChild(xmlDocument.importNode(node, true)); - DOMSource domSource = new DOMSource(xmlDocument); - - PipedOutputStream os = new PipedOutputStream(); - PipedInputStream is = new PipedInputStream(os); - - XMLStreamEncoder xse = new XMLStreamEncoder(domSource, os); - xse.start(); - - return is; - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); - } - } - - /* - * XML methods : set, get properties - */ - - /** - * Set a property in XML. - * - * @param document XML document - * @param xmlElement Node to modify - * @param tagName Tag of created node - * @param value Value of node - */ - protected void setXMLProperty(Document document, Element xmlElement, String tagName, Object value) { - if (value != null) { - Element xmlProperty = document.createElement(tagName); - Text xmlDescriptionText = document.createTextNode(value.toString()); - xmlProperty.appendChild(xmlDescriptionText); - xmlElement.appendChild(xmlProperty); - } - } - - /** - * Get a property in XML. - * - * @param xmlElement Source node - * @param tagName Tag name of property - * - * @return Property value - */ - public String getXMLProperty(Element xmlElement, String tagName) { - Element element = getXMLElementByTagName(xmlElement, tagName); - if (element != null) { - return element.getFirstChild().getNodeValue(); - } - return null; - } - - /* - * XML methods : retrieve nodes - */ - - /** - * Retrieve XML element just under with specified tag name. - * - * @param xmlElement the xml element - * @param tagName the tag name - * - * @return First child element with tagName - */ - public Element getXMLElementByTagName(Element xmlElement, String tagName) { - List<Element> elements = getXMLElementsByTagName(xmlElement, tagName); - if (elements.size() > 0) { - return elements.iterator().next(); - } - return null; - } - - /** - * Retrieve all XML elements just under with specified tag name. - * - * @param xmlElement the xml element - * @param tagName the tag name - * - * @return Children with tagName - */ - public List<Element> getXMLElementsByTagName(Element xmlElement, String tagName) { - List<Element> elements = new ArrayList<Element>(); - - NodeList nodes = xmlElement.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node instanceof Element && tagName.equals(((Element) node).getTagName())) { - elements.add((Element) node); - } - } - return elements; - } - } Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/CodeFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/CodeFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/CodeFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,62 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import fr.cemagref.simexplorer.is.entities.data.Code; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - -/** - * A factory for creating Code objects. - * @param <E> Code - */ -public class CodeFactory<E extends Code> extends BaseEntityFactory<Code> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public Code createInstance() { - return new Code(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#loadElement(org.w3c.dom.Element) - */ - @Override - public Code loadElement(Element xmlElement) throws SimExplorerException { - Code code = super.loadElement(xmlElement); - code.setLanguage(getXMLProperty(xmlElement, KEY_CODE_LANGUAGE)); - code.setCode(getXMLProperty(xmlElement, KEY_CODE_CODE)); - return code; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) - */ - @Override - public void saveElement(Document document, Element xmlElement, Code element) - throws SimExplorerException { - setXMLProperty(document, xmlElement, KEY_CODE_LANGUAGE, element - .getLanguage()); - setXMLProperty(document, xmlElement, KEY_CODE_CODE, element.getCode()); - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ComponentFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ComponentFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ComponentFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,88 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import fr.cemagref.simexplorer.is.entities.data.Code; -import fr.cemagref.simexplorer.is.entities.data.Component; -import fr.cemagref.simexplorer.is.entities.data.Constant; -import fr.cemagref.simexplorer.is.entities.data.Library; -import fr.cemagref.simexplorer.is.entities.data.Structure; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - -/** - * A factory for creating Component objects. - * @param <E> Component - */ -public class ComponentFactory<E extends Component> extends - LoggableElementFactory<Component> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public Component createInstance() { - return new Component(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.LoggableElementFactory#loadElement(org.w3c.dom.Element) - */ - @Override - public Component loadElement(Element xmlElement) throws SimExplorerException { - Component component = super.loadElement(xmlElement); - - component.setConstants(loadCollection(KEY_COMPONENT_CONSTANTS, - KEY_COMPONENT_CONSTANT_NODE, Constant.class, xmlElement, - component)); - component.setStructures(loadCollection(KEY_COMPONENT_STRUCTURE, - KEY_COMPONENT_STRUCTURE_NODE, Structure.class, xmlElement, - component)); - component.setCodes(loadCollection(KEY_COMPONENT_CODES, - KEY_COMPONENT_CODE_NODE, Code.class, xmlElement, component)); - component.setLibraries(loadCollection(KEY_COMPONENT_LIBRARIES, - KEY_COMPONENT_LIBRARY_NODE, Library.class, xmlElement, - component)); - - return component; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.LoggableElementFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.data.LoggableElement) - */ - @Override - public void saveElement(Document document, Element xmlElement, - Component element) throws SimExplorerException { - - super.saveElement(document, xmlElement, element); - - saveCollection(element.getConstants(), KEY_COMPONENT_CONSTANTS, - KEY_COMPONENT_CONSTANT_NODE, Constant.class, document, - xmlElement); - saveCollection(element.getStructures(), KEY_COMPONENT_STRUCTURE, - KEY_COMPONENT_STRUCTURE_NODE, Structure.class, document, - xmlElement); - saveCollection(element.getCodes(), KEY_COMPONENT_CODES, - KEY_COMPONENT_CODE_NODE, Code.class, document, xmlElement); - saveCollection(element.getLibraries(), KEY_COMPONENT_LIBRARIES, - KEY_COMPONENT_LIBRARY_NODE, Library.class, document, xmlElement); - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ConstantFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ConstantFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ConstantFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,70 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import fr.cemagref.simexplorer.is.entities.data.Constant; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerTechnicalException; - -/** - * A factory for creating Constant objects. - * @param <E> Constant - */ -public class ConstantFactory<E extends Constant> extends - BaseEntityFactory<Constant> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public Constant createInstance() { - return new Constant(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#loadElement(org.w3c.dom.Element) - */ - @Override - public Constant loadElement(Element xmlElement) throws SimExplorerException { - Constant constant = super.loadElement(xmlElement); - constant.setName(getXMLProperty(xmlElement, KEY_CONSTANT_NAME)); - String className = getXMLProperty(xmlElement, KEY_CONSTANT_TYPE); - try { - constant.setType(Class.forName(className)); - } catch (ClassNotFoundException e) { - throw new SimExplorerTechnicalException(e); - } - return constant; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) - */ - @Override - public void saveElement(Document document, Element xmlElement, - Constant element) throws SimExplorerException { - setXMLProperty(document, xmlElement, KEY_CONSTANT_NAME, element - .getName()); - String className = element.getType().getName(); - setXMLProperty(document, xmlElement, KEY_CONSTANT_TYPE, className); - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ConstantValueFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ConstantValueFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ConstantValueFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,74 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import fr.cemagref.simexplorer.is.entities.data.Constant; -import fr.cemagref.simexplorer.is.entities.data.ConstantValue; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - -/** - * A factory for creating ConstantValue objects. - * @param <E> ConstantValue - */ -public class ConstantValueFactory<E extends ConstantValue> extends - BaseEntityFactory<ConstantValue> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public ConstantValue createInstance() { - return new ConstantValue(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#loadElement(org.w3c.dom.Element) - */ - @Override - public ConstantValue loadElement(Element xmlElement) throws SimExplorerException { - ConstantValue constantValue = super.loadElement(xmlElement); - constantValue.setConstant((Constant) getFactory(Constant.class) - .loadElement( - getXMLElementByTagName(xmlElement, - KEY_CONSTANTVALUE_CONSTANT))); - constantValue.setValue(getXMLProperty(xmlElement, - KEY_CONSTANTVALUE_VALUE)); - return constantValue; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) - */ - @Override - public void saveElement(Document document, Element xmlElement, - ConstantValue element) throws SimExplorerException { - - Element xmlConstant = document - .createElement(KEY_CONSTANTVALUE_CONSTANT); - getFactory(Constant.class).saveElement(document, xmlConstant, - element.getConstant()); - xmlElement.appendChild(xmlConstant); - - setXMLProperty(document, xmlElement, KEY_CONSTANTVALUE_VALUE, element - .getValue()); - } - -} Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ContentTypeFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ContentTypeFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ContentTypeFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -17,11 +17,11 @@ * ##% */ package fr.cemagref.simexplorer.is.factories; -import fr.cemagref.simexplorer.is.entities.attachment.ContentType; - import java.util.HashMap; import java.util.Map; +import fr.cemagref.simexplorer.is.entities.attachment.ContentType; + /** * Cache content types. * Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ExplorationApplicationFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ExplorationApplicationFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ExplorationApplicationFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,78 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import fr.cemagref.simexplorer.is.entities.data.Component; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.ExplorationData; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - -/** - * A factory for creating ExplorationApplication objects. - */ -public class ExplorationApplicationFactory extends - LoggableElementFactory<ExplorationApplication> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public ExplorationApplication createInstance() { - return new ExplorationApplication(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.LoggableElementFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.data.LoggableElement) - */ - @Override - public void saveElement(Document document, Element xmlElement, - ExplorationApplication element) throws SimExplorerException { - super.saveElement(document, xmlElement, element); - saveCollection(element.getExplorations(), - KEY_EXPLORATIONAPPLICATION_DATA, - KEY_EXPLORATIONAPPLICATION_DATA_NODE, ExplorationData.class, - document, xmlElement); - saveCollection(element.getComponents(), - KEY_EXPLORATIONAPPLICATION_COMPONENTS, - KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE, Component.class, - document, xmlElement); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.LoggableElementFactory#loadElement(org.w3c.dom.Element) - */ - @Override - public ExplorationApplication loadElement(Element xmlElement) - throws SimExplorerException { - ExplorationApplication explorationApplication = super - .loadElement(xmlElement); - explorationApplication.setExplorations(loadCollection( - KEY_EXPLORATIONAPPLICATION_DATA, - KEY_EXPLORATIONAPPLICATION_DATA_NODE, ExplorationData.class, - xmlElement, explorationApplication)); - explorationApplication.setComponents(loadCollection( - KEY_EXPLORATIONAPPLICATION_COMPONENTS, - KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE, Component.class, - xmlElement, explorationApplication)); - return explorationApplication; - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ExplorationDataFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ExplorationDataFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ExplorationDataFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,77 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import fr.cemagref.simexplorer.is.entities.data.ConstantValue; -import fr.cemagref.simexplorer.is.entities.data.ExplorationData; -import fr.cemagref.simexplorer.is.entities.data.Result; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - -/** - * A factory for creating ExplorationData objects. - */ -public class ExplorationDataFactory extends - LoggableElementFactory<ExplorationData> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public ExplorationData createInstance() { - return new ExplorationData(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.LoggableElementFactory#loadElement(org.w3c.dom.Element) - */ - @Override - public ExplorationData loadElement(Element xmlElement) throws SimExplorerException { - ExplorationData explorationData = super.loadElement(xmlElement); - explorationData.setResult((Result) getFactory(Result.class) - .loadElement( - getXMLElementByTagName(xmlElement, - KEY_EXPLORATIONDATA_RESULT))); - explorationData.setConstantValues(loadCollection(KEY_EXPLORATIONDATA_VALUES, - KEY_EXPLORATIONDATA_VALUE, ConstantValue.class, xmlElement, - explorationData)); - return explorationData; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.LoggableElementFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.data.LoggableElement) - */ - @Override - public void saveElement(Document document, Element xmlElement, - ExplorationData element) throws SimExplorerException { - super.saveElement(document, xmlElement, element); - - Element xmlResult = document.createElement(KEY_EXPLORATIONDATA_RESULT); - getFactory(Result.class).saveElement(document, xmlResult, - element.getResult()); - xmlElement.appendChild(xmlResult); - - saveCollection(element.getConstantValues(), KEY_EXPLORATIONDATA_VALUES, - KEY_EXPLORATIONDATA_VALUE, ConstantValue.class, document, - xmlElement); - - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LibraryFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LibraryFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LibraryFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,35 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import fr.cemagref.simexplorer.is.entities.data.Library; - -/** - * A factory for creating Library objects. - */ -public class LibraryFactory extends LoggableElementFactory<Library> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public Library createInstance() { - return new Library(); - } - -} Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/LoggableElementFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -17,11 +17,13 @@ * ##% */ package fr.cemagref.simexplorer.is.factories; -import org.w3c.dom.Element; +import java.io.IOException; +import java.io.InputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; +import fr.cemagref.simexplorer.is.exceptions.SimExplorerTechnicalException; /** * A factory for creating LoggableElement objects. @@ -32,37 +34,39 @@ public abstract class LoggableElementFactory<E extends LoggableElement> extends BaseEntityFactory<E> { - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#loadElement(org.w3c.dom.Element) + /** + * Parses the stream. + * + * @param xmlData the xml data + * + * @return the loggable element */ - @Override - public E loadElement(Element xmlElement) throws SimExplorerException { - E element = super.loadElement(xmlElement); - - MetaDataFactory<MetaData> elementFactory = MetaDataFactory - .getFactory(MetaData.class); - - // Load metadata informations - Element mdeElement = getXMLElementByTagName(xmlElement, KEY_METADATA); - MetaData metaData = elementFactory.loadElement(mdeElement); - element.setMetaData(metaData); - - return element; + public static LoggableElement parseStream(InputStream xmlData) { + return (LoggableElement) getXstream().fromXML(xmlData); } - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) + /** + * Gets the stream. + * + * @param element the element + * + * @return the stream + * + * @throws SimExplorerTechnicalException the sim explorer technical exception */ - @Override - public void saveElement(org.w3c.dom.Document document, Element xmlElement, - E element) throws SimExplorerException { - MetaDataFactory<MetaData> elementFactory = MetaDataFactory - .getFactory(MetaData.class); + public static InputStream getStream(LoggableElement element) throws SimExplorerTechnicalException { + PipedOutputStream os = new PipedOutputStream(); + PipedInputStream is; + try { + is = new PipedInputStream(os); + } catch (IOException e) { + throw new SimExplorerTechnicalException(e); + } - // Save metadata informations - Element mdeElement = document.createElement(KEY_METADATA); - elementFactory.saveElement(document, mdeElement, element.getMetaData()); - xmlElement.appendChild(mdeElement); + XMLStreamEncoder xse = new XMLStreamEncoder(element, os); + xse.start(); + + return is; } } Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -57,306 +57,306 @@ /** The Constant sdf. */ private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public MetaData createInstance() { - return new MetaData(); - } +// /* (non-Javadoc) +// * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() +// */ +// @Override +// public MetaData createInstance() { +// return new MetaData(); +// } +// +// /** +// * Gets the factory. +// * +// * @param <E> Metadata +// * +// * @param entityClass the entity class +// * +// * @return the factory +// * +// * @throws SimExplorerException the exception +// */ +// @SuppressWarnings( { "unchecked" }) +// public static <E extends MetaData> MetaDataFactory<E> getFactory(Class<E> entityClass) throws SimExplorerException { +// return (MetaDataFactory) BaseEntityFactory.getFactory(entityClass); +// } +// +// /* +// * (non-Javadoc) +// * +// * @see fr.cemagref.simexplorer.is.storage.factories.BaseEntityFactory#loadXMLElement(org.w3c.dom.Element) +// */ +// +// @Override +// public MetaData loadElement(Element xmlElement) throws SimExplorerException { +// MetaData entity = super.loadElement(xmlElement); +// entity.setUuid(getXMLProperty(xmlElement, KEY_METADATA_UUID)); +// entity.setName(getXMLProperty(xmlElement, KEY_METADATA_NAME)); +// entity.setType(getXMLProperty(xmlElement, KEY_METADATA_TYPE)); +// entity.setDescription(getXMLProperty(xmlElement, KEY_METADATA_DESCRIPTION)); +// entity.setVersion(getXMLProperty(xmlElement, KEY_METADATA_VERSION)); +// +// String latestVersion = getXMLProperty(xmlElement, KEY_METADATA_LATESTVERSION); +// if (latestVersion != null && "1".equals(latestVersion)) { +// entity.setLatest(true); +// } else { +// entity.setLatest(false); +// } +// +// String creationDate = getXMLProperty(xmlElement, KEY_METADATA_CREATIONDATE); +// if (creationDate != null) { +// Date date; +// try { +// date = sdf.parse(creationDate); +// } catch (ParseException e) { +// throw new SimExplorerTechnicalException(e); +// } +// entity.setCreationDate(date); +// } +// +// entity.setHash(getXMLProperty(xmlElement, KEY_METADATA_HASH)); +// entity.setParentVersionUuid(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_UUID)); +// entity.setParentVersionVersion(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_VERSION)); +// +// Map<String, String> descriptors = new HashMap<String, String>(); +// +// Element descriptorsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_DESCRIPTORS); +// if (descriptorsElement != null) { +// List<Element> descriptorElements = getXMLElementsByTagName(descriptorsElement, KEY_METADATA_DESCRIPTOR); +// for (Element descriptorElement : descriptorElements) { +// String name = getXMLProperty(descriptorElement, KEY_METADATA_DESCRIPTOR_NAME); +// String value = getXMLProperty(descriptorElement, KEY_METADATA_DESCRIPTOR_VALUE); +// descriptors.put(name, value); +// } +// } +// entity.setDescriptors(descriptors); +// +// List<Attachment> attachments = new ArrayList<Attachment>(); +// +// Element attachmentsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_ATTACHMENTS); +// if (attachmentsElement != null) { +// List<Element> attachmentElements = getXMLElementsByTagName(attachmentsElement, KEY_METADATA_ATTACHMENT); +// for (Element attachmentElement : attachmentElements) { +// Attachment attachment = new Attachment(); +// +// String name = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_NAME); +// attachment.setFileName(name); +// +// String type = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_TYPE); +// ContentType contentType = ContentTypeFactory.getContentTypeInstance(type); +// attachment.setContentType(contentType); +// +// String dataHash = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_HASH); +// attachment.setDataHash(dataHash); +// +// attachments.add(attachment); +// } +// } +// +// entity.setAttachments(attachments); +// +// return entity; +// } +// +// /* (non-Javadoc) +// * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) +// */ +// @Override +// public void saveElement(Document document, Element xmlElement, MetaData element) throws SimExplorerException { +// +// setXMLProperty(document, xmlElement, KEY_METADATA_UUID, element.getUuid()); +// setXMLProperty(document, xmlElement, KEY_METADATA_NAME, element.getName()); +// setXMLProperty(document, xmlElement, KEY_METADATA_TYPE, element.getType()); +// setXMLProperty(document, xmlElement, KEY_METADATA_DESCRIPTION, element.getDescription()); +// setXMLProperty(document, xmlElement, KEY_METADATA_VERSION, element.getVersion().toString()); +// +// if (element.isLatest()) { +// setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, "1"); +// } else { +// setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, "0"); +// } +// +// if (element.getCreationDate() != null) { +// setXMLProperty(document, xmlElement, KEY_METADATA_CREATIONDATE, sdf.format(element.getCreationDate())); +// } +// +// setXMLProperty(document, xmlElement, KEY_METADATA_HASH, element.getHash()); +// setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_UUID, element.getParentVersionUuid()); +// setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_VERSION, element.getParentVersionVersion()); +// +// Map<String, String> descriptors = element.getDescriptors(); +// +// Element descriptorsElement = document.createElement(KEY_METADATA_DESCRIPTORS); +// +// for (Map.Entry<String, String> kv : descriptors.entrySet()) { +// Element descriptorElement = document.createElement(KEY_METADATA_DESCRIPTOR); +// setXMLProperty(document, descriptorElement, KEY_METADATA_DESCRIPTOR_NAME, kv.getKey()); +// setXMLProperty(document, descriptorElement, KEY_METADATA_DESCRIPTOR_VALUE, kv.getValue()); +// descriptorsElement.appendChild(descriptorElement); +// } +// +// xmlElement.appendChild(descriptorsElement); +// +// List<Attachment> attachments = element.getAttachments(); +// +// if (attachments != null) { +// +// Element attachmentsElement = document.createElement(KEY_METADATA_ATTACHMENTS); +// +// for (Attachment attachment : attachments) { +// Element attachmentElement = document.createElement(KEY_METADATA_ATTACHMENT); +// +// setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_NAME, attachment.getFileName()); +// setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_TYPE, attachment.getContentType() +// .getClass().getSimpleName()); +// setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_HASH, attachment.getDataHash()); +// +// attachmentsElement.appendChild(attachmentElement); +// } +// xmlElement.appendChild(attachmentsElement); +// +// } +// +// } +// +// /** +// * As metadata is stored inside an entity, this method loads metadata with parsing stream and retrieve metadata +// * node. +// * +// * @param node the node +// * +// * @return the meta data +// * +// * @throws SimExplorerException the exception +// */ +// public MetaData loadElementFromParentXML(Element node) throws SimExplorerException { +// Element mdeElement = getXMLElementByTagName(node, KEY_METADATA); +// MetaData mde; +// try { +// mde = loadElement(mdeElement); +// } catch (SimExplorerException e) { +// throw new SimExplorerTechnicalException(e); +// } +// return mde; +// } +// +// /** +// * Replace element in parent xml. +// * +// * @param xmlStream the xml stream +// * @param newMetadata the new metadata +// * +// * @return the input stream +// * +// * @throws SimExplorerException the exception +// */ +// public InputStream modifyMedataElementStream(InputStream xmlStream, MetaData newMetadata) +// throws SimExplorerException { +// Document document; +// Element rootElement; +// Element newElement; +// try { +// document = getXMLBuilder().parse(xmlStream); +// rootElement = (Element) document.getFirstChild(); +// newElement = document.createElement(KEY_METADATA); +// } catch (Exception e) { +// throw new SimExplorerTechnicalException(e); +// } +// this.saveElement(document, newElement, newMetadata); +// Element oldElement = getXMLElementByTagName(rootElement, KEY_METADATA); +// rootElement.replaceChild(newElement, oldElement); +// +// DOMSource domSource = new DOMSource(document); +// +// try { +// PipedOutputStream os = new PipedOutputStream(); +// PipedInputStream is = new PipedInputStream(os); +// +// XMLStreamEncoder xse = new XMLStreamEncoder(domSource, os); +// xse.start(); +// +// return is; +// } catch (Exception e) { +// throw new SimExplorerTechnicalException(e); +// } +// } +// +// /** +// * Replace element in parent xml. +// * +// * @param newMetadata the new metadata +// * @param document the document +// * @param xmlNode the xml node +// * +// * @throws SimExplorerException the exception +// */ +// public void replaceMetadataInXML(Document document, Element xmlNode, MetaData newMetadata) +// throws SimExplorerException { +// Element newElement = document.createElement(KEY_METADATA); +// this.saveElement(document, newElement, newMetadata); +// +// Element oldElement = getXMLElementByTagName(xmlNode, KEY_METADATA); +// xmlNode.replaceChild(newElement, oldElement); +// } +// +// /** +// * Compute hash. +// * +// * @param node the xml stream +// * +// * @return the string +// * +// * @throws SimExplorerException the exception +// */ +// public String computeHash(Element node) throws SimExplorerException { +// try { +// Document document = getXMLBuilder().newDocument(); +// document.appendChild(document.importNode(node, true)); +// +// removeMetadatas(document); +// +// DigestGenerator digestGenerator = new DigestGenerator(); +// byte[] digest = digestGenerator.getDigest(document, DigestGenerator.sha1DigestAlgorithm); +// +// return MD5.asHex(digest); +// } catch (Exception e) { +// throw new SimExplorerTechnicalException(e); +// } +// } +// +// /** +// * Removes the metadatas. +// * +// * @param node the node +// * +// * @return the int +// */ +// private int removeMetadatas(Node node) { +// int tot = 0; +// NodeList childNodes = node.getChildNodes(); +// List<Node> toRemove = new ArrayList<Node>(); +// +// for (int i = 0; i < childNodes.getLength(); i++) { +// Node child = childNodes.item(i); +// if (child instanceof Element && KEY_METADATA.equals(((Element) child).getTagName())) { +// toRemove.add(child); +// } +// } +// +// for (Node metadata : toRemove) { +// node.removeChild(metadata); +// tot++; +// } +// +// if (tot == 0) { +// childNodes = node.getChildNodes(); +// for (int i = 0; i < childNodes.getLength(); i++) { +// Node child = childNodes.item(i); +// tot = tot + removeMetadatas(child); +// } +// } +// +// return tot; +// } - /** - * Gets the factory. - * - * @param <E> Metadata - * - * @param entityClass the entity class - * - * @return the factory - * - * @throws SimExplorerException the exception - */ - @SuppressWarnings( { "unchecked" }) - public static <E extends MetaData> MetaDataFactory<E> getFactory(Class<E> entityClass) throws SimExplorerException { - return (MetaDataFactory) BaseEntityFactory.getFactory(entityClass); - } - - /* - * (non-Javadoc) - * - * @see fr.cemagref.simexplorer.is.storage.factories.BaseEntityFactory#loadXMLElement(org.w3c.dom.Element) - */ - - @Override - public MetaData loadElement(Element xmlElement) throws SimExplorerException { - MetaData entity = super.loadElement(xmlElement); - entity.setUuid(getXMLProperty(xmlElement, KEY_METADATA_UUID)); - entity.setName(getXMLProperty(xmlElement, KEY_METADATA_NAME)); - entity.setType(getXMLProperty(xmlElement, KEY_METADATA_TYPE)); - entity.setDescription(getXMLProperty(xmlElement, KEY_METADATA_DESCRIPTION)); - entity.setVersion(getXMLProperty(xmlElement, KEY_METADATA_VERSION)); - - String latestVersion = getXMLProperty(xmlElement, KEY_METADATA_LATESTVERSION); - if (latestVersion != null && "1".equals(latestVersion)) { - entity.setLatest(true); - } else { - entity.setLatest(false); - } - - String creationDate = getXMLProperty(xmlElement, KEY_METADATA_CREATIONDATE); - if (creationDate != null) { - Date date; - try { - date = sdf.parse(creationDate); - } catch (ParseException e) { - throw new SimExplorerTechnicalException(e); - } - entity.setCreationDate(date); - } - - entity.setHash(getXMLProperty(xmlElement, KEY_METADATA_HASH)); - entity.setParentVersionUuid(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_UUID)); - entity.setParentVersionVersion(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_VERSION)); - - Map<String, String> descriptors = new HashMap<String, String>(); - - Element descriptorsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_DESCRIPTORS); - if (descriptorsElement != null) { - List<Element> descriptorElements = getXMLElementsByTagName(descriptorsElement, KEY_METADATA_DESCRIPTOR); - for (Element descriptorElement : descriptorElements) { - String name = getXMLProperty(descriptorElement, KEY_METADATA_DESCRIPTOR_NAME); - String value = getXMLProperty(descriptorElement, KEY_METADATA_DESCRIPTOR_VALUE); - descriptors.put(name, value); - } - } - entity.setDescriptors(descriptors); - - List<Attachment> attachments = new ArrayList<Attachment>(); - - Element attachmentsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_ATTACHMENTS); - if (attachmentsElement != null) { - List<Element> attachmentElements = getXMLElementsByTagName(attachmentsElement, KEY_METADATA_ATTACHMENT); - for (Element attachmentElement : attachmentElements) { - Attachment attachment = new Attachment(); - - String name = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_NAME); - attachment.setFileName(name); - - String type = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_TYPE); - ContentType contentType = ContentTypeFactory.getContentTypeInstance(type); - attachment.setContentType(contentType); - - String dataHash = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_HASH); - attachment.setDataHash(dataHash); - - attachments.add(attachment); - } - } - - entity.setAttachments(attachments); - - return entity; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) - */ - @Override - public void saveElement(Document document, Element xmlElement, MetaData element) throws SimExplorerException { - - setXMLProperty(document, xmlElement, KEY_METADATA_UUID, element.getUuid()); - setXMLProperty(document, xmlElement, KEY_METADATA_NAME, element.getName()); - setXMLProperty(document, xmlElement, KEY_METADATA_TYPE, element.getType()); - setXMLProperty(document, xmlElement, KEY_METADATA_DESCRIPTION, element.getDescription()); - setXMLProperty(document, xmlElement, KEY_METADATA_VERSION, element.getVersion().toString()); - - if (element.isLatest()) { - setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, "1"); - } else { - setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, "0"); - } - - if (element.getCreationDate() != null) { - setXMLProperty(document, xmlElement, KEY_METADATA_CREATIONDATE, sdf.format(element.getCreationDate())); - } - - setXMLProperty(document, xmlElement, KEY_METADATA_HASH, element.getHash()); - setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_UUID, element.getParentVersionUuid()); - setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_VERSION, element.getParentVersionVersion()); - - Map<String, String> descriptors = element.getDescriptors(); - - Element descriptorsElement = document.createElement(KEY_METADATA_DESCRIPTORS); - - for (Map.Entry<String, String> kv : descriptors.entrySet()) { - Element descriptorElement = document.createElement(KEY_METADATA_DESCRIPTOR); - setXMLProperty(document, descriptorElement, KEY_METADATA_DESCRIPTOR_NAME, kv.getKey()); - setXMLProperty(document, descriptorElement, KEY_METADATA_DESCRIPTOR_VALUE, kv.getValue()); - descriptorsElement.appendChild(descriptorElement); - } - - xmlElement.appendChild(descriptorsElement); - - List<Attachment> attachments = element.getAttachments(); - - if (attachments != null) { - - Element attachmentsElement = document.createElement(KEY_METADATA_ATTACHMENTS); - - for (Attachment attachment : attachments) { - Element attachmentElement = document.createElement(KEY_METADATA_ATTACHMENT); - - setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_NAME, attachment.getFileName()); - setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_TYPE, attachment.getContentType() - .getClass().getSimpleName()); - setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_HASH, attachment.getDataHash()); - - attachmentsElement.appendChild(attachmentElement); - } - xmlElement.appendChild(attachmentsElement); - - } - - } - - /** - * As metadata is stored inside an entity, this method loads metadata with parsing stream and retrieve metadata - * node. - * - * @param node the node - * - * @return the meta data - * - * @throws SimExplorerException the exception - */ - public MetaData loadElementFromParentXML(Element node) throws SimExplorerException { - Element mdeElement = getXMLElementByTagName(node, KEY_METADATA); - MetaData mde; - try { - mde = loadElement(mdeElement); - } catch (SimExplorerException e) { - throw new SimExplorerTechnicalException(e); - } - return mde; - } - - /** - * Replace element in parent xml. - * - * @param xmlStream the xml stream - * @param newMetadata the new metadata - * - * @return the input stream - * - * @throws SimExplorerException the exception - */ - public InputStream modifyMedataElementStream(InputStream xmlStream, MetaData newMetadata) - throws SimExplorerException { - Document document; - Element rootElement; - Element newElement; - try { - document = getXMLBuilder().parse(xmlStream); - rootElement = (Element) document.getFirstChild(); - newElement = document.createElement(KEY_METADATA); - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); - } - this.saveElement(document, newElement, newMetadata); - Element oldElement = getXMLElementByTagName(rootElement, KEY_METADATA); - rootElement.replaceChild(newElement, oldElement); - - DOMSource domSource = new DOMSource(document); - - try { - PipedOutputStream os = new PipedOutputStream(); - PipedInputStream is = new PipedInputStream(os); - - XMLStreamEncoder xse = new XMLStreamEncoder(domSource, os); - xse.start(); - - return is; - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); - } - } - - /** - * Replace element in parent xml. - * - * @param newMetadata the new metadata - * @param document the document - * @param xmlNode the xml node - * - * @throws SimExplorerException the exception - */ - public void replaceMetadataInXML(Document document, Element xmlNode, MetaData newMetadata) - throws SimExplorerException { - Element newElement = document.createElement(KEY_METADATA); - this.saveElement(document, newElement, newMetadata); - - Element oldElement = getXMLElementByTagName(xmlNode, KEY_METADATA); - xmlNode.replaceChild(newElement, oldElement); - } - - /** - * Compute hash. - * - * @param node the xml stream - * - * @return the string - * - * @throws SimExplorerException the exception - */ - public String computeHash(Element node) throws SimExplorerException { - try { - Document document = getXMLBuilder().newDocument(); - document.appendChild(document.importNode(node, true)); - - removeMetadatas(document); - - DigestGenerator digestGenerator = new DigestGenerator(); - byte[] digest = digestGenerator.getDigest(document, DigestGenerator.sha1DigestAlgorithm); - - return MD5.asHex(digest); - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); - } - } - - /** - * Removes the metadatas. - * - * @param node the node - * - * @return the int - */ - private int removeMetadatas(Node node) { - int tot = 0; - NodeList childNodes = node.getChildNodes(); - List<Node> toRemove = new ArrayList<Node>(); - - for (int i = 0; i < childNodes.getLength(); i++) { - Node child = childNodes.item(i); - if (child instanceof Element && KEY_METADATA.equals(((Element) child).getTagName())) { - toRemove.add(child); - } - } - - for (Node metadata : toRemove) { - node.removeChild(metadata); - tot++; - } - - if (tot == 0) { - childNodes = node.getChildNodes(); - for (int i = 0; i < childNodes.getLength(); i++) { - Node child = childNodes.item(i); - tot = tot + removeMetadatas(child); - } - } - - return tot; - } - } Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/RepositoryFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/RepositoryFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/RepositoryFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,58 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import fr.cemagref.simexplorer.is.entities.data.Repository; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - -/** - * A factory for creating Repository objects. - * @param <E> Repository - */ -public class RepositoryFactory<E extends Repository> extends - BaseEntityFactory<Repository> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public Repository createInstance() { - return new Repository(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#loadElement(org.w3c.dom.Element) - */ - @Override - public Repository loadElement(Element xmlElement) throws SimExplorerException { - return super.loadElement(xmlElement); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) - */ - @Override - public void saveElement(Document document, Element xmlElement, - Repository element) throws SimExplorerException { - // nothing to do yet - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ResultFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ResultFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/ResultFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,59 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import fr.cemagref.simexplorer.is.entities.data.Result; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - -/** - * A factory for creating Result objects. - * @param <E> Result - */ -public class ResultFactory<E extends Result> extends BaseEntityFactory<Result> { - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance() - */ - @Override - public Result createInstance() { - return new Result(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#loadElement(org.w3c.dom.Element) - */ - @Override - public Result loadElement(Element xmlElement) throws SimExplorerException { - return super.loadElement(xmlElement); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity) - */ - @Override - public void saveElement(Document document, Element xmlElement, - Result element) throws SimExplorerException { - - // not used yet - - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/StructureFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/StructureFactory.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/StructureFactory.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,31 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -import fr.cemagref.simexplorer.is.entities.data.Structure; - -/** - * A factory for creating Structure objects. - * - * @param <E> - * Structure subtype - */ -public abstract class StructureFactory<E extends Structure> extends - BaseEntityFactory<Structure> { - // nothing to do yet -} Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/XMLStreamEncoder.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/XMLStreamEncoder.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/XMLStreamEncoder.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -20,51 +20,35 @@ import java.io.IOException; import java.io.PipedOutputStream; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; +import com.thoughtworks.xstream.XStream; /** * The Class XMLStreamEncoder. */ public class XMLStreamEncoder extends Thread { - /** The dom source. */ - private DOMSource domSource; + /** The object source. */ + private Object source; /** The os. */ @SuppressWarnings("unused") private PipedOutputStream os; - /** The result. */ - private StreamResult result; + /** The x stream. */ + private XStream xStream; - /** The transformer. */ - private Transformer transformer; - /** * Instantiates a new xML stream encoder. * - * @param domSource - * the dom source - * @param os - * the os - * - * @throws TransformerConfigurationException - * the transformer configuration exception + * @param os the os + * @param source the source */ - public XMLStreamEncoder(DOMSource domSource, PipedOutputStream os) - throws TransformerConfigurationException { + public XMLStreamEncoder(Object source, PipedOutputStream os) { super(); - this.domSource = domSource; + this.source = source; this.os = os; - result = new StreamResult(os); - TransformerFactory tf = TransformerFactory.newInstance(); - transformer = tf.newTransformer(); + xStream = new XStream(); } /* (non-Javadoc) @@ -73,10 +57,8 @@ @Override public void run() { try { - transformer.transform(domSource, result); - result.getOutputStream().close(); - } catch (TransformerException e) { - // TODO + xStream.toXML(source, os); + os.close(); } catch (IOException e) { // TODO } Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/XmlConstants.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/XmlConstants.java 2008-02-22 16:47:43 UTC (rev 1194) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/XmlConstants.java 2008-02-22 16:48:16 UTC (rev 1195) @@ -1,180 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.factories; - -/** - * Store all XML constants. - * - * @author glandais - */ -public interface XmlConstants { - - /** The Constant DOT. */ - public static final String DOT = "."; - - /** The Constant FOLDER_SEPARATOR. */ - public static final String FOLDER_SEPARATOR = "/"; - - /** The Constant FACTORY_SUFFIX. */ - public static final String FACTORY_SUFFIX = "Factory"; - - /** The Constant KEY_CODE_LANGUAGE. */ - public static final String KEY_CODE_LANGUAGE = "language"; - - /** The Constant KEY_CODE_CODE. */ - public static final String KEY_CODE_CODE = "code"; - - /** The Constant KEY_COMPONENT_CONSTANTS. */ - public static final String KEY_COMPONENT_CONSTANTS = "constants"; - - /** The Constant KEY_COMPONENT_CONSTANT_NODE. */ - public static final String KEY_COMPONENT_CONSTANT_NODE = "constant"; - - /** The Constant KEY_COMPONENT_STRUCTURE. */ - public static final String KEY_COMPONENT_STRUCTURE = "structures"; - - /** The Constant KEY_COMPONENT_STRUCTURE_NODE. */ - public static final String KEY_COMPONENT_STRUCTURE_NODE = "structure"; - - /** The Constant KEY_COMPONENT_CODES. */ - public static final String KEY_COMPONENT_CODES = "codes"; - - /** The Constant KEY_COMPONENT_CODE_NODE. */ - public static final String KEY_COMPONENT_CODE_NODE = "code"; - - /** The Constant KEY_COMPONENT_LIBRARIES. */ - public static final String KEY_COMPONENT_LIBRARIES = "libraries"; - - /** The Constant KEY_COMPONENT_LIBRARY_NODE. */ - public static final String KEY_COMPONENT_LIBRARY_NODE = "library"; - - /** The Constant KEY_CONSTANT_NAME. */ - public static final String KEY_CONSTANT_NAME = "name"; - - /** The Constant KEY_CONSTANT_TYPE. */ - public static final String KEY_CONSTANT_TYPE = "type"; - - /** The Constant KEY_CONSTANTVALUE_CONSTANT. */ - public static final String KEY_CONSTANTVALUE_CONSTANT = "constant"; - - /** The Constant KEY_CONSTANTVALUE_VALUE. */ - public static final String KEY_CONSTANTVALUE_VALUE = "value"; - - /** The Constant KEY_EXPLORATIONAPPLICATION_DATA. */ - public static final String KEY_EXPLORATIONAPPLICATION_DATA = "data"; - - /** The Constant KEY_EXPLORATIONAPPLICATION_DATA_NODE. */ - public static final String KEY_EXPLORATIONAPPLICATION_DATA_NODE = "explorationdata"; - - /** The Constant KEY_EXPLORATIONAPPLICATION_COMPONENTS. */ - public static final String KEY_EXPLORATIONAPPLICATION_COMPONENTS = "components"; - - /** The Constant KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE. */ - public static final String KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE = "component"; - - /** The Constant KEY_EXPLORATIONDATA_RESULT. */ - public static final String KEY_EXPLORATIONDATA_RESULT = "result"; - - /** The Constant KEY_EXPLORATIONDATA_VALUES. */ - public static final String KEY_EXPLORATIONDATA_VALUES = "values"; - - /** The Constant KEY_EXPLORATIONDATA_VALUE. */ - public static final String KEY_EXPLORATIONDATA_VALUE = "value"; - - /** The Constant KEY_RESULT_FILE. */ - public static final String KEY_RESULT_FILE = "file"; - - /** The Constant KEY_METADATA. */ - public static final String KEY_METADATA = "metadata"; - - /** The Constant KEY_METADATA_UUID. */ - public static final String KEY_METADATA_UUID = "uuid"; - - /** The Constant KEY_METADATA_VERSION. */ - public static final String KEY_METADATA_VERSION = "version"; - - /** The Constant KEY_METADATA_LATESTVERSION. */ - public static final String KEY_METADATA_LATESTVERSION = "latestversion"; - - /** The Constant KEY_METADATA_NAME. */ - public static final String KEY_METADATA_NAME = "name"; - - /** The Constant KEY_METADATA_TYPE. */ - public static final String KEY_METADATA_TYPE = "type"; - - /** The Constant VALUE_METADATA_TYPE_EA. */ - public static final String VALUE_METADATA_TYPE_EA = "ExplorationApplication"; - - /** The Constant VALUE_METADATA_TYPE_COMPONENT. */ - public static final String VALUE_METADATA_TYPE_COMPONENT = "Component"; - - /** The Constant KEY_METADATA_DESCRIPTION. */ - public static final String KEY_METADATA_DESCRIPTION = "description"; - - /** The Constant KEY_METADATA_CREATIONDATE. */ - public static final String KEY_METADATA_CREATIONDATE = "creationdate"; - - /** The Constant KEY_METADATA_HASH. */ - public static final String KEY_METADATA_HASH = "hash"; - - /** The Constant KEY_METADATA_PARENTDATA_UUID. */ - public static final String KEY_METADATA_PARENTDATA_UUID = "parentdatauuid"; - - /** The Constant KEY_METADATA_PARENTDATA_VERSION. */ - public static final String KEY_METADATA_PARENTDATA_VERSION = "parentdataversion"; - - /** The Constant KEY_METADATA_PARENTVERSION_UUID. */ - public static final String KEY_METADATA_PARENTVERSION_UUID = "parentversionuuid"; - - /** The Constant KEY_METADATA_PARENTVERSION_VERSION. */ - public static final String KEY_METADATA_PARENTVERSION_VERSION = "parentversionversion"; - - /** The Constant KEY_METADATA_DESCRIPTORS. */ - public static final String KEY_METADATA_DESCRIPTORS = "descriptors"; - - /** The Constant KEY_METADATA_DESCRIPTOR. */ - public static final String KEY_METADATA_DESCRIPTOR = "descriptor"; - - /** The Constant KEY_METADATA_ATTACHMENTS. */ - public static final String KEY_METADATA_ATTACHMENTS = "attachments"; - - /** The Constant KEY_METADATA_ATTACHMENT. */ - public static final String KEY_METADATA_ATTACHMENT = "attachment"; - - /** The Constant KEY_METADATA_DESCRIPTOR_NAME. */ - public static final String KEY_METADATA_DESCRIPTOR_NAME = "name"; - - /** The Constant KEY_METADATA_DESCRIPTOR_VALUE. */ - public static final String KEY_METADATA_DESCRIPTOR_VALUE = "value"; - - /** The Constant KEY_METADATA_ATTACHMENT_NAME. */ - public static final String KEY_METADATA_ATTACHMENT_NAME = "name"; - - /** The Constant KEY_METADATA_ATTACHMENT_TYPE. */ - public static final String KEY_METADATA_ATTACHMENT_TYPE = "type"; - - /** The Constant KEY_METADATA_ATTACHMENT_HASH. */ - public static final String KEY_METADATA_ATTACHMENT_HASH = "hash"; - - /** The Constant FILE_XML. */ - public static final String FILE_XML = "data.xml"; - - /** The Constant FILE_DATA_PREFIX. */ - public static final String FILE_DATA_PREFIX = "attachment"; - -}
participants (1)
-
glandais@users.labs.libre-entreprise.org