Simexplorer-si-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
February 2008
- 2 participants
- 701 discussions
r1195 - trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories
by glandais@users.labs.libre-entreprise.org 22 Feb '08
by glandais@users.labs.libre-entreprise.org 22 Feb '08
22 Feb '08
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";
-
-}
1
0
r1194 - trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service
by glandais@users.labs.libre-entreprise.org 22 Feb '08
by glandais@users.labs.libre-entreprise.org 22 Feb '08
22 Feb '08
Author: glandais
Date: 2008-02-22 16:47:43 +0000 (Fri, 22 Feb 2008)
New Revision: 1194
Modified:
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
Log:
Split of security DAO : actors and permissions (preparing for list filtering)
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-02-22 16:47:13 UTC (rev 1193)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/AuthenticationServiceImpl.java 2008-02-22 16:47:43 UTC (rev 1194)
@@ -49,7 +49,7 @@
import fr.cemagref.simexplorer.is.exceptions.SimExplorerSecurityException;
import fr.cemagref.simexplorer.is.exceptions.SimExplorerTechnicalException;
import fr.cemagref.simexplorer.is.security.credentials.CredentialManager;
-import fr.cemagref.simexplorer.is.security.dao.DaoSecurity;
+import fr.cemagref.simexplorer.is.security.dao.DaoActor;
import fr.cemagref.simexplorer.is.security.entities.Group;
import fr.cemagref.simexplorer.is.security.entities.LoginAction;
import fr.cemagref.simexplorer.is.security.entities.Permission;
@@ -68,9 +68,9 @@
/** The Constant log. */
private static final Log log = LogFactory.getLog(AuthenticationServiceImpl.class);
- /** The dao. */
+ /** The daoActor. */
@EJB
- private DaoSecurity dao;
+ private DaoActor daoActor;
/** The credential manager. */
@EJB
@@ -175,7 +175,7 @@
return true;
}
if (loggedUser.isAdmin()) {
- return userOwnerOfGroup(loggedUser, dao.getGroup(id));
+ return userOwnerOfGroup(loggedUser, daoActor.getGroup(id));
}
}
return false;
@@ -219,7 +219,7 @@
return true;
}
if (loggedUser.isAdmin()) {
- User user = dao.getUser(id);
+ User user = daoActor.getUser(id);
List<Group> groups = user.getGroups();
for (Group group : groups) {
if (canAdminGroup(token, group.getId())) {
@@ -269,7 +269,7 @@
* @param id the id
*/
private void deleteGroupImpl(String token, Integer id) {
- dao.deleteGroup(id);
+ daoActor.deleteGroup(id);
}
/* (non-Javadoc)
@@ -304,7 +304,7 @@
* @param id the id
*/
private void deleteUserImpl(String token, Integer id) {
- dao.deleteUser(id);
+ daoActor.deleteUser(id);
}
/* (non-Javadoc)
@@ -338,7 +338,7 @@
*/
public Group getGroup(String token, Integer id) throws SimExplorerException {
if (canViewElements(token)) {
- Group group = dao.getGroup(id);
+ Group group = daoActor.getGroup(id);
return group;
}
throw new SimExplorerSecurityException();
@@ -349,7 +349,7 @@
*/
public Group getGroup(String token, String name) throws SimExplorerException {
if (canViewElements(token)) {
- Group group = dao.getGroup(name);
+ Group group = daoActor.getGroup(name);
return group;
}
throw new SimExplorerSecurityException();
@@ -360,7 +360,7 @@
*/
public User getUser(String token, Integer id) throws SimExplorerException {
if (canViewElements(token)) {
- User user = dao.getUser(id);
+ User user = daoActor.getUser(id);
return user;
}
throw new SimExplorerSecurityException();
@@ -371,7 +371,7 @@
*/
public User getUser(String token, String login) throws SimExplorerException {
if (canViewElements(token)) {
- User user = dao.getUser(login);
+ User user = daoActor.getUser(login);
return user;
}
throw new SimExplorerSecurityException();
@@ -397,7 +397,7 @@
*/
public Group saveGroup(String token, String name) throws SimExplorerException {
if (canSaveElement(token)) {
- Group oldGroup = dao.getGroup(name);
+ Group oldGroup = daoActor.getGroup(name);
if (oldGroup != null) {
throw new SimExplorerBusinessException(_("simexplorer.service.business.groupexist"));
}
@@ -405,7 +405,7 @@
Group group = new Group();
group.setName(name);
group.setOwner(getLoggedUser(token));
- dao.saveGroup(group);
+ daoActor.saveGroup(group);
group = getGroup(token, group.getId());
return group;
}
@@ -417,7 +417,7 @@
*/
public User saveUser(String token, String login, String mail) throws SimExplorerException {
if (canSaveElement(token)) {
- User oldUser = dao.getUser(login);
+ User oldUser = daoActor.getUser(login);
if (oldUser != null) {
throw new SimExplorerBusinessException(_("simexplorer.service.business.userexist"));
}
@@ -434,7 +434,7 @@
Arrays.fill(password, (char) 0);
user.setAdmin(false);
user.setSuperAdmin(false);
- dao.saveUser(user);
+ daoActor.saveUser(user);
user = getUser(token, user.getId());
return user;
}
@@ -460,7 +460,7 @@
*/
public Group updateGroup(String token, Group group) throws SimExplorerException {
if (canUpdateGroup(token, group.getId())) {
- return dao.updateGroup(group);
+ return daoActor.updateGroup(group);
}
throw new SimExplorerSecurityException();
}
@@ -480,7 +480,7 @@
if (getLoggedUser(token).isSuperAdmin()) {
return true;
}
- User oldUser = dao.getUser(user.getId());
+ User oldUser = daoActor.getUser(user.getId());
if (oldUser.isAdmin() == user.isAdmin() && oldUser.isSuperAdmin() == user.isSuperAdmin()) {
return true;
}
@@ -493,7 +493,7 @@
*/
public User updateUser(String token, User user) throws SimExplorerException {
if (canUpdateUser(token, user)) {
- return dao.updateUser(user);
+ return daoActor.updateUser(user);
}
throw new SimExplorerSecurityException();
}
@@ -506,7 +506,7 @@
return null;
}
User loggedUser;
- loggedUser = dao.getLoggedUser(token);
+ loggedUser = daoActor.getLoggedUser(token);
if (loggedUser != null) {
return loggedUser;
}
@@ -519,7 +519,7 @@
* @throws SimExplorerException the sim explorer service exception
*/
private void checkSuperAdmin() throws SimExplorerException {
- if (dao.getUser("superadmin") == null) {
+ if (daoActor.getUser("superadmin") == null) {
User user = new User();
user.setLogin("superadmin");
user.setMail("");
@@ -528,7 +528,7 @@
user.setPasswordHash(passwordHash);
user.setAdmin(true);
user.setSuperAdmin(true);
- dao.saveUser(user);
+ daoActor.saveUser(user);
}
}
@@ -543,17 +543,17 @@
}
String token = null;
// le password est deja haché
- // User loggedUser = dao.loginUser(login, AuthenticationServiceHelper.computeHash(password));
- User loggedUser = dao.loginUser(login, password);
+ // User loggedUser = daoActor.loginUser(login, AuthenticationServiceHelper.computeHash(password));
+ User loggedUser = daoActor.loginUser(login, password);
if (loggedUser != null) {
// FIXME delete previous tokens
- // dao.deleteTokens(login, 10 * 60 * 1000);
+ // daoActor.deleteTokens(login, 10 * 60 * 1000);
LoginAction loginAction = new LoginAction();
loginAction.setLoggedUser(loggedUser);
loginAction.setTime(new Date());
loginAction.setToken(UUID.randomUUID().toString());
- dao.saveToken(loginAction);
+ daoActor.saveToken(loginAction);
token = loginAction.getToken();
}
return token;
@@ -563,7 +563,7 @@
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#requestAccount(java.lang.String, java.lang.String)
*/
public void requestAccount(String login, String mail) throws SimExplorerException {
- User superadmin = dao.getUser("superadmin");
+ User superadmin = daoActor.getUser("superadmin");
sendMail(Config.getProperties().getProperty("simexplorer.adminmail"), superadmin.getMail(),
_("simexplorer.service.mail.subject"), getMailContentRequestAccount(login, mail));
}
@@ -576,7 +576,7 @@
// User user = getLoggedUser(token);
// String passwordHash = computeHash(password);
// user.setPasswordHash(passwordHash);
- // dao.updateUser(user);
+ // daoActor.updateUser(user);
// }
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.service.AuthenticationService#resetPassword(java.lang.String, java.lang.String)
@@ -591,7 +591,7 @@
// reset char[]
Arrays.fill(password, (char) 0);
user.setPasswordHash(passwordHash);
- dao.updateUser(user);
+ daoActor.updateUser(user);
} else {
throw new SimExplorerSecurityException();
}
@@ -602,7 +602,7 @@
*/
public Group[] getGroups(String token) throws SimExplorerException {
if (canViewElements(token)) {
- List<Group> groups = dao.getGroups();
+ List<Group> groups = daoActor.getGroups();
return groups.toArray(new Group[groups.size()]);
}
throw new SimExplorerSecurityException();
@@ -613,7 +613,7 @@
*/
public Group[] getGroupsOwnedBy(String token, User user) throws SimExplorerException {
if (canViewElements(token)) {
- List<Group> list = dao.getGroupsOwnedBy(user);
+ List<Group> list = daoActor.getGroupsOwnedBy(user);
return list.toArray(new Group[list.size()]);
}
throw new SimExplorerSecurityException();
@@ -624,7 +624,7 @@
*/
public User[] getUsers(String token) throws SimExplorerException {
if (canViewElements(token)) {
- List<User> users = dao.getUsers();
+ List<User> users = daoActor.getUsers();
return users.toArray(new User[users.size()]);
}
throw new SimExplorerSecurityException();
@@ -635,7 +635,7 @@
*/
public User[] getUsersOfGroup(String token, Group group) throws SimExplorerException {
if (canViewElements(token)) {
- List<User> usersOfGroup = dao.getUsersOfGroup(group);
+ List<User> usersOfGroup = daoActor.getUsersOfGroup(group);
return usersOfGroup.toArray(new User[usersOfGroup.size()]);
}
throw new SimExplorerSecurityException();
@@ -652,7 +652,7 @@
List<Integer> usersToAdd = new ArrayList<Integer>();
List<Integer> usersToRemove = new ArrayList<Integer>();
- List<User> users = dao.getUsersOfGroup(group);
+ List<User> users = daoActor.getUsersOfGroup(group);
List<Integer> currentUsers = new ArrayList<Integer>();
for (User user : users) {
@@ -671,14 +671,14 @@
}
for (Integer idUser : usersToAdd) {
- User user = dao.getUser(idUser);
+ User user = daoActor.getUser(idUser);
user.getGroups().add(group);
- dao.updateUser(user);
+ daoActor.updateUser(user);
}
for (Integer idUser : usersToRemove) {
- User user = dao.getUser(idUser);
+ User user = daoActor.getUser(idUser);
removeUserFromGroup(user, group);
- dao.updateUser(user);
+ daoActor.updateUser(user);
}
} else {
throw new SimExplorerSecurityException();
@@ -690,13 +690,13 @@
*/
public void setGroupsOfUser(String token, User user, Integer[] groupsIds) throws SimExplorerException {
if (canUpdateUser(token, user)) {
- User realUser = dao.getUser(user.getId());
+ User realUser = daoActor.getUser(user.getId());
realUser.getGroups().clear();
for (Integer groupsId : groupsIds) {
- Group group = dao.getGroup(groupsId);
+ Group group = daoActor.getGroup(groupsId);
realUser.getGroups().add(group);
}
- dao.updateUser(realUser);
+ daoActor.updateUser(realUser);
} else {
throw new SimExplorerSecurityException();
}
@@ -707,7 +707,7 @@
*/
public Group[] getGroupsOfUser(String token, User user) throws SimExplorerException {
if (canViewElements(token)) {
- List<Group> list = dao.getGroupsOfUser(user);
+ List<Group> list = daoActor.getGroupsOfUser(user);
return list.toArray(new Group[list.size()]);
}
throw new SimExplorerSecurityException();
@@ -718,7 +718,7 @@
*/
public Group[] getGroupsOfGroup(String token, Group group) throws SimExplorerException {
if (canViewElements(token)) {
- List<Group> groupsOfGroup = dao.getGroupsOfGroup(group);
+ List<Group> groupsOfGroup = daoActor.getGroupsOfGroup(group);
return groupsOfGroup.toArray(new Group[groupsOfGroup.size()]);
}
throw new SimExplorerSecurityException();
@@ -729,13 +729,13 @@
*/
public void setGroupsOfGroup(String token, Group group, Integer[] groupsIds) throws SimExplorerException {
if (canUpdateGroup(token, group.getId())) {
- Group realGroup = dao.getGroup(group.getId());
+ Group realGroup = daoActor.getGroup(group.getId());
realGroup.getGroups().clear();
for (Integer groupsId : groupsIds) {
- Group groupOwned = dao.getGroup(groupsId);
+ Group groupOwned = daoActor.getGroup(groupsId);
realGroup.getGroups().add(groupOwned);
}
- dao.updateGroup(realGroup);
+ daoActor.updateGroup(realGroup);
} else {
throw new SimExplorerSecurityException();
}
@@ -761,8 +761,8 @@
*/
public Permission[] getPermissions(String token, String uuid) throws SimExplorerException {
canAdminPermissions(token, uuid);
- List<Permission> permissions = dao.getPermissions(uuid);
- return permissions.toArray(new Permission[permissions.size()]);
+ Permission[] permissions = credentialManager.getPermissions(uuid);
+ return permissions;
}
/* (non-Javadoc)
@@ -770,7 +770,7 @@
*/
public void setPermissions(String token, String uuid, Permission[] permissions) throws SimExplorerException {
canAdminPermissions(token, uuid);
- dao.setPermissions(uuid, permissions);
+ credentialManager.setPermissions(uuid, permissions);
}
/* (non-Javadoc)
@@ -779,7 +779,7 @@
@Override
public String[] getElementsOwnedBy(String token, User user) {
List<String> uuids = new ArrayList<String>();
- List<Permission> permissions = dao.getPermissionsOwnedBy(user);
+ List<Permission> permissions = credentialManager.getPermissionsOwnedBy(user);
for (Permission permission : permissions) {
uuids.add(permission.getBusinessId());
}
1
0
r1193 - in trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security: credentials dao
by glandais@users.labs.libre-entreprise.org 22 Feb '08
by glandais@users.labs.libre-entreprise.org 22 Feb '08
22 Feb '08
Author: glandais
Date: 2008-02-22 16:47:13 +0000 (Fri, 22 Feb 2008)
New Revision: 1193
Added:
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActor.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermission.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java
Removed:
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java
Modified:
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
Log:
Split of security DAO : actors and permissions (preparing for list filtering)
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java 2008-02-22 16:46:35 UTC (rev 1192)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java 2008-02-22 16:47:13 UTC (rev 1193)
@@ -17,9 +17,12 @@
* ##% */
package fr.cemagref.simexplorer.is.security.credentials;
+import java.util.List;
+
import javax.ejb.Local;
import fr.cemagref.simexplorer.is.security.entities.Permission;
+import fr.cemagref.simexplorer.is.security.entities.User;
/**
* The Interface CredentialManager.
@@ -38,12 +41,37 @@
public Permission getPermission(String token, String businessId);
/**
+ * Gets the permissions.
+ *
+ * @param uuid the uuid
+ *
+ * @return the permissions
+ */
+ public Permission[] getPermissions(String uuid);
+
+ /**
* Save element.
*
* @param token the token
* @param businessId the business id
- *
*/
public void saveElement(String token, String businessId);
+ /**
+ * Sets the permissions.
+ *
+ * @param uuid the uuid
+ * @param permissions the permissions
+ */
+ public void setPermissions(String uuid, Permission[] permissions);
+
+ /**
+ * Gets the permissions owned by.
+ *
+ * @param user the user
+ *
+ * @return the permissions owned by
+ */
+ public List<Permission> getPermissionsOwnedBy(User user);
+
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-02-22 16:46:35 UTC (rev 1192)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-02-22 16:47:13 UTC (rev 1193)
@@ -25,7 +25,8 @@
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
-import fr.cemagref.simexplorer.is.security.dao.DaoSecurity;
+import fr.cemagref.simexplorer.is.security.dao.DaoActor;
+import fr.cemagref.simexplorer.is.security.dao.DaoPermission;
import fr.cemagref.simexplorer.is.security.entities.Actor;
import fr.cemagref.simexplorer.is.security.entities.Group;
import fr.cemagref.simexplorer.is.security.entities.Permission;
@@ -41,8 +42,12 @@
/** The dao. */
@EJB
- private DaoSecurity dao;
+ private DaoActor daoActor;
+ /** The dao. */
+ @EJB
+ private DaoPermission daoPermission;
+
/**
* Gets the relative level.
*
@@ -73,7 +78,7 @@
public Permission getPermission(String token, String businessId) {
Permission p = null;
- User user = dao.getLoggedUser(token);
+ User user = daoActor.getLoggedUser(token);
if (user.isSuperAdmin()) {
p = new Permission();
@@ -81,7 +86,7 @@
p.setBusinessId(businessId);
p.setOwner(true);
} else {
- List<Permission> permissions = dao.getPermissions(businessId);
+ List<Permission> permissions = daoPermission.getPermissions(businessId);
if (permissions.size() > 0) {
int minLevel = 0;
@@ -131,18 +136,44 @@
* @see fr.cemagref.simexplorer.is.security.credentials.CredentialManager#saveElement(java.lang.String, java.lang.String)
*/
public void saveElement(String token, String businessId) {
- User user = dao.getLoggedUser(token);
+ User user = daoActor.getLoggedUser(token);
Permission p = getPermission(token, businessId);
if ((p == null) || (!user.getId().equals(p.getActor().getId()))) {
p = new Permission();
- p.setActor(dao.getLoggedUser(token));
+ p.setActor(user);
p.setBusinessId(businessId);
p.setOwner(true);
- dao.savePermission(p);
+ daoPermission.savePermission(p);
} else {
p.setOwner(true);
- dao.updatePermission(p);
+ daoPermission.updatePermission(p);
}
}
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.credentials.CredentialManager#getPermissions(java.lang.String)
+ */
+ @Override
+ public Permission[] getPermissions(String uuid) {
+ List<Permission> permissions = daoPermission.getPermissions(uuid);
+ return permissions.toArray(new Permission[permissions.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.credentials.CredentialManager#setPermissions(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Permission[])
+ */
+ @Override
+ public void setPermissions(String uuid, Permission[] permissions) {
+ daoPermission.setPermissions(uuid, permissions);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.credentials.CredentialManager#getPermissionsOwnedBy(fr.cemagref.simexplorer.is.security.entities.User)
+ */
+ @Override
+ public List<Permission> getPermissionsOwnedBy(User user) {
+ List<Permission> permissionsOwnedBy = daoPermission.getPermissionsOwnedBy(user);
+ return permissionsOwnedBy;
+ }
+
}
Copied: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActor.java (from rev 1191, trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActor.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActor.java 2008-02-22 16:47:13 UTC (rev 1193)
@@ -0,0 +1,201 @@
+/*
+* ##% 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.security.dao;
+
+import java.util.List;
+
+import fr.cemagref.simexplorer.is.security.entities.Actor;
+import fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.LoginAction;
+import fr.cemagref.simexplorer.is.security.entities.Permission;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+/**
+ * The Interface DaoActor.
+ */
+public interface DaoActor {
+
+ /**
+ * Save user.
+ *
+ * @param user the user
+ */
+ public void saveUser(User user);
+
+ /**
+ * Gets the user.
+ *
+ * @param id the id
+ *
+ * @return the user
+ */
+ public User getUser(Integer id);
+
+ /**
+ * Gets the user.
+ *
+ * @param login the login
+ *
+ * @return the user
+ */
+ public User getUser(String login);
+
+ /**
+ * Update user.
+ *
+ * @param user the user
+ *
+ * @return the user
+ */
+ public User updateUser(User user);
+
+ /**
+ * Delete user.
+ *
+ * @param id the id
+ */
+ public void deleteUser(Integer id);
+
+ /**
+ * Save group.
+ *
+ * @param group the group
+ */
+ public void saveGroup(Group group);
+
+ /**
+ * Gets the group.
+ *
+ * @param id the id
+ *
+ * @return the group
+ */
+ public Group getGroup(Integer id);
+
+ /**
+ * Gets the group.
+ *
+ * @param name the name
+ *
+ * @return the group
+ */
+ public Group getGroup(String name);
+
+ /**
+ * Update group.
+ *
+ * @param group the group
+ *
+ * @return the group
+ */
+ public Group updateGroup(Group group);
+
+ /**
+ * Delete group.
+ *
+ * @param id the id
+ */
+ public void deleteGroup(Integer id);
+
+ /**
+ * Gets the logged user.
+ *
+ * @param token the token
+ *
+ * @return the logged user
+ */
+ public User getLoggedUser(String token);
+
+ /**
+ * Login user.
+ *
+ * @param login the login
+ * @param passwordHash the password hash
+ *
+ * @return the user
+ */
+ public User loginUser(String login, String passwordHash);
+
+ /**
+ * Save token.
+ *
+ * @param loginAction the login action
+ */
+ public void saveToken(LoginAction loginAction);
+
+ /**
+ * Delete old tokens associated to user.
+ *
+ * @param login Login of user
+ * @param before ms before now
+ */
+ public void deleteTokens(String login, long before);
+
+ /**
+ * Gets the groups.
+ *
+ * @return the groups
+ */
+ public List<Group> getGroups();
+
+ /**
+ * Gets the groups owned by.
+ *
+ * @param user the user
+ *
+ * @return the groups owned by
+ */
+ public List<Group> getGroupsOwnedBy(User user);
+
+ /**
+ * Gets the users.
+ *
+ * @return the users
+ */
+ public List<User> getUsers();
+
+ /**
+ * Gets the users of group.
+ *
+ * @param group the group
+ *
+ * @return the users of group
+ */
+ public List<User> getUsersOfGroup(Group group);
+
+ /**
+ * Gets the groups of user.
+ *
+ * @param user the user
+ *
+ * @return the groups of user
+ */
+ public List<Group> getGroupsOfUser(User user);
+
+ /**
+ * Gets the groups of group.
+ *
+ * @param group the group
+ *
+ * @return the groups of group
+ */
+ public List<Group> getGroupsOfGroup(Group group);
+
+
+
+}
Copied: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java (from rev 1191, trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoActorImpl.java 2008-02-22 16:47:13 UTC (rev 1193)
@@ -0,0 +1,261 @@
+/*
+* ##% 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.security.dao;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.codelutin.util.CollectionUtil;
+
+import fr.cemagref.simexplorer.is.security.entities.Actor;
+import fr.cemagref.simexplorer.is.security.entities.Group;
+import fr.cemagref.simexplorer.is.security.entities.LoginAction;
+import fr.cemagref.simexplorer.is.security.entities.Permission;
+import fr.cemagref.simexplorer.is.security.entities.User;
+
+/**
+ * The Class DaoActorImpl.
+ */
+ at Stateless(name = "DaoActor")
+public class DaoActorImpl implements DaoActor {
+
+ /** The em. */
+ @PersistenceContext(unitName = "simexploreris-security")
+ private EntityManager em;
+
+ /**
+ * Gets the single result.
+ *
+ * @param query the query
+ *
+ * @return the single result
+ */
+ private Object getSingleResult(Query query) {
+ Object o;
+ try {
+ o = query.getSingleResult();
+ } catch (NoResultException e) {
+ o = null;
+ }
+ return o;
+ }
+
+ /**
+ * Find.
+ *
+ * @param clazz the clazz
+ * @param arg the arg
+ *
+ * @return the object
+ */
+ private Object find(Class<?> clazz, Object arg) {
+ Object o;
+ try {
+ o = em.find(clazz, arg);
+ } catch (NoResultException e) {
+ o = null;
+ }
+ return o;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#deleteGroup(java.lang.Integer)
+ */
+ public void deleteGroup(Integer id) {
+ Group g = getGroup(id);
+ g.setVisible(false);
+ em.merge(g);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#deleteUser(java.lang.Integer)
+ */
+ public void deleteUser(Integer id) {
+ User u = getUser(id);
+ u.setVisible(false);
+ em.merge(u);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroup(java.lang.Integer)
+ */
+ public Group getGroup(Integer id) {
+ Group g = (Group) find(Group.class, id);
+ return g;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroup(java.lang.String)
+ */
+ public Group getGroup(String name) {
+ Group g = (Group) getSingleResult(em.createQuery("select g from Group g where g.name=:name").setParameter(
+ "name", name));
+ return g;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getUser(java.lang.Integer)
+ */
+ public User getUser(Integer id) {
+ User u = (User) find(User.class, id);
+ return u;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#saveGroup(fr.cemagref.simexplorer.is.security.entities.Group)
+ */
+ public void saveGroup(Group group) {
+ em.persist(group);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#saveUser(fr.cemagref.simexplorer.is.security.entities.User)
+ */
+ public void saveUser(User user) {
+ em.persist(user);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#updateGroup(fr.cemagref.simexplorer.is.security.entities.Group)
+ */
+ public Group updateGroup(Group group) {
+ return em.merge(group);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#updateUser(fr.cemagref.simexplorer.is.security.entities.User)
+ */
+ public User updateUser(User user) {
+ return em.merge(user);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getLoggedUser(java.lang.String)
+ */
+ public User getLoggedUser(String token) {
+ User loggedUser = null;
+ LoginAction loginAction = (LoginAction) getSingleResult(em.createQuery(
+ "select la from LoginAction la where la.token=:token").setParameter("token", token));
+ if (loginAction != null) {
+ loggedUser = loginAction.getLoggedUser();
+ loginAction.setTime(new Date());
+ em.merge(loginAction);
+ }
+ return loggedUser;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#loginUser(java.lang.String, java.lang.String)
+ */
+ public User loginUser(String login, String passwordHash) {
+ User user = (User) getSingleResult(em.createQuery(
+ "select u from User u where u.login=:login and u.passwordHash=:passwordHash").setParameter("login",
+ login).setParameter("passwordHash", passwordHash));
+ return user;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#saveToken(fr.cemagref.simexplorer.is.security.entities.LoginAction)
+ */
+ public void saveToken(LoginAction loginAction) {
+ em.persist(loginAction);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#deleteTokens(java.lang.String, long)
+ */
+ public void deleteTokens(String login, long before) {
+ Date now = new Date();
+ Date date = new Date(now.getTime() - before);
+ em.createQuery("delete from LoginAction la where la.loggedUser.login = :login and la.time < :time")
+ .setParameter("time", date).setParameter("login", login).executeUpdate();
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getUser(java.lang.String)
+ */
+ public User getUser(String login) {
+ User user = (User) getSingleResult(em.createQuery("select u from User u where u.login=:login").setParameter(
+ "login", login));
+ return user;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroups()
+ */
+ public List<Group> getGroups() {
+ List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g").getResultList(),
+ Group.class);
+ return groups;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroupsOwnedBy(fr.cemagref.simexplorer.is.security.entities.User)
+ */
+ public List<Group> getGroupsOwnedBy(User user) {
+ List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g where g.owner=:owner")
+ .setParameter("owner", user).getResultList(), Group.class);
+ return groups;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getUsers()
+ */
+ public List<User> getUsers() {
+ List<User> users = CollectionUtil.toGenericList(em.createQuery("select u from User u").getResultList(),
+ User.class);
+ return users;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getUsersOfGroup(fr.cemagref.simexplorer.is.security.entities.Group)
+ */
+ public List<User> getUsersOfGroup(Group group) {
+ List<User> users = CollectionUtil.toGenericList(em.createQuery(
+ "select distinct u from User u where :group member of u.groups").setParameter("group", group)
+ .getResultList(), User.class);
+ return users;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroupsOfUser(fr.cemagref.simexplorer.is.security.entities.User)
+ */
+ public List<Group> getGroupsOfUser(User user) {
+ List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
+ "select distinct u.groups from User u where u = :user").setParameter("user", user).getResultList(),
+ Group.class);
+ return groups;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getGroupsOfGroup(fr.cemagref.simexplorer.is.security.entities.Group)
+ */
+ public List<Group> getGroupsOfGroup(Group group) {
+ List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
+ "select distinct g.groups from Group g where g = :group").setParameter("group", group).getResultList(),
+ Group.class);
+ return groups;
+ }
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermission.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermission.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermission.java 2008-02-22 16:47:13 UTC (rev 1193)
@@ -0,0 +1,77 @@
+/*
+* ##% 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.security.dao;
+
+import java.util.List;
+
+import fr.cemagref.simexplorer.is.security.entities.Actor;
+import fr.cemagref.simexplorer.is.security.entities.Permission;
+
+public interface DaoPermission {
+
+ /**
+ * Gets the permissions.
+ *
+ * @param businessId the business id
+ *
+ * @return the permissions
+ */
+ public List<Permission> getPermissions(String businessId);
+
+ /**
+ * Gets the permissions.
+ *
+ * @param businessId the business id
+ * @param actor the actor
+ *
+ * @return the permissions
+ */
+ public List<Permission> getPermissions(Actor actor, String businessId);
+
+ /**
+ * Gets the permissions.
+ *
+ * @param actor the actor
+ *
+ * @return the permissions
+ */
+ public List<Permission> getPermissionsOwnedBy(Actor actor);
+
+ /**
+ * Save permission.
+ *
+ * @param p the p
+ */
+ public void savePermission(Permission p);
+
+ /**
+ * Update permission.
+ *
+ * @param p the p
+ */
+ public void updatePermission(Permission p);
+
+ /**
+ * Sets the permissions.
+ *
+ * @param uuid the uuid
+ * @param permissions the permissions
+ */
+ public void setPermissions(String uuid, Permission[] permissions);
+
+}
Added: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java 2008-02-22 16:47:13 UTC (rev 1193)
@@ -0,0 +1,101 @@
+/*
+* ##% 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.security.dao;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.codelutin.util.CollectionUtil;
+
+import fr.cemagref.simexplorer.is.security.entities.Actor;
+import fr.cemagref.simexplorer.is.security.entities.Permission;
+
+/**
+ * The Class DaoPermissionImpl.
+ */
+ at Stateless(name = "DaoPermission")
+public class DaoPermissionImpl implements DaoPermission {
+
+ /** The em. */
+ @PersistenceContext(unitName = "simexploreris-security")
+ private EntityManager em;
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getPermissions(java.lang.String)
+ */
+ @Override
+ public List<Permission> getPermissions(String businessId) {
+ List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
+ "select p from Permission p where p.businessId=:businessId").setParameter("businessId", businessId)
+ .getResultList(), Permission.class);
+ return permissions;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#getPermissions(fr.cemagref.simexplorer.is.security.entities.Actor, java.lang.String)
+ */
+ @Override
+ public List<Permission> getPermissions(Actor actor, String businessId) {
+ List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
+ "select p from Permission p where p.businessId=:businessId and p.actor=:actor").setParameter(
+ "businessId", businessId).setParameter("actor", actor).getResultList(), Permission.class);
+ return permissions;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoPermission#getPermissionsOwnedBy(fr.cemagref.simexplorer.is.security.entities.Actor)
+ */
+ @Override
+ public List<Permission> getPermissionsOwnedBy(Actor actor) {
+ List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
+ "select p from Permission p where p.actor=:actor and p.owner = true").setParameter("actor", actor)
+ .getResultList(), Permission.class);
+ return permissions;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#savePermission(fr.cemagref.simexplorer.is.security.entities.Permission)
+ */
+ @Override
+ public void savePermission(Permission p) {
+ em.persist(p);
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoActor#setPermissions(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Permission[])
+ */
+ @Override
+ public void setPermissions(String uuid, Permission[] permissions) {
+ em.createQuery("delete from Permission p where p.businessId=:businessId").setParameter("businessId", uuid)
+ .executeUpdate();
+ for (Permission permission : permissions) {
+ em.persist(permission);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoPermission#updatePermission(fr.cemagref.simexplorer.is.security.entities.Permission)
+ */
+ @Override
+ public void updatePermission(Permission p) {
+ em.merge(p);
+ }
+}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java 2008-02-22 16:46:35 UTC (rev 1192)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java 2008-02-22 16:47:13 UTC (rev 1193)
@@ -1,249 +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.security.dao;
-
-import java.util.List;
-
-import fr.cemagref.simexplorer.is.security.entities.Actor;
-import fr.cemagref.simexplorer.is.security.entities.Group;
-import fr.cemagref.simexplorer.is.security.entities.LoginAction;
-import fr.cemagref.simexplorer.is.security.entities.Permission;
-import fr.cemagref.simexplorer.is.security.entities.User;
-
-/**
- * The Interface DaoSecurity.
- */
-public interface DaoSecurity {
-
- /**
- * Save user.
- *
- * @param user the user
- */
- public void saveUser(User user);
-
- /**
- * Gets the user.
- *
- * @param id the id
- *
- * @return the user
- */
- public User getUser(Integer id);
-
- /**
- * Gets the user.
- *
- * @param login the login
- *
- * @return the user
- */
- public User getUser(String login);
-
- /**
- * Update user.
- *
- * @param user the user
- *
- * @return the user
- */
- public User updateUser(User user);
-
- /**
- * Delete user.
- *
- * @param id the id
- */
- public void deleteUser(Integer id);
-
- /**
- * Save group.
- *
- * @param group the group
- */
- public void saveGroup(Group group);
-
- /**
- * Gets the group.
- *
- * @param id the id
- *
- * @return the group
- */
- public Group getGroup(Integer id);
-
- /**
- * Gets the group.
- *
- * @param name the name
- *
- * @return the group
- */
- public Group getGroup(String name);
-
- /**
- * Update group.
- *
- * @param group the group
- *
- * @return the group
- */
- public Group updateGroup(Group group);
-
- /**
- * Delete group.
- *
- * @param id the id
- */
- public void deleteGroup(Integer id);
-
- /**
- * Gets the logged user.
- *
- * @param token the token
- *
- * @return the logged user
- */
- public User getLoggedUser(String token);
-
- /**
- * Login user.
- *
- * @param login the login
- * @param passwordHash the password hash
- *
- * @return the user
- */
- public User loginUser(String login, String passwordHash);
-
- /**
- * Save token.
- *
- * @param loginAction the login action
- */
- public void saveToken(LoginAction loginAction);
-
- /**
- * Delete old tokens associated to user.
- *
- * @param login Login of user
- * @param before ms before now
- */
- public void deleteTokens(String login, long before);
-
- /**
- * Gets the groups.
- *
- * @return the groups
- */
- public List<Group> getGroups();
-
- /**
- * Gets the groups owned by.
- *
- * @param user the user
- *
- * @return the groups owned by
- */
- public List<Group> getGroupsOwnedBy(User user);
-
- /**
- * Gets the users.
- *
- * @return the users
- */
- public List<User> getUsers();
-
- /**
- * Gets the users of group.
- *
- * @param group the group
- *
- * @return the users of group
- */
- public List<User> getUsersOfGroup(Group group);
-
- /**
- * Gets the groups of user.
- *
- * @param user the user
- *
- * @return the groups of user
- */
- public List<Group> getGroupsOfUser(User user);
-
- /**
- * Gets the groups of group.
- *
- * @param group the group
- *
- * @return the groups of group
- */
- public List<Group> getGroupsOfGroup(Group group);
-
- /**
- * Gets the permissions.
- *
- * @param businessId the business id
- *
- * @return the permissions
- */
- public List<Permission> getPermissions(String businessId);
-
- /**
- * Gets the permissions.
- *
- * @param businessId the business id
- * @param actor the actor
- *
- * @return the permissions
- */
- public List<Permission> getPermissions(Actor actor, String businessId);
-
- /**
- * Gets the permissions.
- *
- * @param actor the actor
- *
- * @return the permissions
- */
- public List<Permission> getPermissionsOwnedBy(Actor actor);
-
- /**
- * Save permission.
- *
- * @param p the p
- */
- public void savePermission(Permission p);
-
- /**
- * Update permission.
- *
- * @param p the p
- */
- public void updatePermission(Permission p);
-
- /**
- * Sets the permissions.
- *
- * @param uuid the uuid
- * @param permissions the permissions
- */
- public void setPermissions(String uuid, Permission[] permissions);
-
-}
Deleted: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java 2008-02-22 16:46:35 UTC (rev 1192)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java 2008-02-22 16:47:13 UTC (rev 1193)
@@ -1,312 +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.security.dao;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.PersistenceContext;
-import javax.persistence.Query;
-
-import org.codelutin.util.CollectionUtil;
-
-import fr.cemagref.simexplorer.is.security.entities.Actor;
-import fr.cemagref.simexplorer.is.security.entities.Group;
-import fr.cemagref.simexplorer.is.security.entities.LoginAction;
-import fr.cemagref.simexplorer.is.security.entities.Permission;
-import fr.cemagref.simexplorer.is.security.entities.User;
-
-/**
- * The Class DaoSecurityImpl.
- */
- at Stateless(name = "DaoSecurity")
-public class DaoSecurityImpl implements DaoSecurity {
-
- /** The em. */
- @PersistenceContext(unitName = "simexploreris-security")
- private EntityManager em;
-
- /**
- * Gets the single result.
- *
- * @param query the query
- *
- * @return the single result
- */
- private Object getSingleResult(Query query) {
- Object o;
- try {
- o = query.getSingleResult();
- } catch (NoResultException e) {
- o = null;
- }
- return o;
- }
-
- /**
- * Find.
- *
- * @param clazz the clazz
- * @param arg the arg
- *
- * @return the object
- */
- private Object find(Class<?> clazz, Object arg) {
- Object o;
- try {
- o = em.find(clazz, arg);
- } catch (NoResultException e) {
- o = null;
- }
- return o;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#deleteGroup(java.lang.Integer)
- */
- public void deleteGroup(Integer id) {
- Group g = getGroup(id);
- g.setVisible(false);
- em.merge(g);
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#deleteUser(java.lang.Integer)
- */
- public void deleteUser(Integer id) {
- User u = getUser(id);
- u.setVisible(false);
- em.merge(u);
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroup(java.lang.Integer)
- */
- public Group getGroup(Integer id) {
- Group g = (Group) find(Group.class, id);
- return g;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroup(java.lang.String)
- */
- public Group getGroup(String name) {
- Group g = (Group) getSingleResult(em.createQuery("select g from Group g where g.name=:name").setParameter(
- "name", name));
- return g;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUser(java.lang.Integer)
- */
- public User getUser(Integer id) {
- User u = (User) find(User.class, id);
- return u;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#saveGroup(fr.cemagref.simexplorer.is.security.entities.Group)
- */
- public void saveGroup(Group group) {
- em.persist(group);
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#saveUser(fr.cemagref.simexplorer.is.security.entities.User)
- */
- public void saveUser(User user) {
- em.persist(user);
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#updateGroup(fr.cemagref.simexplorer.is.security.entities.Group)
- */
- public Group updateGroup(Group group) {
- return em.merge(group);
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#updateUser(fr.cemagref.simexplorer.is.security.entities.User)
- */
- public User updateUser(User user) {
- return em.merge(user);
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getLoggedUser(java.lang.String)
- */
- public User getLoggedUser(String token) {
- User loggedUser = null;
- LoginAction loginAction = (LoginAction) getSingleResult(em.createQuery(
- "select la from LoginAction la where la.token=:token").setParameter("token", token));
- if (loginAction != null) {
- loggedUser = loginAction.getLoggedUser();
- loginAction.setTime(new Date());
- em.merge(loginAction);
- }
- return loggedUser;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#loginUser(java.lang.String, java.lang.String)
- */
- public User loginUser(String login, String passwordHash) {
- User user = (User) getSingleResult(em.createQuery(
- "select u from User u where u.login=:login and u.passwordHash=:passwordHash").setParameter("login",
- login).setParameter("passwordHash", passwordHash));
- return user;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#saveToken(fr.cemagref.simexplorer.is.security.entities.LoginAction)
- */
- public void saveToken(LoginAction loginAction) {
- em.persist(loginAction);
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#deleteTokens(java.lang.String, long)
- */
- public void deleteTokens(String login, long before) {
- Date now = new Date();
- Date date = new Date(now.getTime() - before);
- em.createQuery("delete from LoginAction la where la.loggedUser.login = :login and la.time < :time")
- .setParameter("time", date).setParameter("login", login).executeUpdate();
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUser(java.lang.String)
- */
- public User getUser(String login) {
- User user = (User) getSingleResult(em.createQuery("select u from User u where u.login=:login").setParameter(
- "login", login));
- return user;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroups()
- */
- public List<Group> getGroups() {
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g").getResultList(),
- Group.class);
- return groups;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroupsOwnedBy(fr.cemagref.simexplorer.is.security.entities.User)
- */
- public List<Group> getGroupsOwnedBy(User user) {
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g where g.owner=:owner")
- .setParameter("owner", user).getResultList(), Group.class);
- return groups;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUsers()
- */
- public List<User> getUsers() {
- List<User> users = CollectionUtil.toGenericList(em.createQuery("select u from User u").getResultList(),
- User.class);
- return users;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUsersOfGroup(fr.cemagref.simexplorer.is.security.entities.Group)
- */
- public List<User> getUsersOfGroup(Group group) {
- List<User> users = CollectionUtil.toGenericList(em.createQuery(
- "select distinct u from User u where :group member of u.groups").setParameter("group", group)
- .getResultList(), User.class);
- return users;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroupsOfUser(fr.cemagref.simexplorer.is.security.entities.User)
- */
- public List<Group> getGroupsOfUser(User user) {
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
- "select distinct u.groups from User u where u = :user").setParameter("user", user).getResultList(),
- Group.class);
- return groups;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroupsOfGroup(fr.cemagref.simexplorer.is.security.entities.Group)
- */
- public List<Group> getGroupsOfGroup(Group group) {
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
- "select distinct g.groups from Group g where g = :group").setParameter("group", group).getResultList(),
- Group.class);
- return groups;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getPermissions(java.lang.String)
- */
- public List<Permission> getPermissions(String businessId) {
- List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
- "select p from Permission p where p.businessId=:businessId").setParameter("businessId", businessId)
- .getResultList(), Permission.class);
- return permissions;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getPermissions(fr.cemagref.simexplorer.is.security.entities.Actor, java.lang.String)
- */
- public List<Permission> getPermissions(Actor actor, String businessId) {
- List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
- "select p from Permission p where p.businessId=:businessId and p.actor=:actor").setParameter(
- "businessId", businessId).setParameter("actor", actor).getResultList(), Permission.class);
- return permissions;
- }
-
- @Override
- public List<Permission> getPermissionsOwnedBy(Actor actor) {
- List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
- "select p from Permission p where p.actor=:actor and p.owner = true").setParameter("actor", actor)
- .getResultList(), Permission.class);
- return permissions;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#savePermission(fr.cemagref.simexplorer.is.security.entities.Permission)
- */
- public void savePermission(Permission p) {
- em.persist(p);
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#setPermissions(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Permission[])
- */
- public void setPermissions(String uuid, Permission[] permissions) {
- em.createQuery("delete from Permission p where p.businessId=:businessId").setParameter("businessId", uuid)
- .executeUpdate();
- for (Permission permission : permissions) {
- em.persist(permission);
- }
- }
-
- @Override
- public void updatePermission(Permission p) {
- em.merge(p);
- }
-
-}
1
0
r1192 - in trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities: . attachment data metadata
by glandais@users.labs.libre-entreprise.org 22 Feb '08
by glandais@users.labs.libre-entreprise.org 22 Feb '08
22 Feb '08
Author: glandais
Date: 2008-02-22 16:46:35 +0000 (Fri, 22 Feb 2008)
New Revision: 1192
Added:
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Descriptor.java
Modified:
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/Attachment.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Code.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Constant.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ConstantValue.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/DataEntity.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationApplication.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationData.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Library.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Repository.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Result.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Structure.java
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java
Log:
Entities are independant of MetaData
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/EntityHelper.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.StringTokenizer;
import javax.swing.tree.DefaultMutableTreeNode;
@@ -70,20 +71,9 @@
if (entity == null) {
return "";
}
- if (entity instanceof LoggableElement) {
- return getLibelle((LoggableElement) entity);
- }
return getLibelle(entity.getClass().getSimpleName());
}
- public static String getLibelle(LoggableElement element) {
- return element == null ? "" : getLibelle(element.getMetaData());
- }
-
- public static String getLibelle(MetaData data) {
- return data == null ? "" : getLibelle(data.getType());
- }
-
public String getLibelle() {
return _(i18nKey);
}
@@ -108,6 +98,10 @@
}
return "";
}
+
+ public static Type getType(Class<?> klass) {
+ return Type.valueOf(klass.getSimpleName());
+ }
private Type(boolean isLE,String i18nKey, String i18nKeys) {
this.le = isLE;
@@ -142,9 +136,9 @@
}
public boolean accept(MetaData metaData) {
- return metaData != null && accept(metaData.getType());
+ return metaData != null && accept(metaData.getElementClass());
}
-
+
private Action(Class<?>... classes) {
this.classes = Arrays.asList(classes);
this.types = new ArrayList<String>(classes.length);
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/SimpleEntityVisitor.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -88,7 +88,8 @@
public void visitMetaData(MetaData v) {
if (v != null) {
- visitAttachments(v.getAttachments());
+ // FIXME !!!
+ //visitAttachments(v.getAttachments());
}
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/Attachment.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/Attachment.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/attachment/Attachment.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -18,6 +18,7 @@
package fr.cemagref.simexplorer.is.entities.attachment;
import org.apache.commons.lang.StringUtils;
+
import fr.cemagref.simexplorer.is.entities.BaseEntity;
import fr.cemagref.simexplorer.is.entities.EntityVisitor;
@@ -52,8 +53,7 @@
/**
* Sets the file name.
*
- * @param fileName
- * the new file name
+ * @param fileName the new file name
*/
public void setFileName(String fileName) {
this.fileName = fileName;
@@ -71,8 +71,7 @@
/**
* Sets the content type.
*
- * @param contentType
- * the new content type
+ * @param contentType the new content type
*/
public void setContentType(ContentType contentType) {
this.contentType = contentType;
@@ -90,8 +89,7 @@
/**
* Sets the data hash.
*
- * @param dataHash
- * the new data hash
+ * @param dataHash the new data hash
*/
public void setDataHash(String dataHash) {
this.dataHash = StringUtils.leftPad(dataHash, 32, '0');
@@ -110,8 +108,7 @@
/**
* Gets the hash from unique id.
*
- * @param uniqueId
- * the unique id
+ * @param uniqueId the unique id
*
* @return the hash from unique id
*/
@@ -122,8 +119,7 @@
/**
* Gets the file name from unique id.
*
- * @param uniqueId
- * the unique id
+ * @param uniqueId the unique id
*
* @return the file name from unique id
*/
@@ -138,10 +134,8 @@
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((dataHash == null) ? 0 : dataHash.hashCode());
- result = prime * result
- + ((fileName == null) ? 0 : fileName.hashCode());
+ result = prime * result + ((dataHash == null) ? 0 : dataHash.hashCode());
+ result = prime * result + ((fileName == null) ? 0 : fileName.hashCode());
return result;
}
@@ -176,7 +170,7 @@
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
- sb.append(getFileName());
+ sb.append(getFileName());
if (getContentType() != null) {
sb.append(" - ").append(getContentType().getDescription());
}
@@ -186,4 +180,5 @@
public void accept(EntityVisitor visitor) {
visitor.visitAttachment(this);
}
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Code.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Code.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Code.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -17,10 +17,10 @@
* ##% */
package fr.cemagref.simexplorer.is.entities.data;
+import java.io.Serializable;
+
import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-import java.io.Serializable;
-
/**
* The Class Code.
*/
@@ -47,8 +47,7 @@
/**
* Sets the language.
*
- * @param language
- * the new language
+ * @param language the new language
*/
public void setLanguage(String language) {
this.language = language;
@@ -66,8 +65,7 @@
/**
* Sets the code.
*
- * @param code
- * the new code
+ * @param code the new code
*/
public void setCode(String code) {
this.code = code;
@@ -84,4 +82,36 @@
public void accept(EntityVisitor visitor) {
visitor.visitCode(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((code == null) ? 0 : code.hashCode());
+ result = prime * result + ((language == null) ? 0 : language.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Code other = (Code) obj;
+ if (code == null) {
+ if (other.code != null)
+ return false;
+ } else if (!code.equals(other.code))
+ return false;
+ if (language == null) {
+ if (other.language != null)
+ return false;
+ } else if (!language.equals(other.language))
+ return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -17,13 +17,12 @@
* ##% */
package fr.cemagref.simexplorer.is.entities.data;
-import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
+import fr.cemagref.simexplorer.is.entities.EntityVisitor;
+
/**
* The Class Component.
*/
@@ -56,8 +55,7 @@
/**
* Sets the constants.
*
- * @param constants
- * the new constants
+ * @param constants the new constants
*/
public void setConstants(List<Constant> constants) {
this.constants = constants;
@@ -75,8 +73,7 @@
/**
* Sets the structures.
*
- * @param structures
- * the new structures
+ * @param structures the new structures
*/
public void setStructures(List<Structure> structures) {
this.structures = structures;
@@ -94,8 +91,7 @@
/**
* Sets the codes.
*
- * @param codes
- * the new codes
+ * @param codes the new codes
*/
public void setCodes(List<Code> codes) {
this.codes = codes;
@@ -113,8 +109,7 @@
/**
* Sets the libraries.
*
- * @param libraries
- * the new libraries
+ * @param libraries the new libraries
*/
public void setLibraries(List<Library> libraries) {
this.libraries = libraries;
@@ -133,4 +128,48 @@
public void accept(EntityVisitor visitor) {
visitor.visitComponent(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((codes == null) ? 0 : codes.hashCode());
+ result = prime * result + ((constants == null) ? 0 : constants.hashCode());
+ result = prime * result + ((libraries == null) ? 0 : libraries.hashCode());
+ result = prime * result + ((structures == null) ? 0 : structures.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Component other = (Component) obj;
+ if (codes == null) {
+ if (other.codes != null)
+ return false;
+ } else if (!codes.equals(other.codes))
+ return false;
+ if (constants == null) {
+ if (other.constants != null)
+ return false;
+ } else if (!constants.equals(other.constants))
+ return false;
+ if (libraries == null) {
+ if (other.libraries != null)
+ return false;
+ } else if (!libraries.equals(other.libraries))
+ return false;
+ if (structures == null) {
+ if (other.structures != null)
+ return false;
+ } else if (!structures.equals(other.structures))
+ return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Constant.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Constant.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Constant.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -17,10 +17,10 @@
* ##% */
package fr.cemagref.simexplorer.is.entities.data;
+import java.io.Serializable;
+
import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-import java.io.Serializable;
-
/** The Class Constant. */
public class Constant extends DataEntity implements Serializable {
@@ -80,4 +80,38 @@
public void accept(EntityVisitor visitor) {
visitor.visitConstant(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.getCanonicalName().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Constant other = (Constant) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (type == null) {
+ if (other.type != null)
+ return false;
+ } else if (!type.getCanonicalName().equals(other.type.getCanonicalName()))
+ return false;
+ return true;
+ }
+
+
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ConstantValue.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ConstantValue.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ConstantValue.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -17,10 +17,10 @@
* ##% */
package fr.cemagref.simexplorer.is.entities.data;
+import java.io.Serializable;
+
import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-import java.io.Serializable;
-
/**
* The Class ConstantValue.
*/
@@ -47,8 +47,7 @@
/**
* Sets the value.
*
- * @param value
- * the new value
+ * @param value the new value
*/
public void setValue(String value) {
this.value = value;
@@ -66,8 +65,7 @@
/**
* Sets the constant.
*
- * @param constant
- * the new constant
+ * @param constant the new constant
*/
public void setConstant(Constant constant) {
this.constant = constant;
@@ -77,4 +75,35 @@
visitor.visitConstantValue(this);
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((constant == null) ? 0 : constant.hashCode());
+ result = prime * result + ((value == null) ? 0 : value.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final ConstantValue other = (ConstantValue) obj;
+ if (constant == null) {
+ if (other.constant != null)
+ return false;
+ } else if (!constant.equals(other.constant))
+ return false;
+ if (value == null) {
+ if (other.value != null)
+ return false;
+ } else if (!value.equals(other.value))
+ return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/DataEntity.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/DataEntity.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/DataEntity.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -24,47 +24,25 @@
*/
public abstract class DataEntity implements BaseEntity {
- /** The parent data. */
- private DataEntity parentData;
-
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -2570073990226703994L;
- /**
- * Gets the parent loggable element.
- *
- * @return the parent loggable element
- */
- public LoggableElement getParentLoggableElement() {
- LoggableElement parentLoggableElement = null;
- if (getParentData() instanceof LoggableElement) {
- parentLoggableElement = (LoggableElement) getParentData();
- } else {
- if (getParentData() != null) {
- parentLoggableElement = getParentData()
- .getParentLoggableElement();
- }
- }
- return parentLoggableElement;
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ return result;
}
- /**
- * Gets the parent data.
- *
- * @return the parentData
- */
- public DataEntity getParentData() {
- return parentData;
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ return true;
}
- /**
- * Sets the parent data.
- *
- * @param parentData
- * the parentData to set
- */
- public void setParentData(DataEntity parentData) {
- this.parentData = parentData;
- }
-
}
Added: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Descriptor.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Descriptor.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Descriptor.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -0,0 +1,132 @@
+/*
+* ##% 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.entities.data;
+
+import fr.cemagref.simexplorer.is.entities.BaseEntity;
+import fr.cemagref.simexplorer.is.entities.EntityVisitor;
+
+/**
+ * The Class Descriptor.
+ */
+public class Descriptor implements BaseEntity, Comparable<Descriptor> {
+
+ /** The Constant serialVersionUID. */
+ private static final long serialVersionUID = -7429465085491453048L;
+
+ /** The name. */
+ private String name;
+
+ /** The value. */
+ private String value;
+
+ /**
+ * Instantiates a new descriptor.
+ *
+ * @param name the name
+ * @param value the value
+ */
+ public Descriptor(String name, String value) {
+ super();
+ this.name = name;
+ this.value = value;
+ }
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.entities.EntityVisitable#accept(fr.cemagref.simexplorer.is.entities.EntityVisitor)
+ */
+ @Override
+ public void accept(EntityVisitor visitor) {
+ // nothing... yet!
+ }
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name.
+ *
+ * @param name the new name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Gets the value.
+ *
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * @param value the new value
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public int compareTo(Descriptor o) {
+ if (this.getName() == null || o == null || o.getName() == null) {
+ return 0;
+ }
+ return this.getName().compareTo(o.getName());
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((value == null) ? 0 : value.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Descriptor other = (Descriptor) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (value == null) {
+ if (other.value != null)
+ return false;
+ } else if (!value.equals(other.value))
+ return false;
+ return true;
+ }
+
+}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationApplication.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationApplication.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationApplication.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -17,18 +17,16 @@
* ##% */
package fr.cemagref.simexplorer.is.entities.data;
-import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
+import fr.cemagref.simexplorer.is.entities.EntityVisitor;
+
/**
* The Class ExplorationApplication.
*/
-public class ExplorationApplication extends LoggableElement implements
- Serializable {
+public class ExplorationApplication extends LoggableElement implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 122049347724394193L;
@@ -51,8 +49,7 @@
/**
* Sets the explorations.
*
- * @param explorations
- * the new explorations
+ * @param explorations the new explorations
*/
public void setExplorations(List<ExplorationData> explorations) {
this.explorations = explorations;
@@ -70,8 +67,7 @@
/**
* Sets the components.
*
- * @param components
- * the new components
+ * @param components the new components
*/
public void setComponents(List<Component> components) {
this.components = components;
@@ -91,4 +87,36 @@
public void accept(EntityVisitor visitor) {
visitor.visitExplorationApplication(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((components == null) ? 0 : components.hashCode());
+ result = prime * result + ((explorations == null) ? 0 : explorations.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final ExplorationApplication other = (ExplorationApplication) obj;
+ if (components == null) {
+ if (other.components != null)
+ return false;
+ } else if (!components.equals(other.components))
+ return false;
+ if (explorations == null) {
+ if (other.explorations != null)
+ return false;
+ } else if (!explorations.equals(other.explorations))
+ return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationData.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationData.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/ExplorationData.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -17,12 +17,11 @@
* ##% */
package fr.cemagref.simexplorer.is.entities.data;
-import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-
import java.io.Serializable;
import java.util.List;
-import java.util.Set;
+import fr.cemagref.simexplorer.is.entities.EntityVisitor;
+
/**
* The Class ExplorationData.
*/
@@ -40,8 +39,7 @@
/**
* Find constant value.
*
- * @param c
- * the constant to find
+ * @param c the constant to find
*
* @return the constant value
*/
@@ -57,10 +55,8 @@
/**
* Sets the constant value.
*
- * @param c
- * the constant to set
- * @param value
- * the value
+ * @param c the constant to set
+ * @param value the value
*/
public void setConstantValue(Constant c, String value) {
ConstantValue constantValue = findConstantValue(c);
@@ -75,8 +71,7 @@
/**
* Gets the constant value.
*
- * @param c
- * the c
+ * @param c the c
*
* @return the constant value
*/
@@ -100,8 +95,7 @@
/**
* Sets the result.
*
- * @param result
- * the new result
+ * @param result the new result
*/
public void setResult(Result result) {
this.result = result;
@@ -119,8 +113,7 @@
/**
* Sets the values map.
*
- * @param constantValues
- * the new values map
+ * @param constantValues the new values map
*/
public void setConstantValues(List<ConstantValue> constantValues) {
this.constantValues = constantValues;
@@ -137,4 +130,36 @@
public void accept(EntityVisitor visitor) {
visitor.visitExplorationData(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((constantValues == null) ? 0 : constantValues.hashCode());
+ result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final ExplorationData other = (ExplorationData) obj;
+ if (constantValues == null) {
+ if (other.constantValues != null)
+ return false;
+ } else if (!constantValues.equals(other.constantValues))
+ return false;
+ if (result == null) {
+ if (other.result != null)
+ return false;
+ } else if (!result.equals(other.result))
+ return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Library.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Library.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Library.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -17,10 +17,10 @@
* ##% */
package fr.cemagref.simexplorer.is.entities.data;
+import java.util.List;
+
import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-import java.util.List;
-
/** The Class Library. */
public class Library extends LoggableElement {
@@ -38,4 +38,33 @@
public void accept(EntityVisitor visitor) {
visitor.visitLibrary(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ // add properties hashes
+ // result = prime * result + property.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Library other = (Library) obj;
+ // add properties tests
+ // if (property == null) {
+ // if (other.property != null)
+ // return false;
+ // } else if (!property.equals(other.property))
+ // return false;
+ return true;
+ }
+
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
+import fr.cemagref.simexplorer.is.entities.attachment.Attachment;
import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
/**
@@ -27,39 +28,30 @@
*/
public abstract class LoggableElement extends DataEntity {
- /** The meta data. */
- private MetaData metaData;
-
+ /** The name. */
+ private String name;
+
+ /** The description. */
+ private String description;
+
+ /** The descriptors. */
+ private List<Descriptor> descriptors;
+
+ /** The attachments. */
+ private List<Attachment> attachments;
+
+ /** The metadata IS, managed only by SimExplorer-IS. */
+ private MetaData metadataIS;
+
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 2000267650904269217L;
- /**
- * Gets the meta data.
- *
- * @return the metaData
- */
- public MetaData getMetaData() {
- return metaData;
- }
-
- /**
- * Sets the meta data.
- *
- * @param metaData the metaData to set
- */
- public void setMetaData(MetaData metaData) {
- this.metaData = metaData;
- }
-
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
- if (metaData == null) {
- return super.toString();
- }
- return metaData.getName() + " [" + metaData.getVersion() + ']';
+ return getName();
}
/**
@@ -88,4 +80,177 @@
return children;
}
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name.
+ *
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Gets the descriptors.
+ *
+ * @return the descriptors
+ */
+ public List<Descriptor> getDescriptors() {
+ return descriptors;
+ }
+
+ /**
+ * Sets the descriptors.
+ *
+ * @param descriptors the descriptors to set
+ */
+ public void setDescriptors(List<Descriptor> descriptors) {
+ this.descriptors = descriptors;
+ }
+
+ /**
+ * Gets the attachments.
+ *
+ * @return the attachments
+ */
+ public List<Attachment> getAttachments() {
+ if (attachments == null) {
+ attachments = new ArrayList<Attachment>();
+ }
+ return attachments;
+ }
+
+ /**
+ * Get attachment by his index.
+ *
+ * @param attachmentIndex index of attachment to find
+ *
+ * @return the correct attachment
+ */
+ public Attachment getAttachment(Integer attachmentIndex) {
+ if (attachmentIndex != null && attachmentIndex > -1 && attachments != null && !attachments.isEmpty()
+ && attachments.size() > attachmentIndex) {
+ return attachments.get(attachmentIndex);
+ }
+ return null;
+ }
+
+ /**
+ * Get attachment by his uniqueId.
+ *
+ * @param attachmentUniqueId unqiue id of attachment to find
+ *
+ * @return the correct attachment
+ */
+ public Attachment getAttachment(String attachmentUniqueId) {
+ if (attachmentUniqueId != null && attachments != null && !attachments.isEmpty()) {
+ for (Attachment attachment : attachments) {
+ if (attachmentUniqueId.equals(attachment.getUniqueId())) {
+ return attachment;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Sets the attachments.
+ *
+ * @param attachments the attachments to set
+ */
+ public void setAttachments(List<Attachment> attachments) {
+ this.attachments = attachments;
+ }
+
+ /**
+ * Gets the metadata is. If element is not retrieved through IS, this data is inconsistent
+ *
+ * @return the metadata is
+ */
+ public MetaData getMetaData() {
+ return metadataIS;
+ }
+
+ /**
+ * Sets the metadata is. Only the IS should set that value.
+ *
+ * @param metadataIS the new metadata is
+ */
+ public void setMetaData(MetaData metadataIS) {
+ this.metadataIS = metadataIS;
+ }
+
+ @Override
+ public int hashCode() {
+ // metadata is and should not included!
+
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((attachments == null) ? 0 : attachments.hashCode());
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((descriptors == null) ? 0 : descriptors.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ // metadata is and should not included!
+
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final LoggableElement other = (LoggableElement) obj;
+ if (attachments == null) {
+ if (other.attachments != null)
+ return false;
+ } else if (!attachments.equals(other.attachments))
+ return false;
+ if (description == null) {
+ if (other.description != null)
+ return false;
+ } else if (!description.equals(other.description))
+ return false;
+ if (descriptors == null) {
+ if (other.descriptors != null)
+ return false;
+ } else if (!descriptors.equals(other.descriptors))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Repository.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Repository.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Repository.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -19,8 +19,6 @@
import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-import java.io.Serializable;
-
/**
* The Class Repository.
*/
@@ -32,4 +30,32 @@
public void accept(EntityVisitor visitor) {
visitor.visitRepository(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ // add properties hashes
+ // result = prime * result + property.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Repository other = (Repository) obj;
+ // add properties tests
+ // if (property == null) {
+ // if (other.property != null)
+ // return false;
+ // } else if (!property.equals(other.property))
+ // return false;
+ return true;
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Result.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Result.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Result.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -19,8 +19,6 @@
import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-import java.io.Serializable;
-
/** The Class Result. */
public class Result extends DataEntity {
@@ -35,4 +33,31 @@
public void accept(EntityVisitor visitor) {
visitor.visitResult(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ // add properties hashes
+ // result = prime * result + property.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Result other = (Result) obj;
+ // add properties tests
+ // if (property == null) {
+ // if (other.property != null)
+ // return false;
+ // } else if (!property.equals(other.property))
+ // return false;
+ return true;
+ }
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Structure.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Structure.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Structure.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -22,7 +22,7 @@
/**
* The Class Structure.
*/
-public class Structure extends DataEntity {
+public abstract class Structure extends DataEntity {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 2594331198459134006L;
@@ -30,4 +30,31 @@
public void accept(EntityVisitor visitor) {
visitor.visitStructure(this);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ // add properties hashes
+ // result = prime * result + property.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Structure other = (Structure) obj;
+ // add properties tests
+ // if (property == null) {
+ // if (other.property != null)
+ // return false;
+ // } else if (!property.equals(other.property))
+ // return false;
+ return true;
+ }
}
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java 2008-02-22 09:59:51 UTC (rev 1191)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java 2008-02-22 16:46:35 UTC (rev 1192)
@@ -17,16 +17,15 @@
* ##% */
package fr.cemagref.simexplorer.is.entities.metadata;
-import fr.cemagref.simexplorer.is.entities.attachment.Attachment;
+import java.util.Date;
+
import fr.cemagref.simexplorer.is.entities.BaseEntity;
import fr.cemagref.simexplorer.is.entities.EntityVisitor;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-/** The Class MetaData. */
+/**
+ * The Class MetaData. Used by IS to store relative data of a LoggableElement. SimExplorer should not set properties of
+ * this class.
+ */
public class MetaData implements BaseEntity {
/** The Constant serialVersionUID. */
@@ -35,42 +34,49 @@
/** The uuid. */
private String uuid;
+ /** The version. */
+ private Version version;
+
/** The name. */
private String name;
- /** The type. */
- private String type;
-
/** The description. */
private String description;
- /** The version. */
- private Version version;
-
/** The creation date. */
private Date creationDate;
/** The hash. */
private String hash;
- /** The descriptors. */
- private Map<String, String> descriptors;
-
- /** The attachments. */
- private List<Attachment> attachments;
-
/** The parent version uuid. */
- private String parentVersionUuid;
+ private String parentUuid;
/** The parent version version. */
- private String parentVersionVersion;
+ private Version parentVersion;
/** The latest. */
private boolean latest;
+ /** The class name of the element. */
+ private Class<?> elementClass;
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(getName()).append(" ").append(getUuid());
+ if (version != null) {
+ sb.append(" [").append(getVersion()).append(']');
+ }
+ return sb.toString();
+ }
+
/**
* Gets the uuid.
- *
+ *
* @return the uuid
*/
public String getUuid() {
@@ -79,7 +85,7 @@
/**
* Sets the uuid.
- *
+ *
* @param uuid the uuid to set
*/
public void setUuid(String uuid) {
@@ -87,62 +93,8 @@
}
/**
- * Gets the name.
- *
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the name.
- *
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * Gets the type.
- *
- * @return the type
- */
- public String getType() {
- return type;
- }
-
- /**
- * Sets the type.
- *
- * @param type the type to set
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * Gets the description.
- *
- * @return the description
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * Sets the description.
- *
- * @param description the description to set
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
- /**
* Gets the version.
- *
+ *
* @return the version
*/
public Version getVersion() {
@@ -151,7 +103,7 @@
/**
* Sets the version.
- *
+ *
* @param version the version to set
*/
public void setVersion(String version) {
@@ -159,8 +111,21 @@
}
/**
+ * Sets the version.
+ *
+ * @param version the version to set
+ */
+ public void setVersion(Version version) {
+ if (version == null) {
+ this.version = null;
+ } else {
+ this.version = version.safeClone();
+ }
+ }
+
+ /**
* Gets the creation date.
- *
+ *
* @return the creationDate
*/
public Date getCreationDate() {
@@ -169,7 +134,7 @@
/**
* Sets the creation date.
- *
+ *
* @param creationDate the creationDate to set
*/
public void setCreationDate(Date creationDate) {
@@ -178,7 +143,7 @@
/**
* Gets the hash.
- *
+ *
* @return the hash
*/
public String getHash() {
@@ -187,7 +152,7 @@
/**
* Sets the hash.
- *
+ *
* @param hash the hash to set
*/
public void setHash(String hash) {
@@ -195,129 +160,132 @@
}
/**
- * Gets the descriptors.
- *
- * @return the descriptors
+ * Gets the parent version uuid.
+ *
+ * @return the parentVersionUuid
*/
- public Map<String, String> getDescriptors() {
- return descriptors;
+ public String getParentUuid() {
+ return parentUuid;
}
/**
- * Sets the descriptors.
- *
- * @param descriptors the descriptors to set
+ * Sets the parent version uuid.
+ *
+ * @param parentUuid the parentUuid to set
*/
- public void setDescriptors(Map<String, String> descriptors) {
- this.descriptors = descriptors;
+ public void setParentUuid(String parentUuid) {
+ this.parentUuid = parentUuid;
}
/**
- * Gets the attachments.
- *
- * @return the attachments
+ * Gets the parent version version.
+ *
+ * @return the parentVersionVersion
*/
- public List<Attachment> getAttachments() {
- if (attachments == null) {
- attachments = new ArrayList<Attachment>();
- }
- return attachments;
+ public Version getParentVersion() {
+ return parentVersion;
}
/**
- * Get attachment by his index
- *
- * @param attachmentIndex index of attachment to find
- * @return the correct attachment
+ * Sets the parent version version.
+ *
+ * @param parentVersion the parentVersionVersion to set
*/
- public Attachment getAttachment(Integer attachmentIndex) {
- if (attachmentIndex != null && attachmentIndex > -1 && attachments != null && !attachments.isEmpty() && attachments.size() > attachmentIndex) {
- return attachments.get(attachmentIndex);
+ public void setParentVersion(Version parentVersion) {
+ if (parentVersion == null) {
+ this.parentVersion = null;
+ } else {
+ this.parentVersion = parentVersion.safeClone();
}
- return null;
}
/**
- * Get attachment by his uniqueId
- *
- * @param attachmentUniqueId unqiue id of attachment to find
- * @return the correct attachment
+ * Sets the parent version version.
+ *
+ * @param parentVersion the parentVersionVersion to set
*/
- public Attachment getAttachment(String attachmentUniqueId) {
- if (attachmentUniqueId != null && attachments != null && !attachments.isEmpty()) {
- for (Attachment attachment : attachments) {
- if (attachmentUniqueId.equals(attachment.getUniqueId())) {
- return attachment;
- }
- }
- }
- return null;
+ public void setParentVersion(String parentVersion) {
+ this.parentVersion = Version.valueOf(parentVersion);
}
/**
- * Sets the attachments.
- *
- * @param attachments the attachments to set
+ * Checks if is latest.
+ *
+ * @return true, if is latest
*/
- public void setAttachments(List<Attachment> attachments) {
- this.attachments = attachments;
+ public boolean isLatest() {
+ return latest;
}
/**
- * Gets the parent version uuid.
- *
- * @return the parentVersionUuid
+ * Sets the latest.
+ *
+ * @param latest the new latest
*/
- public String getParentVersionUuid() {
- return parentVersionUuid;
+ public void setLatest(boolean latest) {
+ this.latest = latest;
}
/**
- * Sets the parent version uuid.
- *
- * @param parentVersionUuid the parentVersionUuid to set
+ * Gets the name.
+ *
+ * @return the name
*/
- public void setParentVersionUuid(String parentVersionUuid) {
- this.parentVersionUuid = parentVersionUuid;
+ public String getName() {
+ return name;
}
/**
- * Gets the parent version version.
- *
- * @return the parentVersionVersion
+ * Sets the name.
+ *
+ * @param name the new name
*/
- public String getParentVersionVersion() {
- return parentVersionVersion;
+ public void setName(String name) {
+ this.name = name;
}
/**
- * Sets the parent version version.
- *
- * @param parentVersionVersion the parentVersionVersion to set
+ * Gets the description.
+ *
+ * @return the description
*/
- public void setParentVersionVersion(String parentVersionVersion) {
- this.parentVersionVersion = parentVersionVersion;
+ public String getDescription() {
+ return description;
}
/**
- * Checks if is latest.
- *
- * @return true, if is latest
+ * Sets the description.
+ *
+ * @param description the new description
*/
- public boolean isLatest() {
- return latest;
+ public void setDescription(String description) {
+ this.description = description;
}
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.entities.EntityVisitable#accept(fr.cemagref.simexplorer.is.entities.EntityVisitor)
+ */
+ @Override
+ public void accept(EntityVisitor visitor) {
+ // nothing yet
+ }
+
/**
- * Sets the latest.
- *
- * @param latest the new latest
+ * Gets the element class.
+ *
+ * @return the element class
*/
- public void setLatest(boolean latest) {
- this.latest = latest;
+ public Class<?> getElementClass() {
+ return elementClass;
}
- public void accept(EntityVisitor visitor) {
- visitor.visitMetaData(this);
+ /**
+ * Sets the element class.
+ *
+ * @param elementClass the new element class
+ */
+ public void setElementClass(Class<?> elementClass) {
+ this.elementClass = elementClass;
}
+
}
1
0
r1191 - trunk/simexplorer-is/simexplorer-is-swing
by tchemit@users.labs.libre-entreprise.org 22 Feb '08
by tchemit@users.labs.libre-entreprise.org 22 Feb '08
22 Feb '08
Author: tchemit
Date: 2008-02-22 09:59:51 +0000 (Fri, 22 Feb 2008)
New Revision: 1191
Modified:
trunk/simexplorer-is/simexplorer-is-swing/pom.xml
Log:
ajout dependance jboss ejb
Modified: trunk/simexplorer-is/simexplorer-is-swing/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/pom.xml 2008-02-22 01:51:26 UTC (rev 1190)
+++ trunk/simexplorer-is/simexplorer-is-swing/pom.xml 2008-02-22 09:59:51 UTC (rev 1191)
@@ -228,5 +228,12 @@
<version>0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
+ <!-- pour avoir les ejb jboss -->
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jbossall-client</artifactId>
+ <version>4.2.2.GA</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
1
0
r1190 - trunk/simexplorer-is/simexplorer-is-swing
by tchemit@users.labs.libre-entreprise.org 22 Feb '08
by tchemit@users.labs.libre-entreprise.org 22 Feb '08
22 Feb '08
Author: tchemit
Date: 2008-02-22 01:51:26 +0000 (Fri, 22 Feb 2008)
New Revision: 1190
Added:
trunk/simexplorer-is/simexplorer-is-swing/go.bat
trunk/simexplorer-is/simexplorer-is-swing/go.sh
Log:
des go utilisateurs qui utilisent uniquement le jar
Added: trunk/simexplorer-is/simexplorer-is-swing/go.bat
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/go.bat (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-swing/go.bat 2008-02-22 01:51:26 UTC (rev 1190)
@@ -0,0 +1,6 @@
+if not "%1" == "debug" goto start
+Set DEBUG="-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=38000,server=y,suspend=n"
+shift
+
+:start
+java -XX:MaxPermSize=256m -Xmx128m -Xms64m %DEBUG% -jar simexplorer-is-swing-0.0.1-SNAPSHOT.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 > error.txt 2>&1
Added: trunk/simexplorer-is/simexplorer-is-swing/go.sh
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/go.sh (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-swing/go.sh 2008-02-22 01:51:26 UTC (rev 1190)
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+DEBUG_PORT=5005
+VERSION=0.0.1-SNAPSHOT
+
+###############################################################################
+####### parse arguments #######################################################
+###############################################################################
+
+while true; do
+ case "$1" in
+ -d|--debug)
+ echo "Debug mode"
+ DEBUG="-server -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$DEBUG_PORT"
+ shift ;;
+ -n|--nosuspend)
+ echo "Debug no suspend mode"
+ DEBUG="$DEBUG,suspend=n"
+ shift ;;
+ \-\-) shift ; break ;;
+ *) break;
+ esac
+done
+
+###############################################################################
+####### init variables ########################################################
+###############################################################################
+
+JAVA=java
+
+dir=$(dirname $0)
+cd $dir
+
+RELEASE="simexplorer-is-swing-$VERSION"
+MX=128M
+
+rep=`dirname $0`
+rep=`cd $rep && pwd`
+
+cd $rep
+
+###############################################################################
+####### launch appli ##########################################################
+###############################################################################
+echo "java $RELEASE $@"
+$JAVA $DEBUG -Xmx$MX -Xms$MX -jar target/$RELEASE.jar $@ > error.txt 2>&1
\ No newline at end of file
Property changes on: trunk/simexplorer-is/simexplorer-is-swing/go.sh
___________________________________________________________________
Name: svn:executable
+ *
1
0
r1189 - trunk/simexplorer-is/simexplorer-is-swing
by tchemit@users.labs.libre-entreprise.org 22 Feb '08
by tchemit@users.labs.libre-entreprise.org 22 Feb '08
22 Feb '08
Author: tchemit
Date: 2008-02-22 01:47:51 +0000 (Fri, 22 Feb 2008)
New Revision: 1189
Added:
trunk/simexplorer-is/simexplorer-is-swing/dev.sh
Removed:
trunk/simexplorer-is/simexplorer-is-swing/go.sh
Log:
rename
Copied: trunk/simexplorer-is/simexplorer-is-swing/dev.sh (from rev 1184, trunk/simexplorer-is/simexplorer-is-swing/go.sh)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/dev.sh (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-swing/dev.sh 2008-02-22 01:47:51 UTC (rev 1189)
@@ -0,0 +1,131 @@
+#!/bin/sh
+
+
+###############################################################################
+####### parse arguments #######################################################
+###############################################################################
+
+#TODO Generate via commadline:generateGo
+#TEMP=`getopt -o kcjuodn:: --long clean,compile,jar,upline,debug,nosuspend,output:: \
+# -n 'dev.sh' -- "$@"`
+#if [ $? != 0 ] ; then
+# echo "bag argument"
+# exit 1
+#fi
+#eval set -- "$TEMP"
+
+CLEAN=""
+COMPILE=""
+DEV="classes"
+OFF_LINE="-o "
+MOUTPUT="target/maven.log"
+while true; do
+ case "$1" in
+ -k|--clean)
+ CLEAN="clean"
+ shift;;
+ -c|--compile)
+ COMPILE="compile"
+ shift;;
+ -j|--jar)
+ DEV="jar"
+ shift;;
+ -u|--upline)
+ OFF_LINE=""
+ shift;;
+ -o|--output)
+ MOUTPUT="$1"
+ shift;;
+ -d|--debug)
+ echo "Debug mode"
+ #DEBUG="-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=38000,server=y"
+ DEBUG="-server -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
+ shift ;;
+ -n|--nosuspend)
+ echo "Debug no suspend mode"
+ DEBUG="$DEBUG,suspend=n"
+ shift ;;
+ \-\-) shift ; break ;;
+ *) break;
+ esac
+done
+
+###############################################################################
+####### init variables ########################################################
+###############################################################################
+
+#JAVA="/opt/repository/jdk1.6.0/bin/java -splash:src/resources/images/splash2.jpg"
+#JAVA="java -Djava.library.path=lib -splash:src/resources/images/splash2.jpg"
+
+JAVA=java
+
+dir=$(dirname $0)
+cd $dir
+
+# Warning, pom.xml must have xmlns info on his root node!
+VER=$(xmlstarlet sel -N "p=http://maven.apache.org/POM/4.0.0" -t -v "/p:project/p:version" pom.xml)
+
+RELEASE="simexplorer-is-swing-$VER"
+MAIN_CLASS="fr.cemagref.simexplorer.is.ui.swing.SimExplorer"
+MX=512M
+
+rep=`dirname $0`
+rep=`cd $rep && pwd`
+
+cd $rep
+
+###############################################################################
+####### build required maven goals ############################################
+###############################################################################
+MVN_ACTION=
+if [ "$CLEAN" = "clean" ]; then
+ MVN_ACTION="clean dependency:copy-dependencies compile"
+ if [ "$DEV" = "jar" ]; then
+ MVN_ACTION="$MVN_ACTION jar:jar"
+ fi
+else
+ if [ ! -d $rep/target/dependency ]; then
+ MVN_ACTION="$MVN_ACTION dependency:copy-dependencies"
+ fi
+ if [ ! -d $rep/target/classes -o "$COMPILE" = "compile" ]; then
+ MVN_ACTION="$MVN_ACTION compile"
+ fi
+ if [ "$DEV" = "jar" -a ! -f $rep/target/$RELEASE.jar ]; then
+ MVN_ACTION="$MVN_ACTION jar:jar"
+ fi
+fi
+
+###############################################################################
+####### launch maven if required ##############################################
+###############################################################################
+if [ ! "$MVN_ACTION" = "" ]; then
+ action="mvn -e $MVN_ACTION $OFF_LINE > $MOUTPUT"
+ echo "$action"
+ mkdir target 2>/dev/null
+ eval "$action"
+ if [ $? != 0 ] ; then
+ echo "error with maven :"
+ cat $MOUTPUT
+ exit 1
+ fi
+ echo "mvn done."
+fi
+
+###############################################################################
+####### build classpath (by default use classes, not jar (one less goal:)) ####
+###############################################################################
+CL=$rep/target/classes
+if [ "$DEV" = "jar" ]; then
+ CL=$rep/target/$RELEASE.jar
+fi
+echo "use CL $CL"
+# add dependencies to class path
+for f in $rep/target/dependency/*.jar; do
+ CL=$CL:$f
+done
+
+###############################################################################
+####### launch appli ##########################################################
+###############################################################################
+echo "java $MAIN_CLASS $@"
+$JAVA $DEBUG -Xmx$MX -Xms$MX -classpath $CL $JVM_OPT $MAIN_CLASS $@
\ No newline at end of file
Property changes on: trunk/simexplorer-is/simexplorer-is-swing/dev.sh
___________________________________________________________________
Name: svn:executable
+ *
Deleted: trunk/simexplorer-is/simexplorer-is-swing/go.sh
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/go.sh 2008-02-22 00:49:11 UTC (rev 1188)
+++ trunk/simexplorer-is/simexplorer-is-swing/go.sh 2008-02-22 01:47:51 UTC (rev 1189)
@@ -1,131 +0,0 @@
-#!/bin/sh
-
-
-###############################################################################
-####### parse arguments #######################################################
-###############################################################################
-
-#TODO Generate via commadline:generateGo
-#TEMP=`getopt -o kcjuodn:: --long clean,compile,jar,upline,debug,nosuspend,output:: \
-# -n 'go.sh' -- "$@"`
-#if [ $? != 0 ] ; then
-# echo "bag argument"
-# exit 1
-#fi
-#eval set -- "$TEMP"
-
-CLEAN=""
-COMPILE=""
-DEV="classes"
-OFF_LINE="-o "
-MOUTPUT="target/maven.log"
-while true; do
- case "$1" in
- -k|--clean)
- CLEAN="clean"
- shift;;
- -c|--compile)
- COMPILE="compile"
- shift;;
- -j|--jar)
- DEV="jar"
- shift;;
- -u|--upline)
- OFF_LINE=""
- shift;;
- -o|--output)
- MOUTPUT="$1"
- shift;;
- -d|--debug)
- echo "Debug mode"
- #DEBUG="-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=38000,server=y"
- DEBUG="-server -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
- shift ;;
- -n|--nosuspend)
- echo "Debug no suspend mode"
- DEBUG="$DEBUG,suspend=n"
- shift ;;
- \-\-) shift ; break ;;
- *) break;
- esac
-done
-
-###############################################################################
-####### init variables ########################################################
-###############################################################################
-
-#JAVA="/opt/repository/jdk1.6.0/bin/java -splash:src/resources/images/splash2.jpg"
-#JAVA="java -Djava.library.path=lib -splash:src/resources/images/splash2.jpg"
-
-JAVA=java
-
-dir=$(dirname $0)
-cd $dir
-
-# Warning, pom.xml must have xmlns info on his root node!
-VER=$(xmlstarlet sel -N "p=http://maven.apache.org/POM/4.0.0" -t -v "/p:project/p:version" pom.xml)
-
-RELEASE="simexplorer-is-swing-$VER"
-MAIN_CLASS="fr.cemagref.simexplorer.is.ui.swing.SimExplorer"
-MX=512M
-
-rep=`dirname $0`
-rep=`cd $rep && pwd`
-
-cd $rep
-
-###############################################################################
-####### build required maven goals ############################################
-###############################################################################
-MVN_ACTION=
-if [ "$CLEAN" = "clean" ]; then
- MVN_ACTION="clean dependency:copy-dependencies compile"
- if [ "$DEV" = "jar" ]; then
- MVN_ACTION="$MVN_ACTION jar:jar"
- fi
-else
- if [ ! -d $rep/target/dependency ]; then
- MVN_ACTION="$MVN_ACTION dependency:copy-dependencies"
- fi
- if [ ! -d $rep/target/classes -o "$COMPILE" = "compile" ]; then
- MVN_ACTION="$MVN_ACTION compile"
- fi
- if [ "$DEV" = "jar" -a ! -f $rep/target/$RELEASE.jar ]; then
- MVN_ACTION="$MVN_ACTION jar:jar"
- fi
-fi
-
-###############################################################################
-####### launch maven if required ##############################################
-###############################################################################
-if [ ! "$MVN_ACTION" = "" ]; then
- action="mvn -e $MVN_ACTION $OFF_LINE > $MOUTPUT"
- echo "$action"
- mkdir target 2>/dev/null
- eval "$action"
- if [ $? != 0 ] ; then
- echo "error with maven :"
- cat $MOUTPUT
- exit 1
- fi
- echo "mvn done."
-fi
-
-###############################################################################
-####### build classpath (by default use classes, not jar (one less goal:)) ####
-###############################################################################
-CL=$rep/target/classes
-if [ "$DEV" = "jar" ]; then
- CL=$rep/target/$RELEASE.jar
-fi
-echo "use CL $CL"
-# add dependencies to class path
-for f in $rep/target/dependency/*.jar; do
- CL=$CL:$f
-done
-
-###############################################################################
-####### launch appli ##########################################################
-###############################################################################
-echo "java $MAIN_CLASS $@"
-$JAVA $DEBUG -Xmx$MX -Xms$MX -classpath $CL $JVM_OPT $MAIN_CLASS $@
\ No newline at end of file
1
0
r1188 - trunk/simexplorer-is/simexplorer-is-swing
by tchemit@users.labs.libre-entreprise.org 22 Feb '08
by tchemit@users.labs.libre-entreprise.org 22 Feb '08
22 Feb '08
Author: tchemit
Date: 2008-02-22 00:49:11 +0000 (Fri, 22 Feb 2008)
New Revision: 1188
Modified:
trunk/simexplorer-is/simexplorer-is-swing/pom.xml
Log:
dependance lutinwidget pendant generation jaxx
Modified: trunk/simexplorer-is/simexplorer-is-swing/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/pom.xml 2008-02-21 23:07:17 UTC (rev 1187)
+++ trunk/simexplorer-is/simexplorer-is-swing/pom.xml 2008-02-22 00:49:11 UTC (rev 1188)
@@ -52,6 +52,14 @@
</goals>
</execution>
</executions>
+ <dependencies>
+ <dependency>
+ <groupId>lutinlib</groupId>
+ <artifactId>lutinwidget</artifactId>
+ <version>0.10-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
@@ -200,6 +208,12 @@
<artifactId>simexplorer-is-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>lutinlib</groupId>
+ <artifactId>lutinwidget</artifactId>
+ <version>0.10-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
<!-- librairie Jaxx -->
<dependency>
<groupId>lutinlib</groupId>
1
0
Author: tchemit
Date: 2008-02-21 23:07:17 +0000 (Thu, 21 Feb 2008)
New Revision: 1187
Modified:
trunk/simexplorer-is/pom.xml
Log:
construction des sources a la phase verify
Modified: trunk/simexplorer-is/pom.xml
===================================================================
--- trunk/simexplorer-is/pom.xml 2008-02-21 23:06:15 UTC (rev 1186)
+++ trunk/simexplorer-is/pom.xml 2008-02-21 23:07:17 UTC (rev 1187)
@@ -172,7 +172,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
- <execution>
+ <execution>
+ <phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
1
0
r1186 - trunk/simexplorer-is/simexplorer-is-swing
by tchemit@users.labs.libre-entreprise.org 21 Feb '08
by tchemit@users.labs.libre-entreprise.org 21 Feb '08
21 Feb '08
Author: tchemit
Date: 2008-02-21 23:06:15 +0000 (Thu, 21 Feb 2008)
New Revision: 1186
Modified:
trunk/simexplorer-is/simexplorer-is-swing/pom.xml
Log:
refactoring pom
Modified: trunk/simexplorer-is/simexplorer-is-swing/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/pom.xml 2008-02-21 23:05:43 UTC (rev 1185)
+++ trunk/simexplorer-is/simexplorer-is-swing/pom.xml 2008-02-21 23:06:15 UTC (rev 1186)
@@ -40,31 +40,13 @@
<build>
<plugins>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <mainClass>
- ${maven.jar.main.class}
- </mainClass>
- <addClasspath>true</addClasspath>
- <addExtensions />
- <classpathPrefix>./dependency/</classpathPrefix>
- </manifest>
- </archive>
- </configuration>
- </plugin>
-
+ <!-- Generate phase -->
<plugin>
<groupId>lutinplugin</groupId>
<artifactId>maven-jaxx-plugin</artifactId>
<version>0.2-SNAPSHOT</version>
<executions>
<execution>
- <phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
@@ -73,61 +55,47 @@
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
+ <configuration>
+ <!-- recopie des fichiers java sources et generes vers src-build/java -->
+ <tasks>
+ <copy todir="${maven.src.dir}/java" verbose="${maven.verbose}" overwrite="true">
+ <fileset dir="${maven.gen.dir}/java"/>
+ </copy>
+ <copy todir="${maven.src.dir}/java" verbose="${maven.verbose}" overwrite="true">
+ <fileset dir="${maven.vcs.src.dir}/java"/>
+ </copy>
+ </tasks>
+ </configuration>
<executions>
<execution>
- <id>CreateDirs</id>
- <phase>validate</phase>
- <configuration>
- <tasks>
- <!-- make sure the directory exists (should be in parent) -->
- <mkdir dir="${maven.gen.dir}/java"/>
- </tasks>
- </configuration>
+ <phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
- <execution>
- <id>CopyJavaVersSrcBuild</id>
- <!-- recopie des fichiers java sources et generes vers src-build/java -->
- <phase>process-sources</phase>
- <configuration>
- <tasks>
- <copy todir="${maven.src.dir}/java" verbose="${maven.verbose}" overwrite="true">
- <fileset dir="${maven.gen.dir}/java"/>
- </copy>
- <copy todir="${maven.src.dir}/java" verbose="${maven.verbose}" overwrite="true">
- <fileset dir="${maven.vcs.src.dir}/java"/>
- </copy>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
</executions>
</plugin>
<plugin>
<groupId>lutinplugin</groupId>
<artifactId>maven-commandline-plugin</artifactId>
<version>0.2-SNAPSHOT</version>
+ <configuration>
+ <prefix>SimExplorer</prefix>
+ <i18nPrefix>simexplorer</i18nPrefix>
+ <source>${maven.vcs.src.dir}/resources/commandline.properties</source>
+ <parserPackageName>fr.cemagref.simexplorer.is.ui.swing.commandline</parserPackageName>
+ <actionSuperClass>fr.cemagref.simexplorer.is.ui.swing.commandline.actions.SimExplorerAbstractOptionAction</actionSuperClass>
+ </configuration>
<executions>
<execution>
- <id>GenerateJava</id>
- <phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
- <configuration>
- <prefix>SimExplorer</prefix>
- <i18nPrefix>simexplorer</i18nPrefix>
- <source>${maven.src.dir}/resources/commandline.properties</source>
- <parserPackageName>fr.cemagref.simexplorer.is.ui.swing.commandline</parserPackageName>
- <actionSuperClass>fr.cemagref.simexplorer.is.ui.swing.commandline.actions.SimExplorerAbstractOptionAction</actionSuperClass>
- </configuration>
</execution>
</executions>
+
</plugin>
+ <!-- Compile phase -->
<plugin>
<groupId>lutinplugin</groupId>
<artifactId>maven-i18n-plugin</artifactId>
@@ -189,6 +157,39 @@
</execution>
</executions>
</plugin>
+ <!-- Package phase -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <configuration>
+ <outputDirectory>${project.build.directory}/dependency</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>false</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>${maven.jar.main.class}</mainClass>
+ <addClasspath>true</addClasspath>
+ <addExtensions />
+ <classpathPrefix>./dependency/</classpathPrefix>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
</plugins>
</build>
1
0