diff options
Diffstat (limited to 'branches')
30 files changed, 2292 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/domain-search/LICENSE b/branches/sca-java-1.x/modules/domain-search/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + + diff --git a/branches/sca-java-1.x/modules/domain-search/NOTICE b/branches/sca-java-1.x/modules/domain-search/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-1.x/modules/domain-search/pom.xml b/branches/sca-java-1.x/modules/domain-search/pom.xml new file mode 100644 index 0000000000..7ab16ac05d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/pom.xml @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>1.5-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-domain-search</artifactId> + <name>Apache Tuscany SCA Domain Search Component</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-extensibility</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-policy</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-api</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.lucene</groupId> + <artifactId>lucene-core</artifactId> + <version>2.4-SNAPSHOT</version> + </dependency> + + </dependencies> + + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + + <configuration> + <instructions> + <Bundle-Version>${tuscany.version}</Bundle-Version> + <Bundle-SymbolicName>org.apache.tuscany.sca.domain.search</Bundle-SymbolicName> + <Bundle-Description>${pom.name}</Bundle-Description> + <Export-Package>org.apache.tuscany.sca.domain.search*</Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java new file mode 100644 index 0000000000..8df1f70269 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentMap.java @@ -0,0 +1,25 @@ +package org.apache.tuscany.sca.domain.search; + +import java.util.HashMap; + +import org.apache.tuscany.sca.domain.search.impl.Document; + +public class DocumentMap extends HashMap<Object, Document> { + + private static final long serialVersionUID = -2402910290314939928L; + + @Override + public Document get(Object key) { + Document doc = super.get(key); + + if (doc == null) { + doc = new Document(); + put(key, doc); + + } + + return doc; + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java new file mode 100644 index 0000000000..6a3de9e8c9 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessor.java @@ -0,0 +1,13 @@ +package org.apache.tuscany.sca.domain.search; + +import org.apache.tuscany.sca.domain.search.impl.Document; + +public interface DocumentProcessor { + + final public static Document FAKE_DOCUMENT = new Document(); + + Document process(DocumentProcessorsMap processors, DocumentMap documents, Object object, Document document, String parent); + + Object getDocumentKey(Object object); + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java new file mode 100644 index 0000000000..19c9e51d8d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DocumentProcessorsMap.java @@ -0,0 +1,125 @@ +package org.apache.tuscany.sca.domain.search; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +import org.apache.tuscany.sca.domain.search.impl.Document; + +public class DocumentProcessorsMap extends + HashMap<Class<?>, List<DocumentProcessor>> implements DocumentProcessor { + + private static final long serialVersionUID = 3967390896890947159L; + + private Object documentKey; + + public void addDocumentProcessor(Class<?> clazz, DocumentProcessor processor) { + List<DocumentProcessor> processors = get(clazz); + + if (processors == null) { + processors = new LinkedList<DocumentProcessor>(); + put(clazz, processors); + + } + + processors.add(processor); + + } + + private void appendProcessors(LinkedList<DocumentProcessor> processorsList, + List<DocumentProcessor> processors, Object object) { + + if (processors != null) { + + for (DocumentProcessor processor : processors) { + + if (this.documentKey == null) { + this.documentKey = processor.getDocumentKey(object); + + if (processorsList == null) { + return; + } + + } + + if (processorsList != null) { + processorsList.add(processor); + } + + } + + } + + } + + private void findAllDocumentProcessors( + LinkedList<DocumentProcessor> processorsList, Object object) { + Class<?> clazz = object.getClass(); + appendProcessors(processorsList, get(clazz), object); + + while (clazz != null) { + Class<?>[] interfaces = clazz.getInterfaces(); + + for (Class<?> interfac : interfaces) { + Class<?>[] interfaces2 = interfac.getInterfaces(); + appendProcessors(processorsList, get(interfac), object); + + for (Class<?> interface2 : interfaces2) { + appendProcessors(processorsList, get(interface2), object); + } + + } + + clazz = clazz.getSuperclass(); + appendProcessors(processorsList, get(clazz), object); + + } + + } + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document document, String parent) { + + LinkedList<DocumentProcessor> processorsList; + + try { + + this.documentKey = document; + processorsList = new LinkedList<DocumentProcessor>(); + findAllDocumentProcessors(processorsList, object); + + if (document == null && this.documentKey != null) { + document = documents.get(this.documentKey); + + if (document == null) { + document = FAKE_DOCUMENT; + } + + } + + } finally { + this.documentKey = null; + } + + for (DocumentProcessor processor : processorsList) { + processor.process(processors, documents, object, document, parent); + } + + return document; + + } + + public Object getDocumentKey(Object object) { + + try { + findAllDocumentProcessors(null, object); + + return this.documentKey; + + } finally { + this.documentKey = null; + } + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java new file mode 100644 index 0000000000..3d26b08d8a --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/DomainSearch.java @@ -0,0 +1,37 @@ +package org.apache.tuscany.sca.domain.search; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface DomainSearch { + + + + /** + * Notifies the listener that a contribution has been added. + * + * @param repository The contribution repository + * @param contribution The new contribution + */ + void contributionAdded(ContributionRepository repository, Contribution contribution); + + /** + * Notifies the listener that a contribution has been removed. + * + * @param repository The contribution repository + * @param contribution The removed contribution. + */ + void contributionRemoved(ContributionRepository repository, Contribution contribution); + + /** + * Notifies the listener that a contribution has been updated. + * + * @param repository The contribution repository + * @param oldContribution The old contribution + * @param contribution The new contribution + */ + void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution); + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/SearchContributionListenerExtensionPoint.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/SearchContributionListenerExtensionPoint.java new file mode 100644 index 0000000000..0138ac6a39 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/SearchContributionListenerExtensionPoint.java @@ -0,0 +1,33 @@ +package org.apache.tuscany.sca.domain.search; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; + +public interface SearchContributionListenerExtensionPoint { + + /** + * Notifies the listener that a contribution has been added. + * + * @param repository The contribution repository + * @param contribution The new contribution + */ + void contributionAdded(ContributionRepository repository, Contribution contribution); + + /** + * Notifies the listener that a contribution has been removed. + * + * @param repository The contribution repository + * @param contribution The removed contribution. + */ + void contributionRemoved(ContributionRepository repository, Contribution contribution); + + /** + * Notifies the listener that a contribution has been updated. + * + * @param repository The contribution repository + * @param oldContribution The old contribution + * @param contribution The new contribution + */ + void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution); + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java new file mode 100644 index 0000000000..815f0a20c7 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java @@ -0,0 +1,68 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class ArtifactDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document document, String parent) { + + if (object instanceof Artifact) { + Artifact artifact = (Artifact) object; + String uri = artifact.getURI(); + + if (uri != null && uri.length() == 0) { + uri = null; + } + + if (uri != null) { + + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.ARTIFACT_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + + if (document == null) { + document = documents.get(uri); + } + + document.add(new Field(SearchFields.ARTIFACT_FIELD, uri, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + if (document != null) { + + document.add(new Field(SearchFields.LOCATION_FIELD, artifact.getLocation(), + Field.Store.YES, Field.Index.ANALYZED)); + + } + + return document == null ? FAKE_DOCUMENT : document; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object obj) { + + if (obj instanceof Artifact) { + Artifact artifact = (Artifact) obj; + String uri = artifact.getURI(); + + if (uri != null && uri.length() == 0) { + return null; + } + + return uri; + + } + + throw new IllegalArgumentException(); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingDocumentProcessor.java new file mode 100644 index 0000000000..5d01bec389 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingDocumentProcessor.java @@ -0,0 +1,59 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class BindingDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document document, String parent) { + + if (object instanceof Binding) { + Binding binding = (Binding) object; + String uri = binding.getURI(); + + if (uri != null && uri.length() == 0) { + uri = null; + } + + if (uri != null) { + + if (document == null) { + document = documents.get(uri); + } + + document.add(new Field(SearchFields.BINDING_FIELD, uri, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + return document == null ? FAKE_DOCUMENT : document; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object obj) { + + if (obj instanceof Binding) { + Binding binding = (Binding) obj; + String uri = binding.getURI(); + + if (uri != null && uri.length() == 0) { + return null; + } + + return uri; + + } + + throw new IllegalArgumentException(); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java new file mode 100644 index 0000000000..284791118a --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentDocumentProcessor.java @@ -0,0 +1,179 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; + +public class ComponentDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document doc, String parent) { + + if (object instanceof Component) { + Component component = (Component) object; + String uri = component.getURI(); + String name = component.getName(); + + uri = (uri == null ? "" : uri) + (name == null ? "" : name); + + if (uri.length() == 0) { + uri = null; + } + + if (uri != null) { + + if (doc == null) { + doc = documents.get(uri); + } + + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPONENT_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + + doc.add(new Field(SearchFields.COMPONENT_FIELD, uri, + Field.Store.YES, Field.Index.ANALYZED)); + + for (ComponentService service : component.getServices()) { + Document serviceDoc = documents.get(uri + ':' + + service.getName()); + + serviceDoc.add(new Field(SearchFields.SERVICE_NAME_FIELD, + service.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + InterfaceContract interfaceContract = service + .getInterfaceContract(); + + if (interfaceContract != null) { + + for (Operation operation : interfaceContract + .getInterface().getOperations()) { + + serviceDoc.add(new Field( + SearchFields.SERVICE_INTERFACE_FIELD, + operation.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + } + + for (Operation operation : interfaceContract + .getCallbackInterface().getOperations()) { + + serviceDoc + .add(new Field( + SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD, + operation.getName(), + Field.Store.YES, + Field.Index.ANALYZED)); + + } + + } + + serviceDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + for (ComponentReference reference : component.getReferences()) { + Document serviceDoc = documents.get(uri + ':' + + reference.getName()); + + serviceDoc.add(new Field(SearchFields.REFERENCE_NAME_FIELD, + reference.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + InterfaceContract interfaceContract = reference + .getInterfaceContract(); + + if (interfaceContract != null) { + + for (Operation operation : interfaceContract + .getInterface().getOperations()) { + + serviceDoc.add(new Field( + SearchFields.REFERENCE_INTERFACE_FIELD, + operation.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + } + + for (Operation operation : interfaceContract + .getCallbackInterface().getOperations()) { + + serviceDoc + .add(new Field( + SearchFields.REFERENCE_INTERFACE_CALLBACK_FIELD, + operation.getName(), + Field.Store.YES, + Field.Index.ANALYZED)); + + } + + } + + serviceDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + Document implementationDoc = processors.process(processors, + documents, component.getImplementation(), null, parent); + + if (uri != null && implementationDoc != null) { + + implementationDoc.add(new Field(SearchFields.IMPLEMENTS_FIELD, + uri, Field.Store.YES, Field.Index.ANALYZED)); + + } + + for (ComponentProperty componentProperty : component + .getProperties()) { + Document propertyDoc = processors.process(processors, + documents, componentProperty.getProperty(), null, parent); + + if (uri != null) { + propertyDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + return doc == null ? FAKE_DOCUMENT : doc; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object obj) { + + if (obj instanceof Component) { + Component component = (Component) obj; + String uri = component.getURI(); + String name = component.getName(); + + uri = (uri == null ? "" : uri) + (name == null ? "" : name); + + if (uri.length() == 0) { + return null; + } + + return uri; + + } + + throw new IllegalArgumentException(); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java new file mode 100644 index 0000000000..b110ce769d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeDocumentProcessor.java @@ -0,0 +1,173 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; + +public class ComponentTypeDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document doc, String parent) { + + if (object instanceof ComponentType) { + ComponentType componentType = (ComponentType) object; + String uri = componentType.getURI(); + + if (uri != null && uri.length() == 0) { + uri = null; + } + + if (doc == null) { + + if (uri != null) { + doc = documents.get(uri); + + } else { + doc = FAKE_DOCUMENT; + } + + } + + if (uri != null) { + + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPONENT_TYPE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + + doc.add(new Field(SearchFields.COMPONENT_TYPE_FIELD, uri, + Field.Store.YES, Field.Index.ANALYZED)); + + for (Service service : componentType.getServices()) { + Document serviceDoc = documents.get(uri + ':' + + service.getName()); + + serviceDoc.add(new Field(SearchFields.SERVICE_NAME_FIELD, + service.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + InterfaceContract interfaceContract = service + .getInterfaceContract(); + + if (interfaceContract != null) { + + for (Operation operation : interfaceContract + .getInterface().getOperations()) { + + serviceDoc.add(new Field( + SearchFields.SERVICE_INTERFACE_FIELD, + operation.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + } + + for (Operation operation : interfaceContract + .getCallbackInterface().getOperations()) { + + serviceDoc + .add(new Field( + SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD, + operation.getName(), + Field.Store.YES, + Field.Index.ANALYZED)); + + } + + } + + serviceDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + for (Reference reference : componentType.getReferences()) { + Document referenceDoc = documents.get(componentType + .getURI() + + ':' + reference.getName()); + + referenceDoc.add(new Field( + SearchFields.REFERENCE_NAME_FIELD, reference + .getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + InterfaceContract interfaceContract = reference + .getInterfaceContract(); + + if (interfaceContract != null) { + + for (Operation operation : interfaceContract + .getInterface().getOperations()) { + + referenceDoc.add(new Field( + SearchFields.REFERENCE_INTERFACE_FIELD, + operation.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + } + + for (Operation operation : interfaceContract + .getCallbackInterface().getOperations()) { + + referenceDoc + .add(new Field( + SearchFields.REFERENCE_INTERFACE_CALLBACK_FIELD, + operation.getName(), + Field.Store.YES, + Field.Index.ANALYZED)); + + } + + } + + referenceDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + for (Property property : componentType.getProperties()) { + Document propertyDoc = processors.process(processors, + documents, property, null, parent); + + if (uri != null) { + + propertyDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + return doc; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object object) { + + if (object instanceof ComponentType) { + ComponentType componentType = (ComponentType) object; + String uri = componentType.getURI(); + + if (uri == null || uri.length() == 0) { + return null; + + } else { + return uri; + } + + } + + throw new IllegalArgumentException(); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java new file mode 100644 index 0000000000..27e1e9b087 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeDocumentProcessor.java @@ -0,0 +1,106 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import javax.xml.namespace.QName; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class CompositeDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document doc, String parent) { + + if (object instanceof Composite) { + Composite composite = (Composite) object; + String uri = composite.getURI(); + QName name = composite.getName(); + + uri = (uri == null ? "" : uri) + (name == null ? "" : name.toString()); + + if (uri.length() == 0) { + uri = null; + + } else if (doc == null) { + doc = documents.get(uri); + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPOSITE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + + } + + for (Component component : composite.getComponents()) { + + + Document componentDoc = processors.process(processors, + documents, component, null, parent); + + if (uri != null) { + + componentDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + if (uri != null) { + + doc.add(new Field(SearchFields.COMPOSITE_FIELD, uri.toString(), + Field.Store.YES, Field.Index.ANALYZED)); + + } + + for (Composite include : composite.getIncludes()) { + Document compositeDoc = processors.process(processors, + documents, include, null, parent); + + if (uri != null) { + + compositeDoc.add(new Field(SearchFields.INCLUDEDBY_FIELD, + uri, Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + for (Component component : composite.getComponents()) { + Document componentDoc = processors.process(processors, + documents, component, null, parent); + + if (uri != null) { + + componentDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + return doc == null ? FAKE_DOCUMENT : doc; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object object) { + + if (object instanceof Composite) { + Composite composite = (Composite) object; + String uri = composite.getURI(); + QName name = composite.getName(); + + uri = (uri == null ? "" : uri) + (name == null ? "" : name.toString()); + + return uri.length() == 0 ? null : uri; + + } + + throw new IllegalArgumentException(); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java new file mode 100644 index 0000000000..86e0e98f95 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java @@ -0,0 +1,120 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Field; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class ContributionDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document doc, String parent) { + + if (object instanceof Contribution) { + Contribution contribution = (Contribution) object; + String uri = contribution.getURI(); + + if (uri != null) { + + if (uri.length() == 0) { + uri = null; + + } else { + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.CONTRIBUTION_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + } + + } + + if (uri != null && doc == null) { + doc = documents.get(uri); + + doc.add(new Field(SearchFields.CONTRIBUTION_FIELD, uri, + Field.Store.YES, Field.Index.ANALYZED)); + + } else { + doc = FAKE_DOCUMENT; + } + + for (Artifact artifact : contribution.getArtifacts()) { + Document artifactDoc = processors.process(processors, + documents, artifact, null, parent); + + if (uri != null) { + + artifactDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + +// for (Import imprt : contribution.getImports()) { +// Document importDoc = processors.process(processors, documents, +// imprt, null); +// +// if (uri != null) { +// +// importDoc.add(new Field(SearchFields.IMPORTEDBY_FIELD, uri, +// Field.Store.YES, Field.Index.ANALYZED)); +// +// } +// +// } +// +// for (Export export : contribution.getExports()) { +// Document exportDoc = processors.process(processors, documents, +// export, null); +// +// if (uri != null) { +// +// exportDoc.add(new Field(SearchFields.EXPORTEDBY_FIELD, uri, +// Field.Store.YES, Field.Index.ANALYZED)); +// +// } +// +// } + + for (Composite composite : contribution.getDeployables()) { + Document compositeDoc = processors.process(processors, + documents, composite, null, parent); + + if (uri != null) { + + compositeDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + return doc; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object object) { + + if (object instanceof Contribution) { + Contribution contribution = (Contribution) object; + String uri = contribution.getURI(); + + if (uri != null && uri.length() == 0) { + return null; + } + + return uri; + + } + + throw new IllegalArgumentException(); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultSearchContributionListenerExtensionPoint.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultSearchContributionListenerExtensionPoint.java new file mode 100644 index 0000000000..6f21983a2e --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultSearchContributionListenerExtensionPoint.java @@ -0,0 +1,35 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; +import org.apache.tuscany.sca.domain.search.SearchContributionListenerExtensionPoint; + +public class DefaultSearchContributionListenerExtensionPoint implements SearchContributionListenerExtensionPoint { + + public void contributionAdded(ContributionRepository repository, + Contribution contribution) { + System.out.println("contributionAdded:"); + System.out.println(repository); + System.out.println(contribution); + + } + + public void contributionRemoved(ContributionRepository repository, + Contribution contribution) { + System.out.println("contributionRemoved:"); + System.out.println(repository); + System.out.println(contribution); + + } + + public void contributionUpdated(ContributionRepository repository, + Contribution oldContribution, Contribution contribution) { + + System.out.println("contributionUpdated:"); + System.out.println(repository); + System.out.println(oldContribution); + System.out.println(contribution); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java new file mode 100644 index 0000000000..95d008250b --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java @@ -0,0 +1,50 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.File; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class DirectoryDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document doc, String parent) { + + if (object instanceof File) { + File file = (File) object; + doc = documents.get(file.getAbsoluteFile()); + + if (file.isDirectory()) { + doc.add(new Field(SearchFields.DIRECTORY_FIELD, file.getAbsolutePath(), + Field.Store.YES, Field.Index.ANALYZED)); + + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.DIRECTORY_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + file.getName(); + + File[] files = file.listFiles(); + + for (File childFile : files) { + Document fileDoc = processors.process(processors, documents, childFile, null, parent); + + fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + return doc; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object object) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java new file mode 100644 index 0000000000..8a1aac2cd5 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java @@ -0,0 +1,61 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.util.Collection; +import java.util.Collections; +import java.util.Hashtable; + +import org.apache.lucene.document.Fieldable; + +public class Document { + + private Hashtable<String, Hashtable<String, Fieldable>> fieldablesTable = new Hashtable<String, Hashtable<String, Fieldable>>(); + + public Document() { + // empty constructor + } + + public void add(Fieldable fieldable) { + Hashtable<String, Fieldable> fieldables = this.fieldablesTable + .get(fieldable.name()); + + if (fieldables == null) { + fieldables = new Hashtable<String, Fieldable>(); + this.fieldablesTable.put(fieldable.name(), fieldables); + + } + + fieldables.put(fieldable.stringValue(), fieldable); + + } + + public org.apache.lucene.document.Document createLuceneDocument() { + org.apache.lucene.document.Document doc = new org.apache.lucene.document.Document(); + + for (Hashtable<String, Fieldable> fieldables : this.fieldablesTable.values()) { + + for (Fieldable fieldable : fieldables.values()) { + doc.add(fieldable); + } + + } + + return doc; + + } + + public Collection<String> getFieldValues(String field) { + Hashtable<String, Fieldable> fieldables = this.fieldablesTable.get(field); + + if (fieldables != null) { + return fieldables.keySet(); + } + + return Collections.EMPTY_LIST; + + } + + public boolean containsField(String field) { + return this.fieldablesTable.containsKey(field); + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java new file mode 100644 index 0000000000..9255f49eef --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzer.java @@ -0,0 +1,197 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.IOException; +import java.io.Reader; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.Token; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.Tokenizer; + +public class DomainPathAnalyzer extends Analyzer { + + final public static char PATH_SEPARATOR = '\u0001'; + + final public static char TYPE_SEPARATOR = '\u0002'; + + static class DomainPathTokenizer extends Tokenizer { + + private int offset = 0, bufferIndex = 0, dataLen = 0; + private static final int MAX_WORD_LEN = 255; + private static final int IO_BUFFER_SIZE = 4096; + private final char[] ioBuffer = new char[IO_BUFFER_SIZE]; + private boolean typeCharFound = false; + + public DomainPathTokenizer(Reader reader) { + super(reader); + } + + @Override + public void reset() throws IOException { + super.reset(); + + typeCharFound = false; + + } + + @Override + public void reset(Reader input) throws IOException { + super.reset(input); + + typeCharFound = false; + + } + + @Override + public Token next(Token reusableToken) throws IOException { + assert reusableToken != null; + reusableToken.clear(); + int length = 0; + int start = bufferIndex; + char[] buffer = reusableToken.termBuffer(); + + boolean lowercaseCharFound = false; + boolean digitFound = false; + + while (true) { + + if (bufferIndex >= dataLen) { + offset += dataLen; + int incr; + + if (lowercaseCharFound || length == 0) { + incr = 0; + + } else { + incr = 2; + ioBuffer[0] = ioBuffer[bufferIndex - 1]; + ioBuffer[1] = ioBuffer[bufferIndex]; + + } + + dataLen = input + .read(ioBuffer, incr, ioBuffer.length - incr); + if (dataLen == -1) { + if (length > 0) + break; + else + return null; + } + bufferIndex = incr; + dataLen += incr; + + } + + final char c = ioBuffer[bufferIndex++]; + boolean breakChar = true; + boolean includeChar = false; + + if (c == PATH_SEPARATOR) { + + if (length == 0) { + includeChar = true; + + } else { + bufferIndex--; + } + + typeCharFound = false; + + } else if (c == TYPE_SEPARATOR && !typeCharFound) { + length = 0; + breakChar = false; + lowercaseCharFound = false; + digitFound = false; + + } else { + + if (Character.isDigit(c)) { + + if (digitFound || length == 0) { + breakChar = false; + digitFound = true; + + } else { + bufferIndex--; + } + + // TODO: normalize accent, it does not index accents for + // now + } else if (c >= 65 && c <= 90 || c >= 97 && c <= 122) { + + if (digitFound) { + bufferIndex--; + + } else if (Character.isLowerCase(c)) { + + if (!(lowercaseCharFound || length <= 1)) { + length--; + bufferIndex -= 2; + + } else { + lowercaseCharFound = true; + breakChar = false; + + } + + } else if (!lowercaseCharFound) { // && uppercase + breakChar = false; + + } else { + bufferIndex--; + } + + } + + } + + if (!breakChar || includeChar) { + + if (length == 0) // start of token + start = offset + bufferIndex - 1; + else if (length == buffer.length) + buffer = reusableToken.resizeTermBuffer(1 + length); + + if (c == TYPE_SEPARATOR && !typeCharFound) { + typeCharFound = true; + + } else { + buffer[length++] = Character.toLowerCase(c); // buffer it, normalized + } + + if (length == MAX_WORD_LEN || (breakChar && length > 0)) // buffer overflow! + break; + + } else if (length > 0) {// at non-Letter w/ chars + + break; // return 'em + + } + + } + + reusableToken.setTermLength(length); + reusableToken.setStartOffset(start); + reusableToken.setEndOffset(start + length); + + return reusableToken; + + } + } + + public TokenStream tokenStream(String fieldName, Reader reader) { + return new DomainPathTokenizer(reader); + } + + public TokenStream reusableTokenStream(String fieldName, Reader reader) + throws IOException { + Tokenizer tokenizer = (Tokenizer) getPreviousTokenStream(); + if (tokenizer == null) { + tokenizer = new DomainPathTokenizer(reader); + setPreviousTokenStream(tokenizer); + } else + tokenizer.reset(reader); + return tokenizer; + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchAnalyzer.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchAnalyzer.java new file mode 100644 index 0000000000..88c1caac40 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchAnalyzer.java @@ -0,0 +1,14 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.analysis.PerFieldAnalyzerWrapper; + +public class DomainSearchAnalyzer extends PerFieldAnalyzerWrapper { + + public DomainSearchAnalyzer() { + super(new NamingAnalyzer()); + + addAnalyzer(SearchFields.PARENT_FIELD, new DomainPathAnalyzer()); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java new file mode 100644 index 0000000000..66c2898ebd --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchDocumentProcessorsMap.java @@ -0,0 +1,27 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class DomainSearchDocumentProcessorsMap extends DocumentProcessorsMap { + + private static final long serialVersionUID = -4651637686945322606L; + + public DomainSearchDocumentProcessorsMap() { + addDocumentProcessor(Contribution.class, new ContributionDocumentProcessor()); + addDocumentProcessor(Artifact.class, new ArtifactDocumentProcessor()); + addDocumentProcessor(Property.class, new PropertyDocumentProcessor()); + addDocumentProcessor(ComponentType.class, new ComponentTypeDocumentProcessor()); + addDocumentProcessor(Binding.class, new BindingDocumentProcessor()); + addDocumentProcessor(Component.class, new ComponentDocumentProcessor()); + addDocumentProcessor(Composite.class, new CompositeDocumentProcessor()); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java new file mode 100644 index 0000000000..56b375685b --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java @@ -0,0 +1,140 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.List; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.document.Field; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.queryParser.ParseException; +import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.search.HitCollector; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.LockObtainFailedException; +import org.apache.lucene.store.RAMDirectory; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DomainSearch; +import org.osoa.sca.annotations.AllowsPassByReference; + +public class DomainSearchImpl implements DomainSearch { + + @AllowsPassByReference + public void contributionAdded(ContributionRepository repository, + Contribution contribution) { + System.out.println("contributionAdded:"); + System.out.println(repository); + System.out.println(contribution); + + try { + Directory dir = new RAMDirectory(); + Analyzer analyzer = new DomainSearchAnalyzer(); + IndexWriter indexWriter = new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); + DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap(); + DocumentMap docs = new DocumentMap(); + + docProcessors.process(docProcessors, docs, contribution, null, ""); + + for (Document doc : docs.values()) { + indexWriter.addDocument(doc.createLuceneDocument()); + } + + indexWriter.close(); + + final IndexSearcher searcher = new IndexSearcher(dir); + BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in)); + QueryParser qp = new QueryParser("", analyzer); + + qp.setAllowLeadingWildcard(true); + + while (true) { + System.out.print("query: "); + String queryString = consoleReader.readLine(); + + if (queryString.equals("exit")) { + break; + } + + try { + Query query = qp.parse(queryString); + + searcher.search(query, new HitCollector() { + + @Override + public void collect(int doc, float score) { + try { + org.apache.lucene.document.Document document = searcher.doc(doc); + List<?> fields = document.getFields(); + System.out.println("---------"); + System.out.println("doc = " + doc); + + for (Object obj : fields) { + Field field = (Field) obj; + String[] values = document.getValues(field.name()); + System.out.println(field); + + for (String value : values) { + System.out.println("\t" + value); + } + + } + + } catch (CorruptIndexException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + }); + + } catch (ParseException e) { + System.out.println(e.getMessage()); + } + + System.out.println(); + + } + + + + } catch (CorruptIndexException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (LockObtainFailedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public void contributionRemoved(ContributionRepository repository, + Contribution contribution) { + System.out.println("contributionRemoved:"); + System.out.println(repository); + System.out.println(contribution); + + } + + public void contributionUpdated(ContributionRepository repository, + Contribution oldContribution, Contribution contribution) { + + System.out.println("contributionUpdated:"); + System.out.println(repository); + System.out.println(oldContribution); + System.out.println(contribution); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java new file mode 100644 index 0000000000..71426717b7 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java @@ -0,0 +1,20 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; + +public class DomainSearchModuleActivator implements ModuleActivator { + + public DomainSearchModuleActivator() { + // empty constructor + } + + public void start(ExtensionPointRegistry registry) { + registry.addExtensionPoint(new DefaultSearchContributionListenerExtensionPoint()); + } + + public void stop(ExtensionPointRegistry registry) { + // does nothing + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java new file mode 100644 index 0000000000..27eb52d659 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java @@ -0,0 +1,50 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.File; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class FileDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document doc, String parent) { + + if (object instanceof File) { + File file = (File) object; + documents.get(file.getAbsoluteFile()); + + if (file.isFile()) { + doc.add(new Field(SearchFields.DIRECTORY_FIELD, file.getAbsolutePath(), + Field.Store.YES, Field.Index.ANALYZED)); + + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.FILE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + file.getName(); + + File[] files = file.listFiles(); + + for (File childFile : files) { + Document fileDoc = processors.process(processors, documents, childFile, null, parent); + + fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + return doc; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object object) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingAnalyzer.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingAnalyzer.java new file mode 100644 index 0000000000..93e34ee875 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingAnalyzer.java @@ -0,0 +1,27 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.IOException; +import java.io.Reader; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.Tokenizer; + +public class NamingAnalyzer extends Analyzer { + + public TokenStream tokenStream(String fieldName, Reader reader) { + return new NamingTokenizer(reader); + } + + public TokenStream reusableTokenStream(String fieldName, Reader reader) + throws IOException { + Tokenizer tokenizer = (Tokenizer) getPreviousTokenStream(); + if (tokenizer == null) { + tokenizer = new NamingTokenizer(reader); + setPreviousTokenStream(tokenizer); + } else + tokenizer.reset(reader); + return tokenizer; + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizer.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizer.java new file mode 100644 index 0000000000..0d71b26b3d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizer.java @@ -0,0 +1,127 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.IOException; +import java.io.Reader; + +import org.apache.lucene.analysis.Token; +import org.apache.lucene.analysis.Tokenizer; + +public class NamingTokenizer extends Tokenizer { + + private int offset = 0, bufferIndex = 0, dataLen = 0; + private static final int MAX_WORD_LEN = 255; + private static final int IO_BUFFER_SIZE = 4096; + private final char[] ioBuffer = new char[IO_BUFFER_SIZE]; + + public NamingTokenizer(Reader reader) { + super(reader); + } + + @Override + public Token next(Token reusableToken) throws IOException { + assert reusableToken != null; + reusableToken.clear(); + int length = 0; + int start = bufferIndex; + char[] buffer = reusableToken.termBuffer(); + + boolean lowercaseCharFound = false; + boolean digitFound = false; + + while (true) { + + if (bufferIndex >= dataLen) { + offset += dataLen; + int incr; + + if (lowercaseCharFound || length == 0) { + incr = 0; + + } else { + incr = 2; + ioBuffer[0] = ioBuffer[bufferIndex - 1]; + ioBuffer[1] = ioBuffer[bufferIndex]; + + } + + dataLen = input.read(ioBuffer, incr, ioBuffer.length - incr); + if (dataLen == -1) { + if (length > 0) + break; + else + return null; + } + bufferIndex = incr; + dataLen += incr; + + } + + final char c = ioBuffer[bufferIndex++]; + boolean breakChar = true; + + if (Character.isDigit(c)) { + + if (digitFound || length == 0) { + breakChar = false; + digitFound = true; + + } else { + bufferIndex--; + } + + // TODO: normalize accent, it does not index accents for now + } else if (c >= 65 && c<= 90 || c >= 97 && c<= 122) { + + if (digitFound) { + bufferIndex--; + + } else if (Character.isLowerCase(c)) { + + if (!(lowercaseCharFound || length <= 1)) { + length--; + bufferIndex -= 2; + + } else { + lowercaseCharFound = true; + breakChar = false; + + } + + } else if (!lowercaseCharFound) { // && uppercase + breakChar = false; + + } else { + bufferIndex--; + } + + } + + if (!breakChar) { + + if (length == 0) // start of token + start = offset + bufferIndex - 1; + else if (length == buffer.length) + buffer = reusableToken.resizeTermBuffer(1 + length); + + buffer[length++] = Character.toLowerCase(c); // buffer it, normalized + + if (length == MAX_WORD_LEN) // buffer overflow! + break; + + } else if (length > 0) {// at non-Letter w/ chars + + + break; // return 'em + + } + + } + + reusableToken.setTermLength(length); + reusableToken.setStartOffset(start); + reusableToken.setEndOffset(start + length); + + return reusableToken; + + } +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java new file mode 100644 index 0000000000..0a0ff9ceeb --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java @@ -0,0 +1,63 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.lang.reflect.Array; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class PropertyDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document doc, String parent) { + + if (object instanceof Property) { + Property property = (Property) object; + String name = property.getName(); + + if (name != null && name.length() > 0) { + + if (doc == null) { + doc = documents.get(name); + } + + Object value = property.getValue(); + + if (value.getClass().isArray()) { + int arraySize = Array.getLength(value); + + for (int i = 0; i < arraySize; i++) { + Object arrayValue = Array.get(value, i); + + doc.add(new Field(SearchFields.VALUE_FIELD, arrayValue.toString(), + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } else { + + doc.add(new Field(SearchFields.VALUE_FIELD, value.toString(), + Field.Store.YES, Field.Index.ANALYZED)); + + } + + return doc == null ? FAKE_DOCUMENT : doc; + + } else { + return FAKE_DOCUMENT; + } + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object object) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java new file mode 100644 index 0000000000..fbb0af8dd8 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java @@ -0,0 +1,55 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public interface SearchFields { + + final public static String LOCATION_FIELD = "location"; + + final public static String DIRECTORY_FIELD = "directory"; + + final public static String FILE_FIELD = "file"; + + final public static String COMPONENT_TYPE_FIELD = "componenttype"; + + final public static String REFERENCE_FIELD = "reference"; + + final public static String COMPOSITE_FIELD = "composite"; + + final public static String SERVICE_FIELD = "service"; + + final public static String BINDING_FIELD = "binding"; + + final public static String ARTIFACT_FIELD = "artifact"; + + final public static String CONTRIBUTION_FIELD = "contribution"; + + final public static String COMPONENT_FIELD = "component"; + + final public static String TYPE_FIELD = "type"; + + final public static String PARENT_FIELD = "parent"; + + final public static String IMPLEMENTS_FIELD = "implements"; + + final public static String SERVICE_NAME_FIELD = "servicename"; + + final public static String SERVICE_INTERFACE_FIELD = "serviceinterface"; + + final public static String SERVICE_INTERFACE_CALLBACK_FIELD = "serviceinterfacecallback"; + + final public static String REFERENCE_NAME_FIELD = "referencename"; + + final public static String REFERENCE_INTERFACE_FIELD = "referenceinterface"; + + final public static String REFERENCE_INTERFACE_CALLBACK_FIELD = "referenceinterfacecallback"; + + final public static String IMPORTEDBY_FIELD = "importedby"; + + final public static String EXPORTEDBY_FIELD = "exportedby"; + + final public static String INCLUDEDBY_FIELD = "includedby"; + + final public static String KEY_FIELD = "propertykey"; + + final public static String VALUE_FIELD = "propertyvalue"; + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java b/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java new file mode 100644 index 0000000000..54a84f0b49 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java @@ -0,0 +1,41 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.IOException; +import java.io.StringReader; + +import org.apache.lucene.analysis.Token; +import org.apache.lucene.analysis.Tokenizer; + +import junit.framework.TestCase; + +public class DomainPathAnalyzerTestCase extends TestCase { + + private Token reusableToken = new Token(); + + public void test() throws IOException { + + Tokenizer tokenizer = new DomainPathAnalyzer.DomainPathTokenizer(new StringReader( + DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.CONTRIBUTION_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + "123tuscany" + DomainPathAnalyzer.TYPE_SEPARATOR + "SCA" + + DomainPathAnalyzer.PATH_SEPARATOR + DomainPathAnalyzer.TYPE_SEPARATOR + "TuscanySCA" + DomainPathAnalyzer.TYPE_SEPARATOR + "123")); + + assertNextToken(Character.toString(DomainPathAnalyzer.PATH_SEPARATOR), tokenizer); + assertNextToken("123", tokenizer); + assertNextToken("tuscany", tokenizer); + assertNextToken("sca", tokenizer); + assertNextToken(Character.toString(DomainPathAnalyzer.PATH_SEPARATOR), tokenizer); + assertNextToken("tuscany", tokenizer); + assertNextToken("sca", tokenizer); + assertNextToken("123", tokenizer); + + } + + private void assertNextToken(String expected, Tokenizer tokenizer) + throws IOException { + Token token = tokenizer.next(reusableToken); + + assertNotNull(token); + assertEquals(expected, token.term()); + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizerTestCase.java b/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizerTestCase.java new file mode 100644 index 0000000000..ea161b48e9 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizerTestCase.java @@ -0,0 +1,140 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.IOException; +import java.io.StringReader; + +import org.apache.lucene.analysis.Token; +import org.apache.lucene.analysis.Tokenizer; + +import junit.framework.TestCase; + +public class NamingTokenizerTestCase extends TestCase { + + private Token reusableToken = new Token(); + + public void testDigits() throws IOException { + NamingTokenizer tokenizer = new NamingTokenizer(new StringReader( + "123tuscany")); + + assertNextToken("123", tokenizer); + assertNextToken("tuscany", tokenizer); + + tokenizer.reset(new StringReader("tuscany123")); + + assertNextToken("tuscany", tokenizer); + assertNextToken("123", tokenizer); + + tokenizer.reset(new StringReader("TUSCANY123")); + + assertNextToken("tuscany", tokenizer); + assertNextToken("123", tokenizer); + + tokenizer.reset(new StringReader("123TUSCANY")); + + assertNextToken("123", tokenizer); + assertNextToken("tuscany", tokenizer); + + tokenizer.reset(new StringReader("tuscany.123")); + + assertNextToken("tuscany", tokenizer); + assertNextToken("123", tokenizer); + + tokenizer.reset(new StringReader("123.tuscany")); + + assertNextToken("123", tokenizer); + assertNextToken("tuscany", tokenizer); + + } + + public void testUppercasedTokens() throws IOException { + NamingTokenizer tokenizer = new NamingTokenizer(new StringReader( + "SCATuscany")); + + assertNextToken("sca", tokenizer); + assertNextToken("tuscany", tokenizer); + + tokenizer.reset(new StringReader("TuscanySCA")); + + assertNextToken("tuscany", tokenizer); + assertNextToken("sca", tokenizer); + + tokenizer.reset(new StringReader("Tuscany.SCA")); + + assertNextToken("tuscany", tokenizer); + assertNextToken("sca", tokenizer); + + tokenizer.reset(new StringReader("SCA.Tuscany")); + + assertNextToken("sca", tokenizer); + assertNextToken("tuscany", tokenizer); + + tokenizer.reset(new StringReader("SCA")); + + assertNextToken("sca", tokenizer); + + } + + public void testRegularTokens() throws IOException { + NamingTokenizer tokenizer = new NamingTokenizer(new StringReader( + "scaTuscany")); + + assertNextToken("sca", tokenizer); + assertNextToken("tuscany", tokenizer); + + tokenizer.reset(new StringReader("ScaTuscany")); + + assertNextToken("sca", tokenizer); + assertNextToken("tuscany", tokenizer); + + tokenizer.reset(new StringReader("ScaTuscanY")); + + assertNextToken("sca", tokenizer); + assertNextToken("tuscan", tokenizer); + assertNextToken("y", tokenizer); + + } + + public void testSingleCharTokens() throws IOException { + + NamingTokenizer tokenizer = new NamingTokenizer(new StringReader("1")); + + assertNextToken("1", tokenizer); + + tokenizer.reset(new StringReader("a")); + + assertNextToken("a", tokenizer); + + tokenizer.reset(new StringReader("A")); + + assertNextToken("a", tokenizer); + + } + + public void testNullTokens() throws IOException { + NamingTokenizer tokenizer = new NamingTokenizer(new StringReader("_")); + assertNull(tokenizer.next(this.reusableToken)); + + tokenizer.reset(new StringReader(".")); + assertNull(tokenizer.next(this.reusableToken)); + + tokenizer.reset(new StringReader(" ")); + assertNull(tokenizer.next(this.reusableToken)); + + tokenizer.reset(new StringReader("")); + assertNull(tokenizer.next(this.reusableToken)); + + tokenizer.reset(new StringReader(" )(%*%")); + assertNull(tokenizer.next(this.reusableToken)); + + } + + private void assertNextToken(String expected, Tokenizer tokenizer) + throws IOException { + Token token = tokenizer.next(reusableToken); + + assertNotNull(token); + assertEquals(expected, token.term()); + + } + +} diff --git a/branches/sca-java-1.x/modules/pom.xml b/branches/sca-java-1.x/modules/pom.xml index 497978a363..87fcc6d32e 100644 --- a/branches/sca-java-1.x/modules/pom.xml +++ b/branches/sca-java-1.x/modules/pom.xml @@ -50,6 +50,7 @@ <module>binding-ejb-runtime</module> <module>binding-erlang</module> <module>binding-erlang-runtime</module> + <module>domain-search</module> <!-- obsolete --> <module>binding-feed</module> <!-- new bindings --> |