Author: chathura Date: Wed Jan 16 19:53:12 2008 New Revision: 12365 Log:
Implemented pluggable query processors. Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/QueryProcessorConfiguration.java Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/QueryProcessorConfiguration.java ============================================================================== --- (empty file) +++ trunk/registry/modules/core/src/main/java/org/wso2/registry/config/QueryProcessorConfiguration.java Wed Jan 16 19:53:12 2008 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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.wso2.registry.config; + +public class QueryProcessorConfiguration { + + private String queryType; + private String processorClassName; + + public String getQueryType() { + return queryType; + } + + public void setQueryType(String queryType) { + this.queryType = queryType; + } + + public String getProcessorClassName() { + return processorClassName; + } + + public void setProcessorClassName(String processorClassName) { + this.processorClassName = processorClassName; + } +} Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java ============================================================================== --- trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java (original) +++ trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java Wed Jan 16 19:53:12 2008 @@ -198,6 +198,31 @@ OMElement urlHandler = (OMElement) urlHandlers.next(); registryContext.addURLHandler(urlHandler.getText()); } + + // process query processor config + Iterator queryProcessors = configElement. + getChildrenWithName(new QName("queryProcessor")); + while (queryProcessors.hasNext()) { + + QueryProcessorConfiguration queryProcessorConfiguration = + new QueryProcessorConfiguration(); + + OMElement queryProcessorElement = (OMElement) queryProcessors.next(); + OMElement queryType = queryProcessorElement. + getFirstChildWithName(new QName("queryType")); + if (queryType != null) { + queryProcessorConfiguration.setQueryType(queryType.getText()); + } + + OMElement processorName = queryProcessorElement. + getFirstChildWithName(new QName("processor")); + if (processorName != null) { + queryProcessorConfiguration. + setProcessorClassName(processorName.getText()); + } + + registryContext.addQueryProcessor(queryProcessorConfiguration); + } } } catch (XMLStreamException e) { Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java ============================================================================== --- trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java (original) +++ trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java Wed Jan 16 19:53:12 2008 @@ -27,6 +27,7 @@ private Map dbconfgigMap = new HashMap(); private List mediaTypeHandlers = new ArrayList(); private List urlHandlers = new ArrayList(); + private List queryProcessors = new ArrayList(); public DataBaseConfiguration getDefaultDataBaseConfiguration() { return defaultDataBaseConfiguration; @@ -67,4 +68,16 @@ public void addURLHandler(String urlHandler) { urlHandlers.add(urlHandler); } + + public List getQueryProcessors() { + return queryProcessors; + } + + public void setQueryProcessors(List queryProcessors) { + this.queryProcessors = queryProcessors; + } + + public void addQueryProcessor(QueryProcessorConfiguration queryProcessorConfiguration) { + queryProcessors.add(queryProcessorConfiguration); + } } Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java ============================================================================== --- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java (original) +++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java Wed Jan 16 19:53:12 2008 @@ -19,23 +19,62 @@ import org.wso2.registry.RegistryConstants; import org.wso2.registry.Resource; import org.wso2.registry.RegistryException; +import org.wso2.registry.config.RegistryContext; +import org.wso2.registry.config.QueryProcessorConfiguration; import org.wso2.usermanager.Realm; import javax.sql.DataSource; import java.util.HashMap; import java.util.Map; +import java.util.Iterator; +import java.lang.reflect.Constructor; public class QueryProcessorManager { private DataSource dataSource; private Map queryProcessors = new HashMap(); - public QueryProcessorManager(DataSource dataSource, Realm realm) { + public QueryProcessorManager(DataSource dataSource, Realm realm) throws RegistryException { this.dataSource = dataSource; - queryProcessors. - put(RegistryConstants.SQL_QUERY_MEDIA_TYPE, new SQLQueryProcessor(dataSource, realm)); + queryProcessors.put( + RegistryConstants.SQL_QUERY_MEDIA_TYPE, new SQLQueryProcessor(dataSource, realm)); + + // add run-time query processors configured using registry.xml + + RegistryContext registryContext = (RegistryContext) System. + getProperties().get(RegistryConstants.REGISTRY_CONTEXT); + + if (registryContext != null) { + Iterator iQueryProcessors = registryContext.getQueryProcessors().iterator(); + while (iQueryProcessors.hasNext()) { + QueryProcessorConfiguration configuration = + (QueryProcessorConfiguration) iQueryProcessors.next(); + + try { + Class qpClass = Class.forName(configuration.getProcessorClassName()); + Constructor constructor = + qpClass.getConstructor(new Class[] {DataSource.class, Realm.class}); + + QueryProcessor queryProcessor = (QueryProcessor) constructor. + newInstance(new Object[] {dataSource, realm}); + + queryProcessors.put(configuration.getQueryType(), queryProcessor); + + } catch (ClassNotFoundException e) { + String msg = "Could not find the query processor class for query type: " + + configuration.getQueryType(); + throw new RegistryException(msg, e); + + } catch (Exception e) { + String msg = "Failed to initiate query processor for query type: " + + configuration.getQueryType(); + throw new RegistryException(msg, e); + + } + } + } } public QueryProcessor getQueryProcessor(String queryType) { Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml ============================================================================== --- trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml (original) +++ trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml Wed Jan 16 19:53:12 2008 @@ -38,4 +38,11 @@ <urlHandler>org.example.com.urlhandlers.SimpleHandler</urlHandler> --> + <!-- + <queryProcessor> + <queryType>my-query-language</queryType> + <processor>org.example.processor.MyQueryProcessor</processor> + </queryProcessor> + --> + </wso2regsitry> \ No newline at end of file _______________________________________________ Registry-dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/registry-dev
