You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2010/12/23 03:48:11 UTC
svn commit: r1052148 [13/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...
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/DbStructFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/DbStructFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/DbStructFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/DbStructFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,100 @@
+/*
+ * 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.sql.ResultSet;
+import java.sql.SQLException;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Element;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.Reference;
+
+/**
+ * @author mattmann
+ * @version $Revsion$
+ *
+ * <p>
+ * Object creation utilities to create File Manager objects from SQL
+ * {@link ResultSet}s.
+ * </p>
+ *
+ */
+public final class DbStructFactory {
+
+ public static ProductType getProductType(ResultSet rs) throws SQLException {
+ ProductType type = new ProductType();
+ type.setDescription(rs.getString("product_type_description"));
+ type.setName(rs.getString("product_type_name"));
+ type.setProductRepositoryPath(rs
+ .getString("product_type_repository_path"));
+ type.setProductTypeId(String.valueOf(rs.getInt("product_type_id")));
+ type.setVersioner(rs.getString("product_type_versioner_class"));
+
+ return type;
+ }
+
+ public static Product getProduct(ResultSet rs) throws SQLException {
+ return getProduct(rs, true);
+ }
+
+ public static Product getProduct(ResultSet rs, boolean getType)
+ throws SQLException {
+ Product product = new Product();
+ product.setProductId(String.valueOf(rs.getInt("product_id")));
+ product.setProductName(rs.getString("product_name"));
+ product.setProductStructure(rs.getString("product_structure"));
+ product.setTransferStatus(rs.getString("product_transfer_status"));
+ if (getType) {
+ product.setProductType(getProductType(rs));
+ } else {
+ // still grab the ID
+ ProductType type = new ProductType();
+ type.setProductTypeId(rs.getString("product_type_id"));
+ product.setProductType(type);
+ }
+
+ return product;
+ }
+
+ public static Reference getReference(ResultSet rs) throws SQLException {
+ Reference r = new Reference();
+ r.setOrigReference(rs.getString("product_orig_reference"));
+ r.setDataStoreReference(rs.getString("product_datastore_reference"));
+ r.setFileSize(rs.getLong("product_reference_filesize"));
+ r.setMimeType(rs.getString("product_reference_mimetype"));
+ return r;
+ }
+
+ public static Element getElement(ResultSet rs) throws SQLException {
+ Element element = new Element();
+ element.setElementId(String.valueOf(rs.getInt("element_id")));
+ element.setElementName(rs.getString("element_name"));
+ element.setDCElement(rs.getString("dc_element"));
+ element.setDescription(rs.getString("element_description"));
+ return element;
+
+ }
+
+ public static String getParent(ResultSet rs) throws SQLException {
+ String parent = rs.getString("parent_id");
+ return parent;
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/GenericFileManagerObjectFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/GenericFileManagerObjectFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/GenericFileManagerObjectFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/GenericFileManagerObjectFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,337 @@
+/*
+ * 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.logging.Level;
+import java.util.logging.Logger;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.catalog.Catalog;
+import org.apache.oodt.cas.filemgr.catalog.CatalogFactory;
+import org.apache.oodt.cas.filemgr.datatransfer.DataTransfer;
+import org.apache.oodt.cas.filemgr.datatransfer.DataTransferFactory;
+import org.apache.oodt.cas.filemgr.ingest.Cache;
+import org.apache.oodt.cas.filemgr.ingest.CacheFactory;
+import org.apache.oodt.cas.filemgr.metadata.extractors.FilemgrMetExtractor;
+import org.apache.oodt.cas.filemgr.repository.RepositoryManager;
+import org.apache.oodt.cas.filemgr.repository.RepositoryManagerFactory;
+import org.apache.oodt.cas.filemgr.structs.query.conv.VersionConverter;
+import org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor;
+import org.apache.oodt.cas.filemgr.structs.type.TypeHandler;
+import org.apache.oodt.cas.filemgr.validation.ValidationLayer;
+import org.apache.oodt.cas.filemgr.validation.ValidationLayerFactory;
+import org.apache.oodt.cas.filemgr.versioning.Versioner;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * Generic object creation utilities for FileManager objects from their
+ * interface class names.
+ * </p>
+ *
+ */
+public final class GenericFileManagerObjectFactory {
+
+ /* our log stream */
+ private static Logger LOG = Logger
+ .getLogger(GenericFileManagerObjectFactory.class.getName());
+
+ private GenericFileManagerObjectFactory() throws InstantiationException {
+ throw new InstantiationException(
+ "Don't construct final factory classes!");
+ }
+
+ /**
+ * <p>
+ * Constructs a new {@link DataTransfer} from the specified
+ * <code>serviceFactory</code>.
+ * </p>
+ *
+ * @param serviceFactory
+ * The Service Factory class name that will be instantiated to
+ * provide DataTransfer objects.
+ * @return A newly instantiated {@link DataTransfer} object.
+ */
+ public static DataTransfer getDataTransferServiceFromFactory(
+ String serviceFactory) {
+ DataTransferFactory dataTransferFactory = null;
+ Class<DataTransferFactory> dataTransferFactoryClass = null;
+
+ try {
+ dataTransferFactoryClass = (Class<DataTransferFactory>) Class.forName(serviceFactory);
+ dataTransferFactory = dataTransferFactoryClass.newInstance();
+ return dataTransferFactory.createDataTransfer();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "ClassNotFoundException when loading data transfer factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "InstantiationException when loading data transfer factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "IllegalAccessException when loading data transfer factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ }
+
+ return null;
+ }
+
+ /**
+ * <p>
+ * Constructs a new {@link RepositoryManager} from the specified
+ * <code>serviceFactory</code>.
+ * </p>
+ *
+ * @param serviceFactory
+ * The class name of the service factory used to create new
+ * RepositoryManager objects.
+ * @return A newly constructed {@link RepositoryManager} object.
+ */
+ public static RepositoryManager getRepositoryManagerServiceFromFactory(
+ String serviceFactory) {
+ RepositoryManagerFactory factory = null;
+ Class<RepositoryManagerFactory> clazz = null;
+
+ try {
+ clazz = (Class<RepositoryManagerFactory>) Class.forName(serviceFactory);
+ factory = clazz.newInstance();
+ return factory.createRepositoryManager();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "ClassNotFoundException when loading data store factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "InstantiationException when loading data store factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "IllegalAccessException when loading data store factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ }
+
+ return null;
+ }
+
+ /**
+ * <p>
+ * Constructs a new {@link Catalog} from the specified
+ * <code>serviceFactory</code>.
+ * </p>
+ *
+ * @param serviceFactory
+ * The class name of the service factory used to create new
+ * Catalog objects.
+ * @return A newly constructed {@link Catalog} object.
+ */
+ public static Catalog getCatalogServiceFromFactory(String serviceFactory) {
+ CatalogFactory factory = null;
+ Class<CatalogFactory> clazz = null;
+
+ try {
+ clazz = (Class<CatalogFactory>) Class.forName(serviceFactory);
+ factory = clazz.newInstance();
+ return factory.createCatalog();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "ClassNotFoundException when loading metadata store factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "InstantiationException when loading metadata store factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "IllegalAccessException when loading metadata store factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ }
+
+ return null;
+ }
+
+ /**
+ * <p>
+ * Creates a {@link ValidationLayer} from the specified
+ * <code>serviceFactory</code>.
+ * </p>
+ *
+ * @param serviceFactory
+ * The classname of the ValidationLayerFactory to use to create
+ * the ValidationLayer.
+ * @return A new {@link ValidationLayer}, created from the specified
+ * ValidationLayerFactory.
+ */
+ public static ValidationLayer getValidationLayerFromFactory(
+ String serviceFactory) {
+ ValidationLayerFactory factory = null;
+ Class<ValidationLayerFactory> clazz = null;
+
+ try {
+ clazz = (Class<ValidationLayerFactory>) Class.forName(serviceFactory);
+ factory = clazz.newInstance();
+ return factory.createValidationLayer();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "ClassNotFoundException when loading validation layer factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "InstantiationException when loading validation layer factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "IllegalAccessException when loading validation layer factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ }
+
+ return null;
+ }
+
+ public static Cache getCacheFromFactory(String serviceFactory){
+ CacheFactory factory = null;
+ Class<CacheFactory> clazz = null;
+
+ try {
+ clazz = (Class<CacheFactory>) Class.forName(serviceFactory);
+ factory = clazz.newInstance();
+ return factory.createCache();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "ClassNotFoundException when loading cache factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "InstantiationException when loading cache factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "IllegalAccessException when loading cache factory class "
+ + serviceFactory + " Message: " + e.getMessage());
+ }
+
+ return null;
+ }
+
+ /**
+ * <p>
+ * Constructs a new {@link Versioner} from the specified
+ * <code>className</code>.
+ * </p>
+ *
+ * @param className
+ * The class name of the Versioner object to create.
+ * @return A newly constructed {@link Versioner} object.
+ */
+ public static Versioner getVersionerFromClassName(String className) {
+ try {
+ Class<Versioner> versionerClass = (Class<Versioner>) Class.forName(className);
+ return versionerClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "ClassNotFoundException when loading versioner class "
+ + className + " Message: " + e.getMessage());
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "InstantiationException when loading versioner class "
+ + className + " Message: " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "IllegalAccessException when loading versioner class "
+ + className + " Message: " + e.getMessage());
+ }
+
+ return null;
+ }
+
+ public static FilemgrMetExtractor getExtractorFromClassName(String className) {
+ try {
+ Class<FilemgrMetExtractor> extractorClass = (Class<FilemgrMetExtractor>) Class.forName(className);
+ return extractorClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "ClassNotFoundException when loading extractor class "
+ + className + " Message: " + e.getMessage());
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "InstantiationException when loading extractor class "
+ + className + " Message: " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING,
+ "IllegalAccessException when loading extractor class "
+ + className + " Message: " + e.getMessage());
+ }
+ return null;
+ }
+
+ public static TypeHandler getTypeHandlerFromClassName(String className) {
+ try {
+ return (TypeHandler) Class.forName(className).newInstance();
+ }catch (Exception e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING, "Failed to load TypeHandler class '" + className + "' : " + e.getMessage());
+ }
+ return null;
+ }
+
+ public static FilterAlgor getFilterAlgorFromClassName(String className) {
+ try {
+ return (FilterAlgor) Class.forName(className).newInstance();
+ }catch (Exception e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING, "Failed to load TypeHandler class '" + className + "' : " + e.getMessage());
+ }
+ return null;
+ }
+
+ public static VersionConverter getVersionConverterFromClassName(String className) {
+ try {
+ return (VersionConverter) Class.forName(className).newInstance();
+ }catch (Exception e) {
+ e.printStackTrace();
+ LOG.log(Level.WARNING, "Failed to load TypeHandler class '" + className + "' : " + e.getMessage());
+ }
+ return null;
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/Pagination.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/Pagination.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/Pagination.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/Pagination.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,78 @@
+/*
+ * 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.List; //for javadoc
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductPage;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>
+ * An interface for pagination of {@link Product} {@link List}s..
+ * </p>
+ *
+ */
+public interface Pagination {
+
+ /**
+ * @param type
+ * The ProductType to obtain the first {@link ProductPage} for.
+ * @return The first page of products for a particular {@link ProductType}.
+ */
+ public ProductPage getFirstPage(ProductType type);
+
+ /**
+ *
+ * @param type
+ * The ProductType to obtain the last {@link ProductPage} for.
+ * @return The last page of products for a particular {@link ProductType}.
+ */
+ public ProductPage getLastProductPage(ProductType type);
+
+ /**
+ *
+ * @param type
+ * The ProductType to obtain the next page for, given the
+ * <code>currentPage</code>.
+ * @param currentPage
+ * The current page that tells the function what the next page to
+ * obtain is.
+ * @return The next page in the ProductType product list, given the
+ * currentPage.
+ */
+ public ProductPage getNextPage(ProductType type, ProductPage currentPage);
+
+ /**
+ *
+ * @param type
+ * The ProductType to obtain the previous page for, given the
+ * <code>currentPage</code>.
+ * @param currentPage
+ * The currentPage that tells the function what the previous page
+ * to obtain is.
+ * @return The previous page in the ProductType product list, given the
+ * currentPage.
+ */
+ public ProductPage getPrevPage(ProductType type, ProductPage currentPage);
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/QueryUtils.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/QueryUtils.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/QueryUtils.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/QueryUtils.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,84 @@
+/*
+ * 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.List;
+import java.util.Vector;
+
+//APACHE imports
+import org.apache.commons.lang.StringUtils;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.query.QueryResult;
+
+
+/**
+ * @author bfoster
+ * @version $Revsion$
+ *
+ * <p>
+ * Utility Class
+ * </p>
+ *
+ */
+public class QueryUtils {
+
+ public static String getQueryResultsAsString(List<QueryResult> queryResults) {
+ return getQueryResultsAsString(queryResults, null);
+ }
+
+ public static String getQueryResultsAsString(List<QueryResult> queryResults, String resultsDelimiter) {
+ return getQueryResultsAsString(queryResults, null, resultsDelimiter);
+ }
+
+ public static String getQueryResultsAsString(List<QueryResult> queryResults, String valueDelimiter, String resultsDelimiter) {
+ if (valueDelimiter == null)
+ valueDelimiter = ",";
+ if (resultsDelimiter == null)
+ resultsDelimiter = "//n";
+ StringBuffer returnString = new StringBuffer("");
+ boolean firstRun = true;
+ for (QueryResult queryResult : queryResults) {
+ List<String> keys = queryResult.getMetadata().getAllKeys();
+ if (keys.size() > 0) {
+ if (!firstRun)
+ returnString.append(resultsDelimiter);
+ else
+ firstRun = false;
+ returnString.append(queryResult.getMetadata().getAllMetadata(keys.get(0)));
+ for (int i = 1; i < keys.size(); i++)
+ returnString.append(valueDelimiter + queryResult.getMetadata().getAllMetadata(keys.get(i)));
+ }
+ }
+ return returnString.toString();
+ }
+
+ public static String getQueryResultsAsFormattedString(List<QueryResult> queryResults, String format, String delimiter) {
+ if (format == null)
+ return getQueryResultsAsString(queryResults, delimiter);
+ Vector<String> stringResults = new Vector<String>();
+ for (QueryResult queryResult : queryResults) {
+ String outputString = format;
+ for (String key : queryResult.getMetadata().getAllKeys())
+ outputString = outputString.replaceAll("\\$" + key, StringUtils.join(queryResult.getMetadata().getAllMetadata(key).iterator(), ","));
+ stringResults.add(outputString);
+ }
+ return StringUtils.join(stringResults.iterator(), delimiter);
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/SpringUtils.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/SpringUtils.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/SpringUtils.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/SpringUtils.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,49 @@
+/*
+ * 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.HashSet;
+import java.util.Map;
+
+//Spring imports
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+
+/**
+ *
+ * @author bfoster
+ *
+ */
+public class SpringUtils {
+
+ public static HashSet<?> loadBeans(String beanRepo) throws Exception {
+ return loadBeans(beanRepo, Object.class);
+ }
+
+ public static <T> HashSet<? extends T> loadBeans(String beanRepo, Class<T> classFilter) throws Exception {
+ FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext(beanRepo);
+ Map<String, T> catalogsMap = appContext.getBeansOfType(classFilter);
+ HashSet<T> catalogs = new HashSet<T>();
+ for (String key : catalogsMap.keySet()) {
+ T curCatalog = catalogsMap.get(key);
+ catalogs.add(curCatalog);
+ }
+ return catalogs;
+ }
+
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/SqlParser.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/SqlParser.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/SqlParser.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/SqlParser.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,463 @@
+/*
+ * 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.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Stack;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.exceptions.QueryFormulationException;
+import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
+import org.apache.oodt.cas.filemgr.structs.query.QueryFilter;
+import org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * A fairly robust SQL parser, based on the Shunting yard
+ * algorithm
+ * </p>
+ *
+ * <p>
+ * Evaluates SQL like string statements contained in a string. The SQL
+ * statement should be enclosed within: SQL ({@literal <sql_arguments>}
+ * ) { {@literal <sql_statement>} . the {@literal <sql_arguments>} can
+ * be either FORMAT, SORT_BY, or FILTER. Syntax: SQL (FORMAT='<metadata
+ * formated output>',SORT_BY='<metadata name>', FILTER='<start_time
+ * metadata element>, <end_time metadata element>, <priority metadata
+ * element>, <filter type>') { SELECT
+ * <list-of-comma-segregated-metadata-elements-to-query-on> FROM
+ * <productTypes-comma-segregated> WHERE <metadata-boolean-expressions>
+ * } Here is an example SQL statement: SQL (FORMAT='FileLocation/Filename',
+ * SORT_BY='FileSize',FILTER=<StartDateTime,EndDateTime,DataVersion,
+ * TakeHighestPriority) { SELECT FileLocation,Filename,FileSize FROM IASI_L1C
+ * WHERE ProductionDateTime >= '2007-12-01T00:00:00.000000Z' } This example
+ * would query the cas-filemgr for metadata values:
+ * FileLocation,Filename,FileSize for any data file where the
+ * ProductType == IASI_L1C and the ProductionDateTime >=
+ * 2007-12-01T00:00:00.000000Z. It would then combine the return data
+ * files metadata via the specified FORMAT. Each data file's metadata
+ * will be formated to a string representation of (with the actual
+ * values replaced in the location of the metadata keys):
+ * FileLocation/Filename. They will be concatenated together, in
+ * FileSize order.
+ * </p>
+ */
+public class SqlParser {
+
+ private SqlParser() {
+ }
+
+ public static ComplexQuery parseSqlQueryMethod(String sqlStringQueryMethod)
+ throws QueryFormulationException {
+ if (!Pattern.matches("((?:SQL)|(?:sql))\\s*(.*)\\s*\\{\\s*SELECT.*FROM.*(?:WHERE.*){0,1}\\}", sqlStringQueryMethod))
+ throw new QueryFormulationException("Malformed SQL method");
+
+ try {
+ ComplexQuery complexQuery = parseSqlQuery(stripOutSqlDefinition(sqlStringQueryMethod));
+
+ for (Expression expr : getSqlStatementArgs(sqlStringQueryMethod)) {
+ if (expr.getKey().toUpperCase().equals("SORT_BY"))
+ complexQuery.setSortByMetKey(expr.getValue());
+ else if (expr.getKey().toUpperCase().equals("FILTER"))
+ complexQuery.setQueryFilter(createFilter(expr));
+ }
+
+ return complexQuery;
+ }catch (Exception e) {
+ e.printStackTrace();
+ throw new QueryFormulationException("Failed to parse SQL method : " + e.getMessage());
+ }
+ }
+
+ public static ComplexQuery parseSqlQuery(String sqlStringQuery)
+ throws QueryFormulationException {
+ String[] splitSqlStatement = sqlStringQuery
+ .split("((?:SELECT)|(?:FROM)|(?:WHERE))");
+ String[] selectValues = (splitSqlStatement[1].trim() + ",").split(",");
+ String[] fromValues = (splitSqlStatement[2].trim() + ",").split(",");
+ ComplexQuery sq = new ComplexQuery();
+ List<String> selectValuesList = Arrays.asList(selectValues);
+ if (!selectValuesList.contains("*"))
+ sq.setReducedMetadata(selectValuesList);
+ List<String> fromValuesList = Arrays.asList(fromValues);
+ if (!fromValuesList.contains("*"))
+ sq.setReducedProductTypeNames(fromValuesList);
+
+ if (splitSqlStatement.length > 3)
+ sq.addCriterion(parseStatement(toPostFix(splitSqlStatement[3]
+ .trim())));
+ return sq;
+ }
+
+ public static QueryCriteria parseSqlWhereClause(String sqlWhereClause)
+ throws QueryFormulationException {
+ return parseStatement(toPostFix(sqlWhereClause.trim()));
+ }
+
+ public static String unparseSqlQuery(ComplexQuery complexQuery) throws QueryFormulationException {
+ LinkedList<String> outputArgs = new LinkedList<String>();
+ if (complexQuery.getSortByMetKey() != null)
+ outputArgs.add("SORT_BY = '" + complexQuery.getSortByMetKey() + "'");
+ if (complexQuery.getQueryFilter() != null) {
+ String filterString = "FILTER = '"
+ + complexQuery.getQueryFilter().getStartDateTimeMetKey() + ","
+ + complexQuery.getQueryFilter().getEndDateTimeMetKey() + ","
+ + complexQuery.getQueryFilter().getPriorityMetKey() + ","
+ + complexQuery.getQueryFilter().getFilterAlgor().getClass().getCanonicalName() + ","
+ + complexQuery.getQueryFilter().getFilterAlgor().getEpsilon();
+ outputArgs.add(filterString + "'");
+ }
+ String sqlQueryString = getInfixCriteriaString(complexQuery.getCriteria());
+ if (sqlQueryString != null && sqlQueryString.startsWith("(") && sqlQueryString.endsWith(")"))
+ sqlQueryString = sqlQueryString.substring(1, sqlQueryString.length() - 1);
+ return "SQL ("
+ + listToString(outputArgs)
+ + ") { SELECT "
+ + ((complexQuery.getReducedMetadata() == null || complexQuery
+ .getReducedMetadata().contains("*")) ? "*"
+ : listToString(complexQuery.getReducedMetadata()))
+ + " FROM "
+ + ((complexQuery.getReducedProductTypeNames() == null || complexQuery
+ .getReducedProductTypeNames().contains("*")) ? "*"
+ : listToString(complexQuery.getReducedProductTypeNames()))
+ + (sqlQueryString != null ? " WHERE " + sqlQueryString : "")
+ + " }";
+ }
+
+ public static String getInfixCriteriaString(List<QueryCriteria> criteriaList) throws QueryFormulationException {
+ if (criteriaList.size() > 1)
+ return getInfixCriteriaString(new BooleanQueryCriteria(criteriaList, BooleanQueryCriteria.AND));
+ else if (criteriaList.size() == 1)
+ return getInfixCriteriaString(criteriaList.get(0));
+ else
+ return null;
+ }
+
+ public static String getInfixCriteriaString(QueryCriteria criteria) {
+ String returnString = "";
+ if (criteria instanceof BooleanQueryCriteria) {
+ BooleanQueryCriteria bqc = (BooleanQueryCriteria) criteria;
+ List<QueryCriteria> terms = bqc.getTerms();
+ switch(bqc.getOperator()){
+ case 0:
+ returnString = "(" + getInfixCriteriaString((QueryCriteria) terms.get(0));
+ for (int i = 1; i < terms.size(); i++)
+ returnString += " AND " + getInfixCriteriaString((QueryCriteria) terms.get(i));
+ returnString += ")";
+ break;
+ case 1:
+ returnString = "(" + getInfixCriteriaString((QueryCriteria) terms.get(0));
+ for (int i = 1; i < terms.size(); i++)
+ returnString += " OR " + getInfixCriteriaString((QueryCriteria) terms.get(i));
+ returnString += ")";
+ break;
+ case 2:
+ QueryCriteria qc = bqc.getTerms().get(0);
+ if (qc instanceof TermQueryCriteria) {
+ TermQueryCriteria tqc = (TermQueryCriteria) qc;
+ returnString = tqc.getElementName() + " != '" + tqc.getValue() + "'";
+ }else {
+ returnString = "NOT(" + getInfixCriteriaString(qc) + ")";
+ }
+ break;
+ }
+ }else if (criteria instanceof RangeQueryCriteria) {
+ RangeQueryCriteria rqc = (RangeQueryCriteria) criteria;
+ String opString = rqc.getInclusive() ? "=" : "";
+ if (rqc.getStartValue() != null) {
+ opString = ">" + opString + " '" + rqc.getStartValue() + "'";
+ }else
+ opString = "<" + opString + " '" + rqc.getEndValue() + "'";
+ returnString = rqc.getElementName() + " " + opString;
+ }else if (criteria instanceof TermQueryCriteria) {
+ TermQueryCriteria tqc = (TermQueryCriteria) criteria;
+ returnString = tqc.getElementName() + " == '" + tqc.getValue() + "'";
+ }
+ return returnString;
+ }
+
+ private static String stripOutSqlDefinition(String sqlStringQueryMethod) {
+ return sqlStringQueryMethod.trim().replaceAll("((?:SQL)|(?:sql))\\s*(.*)\\s*\\{", "").replaceAll("}$", "").trim();
+ }
+
+ private static List<Expression> getSqlStatementArgs(String sqlStringQueryMethod) throws QueryFormulationException {
+ boolean inExpr = false;
+ int startArgs = 0;
+ for (int i = 0; i < sqlStringQueryMethod.length(); i++) {
+ char curChar = sqlStringQueryMethod.charAt(i);
+ switch (curChar) {
+ case '(':
+ startArgs = i + 1;
+ break;
+ case ')':
+ if (!inExpr) {
+ String[] args = sqlStringQueryMethod.substring(startArgs, i).trim().split("'\\s*,");
+ LinkedList<Expression> argsList = new LinkedList<Expression>();
+ for (String arg : args)
+ argsList.add(new Expression((arg = arg.trim()).endsWith("'") ? arg : (arg + "'")));
+ return argsList;
+ } else {
+ break;
+ }
+ case '\'':
+ inExpr = !inExpr;
+ break;
+ }
+ }
+ throw new QueryFormulationException("Failed to read in args");
+ }
+
+ private static QueryFilter createFilter(Expression expr) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ String[] filterArgs = expr.getValue().split(",");
+ FilterAlgor filterAlgor = (FilterAlgor) Class.forName(filterArgs[3]).newInstance();
+ QueryFilter qf = new QueryFilter(filterArgs[0], filterArgs[1], filterArgs[2], filterAlgor);
+ filterAlgor.setEpsilon(Integer.parseInt(filterArgs[4]));
+ return qf;
+ }
+
+ /**
+ * Uses "Shunting yard algorithm" (see:
+ * http://en.wikipedia.org/wiki/Shunting_yard_algorithm)
+ */
+ private static LinkedList<String> toPostFix(String statement) {
+ LinkedList<String> postFix = new LinkedList<String>();
+ Stack<String> stack = new Stack<String>();
+
+ for (int i = 0; i < statement.length(); i++) {
+ char curChar = statement.charAt(i);
+ switch (curChar) {
+ case '(':
+ stack.push(new String("("));
+ break;
+ case ')':
+ String value = null;
+ while (!(value = stack.pop()).equals("("))
+ postFix.add(value);
+ if (stack.peek().equals("NOT"))
+ postFix.add(stack.pop());
+ break;
+ case ' ':
+ break;
+ default:
+ if (statement.substring(i, i + 3).equals("AND")) {
+ while (!stack.isEmpty()
+ && (stack.peek().equals("AND")))
+ postFix.add(stack.pop());
+ stack.push("AND");
+ i += 2;
+ } else if (statement.substring(i, i + 2).equals("OR")) {
+ while (!stack.isEmpty()
+ && (stack.peek().equals("AND") || stack.peek()
+ .equals("OR")))
+ postFix.add(stack.pop());
+ stack.push("OR");
+ i += 1;
+ } else if (statement.substring(i, i + 3).equals("NOT")) {
+ stack.push("NOT");
+ i += 2;
+ } else {
+ int endIndex = statement.indexOf('\'', statement.indexOf(
+ '\'', i) + 1) + 1;
+ postFix.add(statement.substring(i, endIndex));
+ i = endIndex - 1;
+ }
+ }
+ }
+
+ while (!stack.isEmpty())
+ postFix.add(stack.pop());
+
+ return postFix;
+ }
+
+ private static QueryCriteria parseStatement(LinkedList<String> postFixStatement)
+ throws QueryFormulationException {
+ Stack<QueryCriteria> stack = new Stack<QueryCriteria>();
+ for (String item : postFixStatement) {
+ if (item.equals("AND")) {
+ BooleanQueryCriteria bQC = new BooleanQueryCriteria();
+ bQC.addTerm(stack.pop());
+ bQC.addTerm(stack.pop());
+ stack.push(bQC);
+ } else if (item.equals("OR")) {
+ BooleanQueryCriteria bQC = new BooleanQueryCriteria();
+ bQC.setOperator(BooleanQueryCriteria.OR);
+ bQC.addTerm(stack.pop());
+ bQC.addTerm(stack.pop());
+ stack.push(bQC);
+ } else if (item.equals("NOT")) {
+ BooleanQueryCriteria bQC = new BooleanQueryCriteria();
+ bQC.setOperator(BooleanQueryCriteria.NOT);
+ bQC.addTerm(stack.pop());
+ stack.push(bQC);
+ } else {
+ stack.push(new Expression(item).convertToQueryCriteria());
+ }
+ }
+ return stack.pop();
+ }
+
+ private static String listToString(List<String> list) {
+ String arrayString = "";
+ if (list.size() > 0) {
+ arrayString = list.get(0);
+ for (int i = 1; i < list.size(); i++)
+ arrayString += "," + list.get(i);
+ }
+ return arrayString;
+ }
+
+
+ private static class Expression {
+
+ public static final short GREATER_THAN = 12;
+
+ public static final short LESS_THAN = 3;
+
+ public static final short EQUAL_TO = 9;
+
+ public static final short NOT_EQUAL_TO = 15;
+
+ public static final short GREATER_THAN_OR_EQUAL_TO = 13;
+
+ public static final short LESS_THAN_OR_EQUAL_TO = 11;
+
+ public static final short NOT = 6;
+
+ private String[] stringValues = new String[] { "`", "`", "`", "<", "`",
+ "`", "!", "`", "`", "=", "`", "<=", ">", ">=", "`", "!=" };
+
+ private String expression;
+
+ private String key;
+
+ private String val;
+
+ private int op;
+
+ public Expression(String expression) {
+ this.parseExpression(this.expression = expression);
+ }
+
+ public Expression(String key, int op, String val) {
+ this.key = key.trim();
+ this.op = op;
+ this.val = this.removeTickBounds(val.trim());
+ }
+
+ private void parseExpression(String expression) {
+ Matcher matcher = Pattern.compile("((?:>=)|(?:<=)|(?:==)|(?:!=)|(?:=)|(?:>)|(?:<))").matcher(expression);
+ matcher.find();
+ this.key = expression.substring(0, matcher.start()).trim();
+ this.val = this.removeTickBounds(expression.substring(matcher.end()).trim());
+ String opString = matcher.group();
+ for (char c : opString.toCharArray())
+ this.op = this.op | this.getShortValueForOp(c);
+ }
+
+ private String removeTickBounds(String value) {
+ if (value.startsWith("'") && value.endsWith("'"))
+ value = value.substring(1, value.length() - 1);
+ return value;
+ }
+
+ private int getShortValueForOp(char op) {
+ switch (op) {
+ case '>':
+ return GREATER_THAN;
+ case '<':
+ return LESS_THAN;
+ case '=':
+ return EQUAL_TO;
+ case '!':
+ return NOT;
+ default:
+ return 0;
+ }
+ }
+
+ public QueryCriteria convertToQueryCriteria()
+ throws QueryFormulationException {
+ switch (this.op) {
+ case GREATER_THAN:
+ return new RangeQueryCriteria(this.key, this.val, null, false);
+ case LESS_THAN:
+ return new RangeQueryCriteria(this.key, null, this.val, false);
+ case EQUAL_TO:
+ return new TermQueryCriteria(this.key, this.val);
+ case NOT_EQUAL_TO:
+ BooleanQueryCriteria notEqBQC = new BooleanQueryCriteria();
+ notEqBQC.setOperator(BooleanQueryCriteria.NOT);
+ notEqBQC.addTerm(new TermQueryCriteria(this.key, this.val));
+ return notEqBQC;
+ case GREATER_THAN_OR_EQUAL_TO:
+ return new RangeQueryCriteria(this.key, this.val, null, true);
+ case LESS_THAN_OR_EQUAL_TO:
+ return new RangeQueryCriteria(this.key, null, this.val, true);
+ }
+ throw new QueryFormulationException(
+ "Was not able to form query . . . probably an invalid operator -- "
+ + this.toString());
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ public String getValue() {
+ return this.val;
+ }
+
+ public int getOp() {
+ return this.op;
+ }
+
+ public String getExpression() {
+ return this.expression;
+ }
+
+ public String toString() {
+ return this.key + " " + this.stringValues[this.op] + " " + this.val;
+ }
+
+ }
+
+ public static void main(String[] args) throws QueryFormulationException {
+ String query = "SELECT * FROM IASI_L1C WHERE one == '1' AND two == '2' OR NOT(five == '5') OR three == '3' AND four == '4'";
+ System.out.println("query: " + query);
+ System.out.println("query after : " + unparseSqlQuery(parseSqlQuery(query)));
+ query = "SELECT * FROM IASI_L1C";
+ System.out.println("query: " + query);
+ System.out.println("query after : " + unparseSqlQuery(parseSqlQuery(query)));
+ query = "SELECT * FROM *";
+ System.out.println("query: " + query);
+ System.out.println("query after : " + unparseSqlQuery(parseSqlQuery(query)));
+ }
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/XmlRpcStructFactory.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,692 @@
+/*
+ * 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;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.Element;
+import org.apache.oodt.cas.filemgr.structs.ExtractorSpec;
+import org.apache.oodt.cas.filemgr.structs.FileTransferStatus;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductPage;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.Query;
+import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.Reference;
+import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.exceptions.QueryFormulationException;
+import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
+import org.apache.oodt.cas.filemgr.structs.query.QueryFilter;
+import org.apache.oodt.cas.filemgr.structs.query.QueryResult;
+import org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor;
+import org.apache.oodt.cas.filemgr.structs.type.TypeHandler;
+import org.apache.oodt.cas.metadata.Metadata;
+
+//JDK imports
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * A factory class for creating File Manager structures suitable for transfer
+ * over the XML-RPC pipe, and for reading objects from the XML-RPC pipe into
+ * File Manager structs.
+ * </p>
+ *
+ */
+public final class XmlRpcStructFactory {
+
+ /* our log stream */
+ private static Logger LOG = Logger
+ .getLogger(XmlRpcStructFactory.class.getName());
+
+ private XmlRpcStructFactory() throws InstantiationException {
+ throw new InstantiationException(
+ "Don't instantiate XmlRpcStructFactories!");
+ }
+
+ public static Hashtable<String, Object> getXmlRpcFileTransferStatus(
+ FileTransferStatus status) {
+ Hashtable<String, Object> statusHash = new Hashtable<String, Object>();
+ statusHash.put("bytesTransferred", new Integer((int) status
+ .getBytesTransferred()));
+ statusHash.put("parentProduct", getXmlRpcProduct(status
+ .getParentProduct()));
+ statusHash.put("fileRef", getXmlRpcReference(status.getFileRef()));
+ return statusHash;
+ }
+
+ public static FileTransferStatus getFileTransferStatusFromXmlRpc(
+ Hashtable<String, Object> statusHash) {
+ FileTransferStatus status = new FileTransferStatus();
+ status.setBytesTransferred((long) ((Integer) statusHash
+ .get("bytesTransferred")).intValue());
+ status.setParentProduct(getProductFromXmlRpc((Hashtable<String, Object>) statusHash.get("parentProduct")));
+ status.setFileRef(getReferenceFromXmlRpc((Hashtable<String, Object>) statusHash.get("fileRef")));
+ return status;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcFileTransferStatuses(List<FileTransferStatus> statuses) {
+ Vector<Hashtable<String, Object>> statusVector = new Vector<Hashtable<String, Object>>();
+
+ if (statuses != null && statuses.size() > 0) {
+
+ for (Iterator<FileTransferStatus> i = statuses.iterator(); i.hasNext();) {
+ FileTransferStatus status = i.next();
+ statusVector.add(getXmlRpcFileTransferStatus(status));
+ }
+ }
+
+ return statusVector;
+ }
+
+ public static List<FileTransferStatus> getFileTransferStatusesFromXmlRpc(Vector<Hashtable<String, Object>> statusVector) {
+ List<FileTransferStatus> statuses = new Vector<FileTransferStatus>();
+
+ if (statusVector != null && statusVector.size() > 0) {
+ for (Iterator<Hashtable<String, Object>> i = statusVector.iterator(); i.hasNext();) {
+ Hashtable<String, Object> statusHash = i.next();
+ FileTransferStatus status = getFileTransferStatusFromXmlRpc(statusHash);
+ statuses.add(status);
+ }
+ }
+
+ return statuses;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcProductPage(ProductPage page) {
+ Hashtable<String, Object>productPageHash = new Hashtable<String, Object>();
+// productPageHash.put("totalPages", new Integer(page.getTotalPages()));
+ productPageHash.put("pageNum", new Integer(page.getPageNum()));
+ productPageHash.put("pageSize", new Integer(page.getPageSize()));
+ productPageHash.put("numOfHits", new Integer(page.getNumOfHits()));
+ productPageHash.put("pageProducts", getXmlRpcProductList(page
+ .getPageProducts()));
+ return productPageHash;
+ }
+
+ public static ProductPage getProductPageFromXmlRpc(Hashtable<String, Object> productPageHash) {
+ ProductPage page = new ProductPage();
+ page.setPageNum(((Integer) productPageHash.get("pageNum")).intValue());
+ page
+ .setPageSize(((Integer) productPageHash.get("pageSize"))
+ .intValue());
+// page.setTotalPages(((Integer) productPageHash.get("totalPages"))
+// .intValue());
+ page.setNumOfHits(((Integer) productPageHash.get("numOfHits"))
+ .intValue());
+ page.setPageProducts(getProductListFromXmlRpc((Vector<Hashtable<String, Object>>) productPageHash
+ .get("pageProducts")));
+ return page;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcComplexQuery(ComplexQuery complexQuery) {
+ Hashtable<String, Object> complexQueryHash = getXmlRpcQuery(complexQuery);
+ if (complexQuery.getReducedProductTypeNames() != null)
+ complexQueryHash.put("reducedProductTypeNames", new Vector<String>(complexQuery.getReducedProductTypeNames()));
+ else
+ complexQueryHash.put("reducedProductTypeNames", new Vector<String>());
+ if (complexQuery.getReducedMetadata() != null)
+ complexQueryHash.put("reducedMetadata", new Vector<String>(complexQuery.getReducedMetadata()));
+ else
+ complexQueryHash.put("reducedMetadata", new Vector<String>());
+ if (complexQuery.getSortByMetKey() != null)
+ complexQueryHash.put("sortByMetKey", complexQuery.getSortByMetKey());
+ if (complexQuery.getQueryFilter() != null)
+ complexQueryHash.put("queryFilter", getXmlRpcQueryFilter(complexQuery.getQueryFilter()));
+ return complexQueryHash;
+ }
+
+ public static ComplexQuery getComplexQueryFromXmlRpc(Hashtable<String, Object> complexQueryHash) {
+ ComplexQuery complexQuery = new ComplexQuery();
+ complexQuery.setCriteria(getQueryFromXmlRpc(complexQueryHash).getCriteria());
+ if (((Vector<String>) complexQueryHash.get("reducedProductTypeNames")).size() > 0)
+ complexQuery.setReducedProductTypeNames((Vector<String>) complexQueryHash.get("reducedProductTypeNames"));
+ if (((Vector<String>) complexQueryHash.get("reducedMetadata")).size() > 0)
+ complexQuery.setReducedMetadata((Vector<String>) complexQueryHash.get("reducedMetadata"));
+ complexQuery.setSortByMetKey((String) complexQueryHash.get("sortByMetKey"));
+ if (complexQueryHash.get("queryFilter") != null)
+ complexQuery.setQueryFilter(getQueryFilterFromXmlRpc((Hashtable<String, Object>) complexQueryHash.get("queryFilter")));
+ return complexQuery;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcQueryFilter(QueryFilter queryFilter) {
+ Hashtable<String, Object> queryFilterHash = new Hashtable<String, Object>();
+ queryFilterHash.put("startDateTimeMetKey", queryFilter.getStartDateTimeMetKey());
+ queryFilterHash.put("endDateTimeMetKey", queryFilter.getEndDateTimeMetKey());
+ queryFilterHash.put("priorityMetKey", queryFilter.getPriorityMetKey());
+ queryFilterHash.put("filterAlgor", getXmlRpcFilterAlgor(queryFilter.getFilterAlgor()));
+ queryFilterHash.put("versionConverterClass", queryFilter.getConverter().getClass().getCanonicalName());
+ return queryFilterHash;
+ }
+
+ public static QueryFilter getQueryFilterFromXmlRpc(Hashtable<String, Object> queryFilterHash) {
+ String startDateTimeMetKey = (String) queryFilterHash.get("startDateTimeMetKey");
+ String endDateTimeMetKey = (String) queryFilterHash.get("endDateTimeMetKey");
+ String priorityMetKey = (String) queryFilterHash.get("priorityMetKey");
+ FilterAlgor filterAlgor = getFilterAlgorFromXmlRpc((Hashtable<String, Object>) queryFilterHash.get("filterAlgor"));
+ QueryFilter queryFilter = new QueryFilter(startDateTimeMetKey, endDateTimeMetKey, priorityMetKey, filterAlgor);
+ queryFilter.setConverter(GenericFileManagerObjectFactory.getVersionConverterFromClassName((String) queryFilterHash.get("versionConverterClass")));
+ return queryFilter;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcFilterAlgor(FilterAlgor filterAlgor) {
+ Hashtable<String, Object> filterAlgorHash = new Hashtable<String, Object>();
+ filterAlgorHash.put("class", filterAlgor.getClass().getCanonicalName());
+ filterAlgorHash.put("epsilon", Long.toString(filterAlgor.getEpsilon()));
+ return filterAlgorHash;
+ }
+
+ public static FilterAlgor getFilterAlgorFromXmlRpc(Hashtable<String, Object> filterAlgorHash) {
+ FilterAlgor filterAlgor = GenericFileManagerObjectFactory.getFilterAlgorFromClassName((String) filterAlgorHash.get("class"));
+ filterAlgor.setEpsilon(Long.parseLong((String) filterAlgorHash.get("epsilon")));
+ return filterAlgor;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcQueryResults(List<QueryResult> queryResults) {
+ Vector<Hashtable<String, Object>> queryResultHashVector = new Vector<Hashtable<String, Object>>();
+ for (QueryResult queryResult : queryResults)
+ queryResultHashVector.add(getXmlRpcQueryResult(queryResult));
+ return queryResultHashVector;
+ }
+
+ public static List<QueryResult> getQueryResultsFromXmlRpc(Vector<Hashtable<String, Object>> queryResultHashVector) {
+ List<QueryResult> queryResults = new Vector<QueryResult>();
+ for (Hashtable<String, Object> queryResultHash : queryResultHashVector)
+ queryResults.add(getQueryResultFromXmlRpc(queryResultHash));
+ return queryResults;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcQueryResult(QueryResult queryResult) {
+ Hashtable<String, Object> queryResultHash = new Hashtable<String, Object>();
+ queryResultHash.put("product", getXmlRpcProduct(queryResult.getProduct()));
+ queryResultHash.put("metadata", queryResult.getMetadata().getHashtable());
+ return queryResultHash;
+ }
+
+ public static QueryResult getQueryResultFromXmlRpc(Hashtable<String, Object> queryResultHash) {
+ Product product = getProductFromXmlRpc((Hashtable<String, Object>) queryResultHash.get("product"));
+ Metadata metadata = new Metadata();
+ metadata.addMetadata((Hashtable<String, Object>) queryResultHash.get("metadata"));
+ QueryResult queryResult = new QueryResult(product, metadata);
+ return queryResult;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcProduct(Product product) {
+ Hashtable<String, Object> productHash = new Hashtable<String, Object>();
+ productHash.put("id", product.getProductId() != null ? product
+ .getProductId() : "");
+ productHash.put("name", product.getProductName());
+ productHash.put("type", getXmlRpcProductType(product.getProductType()));
+ productHash.put("structure", product.getProductStructure());
+ productHash.put("transferStatus",
+ product.getTransferStatus() != null ? product
+ .getTransferStatus() : "");
+ productHash.put("references", getXmlRpcReferences(product
+ .getProductReferences()));
+ return productHash;
+ }
+
+ public static Product getProductFromXmlRpc(Hashtable<String, Object> productHash) {
+ Product product = new Product();
+ String productId = (String) productHash.get("id");
+ product.setProductId(productId.equals("") ? null : productId);
+ product.setProductName((String) productHash.get("name"));
+ product.setProductType(getProductTypeFromXmlRpc((Hashtable<String, Object>) productHash.get("type")));
+ product.setProductStructure((String) productHash.get("structure"));
+ String transferStatus = (String) productHash.get("transferStatus");
+ product.setTransferStatus(transferStatus.equals("") ? null : transferStatus);
+ product.setProductReferences(getReferencesFromXmlRpc((Vector<Hashtable<String, Object>>) productHash
+ .get("references")));
+ return product;
+ }
+
+ public static List<Product> getProductListFromXmlRpc(Vector<Hashtable<String, Object>> productVector) {
+ List<Product> productList = new Vector<Product>();
+
+ for (Iterator<Hashtable<String, Object>> i = productVector.iterator(); i.hasNext();) {
+ Hashtable<String, Object> productHash = i.next();
+ Product product = getProductFromXmlRpc(productHash);
+ productList.add(product);
+ }
+
+ return productList;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcProductList(List<Product> products) {
+ Vector<Hashtable<String, Object>> productVector = new Vector<Hashtable<String, Object>>();
+
+ if (products == null) {
+ return productVector;
+ }
+
+ for (Iterator<Product> i = products.iterator(); i.hasNext();) {
+ Product product = i.next();
+ Hashtable<String, Object> productHash = getXmlRpcProduct(product);
+ productVector.add(productHash);
+ }
+
+ return productVector;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcProductTypeList(List<ProductType> productTypes) {
+ Vector<Hashtable<String, Object>> productTypeVector = new Vector<Hashtable<String, Object>>();
+
+ if (productTypes == null) {
+ return productTypeVector;
+ }
+
+ for (Iterator<ProductType> i = productTypes.iterator(); i.hasNext();) {
+ ProductType type = i.next();
+ Hashtable<String, Object> typeHash = getXmlRpcProductType(type);
+ productTypeVector.add(typeHash);
+ }
+ return productTypeVector;
+ }
+
+ public static List<ProductType> getProductTypeListFromXmlRpc(Vector<Hashtable<String, Object>> productTypeVector) {
+ List<ProductType> productTypeList = new Vector<ProductType>();
+ for (Iterator<Hashtable<String, Object>> i = productTypeVector.iterator(); i.hasNext();) {
+ Hashtable<String, Object> productTypeHash = i.next();
+ ProductType type = getProductTypeFromXmlRpc(productTypeHash);
+ productTypeList.add(type);
+ }
+
+ return productTypeList;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcProductType(ProductType type) {
+ Hashtable<String, Object> productTypeHash = new Hashtable<String, Object>();
+ productTypeHash.put("id", type.getProductTypeId());
+ productTypeHash.put("name", type.getName() != null ? type.getName()
+ : "");
+ productTypeHash.put("description", type.getDescription() != null ? type
+ .getDescription() : "");
+ productTypeHash.put("repositoryPath",
+ type.getProductRepositoryPath() != null ? type
+ .getProductRepositoryPath() : "");
+ productTypeHash.put("versionerClass",
+ type.getVersioner() != null ? type.getVersioner() : "");
+ productTypeHash.put("typeMetadata",
+ type.getTypeMetadata() != null ? type.getTypeMetadata()
+ .getHashtable() : new Hashtable<String, Object>());
+
+ productTypeHash.put("typeExtractors",
+ type.getExtractors() != null ? getXmlRpcTypeExtractors(type
+ .getExtractors()) : new Vector<Hashtable<String, Object>>());
+
+ productTypeHash.put("typeHandlers",
+ type.getHandlers() != null ? getXmlRpcTypeHandlers(type
+ .getHandlers()) : new Vector<Hashtable<String, Object>>());
+
+ return productTypeHash;
+ }
+
+ public static ProductType getProductTypeFromXmlRpc(Hashtable<String, Object> productTypeHash) {
+ ProductType type = new ProductType();
+ type.setDescription((String) productTypeHash.get("description"));
+ type.setName((String) productTypeHash.get("name"));
+ type.setProductRepositoryPath((String) productTypeHash
+ .get("repositoryPath"));
+ type.setProductTypeId((String) productTypeHash.get("id"));
+ type.setVersioner((String) productTypeHash.get("versionerClass"));
+ Metadata typeMet = new Metadata();
+ if (productTypeHash.get("typeMetadata") != null) {
+ typeMet
+ .addMetadata((Hashtable<String, Object>) productTypeHash.get("typeMetadata"));
+ }
+
+ if (productTypeHash.get("typeExtractors") != null) {
+ type
+ .setExtractors(getTypeExtractorsFromXmlRpc((Vector<Hashtable<String, Object>>) productTypeHash
+ .get("typeExtractors")));
+ }
+
+ if (productTypeHash.get("typeHandlers") != null) {
+ type.setHandlers(getTypeHandlersFromXmlRpc((Vector<Hashtable<String, Object>>) productTypeHash
+ .get("typeHandlers")));
+ }
+
+ type.setTypeMetadata(typeMet);
+ return type;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcTypeExtractors(List<ExtractorSpec> extractors) {
+ Vector<Hashtable<String, Object>> extractorsVector = new Vector<Hashtable<String, Object>>();
+
+ if (extractors != null && extractors.size() > 0) {
+ for (Iterator<ExtractorSpec> i = extractors.iterator(); i.hasNext();) {
+ ExtractorSpec spec = i.next();
+ extractorsVector.add(getXmlRpcExtractorSpec(spec));
+ }
+ }
+
+ return extractorsVector;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcExtractorSpec(ExtractorSpec spec) {
+ Hashtable<String, Object> extractorHash = new Hashtable<String, Object>();
+ extractorHash.put("className", spec.getClassName());
+ extractorHash.put("config",
+ getXmlRpcProperties(spec.getConfiguration()));
+ return extractorHash;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcTypeHandlers(List<TypeHandler> typeHandlers) {
+ Vector<Hashtable<String, Object>> handlersVector = new Vector<Hashtable<String, Object>>();
+
+ if (typeHandlers != null && typeHandlers.size() > 0) {
+ for (Iterator<TypeHandler> i = typeHandlers.iterator(); i.hasNext();) {
+ TypeHandler typeHandler = i.next();
+ handlersVector.add(getXmlRpcTypeHandler(typeHandler));
+ }
+ }
+
+ return handlersVector;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcTypeHandler(TypeHandler typeHandler) {
+ Hashtable<String, Object> handlerHash = new Hashtable<String, Object>();
+ handlerHash.put("className", typeHandler.getClass().getCanonicalName());
+ handlerHash.put("elementName", typeHandler.getElementName());
+ return handlerHash;
+ }
+
+ public static List<ExtractorSpec> getTypeExtractorsFromXmlRpc(Vector<Hashtable<String, Object>> extractorsVector) {
+ List<ExtractorSpec> extractors = new Vector<ExtractorSpec>();
+
+ if (extractorsVector != null && extractorsVector.size() > 0) {
+ for (Iterator<Hashtable<String, Object>> i = extractorsVector.iterator(); i.hasNext();) {
+ Hashtable<String, Object> extractorSpecHash = i.next();
+ extractors.add(getExtractorSpecFromXmlRpc(extractorSpecHash));
+ }
+ }
+
+ return extractors;
+ }
+
+ public static ExtractorSpec getExtractorSpecFromXmlRpc(
+ Hashtable<String, Object> extractorSpecHash) {
+ ExtractorSpec spec = new ExtractorSpec();
+ spec.setClassName((String) extractorSpecHash.get("className"));
+ spec
+ .setConfiguration(getPropertiesFromXmlRpc((Hashtable<String, String>) extractorSpecHash
+ .get("config")));
+ return spec;
+ }
+
+ public static List<TypeHandler> getTypeHandlersFromXmlRpc(Vector<Hashtable<String, Object>> handlersVector) {
+ List<TypeHandler> handlers = new Vector<TypeHandler>();
+
+ if (handlersVector != null && handlersVector.size() > 0) {
+ for (Iterator<Hashtable<String, Object>> i = handlersVector.iterator(); i.hasNext();) {
+ Hashtable<String, Object> typeHandlerHash = i.next();
+ handlers.add(getTypeHandlerFromXmlRpc(typeHandlerHash));
+ }
+ }
+
+ return handlers;
+ }
+
+ public static TypeHandler getTypeHandlerFromXmlRpc(
+ Hashtable<String, Object> typeHandlerHash) {
+ TypeHandler typeHandler = GenericFileManagerObjectFactory
+ .getTypeHandlerFromClassName((String) typeHandlerHash.get("className"));
+ typeHandler.setElementName((String) typeHandlerHash.get("elementName"));
+ return typeHandler;
+ }
+
+ public static Properties getPropertiesFromXmlRpc(Hashtable<String, String> propHash) {
+ Properties props = new Properties();
+
+ if (propHash != null && propHash.keySet().size() > 0) {
+ for (Iterator<String> i = propHash.keySet().iterator(); i.hasNext();) {
+ String propName = i.next();
+ String propValue = propHash.get(propName);
+ props.setProperty(propName, propValue);
+ }
+ }
+
+ return props;
+ }
+
+ public static Hashtable<String, String> getXmlRpcProperties(Properties props) {
+ Hashtable<String, String> propHash = new Hashtable<String, String>();
+
+ if (props != null && props.keySet().size() > 0) {
+ for (Iterator<Object> i = props.keySet().iterator(); i.hasNext();) {
+ String propName = (String) i.next();
+ String propValue = props.getProperty(propName);
+ propHash.put(propName, propValue);
+ }
+ }
+
+ return propHash;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcReferences(List<Reference> references) {
+ Vector<Hashtable<String, Object>> refVector = new Vector<Hashtable<String, Object>>();
+
+ if (references == null) {
+ return refVector;
+ }
+
+ for (Iterator<Reference> i = references.iterator(); i.hasNext();) {
+ Hashtable<String, Object> refHash = getXmlRpcReference(i.next());
+ refVector.add(refHash);
+ }
+
+ return refVector;
+ }
+
+ public static List<Reference> getReferencesFromXmlRpc(Vector<Hashtable<String, Object>> referenceVector) {
+ List<Reference> references = new Vector<Reference>();
+ for (Iterator<Hashtable<String, Object>> i = referenceVector.iterator(); i.hasNext();) {
+ Reference r = getReferenceFromXmlRpc(i.next());
+ references.add(r);
+ }
+ return references;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcReference(Reference reference) {
+ Hashtable<String, Object> referenceHash = new Hashtable<String, Object>();
+ referenceHash.put("origReference", reference.getOrigReference());
+ referenceHash.put("dataStoreReference", reference
+ .getDataStoreReference() != null ? reference
+ .getDataStoreReference() : "");
+ referenceHash.put("fileSize",
+ new Integer((int) reference.getFileSize()));
+ referenceHash.put("mimeType", (reference.getMimeType() == null) ? ""
+ : reference.getMimeType().getName());
+ return referenceHash;
+ }
+
+ public static Reference getReferenceFromXmlRpc(Hashtable<String, Object> referenceHash) {
+ Reference reference = new Reference();
+ reference.setDataStoreReference((String) referenceHash
+ .get("dataStoreReference"));
+ reference.setOrigReference((String) referenceHash.get("origReference"));
+ reference.setFileSize(((Integer) referenceHash.get("fileSize"))
+ .longValue());
+ reference.setMimeType((String) referenceHash.get("mimeType"));
+ return reference;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcElementList(List<Element> elementList) {
+ Vector<Hashtable<String, Object>> elementVector = new Vector<Hashtable<String, Object>>(elementList.size());
+ for (Iterator<Element> i = elementList.iterator(); i.hasNext();) {
+ Element element = i.next();
+ Hashtable<String, Object> elementHash = getXmlRpcElement(element);
+ elementVector.add(elementHash);
+ }
+ return elementVector;
+ }
+
+ public static List<Element> getElementListFromXmlRpc(Vector<Hashtable<String, Object>> elementVector) {
+ List<Element> elementList = new Vector<Element>(elementVector.size());
+ for (Iterator<Hashtable<String, Object>> i = elementVector.iterator(); i.hasNext();) {
+ Hashtable<String, Object> elementHash = i.next();
+ Element element = getElementFromXmlRpc(elementHash);
+ elementList.add(element);
+ }
+ return elementList;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcElement(Element element) {
+ Hashtable<String, Object> elementHash = new Hashtable<String, Object>();
+
+ elementHash.put("id", element.getElementId());
+ elementHash.put("name", element.getElementName());
+ elementHash.put("dcElement", element.getDCElement() != null ? element
+ .getDCElement() : "");
+ elementHash.put("description",
+ element.getDescription() != null ? element.getDescription()
+ : "");
+
+ return elementHash;
+ }
+
+ public static Element getElementFromXmlRpc(Hashtable<String, Object> elementHash) {
+ Element element = new Element();
+ element.setElementId((String) elementHash.get("id"));
+ element.setElementName((String) elementHash.get("name"));
+ element.setDescription((String) elementHash.get("description"));
+ element.setDCElement((String) elementHash.get("dcElement"));
+
+ return element;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcQuery(Query query) {
+ Hashtable<String, Object> queryHash = new Hashtable<String, Object>();
+ Vector<Hashtable<String, Object>> criteriaVector = getXmlRpcQueryCriteriaList(query.getCriteria());
+ queryHash.put("criteria", criteriaVector);
+ return queryHash;
+ }
+
+ public static Query getQueryFromXmlRpc(Hashtable<String, Object> queryHash) {
+ Query query = new Query();
+ List<QueryCriteria> criteria = getQueryCriteriaListFromXmlRpc((Vector<Hashtable<String, Object>>) queryHash
+ .get("criteria"));
+ query.setCriteria(criteria);
+ return query;
+ }
+
+ public static Vector<Hashtable<String, Object>> getXmlRpcQueryCriteriaList(List<QueryCriteria> criteriaList) {
+ Vector<Hashtable<String, Object>> criteriaVector = new Vector<Hashtable<String, Object>>(criteriaList.size());
+ for (Iterator<QueryCriteria> i = criteriaList.iterator(); i.hasNext();) {
+ QueryCriteria criteria = i.next();
+ Hashtable<String, Object> criteriaHash = getXmlRpcQueryCriteria(criteria);
+ criteriaVector.add(criteriaHash);
+ }
+
+ return criteriaVector;
+ }
+
+ public static List<QueryCriteria> getQueryCriteriaListFromXmlRpc(Vector<Hashtable<String, Object>> criteriaVector) {
+
+ List<QueryCriteria> criteriaList = new Vector<QueryCriteria>(criteriaVector.size());
+ for (Iterator<Hashtable<String, Object>> i = criteriaVector.iterator(); i.hasNext();) {
+ Hashtable<String, Object> criteriaHash = i.next();
+ QueryCriteria criteria = getQueryCriteriaFromXmlRpc(criteriaHash);
+ criteriaList.add(criteria);
+ }
+ return criteriaList;
+ }
+
+ public static Hashtable<String, Object> getXmlRpcQueryCriteria(QueryCriteria criteria) {
+ Hashtable<String, Object> criteriaHash = new Hashtable<String, Object>();
+ criteriaHash.put("class",criteria.getClass().getCanonicalName());
+
+ if(criteria instanceof TermQueryCriteria){
+ criteriaHash.put("elementName", criteria.getElementName());
+ criteriaHash.put("elementValue", ((TermQueryCriteria)criteria).getValue());
+ } else if(criteria instanceof RangeQueryCriteria){
+ criteriaHash.put("elementName", criteria.getElementName());
+ criteriaHash.put("elementStartValue", ((RangeQueryCriteria)criteria).getStartValue() != null ?
+ ((RangeQueryCriteria)criteria).getStartValue():"");
+ criteriaHash.put("elementEndValue", ((RangeQueryCriteria)criteria).getEndValue() != null ?
+ ((RangeQueryCriteria)criteria).getEndValue():"");
+ criteriaHash.put("inclusive", Boolean.toString(((RangeQueryCriteria) criteria).getInclusive()));
+ } else if(criteria instanceof BooleanQueryCriteria){
+ BooleanQueryCriteria boolQuery = (BooleanQueryCriteria) criteria;
+ criteriaHash.put("operator", new Integer(boolQuery.getOperator()));
+ Vector<Hashtable<String, Object>> termsHash = new Vector<Hashtable<String, Object>>();
+ List<QueryCriteria> terms = boolQuery.getTerms();
+
+ for(int i=0;i<terms.size();i++){
+ QueryCriteria term = terms.get(i);
+ Hashtable<String, Object> termHash = getXmlRpcQueryCriteria(term);
+ termsHash.add(termHash);
+ }
+ criteriaHash.put("terms", termsHash);
+
+ } else {
+ //should not happen
+ }
+ return criteriaHash;
+ }
+
+ public static QueryCriteria getQueryCriteriaFromXmlRpc(Hashtable<String, Object> criteriaHash) {
+ QueryCriteria criteria = null;
+ if(((String)criteriaHash.get("class")).equals(TermQueryCriteria.class.getCanonicalName())){
+ criteria = new TermQueryCriteria();
+ criteria.setElementName((String) criteriaHash.get("elementName"));
+ ((TermQueryCriteria)criteria).setValue((String) criteriaHash.get("elementValue"));
+ } else if(((String)criteriaHash.get("class")).equals(RangeQueryCriteria.class.getCanonicalName())){
+ criteria = new RangeQueryCriteria();
+ criteria.setElementName((String) criteriaHash.get("elementName"));
+ String startVal = criteriaHash.get("elementStartValue").equals("") ?
+ null : (String)criteriaHash.get("elementStartValue");
+ String endVal = criteriaHash.get("elementEndValue").equals("") ?
+ null : (String)criteriaHash.get("elementEndValue");
+ ((RangeQueryCriteria)criteria).setStartValue(startVal);
+ ((RangeQueryCriteria)criteria).setEndValue(endVal);
+ ((RangeQueryCriteria)criteria).setInclusive(Boolean.parseBoolean((String) criteriaHash.get("inclusive")));
+ } else if(((String)criteriaHash.get("class")).equals(BooleanQueryCriteria.class.getCanonicalName())){
+ criteria = new BooleanQueryCriteria();
+ try{
+ ((BooleanQueryCriteria)criteria).setOperator( ((Integer)criteriaHash.get("operator")).intValue() );
+ } catch (QueryFormulationException e){
+ System.out.println("Error generating Boolean Query.");
+ }
+ List<Hashtable<String, Object>> terms = (List<Hashtable<String, Object>>) criteriaHash.get("terms");
+ for(int i=0;i<terms.size();i++){
+ Hashtable<String, Object> term = terms.get(i);
+ QueryCriteria termCriteria = getQueryCriteriaFromXmlRpc(term);
+ try{
+ ((BooleanQueryCriteria)criteria).addTerm(termCriteria);
+ } catch (QueryFormulationException e){
+ System.out.println("Error generating Boolean Query.");
+ }
+ }
+
+ }
+
+ return criteria;
+
+ }
+
+}