oodt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfos...@apache.org
Subject svn commit: r1052148 [14/17] - in /oodt/branches/wengine-branch/filemgr: ./ .settings/ src/ src/main/ src/main/assembly/ src/main/bin/ src/main/java/ src/main/java/gov/ src/main/java/gov/nasa/ src/main/java/gov/nasa/jpl/ src/main/java/gov/nasa/jpl/oodt...
Date Thu, 23 Dec 2010 02:48:11 GMT
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlStructFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.util;
+
+//JDK imports
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.ExtractorSpec;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.type.TypeHandler;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.metadata.util.PathUtils;
+import org.apache.oodt.commons.xml.XMLUtils;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * A Generic class for constructing File Manager objects out of XML {@link Node}s.
+ * </p>
+ * 
+ */
+public final class XmlStructFactory {
+
+    /* our log stream */
+    private static Logger LOG = Logger.getLogger(XmlStructFactory.class
+            .getName());
+
+    private XmlStructFactory() throws InstantiationException {
+        throw new InstantiationException("Don't construct XmlStructFactories!");
+    }
+
+    public static ProductType getProductType(Node productTypeNode) {
+        org.w3c.dom.Element productTypeElem = (org.w3c.dom.Element) productTypeNode;
+
+        String id = productTypeElem.getAttribute("id");
+        String name = productTypeElem.getAttribute("name");
+
+        org.w3c.dom.Element repositoryElem = XMLUtils.getFirstElement(
+                "repository", productTypeElem);
+
+        String repositoryPath = repositoryElem.getAttribute("path");
+
+        org.w3c.dom.Element versionerElem = XMLUtils.getFirstElement(
+                "versioner", productTypeElem);
+
+        String versionerClass = versionerElem.getAttribute("class");
+
+        org.w3c.dom.Element descElem = XMLUtils.getFirstElement("description",
+                productTypeElem);
+
+        String description = null;
+        if (descElem.getAttribute("trim") != null
+                && !descElem.getAttribute("trim").equals("")
+                && !Boolean.valueOf(descElem.getAttribute("trim"))) {
+            description = XMLUtils.getElementText("description",
+                    productTypeElem);
+        } else {
+            description = XMLUtils.getElementText("description",
+                    productTypeElem, true);
+        }
+
+        repositoryPath = PathUtils.replaceEnvVariables(repositoryPath);
+
+        // grab metadata
+        Metadata met = null;
+        Element metadataRoot = XMLUtils.getFirstElement("metadata",
+                productTypeElem);
+        if (metadataRoot != null) {
+            Hashtable<String, Object> metHash = new Hashtable<String, Object>();
+            met = new Metadata();
+            NodeList keyValElems = metadataRoot.getElementsByTagName("keyval");
+
+            for (int i = 0; i < keyValElems.getLength(); i++) {
+                Element keyValElem = (Element) keyValElems.item(i);
+
+                String elemName = XMLUtils.read(keyValElem, "key");
+                List<String> elemValues = XMLUtils.readMany(keyValElem, "val");
+                metHash.put(elemName, elemValues);
+            }
+
+            met.replaceMetadata(metHash);
+        }
+
+        // grab extractors
+        List<ExtractorSpec> extractors = null;
+        Element extractorRoot = XMLUtils.getFirstElement("metExtractors",
+                productTypeElem);
+
+        if (extractorRoot != null) {
+            NodeList extractorNodes = extractorRoot
+                    .getElementsByTagName("extractor");
+
+            if (extractorNodes != null && extractorNodes.getLength() > 0) {
+                extractors = new Vector<ExtractorSpec>();
+                for (int i = 0; i < extractorNodes.getLength(); i++) {
+                    Element extractorElem = (Element) extractorNodes.item(i);
+                    ExtractorSpec spec = new ExtractorSpec();
+                    String className = extractorElem.getAttribute("class");
+                    spec.setClassName(className);
+
+                    // see if there are any configuration properties
+                    Element configuration = XMLUtils.getFirstElement(
+                            "configuration", extractorElem);
+
+                    if (configuration != null) {
+                        Properties config = new Properties();
+                        NodeList propertyNodes = configuration
+                                .getElementsByTagName("property");
+
+                        if (propertyNodes != null
+                                && propertyNodes.getLength() > 0) {
+                            for (int j = 0; j < propertyNodes.getLength(); j++) {
+                                Element propertyElem = (Element) propertyNodes
+                                        .item(j);
+                                String propertyName = propertyElem
+                                        .getAttribute("name");
+                                String propertyValue = propertyElem
+                                        .getAttribute("value");
+                                if (Boolean
+                                        .valueOf(
+                                                propertyElem
+                                                        .getAttribute("envReplace"))
+                                        .booleanValue()) {
+                                    propertyValue = PathUtils
+                                            .replaceEnvVariables(propertyValue);
+                                }
+
+                                config.setProperty(propertyName, propertyValue);
+                            }
+
+                            spec.setConfiguration(config);
+                        }
+                    }
+
+                    extractors.add(spec);
+                }
+
+            }
+        }
+        
+        List<TypeHandler> handlers = null;
+        Element handlerRoot = XMLUtils.getFirstElement("typeHandlers",
+                productTypeElem);
+        if (handlerRoot != null) {
+            NodeList handlerNodes = handlerRoot.getElementsByTagName("typeHandler");
+            if (handlerNodes != null && handlerNodes.getLength() > 0) {
+                handlers = new Vector<TypeHandler>();
+                for (int i = 0; i < handlerNodes.getLength(); i++) {
+                    Node handlerNode = handlerNodes.item(i);
+                    String handlerClass = ((Element) handlerNode).getAttribute("class");
+                    String elementName = ((Element) handlerNode).getAttribute("elementName");
+                    try {
+                        TypeHandler typeHandler = (TypeHandler) Class.forName(handlerClass).newInstance();
+                        typeHandler.setElementName(elementName);
+                        handlers.add(typeHandler);
+                    }catch (Exception e) {
+                        e.printStackTrace();
+                        LOG.log(Level.WARNING, "Failed to load handler for ProductType [name = " + name 
+                                + "] and element [name = " + elementName + "] : " + e.getMessage());
+                    }
+                }
+            }
+        }
+        
+        ProductType productType = new ProductType();
+        productType.setName(name);
+        productType.setProductTypeId(id);
+        productType.setProductRepositoryPath(repositoryPath);
+        productType.setVersioner(versionerClass);
+        productType.setDescription(description);
+        productType.setTypeMetadata(met);
+        productType.setExtractors(extractors);
+        productType.setHandlers(handlers);
+
+        return productType;
+    }
+
+    public static void writeProductTypeMapXmLDocument(HashMap<String, List<org.apache.oodt.cas.filemgr.structs.Element>> productTypeMap,
+            HashMap<String, String> subToSuperMap, String xmlFilePath) {
+        XMLUtils.writeXmlFile(getProductTypeMapXmlDocument(productTypeMap,
+                subToSuperMap), xmlFilePath);
+    }
+
+    public static void writeElementXmlDocument(List<org.apache.oodt.cas.filemgr.structs.Element> elements, String xmlFilePath) {
+        XMLUtils.writeXmlFile(getElementXmlDocument(elements), xmlFilePath);
+    }
+
+    public static void writeProductTypeXmlDocument(List<ProductType> productTypes,
+            String xmlFilePath) {
+        XMLUtils.writeXmlFile(getProductTypeXmlDocument(productTypes),
+                xmlFilePath);
+    }
+
+    public static Document getProductTypeMapXmlDocument(HashMap<String, List<org.apache.oodt.cas.filemgr.structs.Element>> productTypeMap,
+            HashMap<String, String> subToSuperMap) {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        Document document = null;
+
+        try {
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            document = builder.newDocument();
+
+            Element root = (Element) document
+                    .createElement("cas:producttypemap");
+            root.setAttribute("xmlns:cas", "http://oodt.jpl.nasa.gov/1.0/cas");
+            document.appendChild(root);
+
+            for (Iterator<String> i = productTypeMap.keySet().iterator(); i.hasNext();) {
+                String typeId = i.next();
+
+                Element typeElem = document.createElement("type");
+                typeElem.setAttribute("id", typeId);
+
+                if (subToSuperMap.containsKey(typeId)) {
+                    typeElem.setAttribute("parent", subToSuperMap
+                            .get(typeId));
+                }
+
+                List<org.apache.oodt.cas.filemgr.structs.Element> elementIds = productTypeMap.get(typeId);
+
+                for (Iterator<org.apache.oodt.cas.filemgr.structs.Element> j = elementIds.iterator(); j.hasNext();) {
+                    String elementId = j.next().getElementId();
+
+                    Element elementElem = document.createElement("element");
+                    elementElem.setAttribute("id", elementId);
+                    typeElem.appendChild(elementElem);
+                }
+
+                root.appendChild(typeElem);
+            }
+
+            return document;
+
+        } catch (ParserConfigurationException pce) {
+            LOG.log(Level.WARNING,
+                    "Error generating product-type-element-map xml file!: "
+                            + pce.getMessage());
+        }
+
+        return null;
+    }
+
+    public static Document getElementXmlDocument(List<org.apache.oodt.cas.filemgr.structs.Element> elements) {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        Document document = null;
+
+        try {
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            document = builder.newDocument();
+
+            Element root = (Element) document.createElement("cas:elements");
+            root.setAttribute("xmlns:cas", "http://oodt.jpl.nasa.gov/1.0/cas");
+            document.appendChild(root);
+
+            for (Iterator<org.apache.oodt.cas.filemgr.structs.Element> i = elements.iterator(); i.hasNext();) {
+                org.apache.oodt.cas.filemgr.structs.Element element = i.next();
+                Element elementElem = document.createElement("element");
+                elementElem.setAttribute("id", element.getElementId());
+                elementElem.setAttribute("name", element.getElementName());
+
+                Element descriptionElem = document.createElement("description");
+                descriptionElem.appendChild(document.createTextNode(element
+                        .getDescription()));
+                elementElem.appendChild(descriptionElem);
+
+                Element dcElementElem = document.createElement("dcElement");
+                dcElementElem.appendChild(document.createTextNode(element
+                        .getDCElement() != null ? element.getDCElement() : ""));
+                elementElem.appendChild(dcElementElem);
+                
+                root.appendChild(elementElem);
+            }
+
+            return document;
+
+        } catch (ParserConfigurationException pce) {
+            LOG.log(Level.WARNING, "Error generating elements xml file!: "
+                    + pce.getMessage());
+        }
+
+        return null;
+    }
+
+    public static Document getProductTypeXmlDocument(List<ProductType> productTypes) {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        Document document = null;
+
+        try {
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            document = builder.newDocument();
+
+            Element root = (Element) document.createElement("cas:producttypes");
+            root.setAttribute("xmlns:cas", "http://oodt.jpl.nasa.gov/1.0/cas");
+            document.appendChild(root);
+
+            // now add the set of metadata elements in the properties object
+            for (Iterator<ProductType> i = productTypes.iterator(); i.hasNext();) {
+                ProductType type = i.next();
+
+                Element typeElem = document.createElement("type");
+                typeElem.setAttribute("id", type.getProductTypeId());
+                typeElem.setAttribute("name", type.getName());
+
+                Element descriptionElem = document.createElement("description");
+                descriptionElem.appendChild(document.createTextNode(type
+                        .getDescription()));
+                typeElem.appendChild(descriptionElem);
+
+                Element repositoryPathElem = document
+                        .createElement("repository");
+                repositoryPathElem.setAttribute("path", type
+                        .getProductRepositoryPath());
+                typeElem.appendChild(repositoryPathElem);
+
+                Element versionerClassPathElem = document
+                        .createElement("versioner");
+                versionerClassPathElem.setAttribute("class", type
+                        .getVersioner());
+                typeElem.appendChild(versionerClassPathElem);
+
+                root.appendChild(typeElem);
+            }
+
+            return document;
+        } catch (ParserConfigurationException pce) {
+            LOG.log(Level.WARNING, "Error generating producttypes xml file!: "
+                    + pce.getMessage());
+        }
+
+        return null;
+
+    }
+
+    public static org.apache.oodt.cas.filemgr.structs.Element getElement(
+            Node elementNode) {
+        org.w3c.dom.Element elementElem = (org.w3c.dom.Element) elementNode;
+
+        String id = elementElem.getAttribute("id");
+        String name = elementElem.getAttribute("name");
+
+        String dcElement = XMLUtils.getElementText("dcElement", elementElem);
+
+        org.w3c.dom.Element descElem = XMLUtils.getFirstElement("description",
+                elementElem);
+        String description = null;
+        if (descElem.getAttribute("trim") != null
+                && !descElem.getAttribute("trim").equals("")
+                && !Boolean.valueOf(descElem.getAttribute("trim"))) {
+            description = XMLUtils.getElementText("description", elementElem);
+        } else {
+            description = XMLUtils.getElementText("description", elementElem,
+                    true);
+        }
+
+        org.apache.oodt.cas.filemgr.structs.Element element = new org.apache.oodt.cas.filemgr.structs.Element();
+        element.setDCElement(dcElement);
+        element.setDescription(description);
+        element.setElementId(id);
+        element.setElementName(name);
+        return element;
+    }
+
+    public static HashMap<String, List<org.apache.oodt.cas.filemgr.structs.Element>> 
+            getProductTypeElementList(Node typeMapNode, HashMap<String, org.apache.oodt.cas.filemgr.structs.Element> elements) {
+        org.w3c.dom.Element typeMapElement = (org.w3c.dom.Element) typeMapNode;
+
+        String typeId = typeMapElement.getAttribute("id");
+
+        HashMap<String, List<org.apache.oodt.cas.filemgr.structs.Element>> productTypeElementMap = new HashMap<String, List<org.apache.oodt.cas.filemgr.structs.Element>>();
+
+        org.w3c.dom.Element elementListRoot = XMLUtils.getFirstElement(
+                "elements", typeMapElement);
+        NodeList elementNodeList = elementListRoot
+                .getElementsByTagName("element");
+
+        List<org.apache.oodt.cas.filemgr.structs.Element> elementList = new Vector<org.apache.oodt.cas.filemgr.structs.Element>(elementNodeList.getLength());
+
+        for (int i = 0; i < elementNodeList.getLength(); i++) {
+            org.w3c.dom.Element elementElem = (org.w3c.dom.Element) elementNodeList
+                    .item(i);
+            String elementId = elementElem.getAttribute("id");
+            org.apache.oodt.cas.filemgr.structs.Element element = elements
+                    .get(elementId);
+            elementList.add(element);
+        }
+
+        productTypeElementMap.put(typeId, elementList);
+        return productTypeElementMap;
+    }
+
+}

Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/DataSourceValidationLayer.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/DataSourceValidationLayer.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/DataSourceValidationLayer.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/DataSourceValidationLayer.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,854 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.validation;
+
+//JAVAX imports
+import javax.sql.DataSource;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Element;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.exceptions.ValidationLayerException;
+import org.apache.oodt.cas.filemgr.util.DbStructFactory;
+
+//JDK imports
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * An implementation of a ValidationLayer that queries a {@link DataSource}
+ * backed database for validation information.
+ * </p>
+ * 
+ */
+public class DataSourceValidationLayer implements ValidationLayer {
+
+    /* our log stream */
+    private static Logger LOG = Logger
+            .getLogger(DataSourceValidationLayer.class.getName());
+
+    /* our data source */
+    private DataSource dataSource = null;
+
+    /* should we quote product_type_id? */
+    private boolean quoteFields = false;
+
+    /**
+     * <p>
+     * Default Constructor
+     * </p>.
+     */
+    public DataSourceValidationLayer(DataSource ds, boolean fieldQuote) {
+        dataSource = ds;
+        quoteFields = fieldQuote;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#addElement(gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void addElement(Element element) throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+        ResultSet rs = null;
+
+        try {
+            conn = dataSource.getConnection();
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            String addMetaElemSql = "INSERT INTO elements (element_name, dc_element, element_description) VALUES ('"
+                    + element.getElementName()
+                    + ", '"
+                    + element.getDCElement()
+                    + "', '" + element.getDescription() + "')";
+
+            LOG.log(Level.FINE, "addMetadataElement: Executing: "
+                    + addMetaElemSql);
+            statement.execute(addMetaElemSql);
+
+            String elementId = new String();
+
+            String getMetaIdSql = "SELECT MAX(element_id) AS max_id FROM elements";
+            LOG.log(Level.FINE, "addElement: Executing: " + getMetaIdSql);
+            rs = statement.executeQuery(getMetaIdSql);
+
+            while (rs.next()) {
+                elementId = String.valueOf(rs.getInt("max_id"));
+            }
+
+            element.setElementId(elementId);
+            conn.commit();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG
+                    .log(Level.WARNING, "Exception adding element "
+                            + element.getElementName() + ". Message: "
+                            + e.getMessage());
+            try {
+                conn.rollback();
+            } catch (SQLException e2) {
+                LOG.log(Level.SEVERE,
+                        "Unable to rollback addElement transaction. Message: "
+                                + e2.getMessage());
+            }
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (SQLException ignore) {
+                }
+
+                rs = null;
+            }
+
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#modifyElement(gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void modifyElement(Element element) throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+
+        try {
+            conn = dataSource.getConnection();
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            String elementSql = "UPDATE elements SET element_name = '"
+                    + element.getElementName() + "', dc_element='"
+                    + element.getDCElement() + "', " + "element_description='"
+                    + element.getDescription() + "' WHERE " + "element_id = "
+                    + element.getElementId();
+
+            LOG.log(Level.FINE, "modifyElement: Executing: " + elementSql);
+            statement.execute(elementSql);
+            conn.commit();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Exception modifying element. Message: "
+                    + e.getMessage());
+            try {
+                conn.rollback();
+            } catch (SQLException e2) {
+                LOG.log(Level.SEVERE,
+                        "Unable to rollback modifyElement transaction. Message: "
+                                + e2.getMessage());
+            }
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#removeElement(gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void removeElement(Element element) throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+
+        try {
+            conn = dataSource.getConnection();
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            String deleteElementSql = "DELETE FROM elements WHERE element_id = "
+                    + element.getElementId();
+
+            LOG
+                    .log(Level.FINE, "removeElement: Executing: "
+                            + deleteElementSql);
+            statement.execute(deleteElementSql);
+            conn.commit();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Exception removing element. Message: "
+                    + e.getMessage());
+            try {
+                conn.rollback();
+            } catch (SQLException e2) {
+                LOG.log(Level.SEVERE,
+                        "Unable to rollback removeElement transaction. Message: "
+                                + e2.getMessage());
+            }
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#addElementToProductType(gov.nasa.jpl.oodt.cas.filemgr.structs.ProductType,
+     *      gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void addElementToProductType(ProductType type, Element element)
+            throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+
+        try {
+            conn = dataSource.getConnection();
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            String addMetaElemSql = "INSERT INTO product_type_element_map (product_type_id, element_id) VALUES(";
+
+            if (quoteFields) {
+                addMetaElemSql += "'" + type.getProductTypeId() + "',";
+            } else {
+                addMetaElemSql += type.getProductTypeId() + ",";
+            }
+            addMetaElemSql += " " + element.getElementId() + ")";
+
+            LOG.log(Level.FINE, "addElementToProductType: Executing: "
+                    + addMetaElemSql);
+            statement.execute(addMetaElemSql);
+            conn.commit();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Exception adding element "
+                    + element.getElementName() + " to product type "
+                    + type.getName() + " . Message: " + e.getMessage());
+            try {
+                conn.rollback();
+            } catch (SQLException e2) {
+                LOG.log(Level.SEVERE,
+                        "Unable to rollback addElementToProductType transaction. Message: "
+                                + e2.getMessage());
+            }
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#removeElementFromProductType(gov.nasa.jpl.oodt.cas.filemgr.structs.ProductType,
+     *      gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void removeElementFromProductType(ProductType type, Element element)
+            throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+
+        try {
+            conn = dataSource.getConnection();
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            String deleteElemSql = "DELETE FROM product_type_element_map WHERE product_type_id = ";
+
+            if (quoteFields) {
+                deleteElemSql += "'" + type.getProductTypeId() + "'";
+            } else {
+                deleteElemSql += type.getProductTypeId();
+            }
+
+            deleteElemSql += " AND element_id = " + element.getElementId();
+
+            LOG.log(Level.FINE, "removeElementFromProductType: Executing: "
+                    + deleteElemSql);
+            statement.execute(deleteElemSql);
+            conn.commit();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Exception removing element "
+                    + element.getElementName() + " from product type "
+                    + type.getName() + ". Message: " + e.getMessage());
+            try {
+                conn.rollback();
+            } catch (SQLException e2) {
+                LOG.log(Level.SEVERE,
+                        "Unable to rollback removeElementFromProductType transaction. Message: "
+                                + e2.getMessage());
+            }
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+
+    }
+
+    public void addParentToProductType(ProductType type, String parent)
+            throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+
+        try {
+            conn = dataSource.getConnection();
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            String addParentInfoSql = "INSERT INTO sub_to_super_map (product_type_id, parent_id) VALUES(";
+            if (quoteFields) {
+                addParentInfoSql += "'" + type.getProductTypeId() + "','"
+                        + parent + "')";
+            } else {
+                addParentInfoSql += type.getProductTypeId() + "," + parent
+                        + ")";
+            }
+
+            LOG.log(Level.FINE, "addParentToProductType: Executing: "
+                    + addParentInfoSql);
+            statement.execute(addParentInfoSql);
+            conn.commit();
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING,
+                    "Exception adding parent info to product type "
+                            + type.getName() + " . Message: " + e.getMessage());
+            try {
+                conn.rollback();
+            } catch (SQLException e2) {
+                LOG.log(Level.SEVERE,
+                        "Unable to rollback addParentToProductType transaction. Message: "
+                                + e2.getMessage());
+            }
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+    }
+
+    public void removeParentFromProductType(ProductType type, String parent)
+            throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+
+        try {
+            conn = dataSource.getConnection();
+            conn.setAutoCommit(false);
+            statement = conn.createStatement();
+
+            String deleteParSql = "DELETE FROM sub_to_super_map WHERE product_type_id = ";
+
+            if (quoteFields) {
+                deleteParSql += "'" + type.getProductTypeId()
+                        + "' AND parent_id ='" + parent + "'";
+            } else {
+                deleteParSql += type.getProductTypeId() + " AND parent_id ="
+                        + parent;
+            }
+
+            LOG.log(Level.FINE, "removeParentFromProductType: Executing: "
+                    + deleteParSql);
+            statement.execute(deleteParSql);
+            conn.commit();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING,
+                    "Exception removing parent from product type "
+                            + type.getName() + ". Message: " + e.getMessage());
+            try {
+                conn.rollback();
+            } catch (SQLException e2) {
+                LOG.log(Level.SEVERE,
+                        "Unable to rollback removeParentFromProductType transaction. Message: "
+                                + e2.getMessage());
+            }
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#getElements(gov.nasa.jpl.oodt.cas.filemgr.structs.ProductType)
+     */
+    public List<Element> getElements(ProductType type)
+            throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+        ResultSet rs = null;
+        List<Element> elements = null;
+
+        elements = new Vector<Element>();
+
+        String currProduct = type.getProductTypeId();
+        while (currProduct != null) {
+
+            try {
+                conn = dataSource.getConnection();
+                statement = conn.createStatement();
+
+                String elementSql = "SELECT elements.* from elements, product_type_element_map WHERE product_type_element_map.product_type_id = ";
+
+                if (quoteFields) {
+                    elementSql += "'" + currProduct + "'";
+                } else {
+                    elementSql += currProduct;
+                }
+
+                elementSql += " AND product_type_element_map.element_id = elements.element_id";
+
+                LOG.log(Level.FINE, "getElements: Executing: " + elementSql);
+                rs = statement.executeQuery(elementSql);
+
+                while (rs.next()) {
+                    Element element = DbStructFactory.getElement(rs);
+                    elements.add(element);
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.log(Level.WARNING, "Exception reading elements. Message: "
+                        + e.getMessage());
+                throw new ValidationLayerException(e.getMessage());
+            } finally {
+
+                if (rs != null) {
+                    try {
+                        rs.close();
+                    } catch (SQLException ignore) {
+                    }
+
+                    rs = null;
+                }
+
+                if (statement != null) {
+                    try {
+                        statement.close();
+                    } catch (SQLException ignore) {
+                    }
+
+                    statement = null;
+                }
+
+                if (conn != null) {
+                    try {
+                        conn.close();
+
+                    } catch (SQLException ignore) {
+                    }
+
+                    conn = null;
+                }
+            }
+
+            // advance to the product parent
+            try {
+                conn = dataSource.getConnection();
+                statement = conn.createStatement();
+
+                String getParentSql = "SELECT parent_id from sub_to_super_map where product_type_id = ";
+                if (quoteFields) {
+                    getParentSql += "'" + currProduct + "'";
+                } else {
+                    getParentSql += currProduct;
+                }
+
+                LOG.log(Level.FINE, "getElements: Executing: " + getParentSql);
+                rs = statement.executeQuery(getParentSql);
+
+                currProduct = null;
+                while (rs.next()) {
+                    currProduct = DbStructFactory.getParent(rs);
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.log(Level.WARNING,
+                        "Exception reading product parent. Message: "
+                                + e.getMessage());
+                throw new ValidationLayerException(e.getMessage());
+            } finally {
+                if (rs != null) {
+                    try {
+                        rs.close();
+                    } catch (SQLException ignore) {
+                    }
+                    rs = null;
+                }
+                if (statement != null) {
+                    try {
+                        statement.close();
+                    } catch (SQLException ignore) {
+                    }
+                    statement = null;
+                }
+                if (conn != null) {
+                    try {
+                        conn.close();
+                    } catch (SQLException ignore) {
+                    }
+                    conn = null;
+                }
+            }
+
+        }
+
+        return elements;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#getElements()
+     */
+    public List<Element> getElements() throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+        ResultSet rs = null;
+        List<Element> elements = null;
+
+        try {
+            conn = dataSource.getConnection();
+            statement = conn.createStatement();
+
+            String dataTypeSql = "SELECT * from elements";
+
+            LOG.log(Level.FINE, "getElements: Executing: " + dataTypeSql);
+            rs = statement.executeQuery(dataTypeSql);
+
+            elements = new Vector<Element>();
+
+            while (rs.next()) {
+                Element element = DbStructFactory.getElement(rs);
+                LOG.log(Level.FINE, "getElements: adding element: "
+                        + element.getElementName());
+                elements.add(element);
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Exception reading elements. Message: "
+                    + e.getMessage());
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (SQLException ignore) {
+                }
+
+                rs = null;
+            }
+
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+
+        return elements;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#getElementById(java.lang.String)
+     */
+    public Element getElementById(String elementId)
+            throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+        ResultSet rs = null;
+        Element element = null;
+
+        try {
+            conn = dataSource.getConnection();
+            statement = conn.createStatement();
+
+            String elementSql = "SELECT * from elements WHERE element_id = "
+                    + elementId;
+
+            LOG.log(Level.FINE, "getElementById: Executing: " + elementSql);
+            rs = statement.executeQuery(elementSql);
+
+            while (rs.next()) {
+                element = DbStructFactory.getElement(rs);
+                LOG.log(Level.FINE, "getElementById: adding element: "
+                        + element.getElementName());
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Exception reading element. Message: "
+                    + e.getMessage());
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (SQLException ignore) {
+                }
+
+                rs = null;
+            }
+
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+
+        return element;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#getElementByName(java.lang.String)
+     */
+    public Element getElementByName(String elementName)
+            throws ValidationLayerException {
+        Connection conn = null;
+        Statement statement = null;
+        ResultSet rs = null;
+        Element element = null;
+
+        try {
+            conn = dataSource.getConnection();
+            statement = conn.createStatement();
+
+            String elementSql = "SELECT * from elements WHERE element_name = "
+                    + elementName;
+
+            LOG.log(Level.FINE, "getElementByName: Executing: " + elementSql);
+            rs = statement.executeQuery(elementSql);
+
+            while (rs.next()) {
+                element = DbStructFactory.getElement(rs);
+                LOG.log(Level.FINE, "getElementByName: adding element: "
+                        + element.getElementName());
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Exception reading element. Message: "
+                    + e.getMessage());
+            throw new ValidationLayerException(e.getMessage());
+        } finally {
+
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (SQLException ignore) {
+                }
+
+                rs = null;
+            }
+
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException ignore) {
+                }
+
+                statement = null;
+            }
+
+            if (conn != null) {
+                try {
+                    conn.close();
+
+                } catch (SQLException ignore) {
+                }
+
+                conn = null;
+            }
+        }
+
+        return element;
+    }
+}

Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/DataSourceValidationLayerFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/DataSourceValidationLayerFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/DataSourceValidationLayerFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/DataSourceValidationLayerFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.validation;
+
+//OODT imports
+import org.apache.oodt.commons.database.DatabaseConnectionBuilder;
+
+//JDK imports
+import javax.sql.DataSource;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ * 
+ * <p>
+ * A Factory class for creating {@link DataSourceValidationLayer}s.
+ * </p>
+ * 
+ */
+public class DataSourceValidationLayerFactory implements ValidationLayerFactory {
+    /* our data source */
+    private DataSource dataSource = null;
+
+    /* should we quote fields or not? */
+    private boolean quoteFields = false;
+
+    /**
+     * <p>
+     * Default Constructor
+     * </p>
+     */
+    public DataSourceValidationLayerFactory() throws Exception {
+        String jdbcUrl = null, user = null, pass = null, driver = null;
+
+        jdbcUrl = System
+                .getProperty("gov.nasa.jpl.oodt.cas.filemgr.validation.datasource.jdbc.url");
+        user = System
+                .getProperty("gov.nasa.jpl.oodt.cas.filemgr.validation.datasource.jdbc.user");
+        pass = System
+                .getProperty("gov.nasa.jpl.oodt.cas.filemgr.validation.datasource.jdbc.pass");
+        driver = System
+                .getProperty("gov.nasa.jpl.oodt.cas.filemgr.validation.datasource.jdbc.driver");
+
+        dataSource = DatabaseConnectionBuilder.buildDataSource(user, pass,
+                driver, jdbcUrl);
+        quoteFields = Boolean
+                .getBoolean("gov.nasa.jpl.oodt.cas.filemgr.validation.datasource.quoteFields");
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayerFactory#createValidationLayer()
+     */
+    public ValidationLayer createValidationLayer() {
+        return new DataSourceValidationLayer(dataSource, quoteFields);
+    }
+
+}

Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/ValidationLayer.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/ValidationLayer.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/ValidationLayer.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/ValidationLayer.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.validation;
+
+//JDK imports
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Element;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.exceptions.ValidationLayerException;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * The Validation Layer for the File Manager, allowing {@link Element}s to be
+ * mapped to {@link ProductType}s.
+ * </p>
+ * 
+ */
+public interface ValidationLayer {
+
+    /**
+     * <p>
+     * Adds the <code>Element</code> to the ValidationLayer.
+     * </p>
+     * 
+     * @param element
+     *            The element to add.
+     * @throws ValidationLayerException
+     *             If any error occurs during the add.
+     */
+    public void addElement(Element element) throws ValidationLayerException;
+
+    /**
+     * <p>
+     * Modifies an existing {@link Element} in the ValidationLayer.
+     * </p>
+     * 
+     * @param element
+     *            The new {@link Element} data to update.
+     * @throws ValidationLayerException
+     *             If any error occurs.
+     */
+    public void modifyElement(Element element) throws ValidationLayerException;
+
+    /**
+     * <p>
+     * Removes a metadata {@link Element} from the ValidationLayer.
+     * 
+     * @param element
+     *            The element to remove.
+     * @throws ValidationLayerException
+     *             If any error occurs.
+     */
+    public void removeElement(Element element) throws ValidationLayerException;
+
+    /**
+     * <p>
+     * Adds the specified <code>element</code> to the {@link ProductType}
+     * specified by its <code>productTypeId</code>.
+     * 
+     * @param type
+     *            The {@link ProductType} to associate the metadata Element
+     *            with.
+     * @param element
+     *            The {@link Element} to associate with the ProductType.
+     * @throws ValidationLayerException
+     *             If any error occurs.
+     */
+    public void addElementToProductType(ProductType type, Element element)
+            throws ValidationLayerException;
+
+    /**
+     * <p>
+     * Removes a metadata {@link Element} from the specified
+     * <code>productTypeId</code>.
+     * </p>
+     * 
+     * @param type
+     *            The {@link ProductType} to remove the association of the
+     *            specified <code>element</code> with.
+     * @param element
+     *            The element whose association will be removed from the
+     *            specified ProductType.
+     * @throws ValidationLayerException
+     *             If any error occurs.
+     */
+    public void removeElementFromProductType(ProductType type, Element element)
+            throws ValidationLayerException;
+
+    /**
+     * <p>
+     * Returns a {@link List} of {@link Element}s corresponding to the given
+     * ProductType.
+     * 
+     * @param type
+     *            The product type to retrieve the metadata {@link Element}s
+     *            for.
+     * @return A {@link List} of {@link Element}s corresponding to the given
+     *         ProductType.
+     * @throws ValidationLayerException
+     *             If any error occurs.
+     */
+    public List<Element> getElements(ProductType type)
+            throws ValidationLayerException;
+
+    /**
+     * @return A {@link List} of all the metadata {@link Element}s in the
+     *         ValidationLayer.
+     * @throws ValidationLayerException
+     *             If any error occurs.
+     */
+    public List<Element> getElements() throws ValidationLayerException;
+
+    /**
+     * Gets an element by its String identifier.
+     * 
+     * @param elementId
+     *            The String identifier of the {@link Element} to get.
+     * @return An {@link Element} by its String identifier.
+     * @throws ValidationLayerException
+     *             If any error occurs.
+     */
+    public Element getElementById(String elementId)
+            throws ValidationLayerException;
+
+    /**
+     * Gets an element by its String name.
+     * 
+     * @param elementName
+     *            The String name of the {@link Element} to get.
+     * @return An {@link Element} by its String name.
+     * @throws ValidationLayerException
+     *             If any error occurs.
+     */
+    public Element getElementByName(String elementName)
+            throws ValidationLayerException;
+
+}

Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/ValidationLayerFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/ValidationLayerFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/ValidationLayerFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/ValidationLayerFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.validation;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ * 
+ * <p>
+ * A Factory for creating {@link ValidationLayer}s.
+ * </p>
+ * 
+ */
+public interface ValidationLayerFactory {
+
+    public ValidationLayer createValidationLayer();
+}

Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayer.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayer.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayer.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayer.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,446 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.validation;
+
+//JDK imports
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+//JAVAX imports
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Element;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.exceptions.ValidationLayerException;
+import org.apache.oodt.cas.filemgr.util.XmlStructFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * An XML ValidationLayer based on two xml files, <code>elements.xml</code>,
+ * and <code>product-type-element-map.xml</code>.
+ * </p>
+ * 
+ */
+public class XMLValidationLayer implements ValidationLayer {
+
+    /* our log stream */
+    private static Logger LOG = Logger.getLogger(XMLValidationLayer.class
+            .getName());
+
+    /* product type ID to element map */
+    private HashMap<String, List<Element>> productTypeElementMap = new HashMap<String, List<Element>>();
+
+    /* sub-type to super-type map */
+    private HashMap<String, String> subToSuperMap = new HashMap<String, String>();
+
+    /* element map */
+    private HashMap<String, Element> elementMap = new HashMap<String, Element>();
+
+    /*
+     * URIs pointing to directories with product-type-element-map.xml and
+     * elements.xml files
+     */
+    private List<String> xmlFileDirUris = null;
+
+    /**
+     * 
+     */
+    public XMLValidationLayer(List<String> uris) {
+        this.xmlFileDirUris = uris;
+        loadElements(xmlFileDirUris);
+        loadProductTypeMap(xmlFileDirUris);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#addElement(gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void addElement(Element element) throws ValidationLayerException {
+        elementMap.put(element.getElementId(), element);
+        saveElementsAndMappings();
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#modifyElement(gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void modifyElement(Element element) throws ValidationLayerException {
+        elementMap.put(element.getElementId(), element);
+        saveElementsAndMappings();
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#removeElement(gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void removeElement(Element element) throws ValidationLayerException {
+        elementMap.remove(element.getElementId());
+        saveElementsAndMappings();
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#addElementToProductType(gov.nasa.jpl.oodt.cas.filemgr.structs.ProductType,
+     *      gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void addElementToProductType(ProductType type, Element element)
+            throws ValidationLayerException {
+        List<Element> elements = productTypeElementMap.get(type
+                .getProductTypeId());
+
+        if (elements == null) {
+            elements = new Vector<Element>();
+            productTypeElementMap.put(type.getProductTypeId(), elements);
+        }
+        elements.add(element);
+        saveElementsAndMappings();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#removeElementFromProductType(gov.nasa.jpl.oodt.cas.filemgr.structs.ProductType,
+     *      gov.nasa.jpl.oodt.cas.filemgr.structs.Element)
+     */
+    public void removeElementFromProductType(ProductType type, Element element)
+            throws ValidationLayerException {
+        List<Element> elements = productTypeElementMap.get(type
+                .getProductTypeId());
+
+        for (Iterator<Element> i = elements.iterator(); i.hasNext();) {
+            Element elementObj = i.next();
+            if (elementObj.getElementId().equals(element.getElementId())) {
+                elements.remove(elementObj);
+                saveElementsAndMappings();
+                break;
+            }
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#getElements(gov.nasa.jpl.oodt.cas.filemgr.structs.ProductType)
+     */
+    public List<Element> getElements(ProductType type)
+            throws ValidationLayerException {
+        List<Element> elems = new Vector<Element>();
+        String currType = type.getProductTypeId();
+        if (productTypeElementMap.containsKey(currType)) {
+            elems.addAll(productTypeElementMap.get(currType));
+        }
+
+        while (subToSuperMap.containsKey(currType)) {
+            currType = subToSuperMap.get(currType);
+            if (productTypeElementMap.containsKey(currType)) {
+                elems.addAll(productTypeElementMap.get(currType));
+            }
+        }
+
+        return elems;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#getElements()
+     */
+    public List<Element> getElements() throws ValidationLayerException {
+        return Arrays.asList(elementMap.values().toArray(
+                new Element[elementMap.size()]));
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#getElementById(java.lang.String)
+     */
+    public Element getElementById(String elementId)
+            throws ValidationLayerException {
+        return elementMap.get(elementId);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayer#getElementByName(java.lang.String)
+     */
+    public Element getElementByName(String elementName)
+            throws ValidationLayerException {
+        for (Iterator<String> i = elementMap.keySet().iterator(); i.hasNext();) {
+            String elementId = i.next();
+            Element element = (Element) elementMap.get(elementId);
+            if (element.getElementName().equals(elementName)) {
+                return element;
+            }
+        }
+
+        return null;
+
+    }
+
+    private void saveElementsAndMappings() {
+        for (Iterator<String> i = xmlFileDirUris.iterator(); i.hasNext();) {
+            String dirUri = i.next();
+            File elementDir = null;
+
+            try {
+                elementDir = new File(new URI(dirUri));
+
+                if (!elementDir.isDirectory()) {
+                    LOG
+                            .log(
+                                    Level.WARNING,
+                                    "Element directory: "
+                                            + dirUri
+                                            + " is not "
+                                            + "a directory: skipping element and product type map saving to it.");
+                    continue;
+                }
+
+                String elementDirStr = elementDir.getAbsolutePath();
+                if (!elementDirStr.endsWith("/")) {
+                    elementDirStr += "/";
+                }
+
+                String elementXmlFile = elementDirStr + "elements.xml";
+
+                String productTypeMapXmlFile = elementDirStr
+                        + "product-type-element-map.xml";
+
+                XmlStructFactory.writeElementXmlDocument(Arrays
+                        .asList(elementMap.values().toArray(
+                                new Element[elementMap.size()])),
+                        elementXmlFile);
+
+                XmlStructFactory.writeProductTypeMapXmLDocument(
+                        productTypeElementMap, subToSuperMap,
+                        productTypeMapXmlFile);
+
+            } catch (URISyntaxException e) {
+                LOG
+                        .log(
+                                Level.WARNING,
+                                "URISyntaxException when saving element "
+                                        + "directory URI: "
+                                        + dirUri
+                                        + ": Skipping Element and Product Type map saving"
+                                        + "for it: Message: " + e.getMessage());
+                continue;
+            }
+
+        }
+
+    }
+
+    private void loadElements(List<String> dirUris) {
+        for (Iterator<String> i = dirUris.iterator(); i.hasNext();) {
+            File elementDir = null;
+            String dirUri = i.next();
+
+            try {
+                elementDir = new File(new URI(dirUri));
+
+                if (!elementDir.isDirectory()) {
+                    LOG.log(Level.WARNING, "Element directory: " + dirUri
+                            + " is not "
+                            + "a directory: skipping element loading from it.");
+                    continue;
+                }
+
+                String elementDirStr = elementDir.getAbsolutePath();
+                if (!elementDirStr.endsWith("/")) {
+                    elementDirStr += "/";
+                }
+
+                String elementXmlFile = elementDirStr + "elements.xml";
+                Document elementDoc = getDocumentRoot(elementXmlFile);
+
+                org.w3c.dom.Element elementRootElem = elementDoc
+                        .getDocumentElement();
+
+                NodeList elementNodeList = elementRootElem
+                        .getElementsByTagName("element");
+
+                if (elementNodeList != null && elementNodeList.getLength() > 0) {
+                    for (int j = 0; j < elementNodeList.getLength(); j++) {
+                        Node elementNode = elementNodeList.item(j);
+                        Element element = XmlStructFactory
+                                .getElement(elementNode);
+                        elementMap.put(element.getElementId(), element);
+                    }
+                }
+
+            } catch (URISyntaxException e) {
+                LOG.log(Level.WARNING,
+                        "URISyntaxException when loading element "
+                                + "directory URI: " + dirUri
+                                + ": Skipping element loading"
+                                + "for it: Message: " + e.getMessage());
+                continue;
+            }
+        }
+    }
+
+    private void loadProductTypeMap(List<String> dirUris) {
+        for (Iterator<String> i = dirUris.iterator(); i.hasNext();) {
+            File elementDir = null;
+            String dirUri = i.next();
+
+            try {
+                elementDir = new File(new URI(dirUri));
+
+                if (!elementDir.isDirectory()) {
+                    LOG
+                            .log(
+                                    Level.WARNING,
+                                    "Element directory: "
+                                            + dirUri
+                                            + " is not "
+                                            + "a directory: skipping product type element map loading from it.");
+                    continue;
+                }
+
+                String elementDirStr = elementDir.getAbsolutePath();
+                if (!elementDirStr.endsWith("/")) {
+                    elementDirStr += "/";
+                }
+
+                String productTypeMapXmlFile = elementDirStr
+                        + "product-type-element-map.xml";
+                Document productTypeMapDoc = getDocumentRoot(productTypeMapXmlFile);
+
+                org.w3c.dom.Element mapRootElem = productTypeMapDoc
+                        .getDocumentElement();
+
+                NodeList typeNodeList = mapRootElem
+                        .getElementsByTagName("type");
+
+                if (typeNodeList != null && typeNodeList.getLength() > 0) {
+                    for (int j = 0; j < typeNodeList.getLength(); j++) {
+                        org.w3c.dom.Element typeElement = (org.w3c.dom.Element) typeNodeList
+                                .item(j);
+                        String typeId = typeElement.getAttribute("id");
+
+                        // get inheritance info
+                        String typeParent = typeElement.getAttribute("parent");
+                        if (typeParent != null) {
+                            subToSuperMap.put(typeId, typeParent);
+                        }
+
+                        // get its element list
+                        NodeList elementIdNodeList = typeElement
+                                .getElementsByTagName("element");
+
+                        // allow for 0 sized element list
+                        List<Element> productTypeElementList = new Vector<Element>();
+
+                        if (elementIdNodeList != null
+                                && elementIdNodeList.getLength() > 0) {
+                            productTypeElementList = new Vector<Element>(
+                                    elementIdNodeList.getLength());
+                            for (int k = 0; k < elementIdNodeList.getLength(); k++) {
+                                org.w3c.dom.Element elementIdElement = (org.w3c.dom.Element) elementIdNodeList
+                                        .item(k);
+                                String elementId = elementIdElement
+                                        .getAttribute("id");
+
+                                if (elementMap.get(elementId) != null) {
+                                    productTypeElementList.add(elementMap
+                                            .get(elementId));
+                                }
+                            }
+                        }
+
+                        productTypeElementMap.put(typeId,
+                                productTypeElementList);
+                    }
+                }
+
+            } catch (URISyntaxException e) {
+                LOG.log(Level.WARNING,
+                        "URISyntaxException when loading element "
+                                + "directory URI: " + dirUri
+                                + ": Skipping product type map loading"
+                                + "for it: Message: " + e.getMessage());
+                continue;
+            }
+        }
+    }
+
+    private Document getDocumentRoot(String xmlFile) {
+        // open up the XML file
+        DocumentBuilderFactory factory = null;
+        DocumentBuilder parser = null;
+        Document document = null;
+        InputSource inputSource = null;
+
+        InputStream xmlInputStream = null;
+
+        try {
+            xmlInputStream = new File(xmlFile).toURL().openStream();
+        } catch (IOException e) {
+            LOG.log(Level.WARNING,
+                    "IOException when getting input stream from [" + xmlFile
+                            + "]: returning null document root");
+            return null;
+        }
+
+        inputSource = new InputSource(xmlInputStream);
+
+        try {
+            factory = DocumentBuilderFactory.newInstance();
+            parser = factory.newDocumentBuilder();
+            document = parser.parse(inputSource);
+        } catch (Exception e) {
+            LOG.warning("Unable to parse xml file [" + xmlFile + "]."
+                    + "Reason is [" + e + "]");
+            return null;
+        }
+
+        return document;
+    }
+
+}

Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/validation/XMLValidationLayerFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.validation;
+
+//JDK imports
+import java.util.Arrays;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.util.PathUtils;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * A Factory class for creating XMLValidationLayer objects.
+ * </p>
+ * 
+ */
+public class XMLValidationLayerFactory implements ValidationLayerFactory {
+
+    /*
+     * list of dir uris specifying file paths to elements and product type map
+     * directories
+     */
+    private List<String> dirList = null;
+
+    /**
+     * <p>
+     * Default Constructor
+     * </p>.
+     */
+    public XMLValidationLayerFactory() {
+        String dirUris = System
+                .getProperty("gov.nasa.jpl.oodt.cas.filemgr.validation.dirs");
+
+        if (dirUris != null) {
+            dirUris = PathUtils.replaceEnvVariables(dirUris);
+            String[] dirUriList = dirUris.split(",");
+            dirList = Arrays.asList(dirUriList);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.filemgr.validation.ValidationLayerFactory#createValidationLayer()
+     */
+    public ValidationLayer createValidationLayer() {
+        return new XMLValidationLayer(dirList);
+    }
+
+}

Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/BasicVersioner.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/BasicVersioner.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/BasicVersioner.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/versioning/BasicVersioner.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.versioning;
+
+//JDK imports
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLEncoder;
+import java.net.MalformedURLException;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.Reference;
+import org.apache.oodt.cas.filemgr.structs.exceptions.VersioningException;
+import org.apache.oodt.cas.metadata.Metadata;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ * 
+ * <p>
+ * A basic versioner that doesn't do anything special: it just creates data
+ * store refs from product refs using the product name and product repo path.
+ * </p>
+ * 
+ */
+public class BasicVersioner implements Versioner {
+
+    /* our log stream */
+    private static Logger LOG = Logger.getLogger(BasicVersioner.class.getName());
+
+    /**
+     * 
+     */
+    public BasicVersioner() {
+        super();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see gov.nasa.jpl.oodt.cas.versioning.Versioner#createDataStoreReferences(gov.nasa.jpl.oodt.cas.data.structs.Product)
+     */
+    public void createDataStoreReferences(Product product, Metadata metadata)
+            throws VersioningException {
+
+        String productName = product.getProductName();
+        String productRepoPath = product.getProductType()
+                .getProductRepositoryPath();
+
+        if (product.getProductStructure()
+                .equals(Product.STRUCTURE_HIERARCHICAL)) {
+
+            if (product.getProductReferences() == null
+                    || (product.getProductReferences() != null && product
+                            .getProductReferences().size() == 0)) {
+                throw new VersioningException(
+                        "Hierarchical product and references not set!");
+            }
+
+            // get the first reference, it tells us what directory to move it
+            // to
+            // TODO: fix that hack :-)
+            Reference r = (Reference) product.getProductReferences().get(0);
+
+            String dataStoreRef = null;
+
+            try {
+                dataStoreRef = new File(new URI(productRepoPath)).toURL()
+                        .toExternalForm()
+                        + URLEncoder.encode(productName, "UTF-8") + "/";
+                LOG.log(Level.INFO, "BasicVersioner: generated DataStore ref: "
+                        + dataStoreRef + " from origRef: "
+                        + r.getOrigReference());
+                r.setDataStoreReference(dataStoreRef);
+                VersioningUtils.createBasicDataStoreRefsHierarchical(product
+                        .getProductReferences());
+            } catch (URISyntaxException e) {
+                LOG.log(Level.WARNING,
+                        "BasicVersioner: URISyntaxException while generating initial "
+                                + "data store ref for origRef: "
+                                + r.getOrigReference());
+                throw new VersioningException(e);
+            } catch (MalformedURLException e) {
+                LOG.log(Level.WARNING,
+                        "BasicVersioner: MalformedURLException while generating initial "
+                                + "data store ref for origRef: "
+                                + r.getOrigReference());
+                throw new VersioningException(e);
+            } catch (UnsupportedEncodingException e) {
+                LOG.log(Level.WARNING,
+                        "BasicVersioner: UnsupportedEncodingException while generating "
+                                + "initial data store ref for origRef: "
+                                + r.getOrigReference());
+                throw new VersioningException(e);
+            }
+
+        } else if (product.getProductStructure().equals(Product.STRUCTURE_FLAT)) {
+            // just use the VersioningUtils
+            VersioningUtils.createBasicDataStoreRefsFlat(productName,
+                    productRepoPath, product.getProductReferences());
+        } else {
+            throw new VersioningException("Unsupported product structure: "
+                    + product.getProductStructure());
+        }
+
+    }
+
+}



Mime
View raw message