From 53c043ac18ca8dd9d7f823bf7a399058c305003d Mon Sep 17 00:00:00 2001 From: adrianocrestani Date: Mon, 17 Aug 2009 06:24:15 +0000 Subject: committing domain-search changes from patch tuscany_2552_phillipe_ramalho_08_16_2009.patch git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@804871 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/domain/search/DocumentMap.java | 32 +- .../sca/domain/search/DocumentProcessor.java | 16 +- .../sca/domain/search/DocumentProcessorsMap.java | 160 +++---- .../tuscany/sca/domain/search/DomainSearch.java | 32 +- .../apache/tuscany/sca/domain/search/Result.java | 36 +- .../tuscany/sca/domain/search/ResultFactory.java | 8 +- .../tuscany/sca/domain/search/ResultProcessor.java | 4 +- .../SearchContributionListenerExtensionPoint.java | 14 +- .../search/impl/BindingDocumentProcessor.java | 72 ++-- .../search/impl/ComponentDocumentProcessor.java | 224 +++++----- .../impl/ComponentTypeDocumentProcessor.java | 199 ++++----- .../search/impl/CompositeDocumentProcessor.java | 136 +++--- .../search/impl/ContributionDocumentProcessor.java | 167 ++++---- .../sca/domain/search/impl/DefaultFileContent.java | 38 +- .../search/impl/DefaultFileDocumentProcessor.java | 99 ++--- ...ltSearchContributionListenerExtensionPoint.java | 49 ++- .../tuscany/sca/domain/search/impl/Document.java | 159 ++++--- .../sca/domain/search/impl/DomainPathAnalyzer.java | 289 +++++++------ .../domain/search/impl/DomainSearchAnalyzer.java | 12 +- .../impl/DomainSearchDocumentProcessorsMap.java | 28 +- .../impl/DomainSearchFileDocumentProcessor.java | 14 +- .../domain/search/impl/DomainSearchFormatter.java | 75 ++-- .../sca/domain/search/impl/DomainSearchImpl.java | 460 ++++++++++----------- .../search/impl/DomainSearchModuleActivator.java | 20 +- .../search/impl/DomainSearchResultFactory.java | 22 +- .../search/impl/DomainSearchResultProcessor.java | 19 +- .../sca/domain/search/impl/FileContent.java | 20 +- .../search/impl/FileContentResultProcessor.java | 99 +++-- .../domain/search/impl/FileDocumentProcessor.java | 107 ++--- .../sca/domain/search/impl/HighlightingUtil.java | 293 ++++++------- .../sca/domain/search/impl/NamingAnalyzer.java | 25 +- .../sca/domain/search/impl/NamingTokenizer.java | 232 +++++------ .../sca/domain/search/impl/ParentField.java | 346 ++++++++-------- .../impl/PriorityFieldListResultFactory.java | 50 +-- .../search/impl/PropertyDocumentProcessor.java | 70 ++-- .../tuscany/sca/domain/search/impl/ResultImpl.java | 323 +++++++-------- .../domain/search/impl/ResultProcessorList.java | 219 +++++----- .../sca/domain/search/impl/SearchFields.java | 90 ++-- .../sca/domain/search/impl/SystemFileContent.java | 86 ++-- .../sca/domain/search/impl/WrappedFileContent.java | 159 +++---- .../domain/search/impl/ZipDocumentProcessor.java | 99 ++--- .../sca/domain/search/impl/ZipFileContent.java | 407 +++++++++--------- 42 files changed, 2469 insertions(+), 2540 deletions(-) (limited to 'branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany') 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 index 5eac0b8080..d185bdf21d 100644 --- 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 @@ -28,20 +28,20 @@ import org.apache.tuscany.sca.domain.search.impl.Document; */ public class DocumentMap extends HashMap { - 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; - - } - + 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 index 36eeabfa54..3f23c4d354 100644 --- 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 @@ -25,11 +25,15 @@ import org.apache.tuscany.sca.domain.search.impl.Document; * @version $Rev$ $Date$ */ public interface DocumentProcessor { - - final public static Document FAKE_DOCUMENT = new Document(); - - Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document document, String parent); - - Object getDocumentKey(Object object); + + final public static Document FAKE_DOCUMENT = new Document(); + + Document process(DocumentProcessor parentProcessor, + 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 index 7f11e97475..065994319b 100644 --- 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 @@ -23,7 +23,6 @@ import java.util.LinkedList; import java.util.List; import org.apache.tuscany.sca.domain.search.impl.Document; - /** * * @version $Rev$ $Date$ @@ -31,117 +30,120 @@ import org.apache.tuscany.sca.domain.search.impl.Document; public class DocumentProcessorsMap extends HashMap, List> implements DocumentProcessor { - private static final long serialVersionUID = 3967390896890947159L; + private static final long serialVersionUID = 3967390896890947159L; + + private Object documentKey; + + public void addDocumentProcessor(Class clazz, DocumentProcessor processor) { + List processors = get(clazz); + + if (processors == null) { + processors = new LinkedList(); + put(clazz, processors); + + } + + processors.add(processor); + + } - private Object documentKey; + private void appendProcessors(LinkedList processorsList, + List processors, + Object object) { - public void addDocumentProcessor(Class clazz, DocumentProcessor processor) { - List processors = get(clazz); + if (processors != null) { - if (processors == null) { - processors = new LinkedList(); - put(clazz, processors); + for (DocumentProcessor processor : processors) { - } + if (this.documentKey == null) { + this.documentKey = processor.getDocumentKey(object); - processors.add(processor); + if (processorsList == null) { + return; + } - } + } - private void appendProcessors(LinkedList processorsList, - List processors, Object object) { + if (processorsList != null) { + processorsList.add(processor); + } - 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 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); + } - private void findAllDocumentProcessors( - LinkedList processorsList, Object object) { - Class clazz = object.getClass(); - appendProcessors(processorsList, get(clazz), object); + } - while (clazz != null) { - Class[] interfaces = clazz.getInterfaces(); + clazz = clazz.getSuperclass(); + appendProcessors(processorsList, get(clazz), object); - for (Class interfac : interfaces) { - Class[] interfaces2 = interfac.getInterfaces(); - appendProcessors(processorsList, get(interfac), object); + } - for (Class interface2 : interfaces2) { - appendProcessors(processorsList, get(interface2), object); - } + } - } + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document document, + String parent) { - clazz = clazz.getSuperclass(); - appendProcessors(processorsList, get(clazz), object); + LinkedList processorsList; - } + try { - } + this.documentKey = document; + processorsList = new LinkedList(); + findAllDocumentProcessors(processorsList, object); - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document document, String parent) { + if (document == null && this.documentKey != null) { + document = documents.get(this.documentKey); - LinkedList processorsList; + if (document == null) { + document = FAKE_DOCUMENT; + } - try { + } - this.documentKey = document; - processorsList = new LinkedList(); - findAllDocumentProcessors(processorsList, object); + } finally { + this.documentKey = null; + } - if (document == null && this.documentKey != null) { - document = documents.get(this.documentKey); + for (DocumentProcessor processor : processorsList) { + processor.process(parentProcessor, documents, object, document, parent); + } - if (document == null) { - document = FAKE_DOCUMENT; - } + return document; - } + } - } finally { - this.documentKey = null; - } + public Object getDocumentKey(Object object) { - for (DocumentProcessor processor : processorsList) { - processor.process(parentProcessor, documents, object, document, parent); - } + try { + findAllDocumentProcessors(null, object); - return document; + return this.documentKey; - } + } finally { + this.documentKey = null; + } - 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 index d6a3dd7f39..53bcdbe4c3 100644 --- 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 @@ -28,36 +28,36 @@ import org.osoa.sca.annotations.Remotable; */ @Remotable public interface DomainSearch { - - boolean indexExists(); - - Result[] parseAndSearch(String searchQuery, boolean highlight) throws Exception; - - Result[] search(Query searchQuery, boolean hightlight) throws Exception; - - String highlight(String field, String text, String searchQuery) throws Exception; - - /** + + boolean indexExists(); + + Result[] parseAndSearch(String searchQuery, boolean highlight) throws Exception; + + Result[] search(Query searchQuery, boolean hightlight) throws Exception; + + String highlight(String field, String text, String searchQuery) throws Exception; + + /** * Notifies the listener that a contribution has been added. * - * @param repository The contribution repository + * @param repository The contribution repository * @param contribution The new contribution */ void contributionAdded(Contribution contribution); - + /** * Notifies the listener that a contribution has been removed. * - * @param repository The contribution repository + * @param repository The contribution repository * @param contribution The removed contribution. */ void contributionRemoved(Contribution contribution); - + /** * Notifies the listener that a contribution has been updated. * - * @param repository The contribution repository - * @param oldContribution The old contribution + * @param repository The contribution repository + * @param oldContribution The old contribution * @param contribution The new contribution */ void contributionUpdated(Contribution oldContribution, Contribution contribution); diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java index 0852d4608f..53fb9c4803 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java @@ -26,23 +26,23 @@ import java.util.Map; * @version $Rev$ $Date$ */ public interface Result extends Serializable { - - String getValue(); - - void setValue(String value); - - Result getContainer(); - - Map getContents(); - - void addContent(Result artifactResult); - - void removeContent(Result artifactResult); - - void setContainer(Result container); - - String getField(); - - void setField(String field); + + String getValue(); + + void setValue(String value); + + Result getContainer(); + + Map getContents(); + + void addContent(Result artifactResult); + + void removeContent(Result artifactResult); + + void setContainer(Result container); + + String getField(); + + void setField(String field); } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java index f19ae0c162..dd4bc74284 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java @@ -25,9 +25,9 @@ import org.apache.lucene.document.Document; * @version $Rev$ $Date$ */ public interface ResultFactory { - - T createResult(String field, String value); - - T createResult(Document document); + + T createResult(String field, String value); + + T createResult(Document document); } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java index 75f0666efd..90638cd2c8 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java @@ -25,7 +25,7 @@ import org.apache.lucene.document.Document; * @version $Rev$ $Date$ */ public interface ResultProcessor { - - Result process(Document document, Result result); + + Result process(Document document, Result result); } 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 index 622f2a735c..827cfce1d1 100644 --- 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 @@ -26,28 +26,28 @@ import org.apache.tuscany.sca.contribution.service.ContributionRepository; * @version $Rev$ $Date$ */ public interface SearchContributionListenerExtensionPoint { - + /** * Notifies the listener that a contribution has been added. * - * @param repository The contribution repository + * @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 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 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/BindingDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingDocumentProcessor.java index 22fe30c549..6ae0ff3d57 100644 --- 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 @@ -29,52 +29,54 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessor; */ public class BindingDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document document, String parent) { + public Document process(DocumentProcessor parentProcessor, + 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 (object instanceof Binding) { + Binding binding = (Binding)object; + String uri = binding.getURI(); - if (uri != null) { - - if (document == null) { - document = documents.get(uri); - } + if (uri != null && uri.length() == 0) { + uri = null; + } - document.add(new Field(SearchFields.BINDING_FIELD, uri, - Field.Store.YES, Field.Index.ANALYZED)); + if (uri != null) { - } - - return document == null ? FAKE_DOCUMENT : document; + if (document == null) { + document = documents.get(uri); + } - } + document.add(new Field(SearchFields.BINDING_FIELD, uri, Field.Store.YES, Field.Index.ANALYZED)); - throw new IllegalArgumentException(); + } - } + return document == null ? FAKE_DOCUMENT : document; - 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; - } + throw new IllegalArgumentException(); - return uri; + } - } + public Object getDocumentKey(Object obj) { - throw new IllegalArgumentException(); + 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 index 310a365a35..28099f055c 100644 --- 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 @@ -36,191 +36,165 @@ import org.apache.tuscany.sca.interfacedef.Operation; */ public class ComponentDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document doc, String parent) { + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document doc, + String parent) { - if (object instanceof Component) { - Component component = (Component) object; - String uri = component.getURI(); - String name = component.getName(); + if (object instanceof Component) { + Component component = (Component)object; + String uri = component.getURI(); + String name = component.getName(); - uri = (uri == null ? "" : uri) + (name == null ? "" : name); + uri = (uri == null ? "" : uri) + (name == null ? "" : name); - if (uri.length() == 0) { - uri = null; - } + if (uri.length() == 0) { + uri = null; + } - if (uri != null) { + if (uri != null) { - if (doc == null) { - doc = documents.get(uri); - } + if (doc == null) { + doc = documents.get(uri); + } - parent += DomainPathAnalyzer.PATH_SEPARATOR - + SearchFields.COMPONENT_FIELD - + DomainPathAnalyzer.TYPE_SEPARATOR + uri - + DomainPathAnalyzer.URI_SEPARATOR - + component.getName(); + parent += + DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPONENT_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + + uri + + DomainPathAnalyzer.URI_SEPARATOR + + component.getName(); - doc.add(new Field(SearchFields.COMPONENT_FIELD, uri, - Field.Store.YES, Field.Index.ANALYZED)); + 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()); + 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)); + serviceDoc.add(new Field(SearchFields.SERVICE_NAME_FIELD, service.getName(), Field.Store.YES, + Field.Index.ANALYZED)); - InterfaceContract interfaceContract = service - .getInterfaceContract(); + InterfaceContract interfaceContract = service.getInterfaceContract(); - if (interfaceContract != null) { + if (interfaceContract != null) { - for (Operation operation : interfaceContract - .getInterface().getOperations()) { + for (Operation operation : interfaceContract.getInterface().getOperations()) { - serviceDoc.add(new Field( - SearchFields.SERVICE_INTERFACE_FIELD, - operation.getName(), Field.Store.YES, - Field.Index.ANALYZED)); + serviceDoc.add(new Field(SearchFields.SERVICE_INTERFACE_FIELD, operation.getName(), + Field.Store.YES, Field.Index.ANALYZED)); - } + } - for (Operation operation : interfaceContract - .getCallbackInterface().getOperations()) { + 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.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)); + serviceDoc.add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); - } + } - for (ComponentReference reference : component.getReferences()) { - Document referenceDoc = documents.get(uri + ':' - + reference.getName()); + for (ComponentReference reference : component.getReferences()) { + Document referenceDoc = documents.get(uri + ':' + reference.getName()); - referenceDoc.add(new Field( - SearchFields.REFERENCE_NAME_FIELD, reference - .getName(), Field.Store.YES, - Field.Index.ANALYZED)); + referenceDoc.add(new Field(SearchFields.REFERENCE_NAME_FIELD, reference.getName(), Field.Store.YES, + Field.Index.ANALYZED)); - InterfaceContract interfaceContract = reference - .getInterfaceContract(); + InterfaceContract interfaceContract = reference.getInterfaceContract(); - if (interfaceContract != null) { + if (interfaceContract != null) { - for (Operation operation : interfaceContract - .getInterface().getOperations()) { + for (Operation operation : interfaceContract.getInterface().getOperations()) { - referenceDoc.add(new Field( - SearchFields.REFERENCE_INTERFACE_FIELD, - operation.getName(), Field.Store.YES, - Field.Index.ANALYZED)); + referenceDoc.add(new Field(SearchFields.REFERENCE_INTERFACE_FIELD, operation.getName(), + Field.Store.YES, Field.Index.ANALYZED)); - } + } - for (Operation operation : interfaceContract - .getCallbackInterface().getOperations()) { + 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.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)); + referenceDoc + .add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); - } + } - } + } - Document implementationDoc = parentProcessor.process( - parentProcessor, documents, component.getImplementation(), - null, parent); + Document implementationDoc = + parentProcessor.process(parentProcessor, documents, component.getImplementation(), null, parent); - if (uri != null && implementationDoc != null) { + if (uri != null && implementationDoc != null) { - implementationDoc.add(new Field(SearchFields.PARENT_FIELD, uri, - Field.Store.YES, Field.Index.ANALYZED)); + implementationDoc.add(new Field(SearchFields.PARENT_FIELD, uri, Field.Store.YES, Field.Index.ANALYZED)); - } + } - for (ComponentProperty componentProperty : component - .getProperties()) { + for (ComponentProperty componentProperty : component.getProperties()) { - Property property = componentProperty.getProperty(); - - if (property != null) { - Document propertyDoc = parentProcessor.process( - parentProcessor, documents, property, null, parent); + Property property = componentProperty.getProperty(); - if (uri != null) { - propertyDoc.add(new Field(SearchFields.PARENT_FIELD, - parent, Field.Store.YES, Field.Index.ANALYZED)); + if (property != null) { + Document propertyDoc = parentProcessor.process(parentProcessor, documents, property, 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; + } - } + return doc == null ? FAKE_DOCUMENT : doc; - throw new IllegalArgumentException(); + } - } + throw new IllegalArgumentException(); - public Object getDocumentKey(Object obj) { + } - if (obj instanceof Component) { - Component component = (Component) obj; - String uri = component.getURI(); - String name = component.getName(); + public Object getDocumentKey(Object obj) { - uri = (uri == null ? "" : uri) + (name == null ? "" : name); + if (obj instanceof Component) { + Component component = (Component)obj; + String uri = component.getURI(); + String name = component.getName(); - if (uri.length() == 0) { - return null; - } + uri = (uri == null ? "" : uri) + (name == null ? "" : name); - return uri; + if (uri.length() == 0) { + return null; + } - } + return uri; - throw new IllegalArgumentException(); + } - } + throw new IllegalArgumentException(); - public Result processDocument(org.apache.lucene.document.Document document, - Result result) { - String componentName = document.get(SearchFields.COMPONENT_FIELD); + } - if (componentName != null) { + public Result processDocument(org.apache.lucene.document.Document document, Result result) { + String componentName = document.get(SearchFields.COMPONENT_FIELD); - } + if (componentName != null) { - return null; + } - } + return null; + + } } 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 index af1dee2ac5..6c6f7e2194 100644 --- 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 @@ -35,173 +35,152 @@ import org.apache.tuscany.sca.interfacedef.Operation; */ public class ComponentTypeDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document doc, String parent) { + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document doc, + String parent) { - if (object instanceof ComponentType) { - ComponentType componentType = (ComponentType) object; - String uri = componentType.getURI(); + if (object instanceof ComponentType) { + ComponentType componentType = (ComponentType)object; + String uri = componentType.getURI(); - if (uri != null && uri.length() == 0) { - uri = null; - } + if (uri != null && uri.length() == 0) { + uri = null; + } - if (doc == null) { + if (doc == null) { - if (uri != null) { - doc = documents.get(uri); + if (uri != null) { + doc = documents.get(uri); - } else { - doc = FAKE_DOCUMENT; - } + } else { + doc = FAKE_DOCUMENT; + } - } + } - if (uri != null) { + if (uri != null) { - parent += DomainPathAnalyzer.PATH_SEPARATOR - + SearchFields.COMPONENT_TYPE_FIELD - + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + 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)); + 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()); + 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)); + serviceDoc.add(new Field(SearchFields.SERVICE_NAME_FIELD, service.getName(), Field.Store.YES, + Field.Index.ANALYZED)); - InterfaceContract interfaceContract = service - .getInterfaceContract(); + InterfaceContract interfaceContract = service.getInterfaceContract(); - if (interfaceContract != null) { + if (interfaceContract != null) { - Interface interfac = interfaceContract.getInterface(); + Interface interfac = interfaceContract.getInterface(); - if (interfac != null) { + if (interfac != null) { - for (Operation operation : interfac.getOperations()) { + for (Operation operation : interfac.getOperations()) { - serviceDoc.add(new Field( - SearchFields.SERVICE_INTERFACE_FIELD, - operation.getName(), Field.Store.YES, - Field.Index.ANALYZED)); + serviceDoc.add(new Field(SearchFields.SERVICE_INTERFACE_FIELD, operation.getName(), + Field.Store.YES, Field.Index.ANALYZED)); - } + } - } + } - interfac = interfaceContract.getCallbackInterface(); + interfac = interfaceContract.getCallbackInterface(); - if (interfac != null) { + if (interfac != null) { - for (Operation operation : interfac.getOperations()) { + for (Operation operation : interfac.getOperations()) { - serviceDoc - .add(new Field( - SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD, - operation.getName(), - Field.Store.YES, - Field.Index.ANALYZED)); + 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)); + 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()); + 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)); + referenceDoc.add(new Field(SearchFields.REFERENCE_NAME_FIELD, reference.getName(), Field.Store.YES, + Field.Index.ANALYZED)); - InterfaceContract interfaceContract = reference - .getInterfaceContract(); + InterfaceContract interfaceContract = reference.getInterfaceContract(); - if (interfaceContract != null) { + if (interfaceContract != null) { - for (Operation operation : interfaceContract - .getInterface().getOperations()) { + for (Operation operation : interfaceContract.getInterface().getOperations()) { - referenceDoc.add(new Field( - SearchFields.REFERENCE_INTERFACE_FIELD, - operation.getName(), Field.Store.YES, - Field.Index.ANALYZED)); + referenceDoc.add(new Field(SearchFields.REFERENCE_INTERFACE_FIELD, operation.getName(), + Field.Store.YES, Field.Index.ANALYZED)); - } + } - for (Operation operation : interfaceContract - .getCallbackInterface().getOperations()) { + 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.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)); + referenceDoc + .add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); - } + } - } + } - for (Property property : componentType.getProperties()) { - Document propertyDoc = parentProcessor.process(parentProcessor, - documents, property, null, parent); + for (Property property : componentType.getProperties()) { + Document propertyDoc = parentProcessor.process(parentProcessor, documents, property, null, parent); - if (uri != null) { + if (uri != null) { - propertyDoc.add(new Field(SearchFields.PARENT_FIELD, - parent, Field.Store.YES, Field.Index.ANALYZED)); + propertyDoc + .add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); - } + } - } + } - return doc; + return doc; - } + } - throw new IllegalArgumentException(); + throw new IllegalArgumentException(); - } + } - public Object getDocumentKey(Object object) { + public Object getDocumentKey(Object object) { - if (object instanceof ComponentType) { - ComponentType componentType = (ComponentType) object; - String uri = componentType.getURI(); + if (object instanceof ComponentType) { + ComponentType componentType = (ComponentType)object; + String uri = componentType.getURI(); - if (uri == null || uri.length() == 0) { - return null; + if (uri == null || uri.length() == 0) { + return null; - } else { - return uri; - } + } else { + return uri; + } - } + } - throw new IllegalArgumentException(); + 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 index 62f2b59db2..07002daa8d 100644 --- 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 @@ -32,95 +32,97 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessor; */ public class CompositeDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document doc, String parent) { + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document doc, + String parent) { - if (object instanceof Composite) { - Composite composite = (Composite) object; - QName name = composite.getName(); - String uri = (name == null ? "" : name.getNamespaceURI() + ';' + name.getLocalPart()); - - if (uri.length() == 0) { - uri = null; - - } else if (doc == null) { - doc = documents.get(uri); - } - - if (uri != null) { - parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPOSITE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; - } - - for (Component component : composite.getComponents()) { - - Document componentDoc = parentProcessor.process(parentProcessor, - documents, component, null, parent); + if (object instanceof Composite) { + Composite composite = (Composite)object; + QName name = composite.getName(); + String uri = (name == null ? "" : name.getNamespaceURI() + ';' + name.getLocalPart()); - if (uri != null) { + if (uri.length() == 0) { + uri = null; - componentDoc.add(new Field(SearchFields.PARENT_FIELD, parent, - Field.Store.YES, Field.Index.ANALYZED)); + } else if (doc == null) { + doc = documents.get(uri); + } - } + if (uri != null) { + parent += + DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPOSITE_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + + uri; + } - } + for (Component component : composite.getComponents()) { - if (uri != null) { + Document componentDoc = parentProcessor.process(parentProcessor, documents, component, null, parent); - doc.add(new Field(SearchFields.COMPOSITE_FIELD, uri, - Field.Store.YES, Field.Index.ANALYZED)); + if (uri != null) { - } + componentDoc + .add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); - for (Composite include : composite.getIncludes()) { - Document compositeDoc = parentProcessor.process(parentProcessor, - documents, include, null, parent); + } - if (uri != null) { + } - compositeDoc.add(new Field(SearchFields.INCLUDEDBY_FIELD, - uri, Field.Store.YES, Field.Index.ANALYZED)); + if (uri != null) { - } + doc.add(new Field(SearchFields.COMPOSITE_FIELD, uri, Field.Store.YES, Field.Index.ANALYZED)); - } + } - for (Component component : composite.getComponents()) { - Document componentDoc = parentProcessor.process(parentProcessor, - documents, component, null, parent); + for (Composite include : composite.getIncludes()) { + Document compositeDoc = parentProcessor.process(parentProcessor, documents, include, null, parent); - if (uri != null) { + if (uri != null) { - componentDoc.add(new Field(SearchFields.PARENT_FIELD, parent, - Field.Store.YES, Field.Index.ANALYZED)); + compositeDoc.add(new Field(SearchFields.INCLUDEDBY_FIELD, uri, Field.Store.YES, + Field.Index.ANALYZED)); - } + } - } + } - return doc == null ? FAKE_DOCUMENT : doc; + for (Component component : composite.getComponents()) { + Document componentDoc = parentProcessor.process(parentProcessor, documents, component, null, parent); - } + if (uri != null) { - throw new IllegalArgumentException(); + componentDoc + .add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); - } + } - public Object getDocumentKey(Object object) { - - if (object instanceof Composite) { - Composite composite = (Composite) object; - String uri = composite.getURI(); - QName name = composite.getName(); + } + + 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(); + + } - 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 index 43fa9bdeb2..7735f9ef1e 100644 --- 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 @@ -32,122 +32,123 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessor; */ public class ContributionDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document doc, String parent) { + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document doc, + String parent) { - if (object instanceof Contribution) { - Contribution contribution = (Contribution) object; - String uri = contribution.getURI(); + if (object instanceof Contribution) { + Contribution contribution = (Contribution)object; + String uri = contribution.getURI(); - if (uri != null) { + if (uri != null) { - if (uri.length() == 0) { - uri = null; + if (uri.length() == 0) { + uri = null; - } else { + } else { - parent += Character.toString(DomainPathAnalyzer.PATH_START) - + SearchFields.CONTRIBUTION_FIELD - + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + parent += + Character.toString(DomainPathAnalyzer.PATH_START) + SearchFields.CONTRIBUTION_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + + uri; - } + } - } + } - if (uri != null) { + if (uri != null) { - if (doc == null) { - doc = documents.get(uri); - } - - doc.add(new Field(SearchFields.CONTRIBUTION_FIELD, uri, - Field.Store.YES, Field.Index.ANALYZED)); + if (doc == null) { + doc = documents.get(uri); + } - } else { - doc = FAKE_DOCUMENT; - } + doc.add(new Field(SearchFields.CONTRIBUTION_FIELD, uri, Field.Store.YES, Field.Index.ANALYZED)); - for (Artifact artifact : contribution.getArtifacts()) { - Document artifactDoc = parentProcessor.process(parentProcessor, - documents, artifact, null, parent); + } else { + doc = FAKE_DOCUMENT; + } - if (uri != null) { + for (Artifact artifact : contribution.getArtifacts()) { + Document artifactDoc = parentProcessor.process(parentProcessor, documents, artifact, null, parent); - artifactDoc.add(new Field(SearchFields.PARENT_FIELD, - parent, Field.Store.YES, Field.Index.ANALYZED)); + 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)); - // - // } - // - // } + } - if (!object.getClass().getSimpleName().contains("Workspace")) { + // 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 = parentProcessor - .process(parentProcessor, documents, composite, - null, parent); + if (!object.getClass().getSimpleName().contains("Workspace")) { - if (uri != null) { + for (Composite composite : contribution.getDeployables()) { + Document compositeDoc = + parentProcessor.process(parentProcessor, documents, composite, null, parent); - compositeDoc.add(new Field(SearchFields.PARENT_FIELD, - parent, Field.Store.YES, Field.Index.ANALYZED)); + if (uri != null) { - } + compositeDoc.add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, + Field.Index.ANALYZED)); - } + } - } + } - return doc; + } - } + return doc; - throw new IllegalArgumentException(); + } - } + throw new IllegalArgumentException(); - public Object getDocumentKey(Object object) { + } - if (object instanceof Contribution) { - Contribution contribution = (Contribution) object; - String uri = contribution.getURI(); + public Object getDocumentKey(Object object) { - if (uri != null && uri.length() == 0) { - return null; - } + if (object instanceof Contribution) { + Contribution contribution = (Contribution)object; + String uri = contribution.getURI(); - return uri; + if (uri != null && uri.length() == 0) { + return null; + } - } + return uri; - throw new IllegalArgumentException(); + } - } + throw new IllegalArgumentException(); + + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java index 6790b94e87..1c32d0cb5e 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileContent.java @@ -28,30 +28,30 @@ import java.net.URL; */ public class DefaultFileContent implements FileContent { - final private URL url; + final private URL url; - public DefaultFileContent(URL url) { - this.url = url; - } + public DefaultFileContent(URL url) { + this.url = url; + } - public FileContent[] getChildren() { - return new FileContent[0]; - } + public FileContent[] getChildren() { + return new FileContent[0]; + } - public InputStream getInputStream() throws IOException { - return this.url.openStream(); - } + public InputStream getInputStream() throws IOException { + return this.url.openStream(); + } - public String getName() { - return this.url.getFile(); - } + public String getName() { + return this.url.getFile(); + } - public String getPath() { - return this.url.getPath(); - } + public String getPath() { + return this.url.getPath(); + } - public boolean isLeaf() { - return false; - } + public boolean isLeaf() { + return false; + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java index 0411e7d875..e997b8f1f2 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java @@ -33,54 +33,55 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessor; */ public class DefaultFileDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document doc, String parent) { - - if (object instanceof FileContent) { - FileContent file = (FileContent) object; - - Reader reader; - try { - reader = new InputStreamReader(file.getInputStream()); - - if (doc == null) { - doc = documents.get(file.getPath()); - } - - doc.add(new Field(SearchFields.FILE_CONTENT_FIELD, reader)); - - doc.add(new Field(SearchFields.FILE_CONTENT_FIELD, - "", Field.Store.YES, - Field.Index.ANALYZED)); - - return doc; - - } catch (IOException e) { - // ignore the file - } - - } - - return null; - - } - - public Object getDocumentKey(Object object) { - - if (object instanceof File) { - File file = (File) object; - String path = file.getPath(); - - if (path != null && path.length() == 0) { - return null; - } - - return path; - - } - - throw new IllegalArgumentException(); - - } + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document doc, + String parent) { + + if (object instanceof FileContent) { + FileContent file = (FileContent)object; + + Reader reader; + try { + reader = new InputStreamReader(file.getInputStream()); + + if (doc == null) { + doc = documents.get(file.getPath()); + } + + doc.add(new Field(SearchFields.FILE_CONTENT_FIELD, reader)); + + doc.add(new Field(SearchFields.FILE_CONTENT_FIELD, "", Field.Store.YES, Field.Index.ANALYZED)); + + return doc; + + } catch (IOException e) { + // ignore the file + } + + } + + return null; + + } + + public Object getDocumentKey(Object object) { + + if (object instanceof File) { + File file = (File)object; + String path = file.getPath(); + + if (path != null && path.length() == 0) { + return null; + } + + return path; + + } + + 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 index 45889038f8..8ed859c2e6 100644 --- 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 @@ -28,30 +28,29 @@ import org.apache.tuscany.sca.domain.search.SearchContributionListenerExtensionP */ 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); - - } + 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/Document.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/Document.java index fe30f569cf..ad50468ed6 100644 --- 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 @@ -31,84 +31,83 @@ import org.apache.lucene.document.Fieldable; */ public class Document { - private Hashtable> fieldablesTable = new Hashtable>(); - - private Hashtable> readerMap = new Hashtable>();; - - public Document() { - // empty constructor - } - - public void add(Fieldable fieldable) { - - String strValue = fieldable.stringValue(); - - if (strValue != null) { - - Hashtable fieldables = this.fieldablesTable - .get(fieldable.name()); - - if (fieldables == null) { - fieldables = new Hashtable(); - this.fieldablesTable.put(fieldable.name(), fieldables); - - } - - fieldables.put(strValue, fieldable); - - } else { - - LinkedList fieldables = this.readerMap - .get(fieldable.name()); - - if (fieldables == null) { - fieldables = new LinkedList(); - this.readerMap.put(fieldable.name(), fieldables); - - } - - fieldables.add(fieldable); - - } - - } - - public org.apache.lucene.document.Document createLuceneDocument() { - org.apache.lucene.document.Document doc = new org.apache.lucene.document.Document(); - - for (Hashtable fieldables : this.fieldablesTable.values()) { - - for (Fieldable fieldable : fieldables.values()) { - doc.add(fieldable); - } - - } - - for (LinkedList fieldables : this.readerMap.values()) { - - for (Fieldable fieldable : fieldables) { - doc.add(fieldable); - } - - } - - return doc; - - } - - public Collection getFieldValues(String field) { - Hashtable fieldables = this.fieldablesTable.get(field); - - if (fieldables != null) { - return fieldables.keySet(); - } - - return Collections.emptyList(); - - } - - public boolean containsField(String field) { - return this.fieldablesTable.containsKey(field); - } - + private Hashtable> fieldablesTable = + new Hashtable>(); + + private Hashtable> readerMap = new Hashtable>();; + + public Document() { + // empty constructor + } + + public void add(Fieldable fieldable) { + + String strValue = fieldable.stringValue(); + + if (strValue != null) { + + Hashtable fieldables = this.fieldablesTable.get(fieldable.name()); + + if (fieldables == null) { + fieldables = new Hashtable(); + this.fieldablesTable.put(fieldable.name(), fieldables); + + } + + fieldables.put(strValue, fieldable); + + } else { + + LinkedList fieldables = this.readerMap.get(fieldable.name()); + + if (fieldables == null) { + fieldables = new LinkedList(); + this.readerMap.put(fieldable.name(), fieldables); + + } + + fieldables.add(fieldable); + + } + + } + + public org.apache.lucene.document.Document createLuceneDocument() { + org.apache.lucene.document.Document doc = new org.apache.lucene.document.Document(); + + for (Hashtable fieldables : this.fieldablesTable.values()) { + + for (Fieldable fieldable : fieldables.values()) { + doc.add(fieldable); + } + + } + + for (LinkedList fieldables : this.readerMap.values()) { + + for (Fieldable fieldable : fieldables) { + doc.add(fieldable); + } + + } + + return doc; + + } + + public Collection getFieldValues(String field) { + Hashtable fieldables = this.fieldablesTable.get(field); + + if (fieldables != null) { + return fieldables.keySet(); + } + + return Collections.emptyList(); + + } + + 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 index c25e5937ee..c0b5bcb218 100644 --- 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 @@ -32,205 +32,202 @@ import org.apache.lucene.analysis.Tokenizer; */ public class DomainPathAnalyzer extends Analyzer { - final public static char PATH_START = '\u0001'; - - final public static char PATH_SEPARATOR = '\u0002'; + final public static char PATH_START = '\u0001'; - final public static char TYPE_SEPARATOR = '\u0003'; + final public static char PATH_SEPARATOR = '\u0002'; - final public static char URI_SEPARATOR = '\u0004'; - - final public static char ARCHIVE_SEPARATOR = '!'; + final public static char TYPE_SEPARATOR = '\u0003'; - static class DomainPathTokenizer extends Tokenizer { + final public static char URI_SEPARATOR = '\u0004'; - private int offset = 0, bufferIndex = 0, dataLen = 0; - private static final int MAX_WORD_LEN = 1024; - private static final int IO_BUFFER_SIZE = 4096; - private final char[] ioBuffer = new char[IO_BUFFER_SIZE]; - private boolean typeCharFound = false; - private boolean uriCharFound = false; + final public static char ARCHIVE_SEPARATOR = '!'; - public DomainPathTokenizer(Reader reader) { - super(reader); - } + static class DomainPathTokenizer extends Tokenizer { - @Override - public void reset() throws IOException { - super.reset(); + private int offset = 0, bufferIndex = 0, dataLen = 0; + private static final int MAX_WORD_LEN = 1024; + private static final int IO_BUFFER_SIZE = 4096; + private final char[] ioBuffer = new char[IO_BUFFER_SIZE]; + private boolean typeCharFound = false; + private boolean uriCharFound = false; - typeCharFound = false; - uriCharFound = false; + public DomainPathTokenizer(Reader reader) { + super(reader); + } - } + @Override + public void reset() throws IOException { + super.reset(); - @Override - public void reset(Reader input) throws IOException { - super.reset(input); + typeCharFound = false; + uriCharFound = false; - uriCharFound = false; - typeCharFound = false; + } - } + @Override + public void reset(Reader input) throws IOException { + super.reset(input); - @Override - public Token next(Token reusableToken) throws IOException { - assert reusableToken != null; - reusableToken.clear(); - int length = 0; - int start = bufferIndex; - char[] buffer = reusableToken.termBuffer(); + uriCharFound = false; + typeCharFound = false; - boolean lowercaseCharFound = false; - boolean digitFound = false; + } - while (true) { + @Override + public Token next(Token reusableToken) throws IOException { + assert reusableToken != null; + reusableToken.clear(); + int length = 0; + int start = bufferIndex; + char[] buffer = reusableToken.termBuffer(); - if (bufferIndex >= dataLen) { - offset += dataLen; - int incr; + boolean lowercaseCharFound = false; + boolean digitFound = false; - if (lowercaseCharFound || length == 0) { - incr = 0; + while (true) { - } else { - incr = 2; - ioBuffer[0] = ioBuffer[bufferIndex - 1]; - ioBuffer[1] = ioBuffer[bufferIndex]; + if (bufferIndex >= dataLen) { + offset += dataLen; + int incr; - } + if (lowercaseCharFound || length == 0) { + incr = 0; - dataLen = input - .read(ioBuffer, incr, ioBuffer.length - incr); - if (dataLen == -1) { - if (length > 0) - break; - else - return null; - } - bufferIndex = incr; - dataLen += incr; + } else { + incr = 2; + ioBuffer[0] = ioBuffer[bufferIndex - 1]; + ioBuffer[1] = ioBuffer[bufferIndex]; - } + } - final char c = ioBuffer[bufferIndex++]; - boolean breakChar = true; - boolean includeChar = false; - - if (c == PATH_START || c == PATH_SEPARATOR) { + dataLen = input.read(ioBuffer, incr, ioBuffer.length - incr); + if (dataLen == -1) { + if (length > 0) + break; + else + return null; + } + bufferIndex = incr; + dataLen += incr; - if (length == 0) { - includeChar = true; + } - } else { - bufferIndex--; - } + final char c = ioBuffer[bufferIndex++]; + boolean breakChar = true; + boolean includeChar = false; - typeCharFound = false; - uriCharFound = false; + if (c == PATH_START || c == PATH_SEPARATOR) { - } else if (c == TYPE_SEPARATOR && !typeCharFound - || c == URI_SEPARATOR && !uriCharFound) { - length = 0; - breakChar = false; - lowercaseCharFound = false; - digitFound = false; + if (length == 0) { + includeChar = true; - } else { + } else { + bufferIndex--; + } - if (Character.isDigit(c)) { + typeCharFound = false; + uriCharFound = false; - if (digitFound || length == 0) { - breakChar = false; - digitFound = true; + } else if (c == TYPE_SEPARATOR && !typeCharFound || c == URI_SEPARATOR && !uriCharFound) { + length = 0; + breakChar = false; + lowercaseCharFound = false; + digitFound = false; - } else { - bufferIndex--; - } + } else { - // TODO: normalize accent, it does not index accents for - // now - } else if (c >= 65 && c <= 90 || c >= 97 && c <= 122) { + if (Character.isDigit(c)) { - if (digitFound) { - bufferIndex--; + if (digitFound || length == 0) { + breakChar = false; + digitFound = true; - } else if (Character.isLowerCase(c)) { + } else { + bufferIndex--; + } - if (!(lowercaseCharFound || length <= 1)) { - length--; - bufferIndex -= 2; + // TODO: normalize accent, it does not index accents for + // now + } else if (c >= 65 && c <= 90 || c >= 97 && c <= 122) { - } else { - lowercaseCharFound = true; - breakChar = false; + if (digitFound) { + bufferIndex--; - } + } else if (Character.isLowerCase(c)) { - } else if (!lowercaseCharFound) { // && uppercase - breakChar = false; + if (!(lowercaseCharFound || length <= 1)) { + length--; + bufferIndex -= 2; - } else { - bufferIndex--; - } + } else { + lowercaseCharFound = true; + breakChar = false; - } + } - } + } else if (!lowercaseCharFound) { // && uppercase + breakChar = false; - if (!breakChar || includeChar) { + } else { + bufferIndex--; + } - 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 if (c == URI_SEPARATOR && !uriCharFound) { - typeCharFound = true; + if (!breakChar || includeChar) { - } else { - buffer[length++] = Character.toLowerCase(c); // buffer - // it, - // normalized - } + if (length == 0) // start of token + start = offset + bufferIndex - 1; + else if (length == buffer.length) + buffer = reusableToken.resizeTermBuffer(1 + length); - if (length == MAX_WORD_LEN || (breakChar && length > 0)) // buffer - // overflow! - break; + if (c == TYPE_SEPARATOR && !typeCharFound) { + typeCharFound = true; - } else if (length > 0) {// at non-Letter w/ chars + } else if (c == URI_SEPARATOR && !uriCharFound) { + typeCharFound = true; - break; // return 'em + } 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 - reusableToken.setTermLength(length); - reusableToken.setStartOffset(start); - reusableToken.setEndOffset(start + length); + break; // return 'em - return reusableToken; + } - } - } + } - public TokenStream tokenStream(String fieldName, Reader reader) { - return new DomainPathTokenizer(reader); - } + reusableToken.setTermLength(length); + reusableToken.setStartOffset(start); + reusableToken.setEndOffset(start + length); - 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; - } + 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 index a29da16b8b..1514a13096 100644 --- 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 @@ -26,11 +26,11 @@ import org.apache.lucene.analysis.PerFieldAnalyzerWrapper; */ public class DomainSearchAnalyzer extends PerFieldAnalyzerWrapper { - public DomainSearchAnalyzer() { - super(new NamingAnalyzer()); - - addAnalyzer(SearchFields.PARENT_FIELD, new DomainPathAnalyzer()); - - } + 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 index 8ba512ff9b..544da46dad 100644 --- 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 @@ -32,20 +32,20 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; * @version $Rev$ $Date$ */ 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()); - addDocumentProcessor(FileContent.class, new DomainSearchFileDocumentProcessor()); - addDocumentProcessor(Property.class, new PropertyDocumentProcessor()); - - } + 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()); + addDocumentProcessor(FileContent.class, new DomainSearchFileDocumentProcessor()); + addDocumentProcessor(Property.class, new PropertyDocumentProcessor()); + + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java index 37d16f6d18..ae6821e8ed 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java @@ -24,12 +24,12 @@ package org.apache.tuscany.sca.domain.search.impl; */ public class DomainSearchFileDocumentProcessor extends FileDocumentProcessor { - private static final long serialVersionUID = -2725616937948969598L; + private static final long serialVersionUID = -2725616937948969598L; + + public DomainSearchFileDocumentProcessor() { + add(new ZipDocumentProcessor()); + add(new DefaultFileDocumentProcessor()); + + } - public DomainSearchFileDocumentProcessor() { - add(new ZipDocumentProcessor()); - add(new DefaultFileDocumentProcessor()); - - } - } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java index 9d3f8b03fb..e9ddf036a0 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java @@ -27,43 +27,42 @@ import org.apache.lucene.search.highlight.TokenGroup; */ public class DomainSearchFormatter implements Formatter { - final public static String HIGHLIGHT_START = "\u0005\u0005\u0006"; - - final public static String HIGHLIGHT_END = "\u0006\u0005\u0005"; - - private StringBuilder sb = new StringBuilder(); - - public String highlightTerm(String originalText, TokenGroup tokenGroup) { - - if (tokenGroup.getTotalScore() > 0) { - sb.setLength(0); - - sb.append(HIGHLIGHT_START).append(originalText).append( - HIGHLIGHT_END); - - return sb.toString(); - - } else { - return originalText; - } - - } - - public static boolean isHighlighted(String text) { - int start = text.indexOf(HIGHLIGHT_START); - int end = text.indexOf(HIGHLIGHT_END); - - if (start < end && start != -1) { - start = text.indexOf(HIGHLIGHT_START, start + 1); - - if (start > end || start == -1) { - return true; - } - - } - - return false; - - } + final public static String HIGHLIGHT_START = "\u0005\u0005\u0006"; + + final public static String HIGHLIGHT_END = "\u0006\u0005\u0005"; + + private StringBuilder sb = new StringBuilder(); + + public String highlightTerm(String originalText, TokenGroup tokenGroup) { + + if (tokenGroup.getTotalScore() > 0) { + sb.setLength(0); + + sb.append(HIGHLIGHT_START).append(originalText).append(HIGHLIGHT_END); + + return sb.toString(); + + } else { + return originalText; + } + + } + + public static boolean isHighlighted(String text) { + int start = text.indexOf(HIGHLIGHT_START); + int end = text.indexOf(HIGHLIGHT_END); + + if (start < end && start != -1) { + start = text.indexOf(HIGHLIGHT_START, start + 1); + + if (start > end || start == -1) { + return true; + } + + } + + return false; + + } } 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 index c078e21716..182f1d09ba 100644 --- 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 @@ -52,356 +52,338 @@ import org.osoa.sca.annotations.Scope; @Scope("COMPOSITE") public class DomainSearchImpl implements DomainSearch { - @Property - public String indexDirectoryPath; + @Property + public String indexDirectoryPath; - private Directory dir; + private Directory dir; - private Analyzer analyzer = new DomainSearchAnalyzer(); + private Analyzer analyzer = new DomainSearchAnalyzer(); - private MultiFieldQueryParser qp = new MultiFieldQueryParser(new String[] { - SearchFields.ARTIFACT_FIELD, SearchFields.BINDING_FIELD, - SearchFields.COMPONENT_FIELD, SearchFields.COMPOSITE_FIELD, - SearchFields.CONTRIBUTION_FIELD, SearchFields.EXPORTEDBY_FIELD, - SearchFields.FILE_CONTENT_FIELD, SearchFields.IMPLEMENTS_FIELD, - SearchFields.IMPORTEDBY_FIELD, SearchFields.INCLUDEDBY_FIELD, - SearchFields.PROPERTY_KEY_FIELD, SearchFields.REFERENCE_FIELD, - SearchFields.REFERENCE_INTERFACE_CALLBACK_FIELD, - SearchFields.REFERENCE_INTERFACE_FIELD, - SearchFields.REFERENCE_NAME_FIELD, SearchFields.SERVICE_FIELD, - SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD, - SearchFields.SERVICE_INTERFACE_FIELD, - SearchFields.SERVICE_NAME_FIELD, SearchFields.TYPE_FIELD, - SearchFields.VALUE_FIELD }, this.analyzer); + private MultiFieldQueryParser qp = + new MultiFieldQueryParser(new String[] {SearchFields.ARTIFACT_FIELD, SearchFields.BINDING_FIELD, + SearchFields.COMPONENT_FIELD, SearchFields.COMPOSITE_FIELD, + SearchFields.CONTRIBUTION_FIELD, SearchFields.EXPORTEDBY_FIELD, + SearchFields.FILE_CONTENT_FIELD, SearchFields.IMPLEMENTS_FIELD, + SearchFields.IMPORTEDBY_FIELD, SearchFields.INCLUDEDBY_FIELD, + SearchFields.PROPERTY_KEY_FIELD, SearchFields.REFERENCE_FIELD, + SearchFields.REFERENCE_INTERFACE_CALLBACK_FIELD, + SearchFields.REFERENCE_INTERFACE_FIELD, + SearchFields.REFERENCE_NAME_FIELD, SearchFields.SERVICE_FIELD, + SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD, + SearchFields.SERVICE_INTERFACE_FIELD, SearchFields.SERVICE_NAME_FIELD, + SearchFields.TYPE_FIELD, SearchFields.VALUE_FIELD}, this.analyzer); - public DomainSearchImpl() { - this.qp.setAllowLeadingWildcard(true); + public DomainSearchImpl() { + this.qp.setAllowLeadingWildcard(true); - } + } - private Directory getIndexDirectory() throws IOException { + private Directory getIndexDirectory() throws IOException { - if (this.dir == null) { + if (this.dir == null) { - if (this.indexDirectoryPath == null - || this.indexDirectoryPath.length() == 0) { - this.dir = new RAMDirectory(); + if (this.indexDirectoryPath == null || this.indexDirectoryPath.length() == 0) { + this.dir = new RAMDirectory(); - } else { + } else { - try { - this.dir = new FSDirectory( - new File(this.indexDirectoryPath), - new SimpleFSLockFactory(this.indexDirectoryPath)); + try { + this.dir = + new FSDirectory(new File(this.indexDirectoryPath), + new SimpleFSLockFactory(this.indexDirectoryPath)); - } catch (IOException e) { - System.err.println("Could not open index at " - + this.indexDirectoryPath); + } catch (IOException e) { + System.err.println("Could not open index at " + this.indexDirectoryPath); - throw e; + throw e; - } + } - } + } - } + } - return this.dir; + return this.dir; - } + } - @AllowsPassByReference - public void contributionAdded(Contribution contribution) { + @AllowsPassByReference + public void contributionAdded(Contribution contribution) { - IndexWriter indexWriter = null; + IndexWriter indexWriter = null; - try { - indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, - IndexWriter.MaxFieldLength.UNLIMITED); + try { + indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, IndexWriter.MaxFieldLength.UNLIMITED); - contributionAdded(contribution, indexWriter); + contributionAdded(contribution, indexWriter); - indexWriter.commit(); + indexWriter.commit(); - } catch (Exception e) { + } catch (Exception e) { - if (indexWriter != null) { + if (indexWriter != null) { - try { - indexWriter.rollback(); + try { + indexWriter.rollback(); - } catch (Exception e1) { - // ignore exception - } + } catch (Exception e1) { + // ignore exception + } - } + } - throw new RuntimeException("Problem while indexing!", e); + throw new RuntimeException("Problem while indexing!", e); - } finally { + } finally { - if (indexWriter != null) { + if (indexWriter != null) { - try { - indexWriter.close(); + try { + indexWriter.close(); - } catch (Exception e) { - // ignore exception - } + } catch (Exception e) { + // ignore exception + } - } + } - } + } - } + } - @AllowsPassByReference - public void contributionRemoved(Contribution contribution) { + @AllowsPassByReference + public void contributionRemoved(Contribution contribution) { - IndexWriter indexWriter = null; + IndexWriter indexWriter = null; - try { - indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, - IndexWriter.MaxFieldLength.UNLIMITED); + if (indexExists()) { - contributionRemoved(contribution, indexWriter); + try { + indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, IndexWriter.MaxFieldLength.UNLIMITED); - indexWriter.commit(); + contributionRemoved(contribution, indexWriter); - } catch (Exception e) { + indexWriter.commit(); - if (indexWriter != null) { + } catch (Exception e) { - try { - indexWriter.rollback(); + if (indexWriter != null) { - } catch (Exception e1) { - // ignore exception - } + try { + indexWriter.rollback(); - } + } catch (Exception e1) { + // ignore exception + } - throw new RuntimeException("Problem while indexing!", e); + } - } finally { + throw new RuntimeException("Problem while indexing!", e); - if (indexWriter != null) { + } finally { - try { - indexWriter.close(); + if (indexWriter != null) { - } catch (Exception e) { - // ignore exception - } + try { + indexWriter.close(); - } + } catch (Exception e) { + // ignore exception + } - } + } - } + } - private void contributionRemoved(Contribution contribution, - IndexWriter indexWriter) throws CorruptIndexException, IOException { + } - String contributionURI = contribution.getURI(); - StringBuilder sb = new StringBuilder(SearchFields.PARENT_FIELD); - sb.append(":\""); - sb.append(DomainPathAnalyzer.PATH_START); - sb.append(contributionURI); - sb.append("\" OR "); - sb.append(SearchFields.CONTRIBUTION_FIELD); - sb.append(":\""); - sb.append(contributionURI); - sb.append('"'); + } - try { - Query query = this.qp.parse(sb.toString()); - indexWriter.deleteDocuments(query); + private void contributionRemoved(Contribution contribution, IndexWriter indexWriter) throws CorruptIndexException, + IOException { - } catch (ParseException e) { - throw new RuntimeException("Could not parse query: " - + sb.toString(), e); - } + String contributionURI = contribution.getURI(); + StringBuilder sb = new StringBuilder(SearchFields.PARENT_FIELD); + sb.append(":\""); + sb.append(DomainPathAnalyzer.PATH_START); + sb.append(contributionURI); + sb.append("\" OR "); + sb.append(SearchFields.CONTRIBUTION_FIELD); + sb.append(":\""); + sb.append(contributionURI); + sb.append('"'); - } + try { + Query query = this.qp.parse(sb.toString()); + indexWriter.deleteDocuments(query); - private void contributionAdded(Contribution contribution, - IndexWriter indexWriter) throws CorruptIndexException, IOException { + } catch (ParseException e) { + throw new RuntimeException("Could not parse query: " + sb.toString(), e); + } - DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap(); - DocumentMap docs = new DocumentMap(); + } - try { - docProcessors.process(docProcessors, docs, contribution, null, ""); + private void contributionAdded(Contribution contribution, IndexWriter indexWriter) throws CorruptIndexException, + IOException { - } catch (Exception e) { - e.printStackTrace(); - } + DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap(); + DocumentMap docs = new DocumentMap(); - FileWriter writer = new FileWriter("indexed.txt"); - for (Document doc : docs.values()) { - org.apache.lucene.document.Document luceneDoc = doc - .createLuceneDocument(); - writer.write(luceneDoc.toString()); - writer.write('\n'); - writer.write('\n'); - indexWriter.addDocument(luceneDoc); + try { + docProcessors.process(docProcessors, docs, contribution, null, ""); - } + } catch (Exception e) { + e.printStackTrace(); + } - writer.close(); + FileWriter writer = new FileWriter("indexed.txt"); + for (Document doc : docs.values()) { + org.apache.lucene.document.Document luceneDoc = doc.createLuceneDocument(); + writer.write(luceneDoc.toString()); + writer.write('\n'); + writer.write('\n'); + indexWriter.addDocument(luceneDoc); - // BufferedReader consoleReader = new BufferedReader( - // new InputStreamReader(System.in)); - // - // while (true) { - // System.out.print("query: "); - // String queryString = consoleReader.readLine(); - // - // if (queryString.equals("exit")) { - // break; - // } - // - // parseAndSearch(queryString, false); - // - // } + } - } + writer.close(); - @AllowsPassByReference - public void contributionUpdated(Contribution oldContribution, - Contribution contribution) { + // BufferedReader consoleReader = new BufferedReader( + // new InputStreamReader(System.in)); + // + // while (true) { + // System.out.print("query: "); + // String queryString = consoleReader.readLine(); + // + // if (queryString.equals("exit")) { + // break; + // } + // + // parseAndSearch(queryString, false); + // + // } - IndexWriter indexWriter = null; + } - try { - indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, - IndexWriter.MaxFieldLength.UNLIMITED); + @AllowsPassByReference + public void contributionUpdated(Contribution oldContribution, Contribution contribution) { - contributionRemoved(oldContribution, indexWriter); - contributionAdded(contribution, indexWriter); + IndexWriter indexWriter = null; - indexWriter.commit(); + try { + indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, IndexWriter.MaxFieldLength.UNLIMITED); - } catch (Exception e) { + contributionRemoved(oldContribution, indexWriter); + contributionAdded(contribution, indexWriter); - if (indexWriter != null) { + indexWriter.commit(); - try { - indexWriter.rollback(); + } catch (Exception e) { - } catch (Exception e1) { - // ignore exception - } + if (indexWriter != null) { - } + try { + indexWriter.rollback(); - throw new RuntimeException("Problem while indexing!", e); + } catch (Exception e1) { + // ignore exception + } - } finally { + } - if (indexWriter != null) { + throw new RuntimeException("Problem while indexing!", e); - try { - indexWriter.close(); + } finally { - } catch (Exception e) { - // ignore exception - } + if (indexWriter != null) { - } + try { + indexWriter.close(); - } + } catch (Exception e) { + // ignore exception + } - } + } - public Result[] parseAndSearch(String searchQuery, final boolean highlight) - throws Exception { + } - final IndexSearcher searcher = new IndexSearcher(getIndexDirectory()); + } - DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor( - new DomainSearchResultFactory()); + public Result[] parseAndSearch(String searchQuery, final boolean highlight) throws Exception { - final Query query = qp.parse(searchQuery); - System.out.println("query: " + searchQuery); + final IndexSearcher searcher = new IndexSearcher(getIndexDirectory()); - TopDocs topDocs = searcher.search(query, 1000); + DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor(new DomainSearchResultFactory()); - int indexed = 0; - HashSet set = new HashSet(); - for (ScoreDoc scoreDoc : topDocs.scoreDocs) { - org.apache.lucene.document.Document luceneDocument = searcher - .doc(scoreDoc.doc); + final Query query = qp.parse(searchQuery); + System.out.println("query: " + searchQuery); - resultProcessor.process(luceneDocument, null); + TopDocs topDocs = searcher.search(query, 1000); - indexed++; - set.add(luceneDocument.toString()); + int indexed = 0; + HashSet set = new HashSet(); + for (ScoreDoc scoreDoc : topDocs.scoreDocs) { + org.apache.lucene.document.Document luceneDocument = searcher.doc(scoreDoc.doc); - System.out.println(luceneDocument); + resultProcessor.process(luceneDocument, null); - } + indexed++; + set.add(luceneDocument.toString()); - /* - * searcher.search(query, new HitCollector() { - * - * @Override public void collect(int doc, float score) { try { - * org.apache.lucene.document.Document document = searcher .doc(doc); - * - * luceneDocuments.put(doc, document); - * - * System.out.println(doc); - * - * } catch (CorruptIndexException e) { // TODO Auto-generated catch - * block e.printStackTrace(); } catch (IOException e) { // TODO - * Auto-generated catch block e.printStackTrace(); } } - * - * }); - */ + System.out.println(luceneDocument); - System.out.println("indexed = " + indexed); - System.out.println("set.size() = " + set.size()); + } - Result[] results = resultProcessor.createResultRoots(); + /* + * searcher.search(query, new HitCollector() { + * @Override public void collect(int doc, float score) { try { + * org.apache.lucene.document.Document document = searcher .doc(doc); + * luceneDocuments.put(doc, document); System.out.println(doc); } catch + * (CorruptIndexException e) { // TODO Auto-generated catch block + * e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated + * catch block e.printStackTrace(); } } }); + */ - if (highlight) { + System.out.println("indexed = " + indexed); + System.out.println("set.size() = " + set.size()); - for (Result result : results) { - HighlightingUtil.highlightResult(result, query); - } + Result[] results = resultProcessor.createResultRoots(); - } + if (highlight) { - return results; + for (Result result : results) { + HighlightingUtil.highlightResult(result, query); + } - } + } - public Result[] search(Query searchQuery, boolean hightlight) { - // TODO Auto-generated method stub - return null; - } + return results; - public String highlight(String field, String text, String searchQuery) - throws Exception { - final Query query = qp.parse(searchQuery); + } - return HighlightingUtil.highlight(field, query, text); + public Result[] search(Query searchQuery, boolean hightlight) { + // TODO Auto-generated method stub + return null; + } - } + public String highlight(String field, String text, String searchQuery) throws Exception { + final Query query = qp.parse(searchQuery); - public boolean indexExists() { + return HighlightingUtil.highlight(field, query, text); - if ((this.indexDirectoryPath == null || this.indexDirectoryPath - .length() == 0) - && this.dir == null) { + } - return false; + public boolean indexExists() { - } else { - return this.dir != null || IndexReader.indexExists(new File(this.indexDirectoryPath)); - } + if ((this.indexDirectoryPath == null || this.indexDirectoryPath.length() == 0) && this.dir == null) { - } + return false; + + } else { + return this.dir != null || IndexReader.indexExists(new File(this.indexDirectoryPath)); + } + + } } 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 index e1909b0cd4..5db27931b6 100644 --- 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 @@ -26,17 +26,17 @@ import org.apache.tuscany.sca.core.ModuleActivator; * @version $Rev$ $Date$ */ public class DomainSearchModuleActivator implements ModuleActivator { - - public DomainSearchModuleActivator() { - // empty constructor - } - public void start(ExtensionPointRegistry registry) { - registry.addExtensionPoint(new DefaultSearchContributionListenerExtensionPoint()); - } + public DomainSearchModuleActivator() { + // empty constructor + } - public void stop(ExtensionPointRegistry registry) { - // does nothing - } + 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/DomainSearchResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java index d2cdfbd794..6a5b875586 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java @@ -24,17 +24,17 @@ package org.apache.tuscany.sca.domain.search.impl; */ public class DomainSearchResultFactory extends PriorityFieldListResultFactory { - private static final long serialVersionUID = -7421799172738469027L; + private static final long serialVersionUID = -7421799172738469027L; - public DomainSearchResultFactory() { - add(SearchFields.COMPOSITE_FIELD); - add(SearchFields.COMPONENT_FIELD); - add(SearchFields.COMPONENT_TYPE_FIELD); - add(SearchFields.CONTRIBUTION_FIELD); - add(SearchFields.BINDING_FIELD); - add(SearchFields.FILE_CONTENT_FIELD); - add(SearchFields.ARTIFACT_FIELD); - - } + public DomainSearchResultFactory() { + add(SearchFields.COMPOSITE_FIELD); + add(SearchFields.COMPONENT_FIELD); + add(SearchFields.COMPONENT_TYPE_FIELD); + add(SearchFields.CONTRIBUTION_FIELD); + add(SearchFields.BINDING_FIELD); + add(SearchFields.FILE_CONTENT_FIELD); + add(SearchFields.ARTIFACT_FIELD); + + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java index 918358f6c4..ee2268b922 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java @@ -27,15 +27,14 @@ import org.apache.tuscany.sca.domain.search.ResultFactory; */ public class DomainSearchResultProcessor extends ResultProcessorList { - private static final long serialVersionUID = 792292814333612713L; - - public DomainSearchResultProcessor( - ResultFactory resultFactory) { - - super(new DomainSearchResultFactory()); - - add(new FileContentResultProcessor()); - - } + private static final long serialVersionUID = 792292814333612713L; + + public DomainSearchResultProcessor(ResultFactory resultFactory) { + + super(new DomainSearchResultFactory()); + + add(new FileContentResultProcessor()); + + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java index ba35de3af9..923eff998a 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java @@ -26,15 +26,15 @@ import java.io.InputStream; * @version $Rev$ $Date$ */ public interface FileContent { - - String getPath(); - - String getName(); - - FileContent[] getChildren(); - - boolean isLeaf(); - - InputStream getInputStream() throws IOException; + + String getPath(); + + String getName(); + + FileContent[] getChildren(); + + boolean isLeaf(); + + InputStream getInputStream() throws IOException; } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java index 769dd6d8da..f6253d6a17 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java @@ -33,76 +33,73 @@ import org.apache.tuscany.sca.domain.search.ResultProcessor; */ public class FileContentResultProcessor implements ResultProcessor { - public Result process(Document document, Result result) { + public Result process(Document document, Result result) { - if (document.getFieldable(SearchFields.FILE_CONTENT_FIELD) != null) { - Reader reader; + if (document.getFieldable(SearchFields.FILE_CONTENT_FIELD) != null) { + Reader reader; - ParentField parentField = new ParentField(document - .get(SearchFields.PARENT_FIELD)); + ParentField parentField = new ParentField(document.get(SearchFields.PARENT_FIELD)); - int lastParentElementIndex = parentField.getElementsCount() - 1; - String parentURI; + int lastParentElementIndex = parentField.getElementsCount() - 1; + String parentURI; - if (SearchFields.ARTIFACT_FIELD.equals(parentField - .getElementType(lastParentElementIndex))) { - parentURI = parentField.getElementURI(lastParentElementIndex); + if (SearchFields.ARTIFACT_FIELD.equals(parentField.getElementType(lastParentElementIndex))) { + parentURI = parentField.getElementURI(lastParentElementIndex); - // if (parentURI.startsWith("jar:")) { + // if (parentURI.startsWith("jar:")) { - try { - reader = new InputStreamReader(new URL(parentURI) - .openStream()); + try { + reader = new InputStreamReader(new URL(parentURI).openStream()); - } catch (IOException e) { - return result; - } + } catch (IOException e) { + return result; + } - // } else { - // - // try { - // reader = new InputStreamReader(new FileInputStream( - // new File(parentURI + (parentURI.length() > 0 ? "/" : "") + - // name))); - // - // } catch (FileNotFoundException e) { - // return result; - // } - // - // } + // } else { + // + // try { + // reader = new InputStreamReader(new FileInputStream( + // new File(parentURI + (parentURI.length() > 0 ? "/" : "") + + // name))); + // + // } catch (FileNotFoundException e) { + // return result; + // } + // + // } - try { + try { - StringBuilder sb = new StringBuilder(); - int c; + StringBuilder sb = new StringBuilder(); + int c; - // TODO: load the chars into an array buffer instead of one - // at a - // time - while ((c = reader.read()) != -1) { - char character = (char) c; + // TODO: load the chars into an array buffer instead of one + // at a + // time + while ((c = reader.read()) != -1) { + char character = (char)c; - if (!Character.isIdentifierIgnorable(character)) { - sb.append(character); - } + if (!Character.isIdentifierIgnorable(character)) { + sb.append(character); + } - } + } - result.setValue(sb.toString()); + result.setValue(sb.toString()); - } catch (Exception e) { - // ignore content loading, TODO: maybe it should return an - // error - // message as the content + } catch (Exception e) { + // ignore content loading, TODO: maybe it should return an + // error + // message as the content - } + } - } + } - } + } - return result; + return result; - } + } } 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 index 87125d5c0e..553a5b57cd 100644 --- 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 @@ -27,81 +27,82 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessor; * * @version $Rev$ $Date$ */ -public class FileDocumentProcessor extends LinkedList - implements DocumentProcessor { +public class FileDocumentProcessor extends LinkedList implements DocumentProcessor { - private static final long serialVersionUID = 7843338343970738591L; + private static final long serialVersionUID = 7843338343970738591L; - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document doc, String parent) { + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document doc, + String parent) { - if (object instanceof FileContent) { - FileContent file = (FileContent) object; + if (object instanceof FileContent) { + FileContent file = (FileContent)object; - if (!file.isLeaf()) { + if (!file.isLeaf()) { - if (doc == null) { - doc = documents.get(SearchFields.FILE_CONTENT_FIELD + file.getPath()); - } + if (doc == null) { + doc = documents.get(SearchFields.FILE_CONTENT_FIELD + file.getPath()); + } - //FileContent[] files = file.getChildren(); + // FileContent[] files = file.getChildren(); -// for (FileContent childFile : files) { -// // Document fileDoc = parentProcessor.process( -// // parentProcessor, documents, childFile, null, -// // parent); -// -// Document fileDoc = null; -// -// fileDoc = process(this, documents, childFile, null, parent); -// -// if (fileDoc == null) { -// continue; -// } -// -// fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, -// Field.Store.YES, Field.Index.ANALYZED)); -// -// } + // for (FileContent childFile : files) { + // // Document fileDoc = parentProcessor.process( + // // parentProcessor, documents, childFile, null, + // // parent); + // + // Document fileDoc = null; + // + // fileDoc = process(this, documents, childFile, null, parent); + // + // if (fileDoc == null) { + // continue; + // } + // + // fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + // Field.Store.YES, Field.Index.ANALYZED)); + // + // } - return doc; + return doc; - } else { + } else { - for (DocumentProcessor processor : this) { - Document newDoc = processor.process(this, documents, file, - doc, parent); + for (DocumentProcessor processor : this) { + Document newDoc = processor.process(this, documents, file, doc, parent); - if (newDoc != null) { - return newDoc; - } + if (newDoc != null) { + return newDoc; + } - } + } - } + } - } + } - return doc; + return doc; - } + } - public Object getDocumentKey(Object object) { + public Object getDocumentKey(Object object) { - if (object instanceof FileContent) { - FileContent file = (FileContent) object; - String path = file.getPath(); + if (object instanceof FileContent) { + FileContent file = (FileContent)object; + String path = file.getPath(); - if (path != null && path.length() == 0) { - return null; - } + if (path != null && path.length() == 0) { + return null; + } - return SearchFields.FILE_CONTENT_FIELD + path; + return SearchFields.FILE_CONTENT_FIELD + path; - } + } - throw new IllegalArgumentException(); + throw new IllegalArgumentException(); - } + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java index fd1d0e102b..cd253c4859 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java @@ -37,151 +37,152 @@ import org.apache.tuscany.sca.domain.search.Result; * @version $Rev$ $Date$ */ final public class HighlightingUtil { - - public static void highlightResult(Result result, Query query) { - highlightResult(result, query, new SimpleFragmenter(70)); - } - - public static void highlightResult(Result result, Query query, Fragmenter fragmenter) { - Map contents = result.getContents(); - - if (contents != null) { - - for (Result content : contents.values()) { - highlightResult(content, query, fragmenter); - } - - } - - try { - String highlightedText = HighlightingUtil.bestFragmentHighlighted( - result.getField(), query, result.getValue(), fragmenter); - - // checks if something was highlighted before resetting the value - if (highlightedText != null && highlightedText.length() > 0) { - result.setValue(highlightedText); - } - - } catch (IOException e) { - // ignore highlighting - } - - } - - public static String highlight(String field, Query query, String text) throws IOException { - String highlightedText = bestFragmentHighlighted(field, query, text, new NullFragmenter()); - - if (highlightedText == null || text.length() >= highlightedText.length()) { - return text; - } - - return highlightedText; - - } - - public static String bestFragmentHighlighted(String field, Query query, String text) throws IOException { - return bestFragmentHighlighted(field, query, text, new SimpleFragmenter(100)); - } - - public static String bestFragmentHighlighted(String field, Query query, String text, Fragmenter fragmenter) throws IOException { - CachingTokenFilter tokenStream = new CachingTokenFilter(new DomainSearchAnalyzer().tokenStream( - field, new StringReader(text))); - - Highlighter highlighter = new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, field, tokenStream, "")); - highlighter.setTextFragmenter(fragmenter); - tokenStream.reset(); - - try { - return highlighter.getBestFragments(tokenStream, text, 2, " ... "); - - } catch (InvalidTokenOffsetsException e) { - - // could not create fragments, return empty string - return ""; - - } - - } - - public static String replaceHighlightMarkupBy(CharSequence text, - String startHighlight, String endHighlight) { - StringBuilder sb = new StringBuilder(); - int start = 0; - int end = 0; - - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - - if (start > 0) { - - if (c == DomainSearchFormatter.HIGHLIGHT_START.charAt(start)) { - start++; - - if (start == DomainSearchFormatter.HIGHLIGHT_START.length()) { - sb.append(startHighlight); - start = 0; - - } - - } else { - - for (int j = 0; j < start; j++) { - sb.append(DomainSearchFormatter.HIGHLIGHT_START.charAt(j)); - } - - start = 0; - - } - - } else if (end > 0) { - - if (c == DomainSearchFormatter.HIGHLIGHT_END.charAt(end)) { - end++; - - if (end == DomainSearchFormatter.HIGHLIGHT_END.length()) { - sb.append(endHighlight); - end = 0; - - } - - } else { - - for (int j = 0; j < end; j++) { - sb.append(DomainSearchFormatter.HIGHLIGHT_END.charAt(j)); - } - - end = 0; - - } - - } else if (c == DomainSearchFormatter.HIGHLIGHT_START.charAt(0)) { - start = 1; - - } else if (c == DomainSearchFormatter.HIGHLIGHT_END.charAt(0)) { - end = 1; - - } else { - sb.append(c); - } - - } - - if (start > 0) { - - for (int j = 0; j < start; j++) { - sb.append(DomainSearchFormatter.HIGHLIGHT_START.charAt(j)); - } - - } else if (end > 0) { - - for (int j = 0; j < start; j++) { - sb.append(DomainSearchFormatter.HIGHLIGHT_END.charAt(j)); - } - - } - - return sb.toString(); - - } + + public static void highlightResult(Result result, Query query) { + highlightResult(result, query, new SimpleFragmenter(70)); + } + + public static void highlightResult(Result result, Query query, Fragmenter fragmenter) { + Map contents = result.getContents(); + + if (contents != null) { + + for (Result content : contents.values()) { + highlightResult(content, query, fragmenter); + } + + } + + try { + String highlightedText = + HighlightingUtil.bestFragmentHighlighted(result.getField(), query, result.getValue(), fragmenter); + + // checks if something was highlighted before resetting the value + if (highlightedText != null && highlightedText.length() > 0) { + result.setValue(highlightedText); + } + + } catch (IOException e) { + // ignore highlighting + } + + } + + public static String highlight(String field, Query query, String text) throws IOException { + String highlightedText = bestFragmentHighlighted(field, query, text, new NullFragmenter()); + + if (highlightedText == null || text.length() >= highlightedText.length()) { + return text; + } + + return highlightedText; + + } + + public static String bestFragmentHighlighted(String field, Query query, String text) throws IOException { + return bestFragmentHighlighted(field, query, text, new SimpleFragmenter(100)); + } + + public static String bestFragmentHighlighted(String field, Query query, String text, Fragmenter fragmenter) + throws IOException { + CachingTokenFilter tokenStream = + new CachingTokenFilter(new DomainSearchAnalyzer().tokenStream(field, new StringReader(text))); + + Highlighter highlighter = + new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, field, tokenStream, "")); + highlighter.setTextFragmenter(fragmenter); + tokenStream.reset(); + + try { + return highlighter.getBestFragments(tokenStream, text, 2, " ... "); + + } catch (InvalidTokenOffsetsException e) { + + // could not create fragments, return empty string + return ""; + + } + + } + + public static String replaceHighlightMarkupBy(CharSequence text, String startHighlight, String endHighlight) { + StringBuilder sb = new StringBuilder(); + int start = 0; + int end = 0; + + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + + if (start > 0) { + + if (c == DomainSearchFormatter.HIGHLIGHT_START.charAt(start)) { + start++; + + if (start == DomainSearchFormatter.HIGHLIGHT_START.length()) { + sb.append(startHighlight); + start = 0; + + } + + } else { + + for (int j = 0; j < start; j++) { + sb.append(DomainSearchFormatter.HIGHLIGHT_START.charAt(j)); + } + + start = 0; + + } + + } else if (end > 0) { + + if (c == DomainSearchFormatter.HIGHLIGHT_END.charAt(end)) { + end++; + + if (end == DomainSearchFormatter.HIGHLIGHT_END.length()) { + sb.append(endHighlight); + end = 0; + + } + + } else { + + for (int j = 0; j < end; j++) { + sb.append(DomainSearchFormatter.HIGHLIGHT_END.charAt(j)); + } + + end = 0; + + } + + } else if (c == DomainSearchFormatter.HIGHLIGHT_START.charAt(0)) { + start = 1; + + } else if (c == DomainSearchFormatter.HIGHLIGHT_END.charAt(0)) { + end = 1; + + } else { + sb.append(c); + } + + } + + if (start > 0) { + + for (int j = 0; j < start; j++) { + sb.append(DomainSearchFormatter.HIGHLIGHT_START.charAt(j)); + } + + } else if (end > 0) { + + for (int j = 0; j < start; j++) { + sb.append(DomainSearchFormatter.HIGHLIGHT_END.charAt(j)); + } + + } + + return sb.toString(); + + } } 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 index 76b0fccaec..2f06b179e4 100644 --- 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 @@ -31,19 +31,18 @@ import org.apache.lucene.analysis.Tokenizer; */ public class NamingAnalyzer extends Analyzer { - public TokenStream tokenStream(String fieldName, Reader reader) { - return new NamingTokenizer(reader); - } + 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; - } + 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 index 13bc1da830..280039a67e 100644 --- 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 @@ -30,120 +30,120 @@ 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; - - } + 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/ParentField.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java index cf4e3ca70d..862db63b2c 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java @@ -29,178 +29,178 @@ import java.util.List; */ public class ParentField implements Serializable { - private static final long serialVersionUID = -2090538050273088026L; - - final private List elements; - - public ParentField(String parentFieldValue) { - int length = parentFieldValue.length(); - - if (length == 0) { - this.elements = Collections.emptyList(); - - return; - - } - - this.elements = new ArrayList(); - - ParentFieldElement element = null; - StringBuilder sb = new StringBuilder(); - - for (int i = 0; i < length ; i++) { - char c = parentFieldValue.charAt(i); - - if (c == DomainPathAnalyzer.PATH_SEPARATOR || c == DomainPathAnalyzer.PATH_START) { - - if (sb.length() > 0 || element != null) { - - if (element == null) { - element = new ParentFieldElement(); - } - - if (element.type == null) { - element.type = ""; - } - - if (element.uri == null) { - element.uri = element.name = sb.toString(); - - } else { - element.name = sb.toString(); - } - - sb.setLength(0); - this.elements.add(element); - element = null; - - } - - } else if (c == DomainPathAnalyzer.TYPE_SEPARATOR) { - - if (element == null) { - element = new ParentFieldElement(); - } - - element.type = sb.toString(); - - sb.setLength(0); - - } else if (c == DomainPathAnalyzer.URI_SEPARATOR) { - - if (element == null) { - element = new ParentFieldElement(); - } - - element.uri = sb.toString(); - - sb.setLength(0); - - } else { - sb.append(c); - } - - } - - if (sb.length() > 0 || element != null) { - - if (element == null) { - element = new ParentFieldElement(); - } - - if (element.type == null) { - element.type = ""; - } - - if (element.uri == null) { - element.uri = element.name = sb.toString(); - - } else { - element.name = sb.toString(); - } - - sb.setLength(0); - this.elements.add(element); - element = null; - - } - - } - - public static String getURIPath(ParentField parentField) { - return getURIPath(parentField, System.getProperty("file.separator")); - } - - public static String getURIPath(ParentField parentField, String pathSeparator) { - StringBuilder sb = new StringBuilder(); - sb.append(pathSeparator); - int elementsCount = parentField.getElementsCount(); - - for (int i = 0 ; i < elementsCount ; i++) { - sb.append(parentField.getElementName(i)); - sb.append(pathSeparator); - - } - - if (sb.length() > pathSeparator.length()) { - sb.setLength(sb.length() - pathSeparator.length()); - } - - return sb.toString(); - - } - - public static int getParentElementsCount(String parent) { - int length = parent.length(); - - if (length == 0) { - return 0; - } - - boolean pathSeparatorBefore = true; - int count = 1; - - for (int i = 0; i < length - 1; i++) { - char c = parent.charAt(i); - - if (c == DomainPathAnalyzer.PATH_SEPARATOR && !pathSeparatorBefore) { - pathSeparatorBefore = true; - count++; - - } else { - pathSeparatorBefore = false; - } - - } - - return count; - - } - - public int getElementsCount() { - return this.elements.size(); - } - - public String getElementType(int index) { - return this.elements.get(index).type; - } - - public String getElementURI(int index) { - return this.elements.get(index).uri; - } - - public String getElementName(int index) { - return this.elements.get(index).name; - } - - final private static class ParentFieldElement { - - String type; - - String uri; - - String name; - - } + private static final long serialVersionUID = -2090538050273088026L; + + final private List elements; + + public ParentField(String parentFieldValue) { + int length = parentFieldValue.length(); + + if (length == 0) { + this.elements = Collections.emptyList(); + + return; + + } + + this.elements = new ArrayList(); + + ParentFieldElement element = null; + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < length; i++) { + char c = parentFieldValue.charAt(i); + + if (c == DomainPathAnalyzer.PATH_SEPARATOR || c == DomainPathAnalyzer.PATH_START) { + + if (sb.length() > 0 || element != null) { + + if (element == null) { + element = new ParentFieldElement(); + } + + if (element.type == null) { + element.type = ""; + } + + if (element.uri == null) { + element.uri = element.name = sb.toString(); + + } else { + element.name = sb.toString(); + } + + sb.setLength(0); + this.elements.add(element); + element = null; + + } + + } else if (c == DomainPathAnalyzer.TYPE_SEPARATOR) { + + if (element == null) { + element = new ParentFieldElement(); + } + + element.type = sb.toString(); + + sb.setLength(0); + + } else if (c == DomainPathAnalyzer.URI_SEPARATOR) { + + if (element == null) { + element = new ParentFieldElement(); + } + + element.uri = sb.toString(); + + sb.setLength(0); + + } else { + sb.append(c); + } + + } + + if (sb.length() > 0 || element != null) { + + if (element == null) { + element = new ParentFieldElement(); + } + + if (element.type == null) { + element.type = ""; + } + + if (element.uri == null) { + element.uri = element.name = sb.toString(); + + } else { + element.name = sb.toString(); + } + + sb.setLength(0); + this.elements.add(element); + element = null; + + } + + } + + public static String getURIPath(ParentField parentField) { + return getURIPath(parentField, System.getProperty("file.separator")); + } + + public static String getURIPath(ParentField parentField, String pathSeparator) { + StringBuilder sb = new StringBuilder(); + sb.append(pathSeparator); + int elementsCount = parentField.getElementsCount(); + + for (int i = 0; i < elementsCount; i++) { + sb.append(parentField.getElementName(i)); + sb.append(pathSeparator); + + } + + if (sb.length() > pathSeparator.length()) { + sb.setLength(sb.length() - pathSeparator.length()); + } + + return sb.toString(); + + } + + public static int getParentElementsCount(String parent) { + int length = parent.length(); + + if (length == 0) { + return 0; + } + + boolean pathSeparatorBefore = true; + int count = 1; + + for (int i = 0; i < length - 1; i++) { + char c = parent.charAt(i); + + if (c == DomainPathAnalyzer.PATH_SEPARATOR && !pathSeparatorBefore) { + pathSeparatorBefore = true; + count++; + + } else { + pathSeparatorBefore = false; + } + + } + + return count; + + } + + public int getElementsCount() { + return this.elements.size(); + } + + public String getElementType(int index) { + return this.elements.get(index).type; + } + + public String getElementURI(int index) { + return this.elements.get(index).uri; + } + + public String getElementName(int index) { + return this.elements.get(index).name; + } + + final private static class ParentFieldElement { + + String type; + + String uri; + + String name; + + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java index 1cd48ce493..bd1912af49 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java @@ -29,30 +29,30 @@ import org.apache.tuscany.sca.domain.search.ResultFactory; * @version $Rev$ $Date$ */ public class PriorityFieldListResultFactory extends LinkedList implements ResultFactory { - - private static final long serialVersionUID = 6806221945324235828L; - - public PriorityFieldListResultFactory() { - // empty constructor - } - - public Result createResult(Document document) { - - for (String field : this) { - String value = document.get(field); - - if (value != null) { - return new ResultImpl(field, value); - } - - } - - return null; - - } - - public Result createResult(String field, String value) { - return new ResultImpl(field, value); - } + + private static final long serialVersionUID = 6806221945324235828L; + + public PriorityFieldListResultFactory() { + // empty constructor + } + + public Result createResult(Document document) { + + for (String field : this) { + String value = document.get(field); + + if (value != null) { + return new ResultImpl(field, value); + } + + } + + return null; + + } + + public Result createResult(String field, String value) { + return new ResultImpl(field, value); + } } 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 index 1ab8d29092..20b6635e05 100644 --- 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 @@ -31,54 +31,58 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessor; */ public class PropertyDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document doc, String parent) { + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document doc, + String parent) { - if (object instanceof Property) { - Property property = (Property) object; - String name = property.getName(); + if (object instanceof Property) { + Property property = (Property)object; + String name = property.getName(); - if (name != null && name.length() > 0) { + if (name != null && name.length() > 0) { - if (doc == null) { - doc = documents.get(name); - } + if (doc == null) { + doc = documents.get(name); + } - Object value = property.getValue(); + Object value = property.getValue(); - if (value.getClass().isArray()) { - int arraySize = Array.getLength(value); + if (value.getClass().isArray()) { + int arraySize = Array.getLength(value); - for (int i = 0; i < arraySize; i++) { - Object arrayValue = Array.get(value, i); + 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)); + doc.add(new Field(SearchFields.VALUE_FIELD, arrayValue.toString(), Field.Store.YES, + Field.Index.ANALYZED)); - } + } - } else { + } else { - doc.add(new Field(SearchFields.VALUE_FIELD, value.toString(), - Field.Store.YES, Field.Index.ANALYZED)); + 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; - } + return doc == null ? FAKE_DOCUMENT : doc; - } + } else { + return FAKE_DOCUMENT; + } - throw new IllegalArgumentException(); + } - } + throw new IllegalArgumentException(); - public Object getDocumentKey(Object object) { - // TODO Auto-generated method stub - return null; - } + } + + 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/ResultImpl.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java index cf45baadcb..66e2b73723 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java @@ -33,253 +33,238 @@ import org.apache.tuscany.sca.domain.search.Result; */ final public class ResultImpl implements Result { - private static final long serialVersionUID = 7084570994751217396L; + private static final long serialVersionUID = 7084570994751217396L; - private Result container; + private Result container; - private HashMap contents; + private HashMap contents; - private String value; - - private String field; + private String value; - public ResultImpl() { - // empty constructor - } + private String field; - public ResultImpl(String field, String value) { - setValue(value); - setField(field); - - } - - public String getField() { - return this.field; - } - - public void setField(String field) { - this.field = field; - } + public ResultImpl() { + // empty constructor + } - public Result getContainer() { - return this.container; - } + public ResultImpl(String field, String value) { + setValue(value); + setField(field); - public Map getContents() { + } - if (this.contents == null) { - return Collections.emptyMap(); - } + public String getField() { + return this.field; + } - return Collections.unmodifiableMap(this.contents); + public void setField(String field) { + this.field = field; + } - } + public Result getContainer() { + return this.container; + } - public String getValue() { - return this.value; - } + public Map getContents() { - public void setContainer(Result container) { + if (this.contents == null) { + return Collections.emptyMap(); + } - if (container != this.container) { - - if (this.container != null) { - this.container.removeContent(this); - } + return Collections.unmodifiableMap(this.contents); - this.container = container; + } - if (container != null) { - container.addContent(this); - } + public String getValue() { + return this.value; + } - } + public void setContainer(Result container) { - } + if (container != this.container) { - @Override - public boolean equals(Object obj) { + if (this.container != null) { + this.container.removeContent(this); + } - if (obj instanceof Result) { - Result artifactResult = (Result) obj; + this.container = container; - if (artifactResult.getValue() == this.value || this.value != null - && this.value.equals(artifactResult.getValue())) { + if (container != null) { + container.addContent(this); + } - if (artifactResult.getContainer() == this.container - || this.container != null - && this.container.equals(artifactResult.getContainer())) { + } - Map contents = artifactResult.getContents(); + } - if (this.contents == null) { - return contents.isEmpty(); + @Override + public boolean equals(Object obj) { - } else if (this.contents.equals(contents)) { - return true; - } + if (obj instanceof Result) { + Result artifactResult = (Result)obj; - } + if (artifactResult.getValue() == this.value || this.value != null + && this.value.equals(artifactResult.getValue())) { - } + if (artifactResult.getContainer() == this.container || this.container != null + && this.container.equals(artifactResult.getContainer())) { - } + Map contents = artifactResult.getContents(); - return false; + if (this.contents == null) { + return contents.isEmpty(); - } + } else if (this.contents.equals(contents)) { + return true; + } - public void addContent(Result artifactResult) { - internalGetContents().put(artifactResult.getValue(), artifactResult); - - if (artifactResult.getContainer() != this) { - artifactResult.setContainer(this); - } + } - } + } - private HashMap internalGetContents() { + } - if (this.contents == null) { - this.contents = new HashMap(); - } + return false; - return this.contents; + } - } + public void addContent(Result artifactResult) { + internalGetContents().put(artifactResult.getValue(), artifactResult); - public void removeContent(Result artifactResult) { + if (artifactResult.getContainer() != this) { + artifactResult.setContainer(this); + } - if (this.contents != null) { - this.contents.remove(artifactResult); + } - artifactResult.setContainer(null); + private HashMap internalGetContents() { - if (this.contents.isEmpty()) { - this.contents = null; - } + if (this.contents == null) { + this.contents = new HashMap(); + } - } + return this.contents; - } + } - @Override - public int hashCode() { - int hash = 11; + public void removeContent(Result artifactResult) { - hash = hash * 31 - + (this.container == null ? 7 : this.container.hashCode()); - hash = hash - * 31 - + (this.contents == null || this.contents.isEmpty() ? 13 - : this.contents.hashCode()); - hash = hash * 31 + (this.value == null ? 17 : this.value.hashCode()); + if (this.contents != null) { + this.contents.remove(artifactResult); - return hash; + artifactResult.setContainer(null); - } + if (this.contents.isEmpty()) { + this.contents = null; + } - public void setValue(String value) { - this.value = value; - } + } - public String toString() { - StringBuilder sb = new StringBuilder("<"); - Result container = getContainer(); - - sb.append(getClass().getName()).append(" name='").append(getValue()) - .append("' container='").append(container != null ? container.getValue() : null).append("'>\n"); + } - Method[] methods = getClass().getMethods(); + @Override + public int hashCode() { + int hash = 11; - for (Method method : methods) { - String methodName = method.getName(); + hash = hash * 31 + (this.container == null ? 7 : this.container.hashCode()); + hash = hash * 31 + (this.contents == null || this.contents.isEmpty() ? 13 : this.contents.hashCode()); + hash = hash * 31 + (this.value == null ? 17 : this.value.hashCode()); - if (method.getReturnType() != void.class) { + return hash; - if (method.getParameterTypes().length == 0) { + } - if (methodName.startsWith("get") - && !"getName".equals(methodName) - && !"getContainer".equals(methodName)) { + public void setValue(String value) { + this.value = value; + } - try { - Object returnedObj = method.invoke(this); + public String toString() { + StringBuilder sb = new StringBuilder("<"); + Result container = getContainer(); - sb.append('\t'); + sb.append(getClass().getName()).append(" name='").append(getValue()).append("' container='") + .append(container != null ? container.getValue() : null).append("'>\n"); - if (returnedObj instanceof Map) { + Method[] methods = getClass().getMethods(); - sb.append("\n"); + for (Method method : methods) { + String methodName = method.getName(); - for (Object obj : ((Map) returnedObj).values()) { + if (method.getReturnType() != void.class) { - sb.append("\t\t").append(obj.toString()) - .append("\n"); + if (method.getParameterTypes().length == 0) { - } + if (methodName.startsWith("get") && !"getName".equals(methodName) + && !"getContainer".equals(methodName)) { - sb.append("\t\n"); + try { + Object returnedObj = method.invoke(this); - } else if (returnedObj instanceof Collection) { + sb.append('\t'); - sb.append("\n"); + if (returnedObj instanceof Map) { - for (Object obj : (Collection) returnedObj) { + sb.append("\n"); - sb.append("\t\t").append(obj.toString()) - .append("\n"); + for (Object obj : ((Map)returnedObj).values()) { - } + sb.append("\t\t").append(obj.toString()).append("\n"); - sb.append("\t\n"); + } - } else if (returnedObj.getClass().isArray()) { + sb.append("\t\n"); - sb.append("\n"); - - int length = Array.getLength(returnedObj); + } else if (returnedObj instanceof Collection) { - for (int i = 0 ; i < length ; i++) { + sb.append("\n"); - sb.append("\t\t").append(Array.get(returnedObj, i).toString()) - .append("\n"); + for (Object obj : (Collection)returnedObj) { - } + sb.append("\t\t").append(obj.toString()).append("\n"); - sb.append("\t\n"); + } - } else { - - sb.append('\t').append(returnedObj).append('\n'); - - } + sb.append("\t\n"); - } catch (Throwable e) { - // ignore exceptions and don't print the object - } + } else if (returnedObj.getClass().isArray()) { - } + sb.append("\n"); - } + int length = Array.getLength(returnedObj); - } + for (int i = 0; i < length; i++) { - } - - sb.append(""); + sb.append("\t\t").append(Array.get(returnedObj, i).toString()).append("\n"); - return sb.toString(); + } + + sb.append("\t\n"); + + } else { + + sb.append('\t').append(returnedObj).append('\n'); + + } + + } catch (Throwable e) { + // ignore exceptions and don't print the object + } + + } + + } + + } + + } + + sb.append(""); + + return sb.toString(); + + } - } - } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java index 9242f0a769..27c192cbee 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java @@ -30,158 +30,157 @@ import org.apache.tuscany.sca.domain.search.ResultProcessor; * * @version $Rev$ $Date$ */ -public class ResultProcessorList extends LinkedList implements - ResultProcessor { +public class ResultProcessorList extends LinkedList implements ResultProcessor { - private static final long serialVersionUID = 7147307292452694895L; - private HashMap resultRoots = new HashMap(); + private static final long serialVersionUID = 7147307292452694895L; - private ResultFactory resultFactory; - - public ResultProcessorList(ResultFactory resultFactory) { - this.resultFactory = resultFactory; - } + private HashMap resultRoots = new HashMap(); - public Result process(Document document, Result result) { + private ResultFactory resultFactory; - if (result == null) { - result = this.resultFactory.createResult(document); - - if (result == null) { - return null; - } - - } + public ResultProcessorList(ResultFactory resultFactory) { + this.resultFactory = resultFactory; + } - ResultHashMap resultHashMap; + public Result process(Document document, Result result) { - String parent = document.get(SearchFields.PARENT_FIELD); + if (result == null) { + result = this.resultFactory.createResult(document); - if (parent == null) { - resultHashMap = new ResultHashMap(result); - resultRoots.put(result.getValue(), resultHashMap); + if (result == null) { + return null; + } - } else { + } - ParentField parentField = new ParentField(parent); - HashMap current = this.resultRoots; - //Result currentResult = null; - int elementsCount = parentField.getElementsCount(); + ResultHashMap resultHashMap; - for (int i = 0; i < elementsCount; i++) { - String actualName = parentField.getElementName(i); - String type = parentField.getElementType(i); + String parent = document.get(SearchFields.PARENT_FIELD); - if (actualName.length() > 0) { - ResultHashMap actualResultHashMap = current.get(actualName); + if (parent == null) { + resultHashMap = new ResultHashMap(result); + resultRoots.put(result.getValue(), resultHashMap); - if (actualResultHashMap == null) { - ResultHashMap aux = new ResultHashMap(type, parentField - .getElementName(i)); + } else { - current.put(aux.result.getValue(), aux); -// if (current.put(aux.result.getValue(), aux) == null -// && currentResult != null) { -// currentResult.addContent(aux.result); -// } + ParentField parentField = new ParentField(parent); + HashMap current = this.resultRoots; + // Result currentResult = null; + int elementsCount = parentField.getElementsCount(); - current = aux; - //currentResult = aux.result; + for (int i = 0; i < elementsCount; i++) { + String actualName = parentField.getElementName(i); + String type = parentField.getElementType(i); - } else { - current = actualResultHashMap; - //currentResult = actualResultHashMap.result; + if (actualName.length() > 0) { + ResultHashMap actualResultHashMap = current.get(actualName); - } + if (actualResultHashMap == null) { + ResultHashMap aux = new ResultHashMap(type, parentField.getElementName(i)); - } + current.put(aux.result.getValue(), aux); + // if (current.put(aux.result.getValue(), aux) == null + // && currentResult != null) { + // currentResult.addContent(aux.result); + // } - } + current = aux; + // currentResult = aux.result; - resultHashMap = current.get(result.getValue()); + } else { + current = actualResultHashMap; + // currentResult = actualResultHashMap.result; - if (resultHashMap == null) { - resultHashMap = new ResultHashMap(result); - current.put(result.getValue(), resultHashMap); + } -// if (currentResult != null) { -// currentResult.addContent(result); -// } + } - } + } - } + resultHashMap = current.get(result.getValue()); - for (ResultProcessor processor : this) { - result = processor.process(document, result); - } + if (resultHashMap == null) { + resultHashMap = new ResultHashMap(result); + current.put(result.getValue(), resultHashMap); - resultHashMap.result = result; + // if (currentResult != null) { + // currentResult.addContent(result); + // } - return result; + } - } - - private static void addContentsToResult(ResultHashMap resultHashMap) { - - for (ResultHashMap actual : resultHashMap.values()) { - addContentsToResult(actual); - - resultHashMap.result.addContent(actual.result); - - } - - } + } - public Result[] createResultRoots() { - int size = this.resultRoots.size(); + for (ResultProcessor processor : this) { + result = processor.process(document, result); + } - if (size == 0) { - return new Result[0]; - } + resultHashMap.result = result; - Result[] res = new Result[size]; + return result; - int i = 0; - for (ResultHashMap resultHashMap : this.resultRoots.values()) { - - addContentsToResult(resultHashMap); - res[i++] = resultHashMap.result; - - } - - this.resultRoots.clear(); + } - return res; + private static void addContentsToResult(ResultHashMap resultHashMap) { - } + for (ResultHashMap actual : resultHashMap.values()) { + addContentsToResult(actual); - private Result createResult(String field, String value) { - Result result = this.resultFactory.createResult(field, value); - - if (result != null) { - return result; - } + resultHashMap.result.addContent(actual.result); - throw new IllegalArgumentException(); + } - } + } - private class ResultHashMap extends HashMap { + public Result[] createResultRoots() { + int size = this.resultRoots.size(); - private static final long serialVersionUID = 7982561264440904411L; + if (size == 0) { + return new Result[0]; + } - Result result; + Result[] res = new Result[size]; - ResultHashMap(String type, String name) { - this(createResult(type, name)); - } + int i = 0; + for (ResultHashMap resultHashMap : this.resultRoots.values()) { - ResultHashMap(Result result) { - this.result = result; - } + addContentsToResult(resultHashMap); + res[i++] = resultHashMap.result; - } + } + + this.resultRoots.clear(); + + return res; + + } + + private Result createResult(String field, String value) { + Result result = this.resultFactory.createResult(field, value); + + if (result != null) { + return result; + } + + throw new IllegalArgumentException(); + + } + + private class ResultHashMap extends HashMap { + + private static final long serialVersionUID = 7982561264440904411L; + + Result result; + + ResultHashMap(String type, String name) { + this(createResult(type, name)); + } + + ResultHashMap(Result result) { + this.result = result; + } + + } } 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 index 7515b5da98..abfaa8c466 100644 --- 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 @@ -24,50 +24,50 @@ package org.apache.tuscany.sca.domain.search.impl; */ public interface SearchFields { - final public static String ARTIFACT_FIELD = "artifact"; - - 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 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 PROPERTY_KEY_FIELD = "propertykey"; - - final public static String VALUE_FIELD = "propertyvalue"; - - final public static String FILE_CONTENT_FIELD = "filecontent"; + final public static String ARTIFACT_FIELD = "artifact"; + + 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 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 PROPERTY_KEY_FIELD = "propertykey"; + + final public static String VALUE_FIELD = "propertyvalue"; + + final public static String FILE_CONTENT_FIELD = "filecontent"; } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java index ad93e3e455..3d75c2b86e 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java @@ -29,48 +29,48 @@ import java.io.InputStream; */ public class SystemFileContent implements FileContent { - private static final long serialVersionUID = -8337926886777467728L; - - final boolean leaf; - - final private File file; - - public SystemFileContent(File file) { - this.leaf = !file.isDirectory(); - this.file = file; - - } - - public File getFile() { - return this.file; - } - - public InputStream getInputStream() throws IOException { - return new FileInputStream(this.file); - } - - public FileContent[] getChildren() { - File[] files = this.file.listFiles(); - FileContent[] ret = new FileContent[files.length]; - - for (int i = 0; i < files.length; i++) { - ret[i] = new SystemFileContent(files[i]); - } - - return ret; - - } - - public boolean isLeaf() { - return this.leaf; - } - - public String getName() { - return this.file.getName(); - } - - public String getPath() { - return this.file.getPath(); - } + private static final long serialVersionUID = -8337926886777467728L; + + final boolean leaf; + + final private File file; + + public SystemFileContent(File file) { + this.leaf = !file.isDirectory(); + this.file = file; + + } + + public File getFile() { + return this.file; + } + + public InputStream getInputStream() throws IOException { + return new FileInputStream(this.file); + } + + public FileContent[] getChildren() { + File[] files = this.file.listFiles(); + FileContent[] ret = new FileContent[files.length]; + + for (int i = 0; i < files.length; i++) { + ret[i] = new SystemFileContent(files[i]); + } + + return ret; + + } + + public boolean isLeaf() { + return this.leaf; + } + + public String getName() { + return this.file.getName(); + } + + public String getPath() { + return this.file.getPath(); + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java index bfb348550f..0a1dfa75e9 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java @@ -30,84 +30,85 @@ import java.net.URL; */ public class WrappedFileContent implements FileContent { - final private FileContent fileContent; - - public WrappedFileContent(URL url) throws IOException { - String protocol = url.getProtocol(); - - if (protocol.equals("jar")) { - JarURLConnection jarConn = (JarURLConnection) url.openConnection(); - //Enumeration entries = jarConn.getJarFile().entries(); - String file = url.getFile(); - file = file.substring(file.lastIndexOf('!') + 1); - -// if (file.charAt(file.length() - 1) != '/') { -// -// int beginIndex; -// -// if (file.charAt(0) == '/') { -// beginIndex = 1; -// -// } else { -// beginIndex = 0; -// } -// -// file = file.substring(beginIndex); -// -// while (entries.hasMoreElements()) { -// String actualFile = entries.nextElement().getName(); -// -// if (actualFile.charAt(0) == '/') { -// beginIndex = 1; -// -// } else { -// beginIndex = 0; -// } -// -// if (actualFile.length() - beginIndex == file.length() + 1 && actualFile.charAt(actualFile.length() - 1) == '/') { -// -// if (actualFile.startsWith(file, beginIndex)) { -// file = actualFile; -// -// break; -// -// } -// -// } -// -// } -// -// } - - this.fileContent = ZipFileContent.createZipFileContent(jarConn.getJarFile(), file); - - } else if (protocol.equals("file")) { - this.fileContent = new SystemFileContent(new File(url.getFile())); - - } else { - this.fileContent = new DefaultFileContent(url); - } - - } - - public FileContent[] getChildren() { - return this.fileContent.getChildren(); - } - - public InputStream getInputStream() throws IOException { - return this.fileContent.getInputStream(); - } - - public String getName() { - return this.fileContent.getName(); - } - - public String getPath() { - return this.fileContent.getPath(); - } - - public boolean isLeaf() { - return this.fileContent.isLeaf(); - } + final private FileContent fileContent; + + public WrappedFileContent(URL url) throws IOException { + String protocol = url.getProtocol(); + + if (protocol.equals("jar")) { + JarURLConnection jarConn = (JarURLConnection)url.openConnection(); + // Enumeration entries = jarConn.getJarFile().entries(); + String file = url.getFile(); + file = file.substring(file.lastIndexOf('!') + 1); + + // if (file.charAt(file.length() - 1) != '/') { + // + // int beginIndex; + // + // if (file.charAt(0) == '/') { + // beginIndex = 1; + // + // } else { + // beginIndex = 0; + // } + // + // file = file.substring(beginIndex); + // + // while (entries.hasMoreElements()) { + // String actualFile = entries.nextElement().getName(); + // + // if (actualFile.charAt(0) == '/') { + // beginIndex = 1; + // + // } else { + // beginIndex = 0; + // } + // + // if (actualFile.length() - beginIndex == file.length() + 1 && + // actualFile.charAt(actualFile.length() - 1) == '/') { + // + // if (actualFile.startsWith(file, beginIndex)) { + // file = actualFile; + // + // break; + // + // } + // + // } + // + // } + // + // } + + this.fileContent = ZipFileContent.createZipFileContent(jarConn.getJarFile(), file); + + } else if (protocol.equals("file")) { + this.fileContent = new SystemFileContent(new File(url.getFile())); + + } else { + this.fileContent = new DefaultFileContent(url); + } + + } + + public FileContent[] getChildren() { + return this.fileContent.getChildren(); + } + + public InputStream getInputStream() throws IOException { + return this.fileContent.getInputStream(); + } + + public String getName() { + return this.fileContent.getName(); + } + + public String getPath() { + return this.fileContent.getPath(); + } + + public boolean isLeaf() { + return this.fileContent.isLeaf(); + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java index e6eeba0e37..2337c40fc1 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java @@ -31,66 +31,73 @@ import org.apache.tuscany.sca.domain.search.DocumentProcessor; * @version $Rev$ $Date$ */ public class ZipDocumentProcessor implements DocumentProcessor { - - public Object getDocumentKey(Object object) { - if (object instanceof File) { - File file = (File) object; - String path = file.getPath(); + public Object getDocumentKey(Object object) { - if (path != null && path.length() == 0) { - return null; - } + if (object instanceof File) { + File file = (File)object; + String path = file.getPath(); - return path; + if (path != null && path.length() == 0) { + return null; + } - } + return path; - throw new IllegalArgumentException(); + } - } + throw new IllegalArgumentException(); - public Document process(DocumentProcessor parentProcessor, - DocumentMap documents, Object object, Document document, - String parent) { + } - if (object instanceof SystemFileContent) { - SystemFileContent file = (SystemFileContent) object; + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, + Object object, + Document document, + String parent) { - try { - ZipFile zip = new ZipFile(file.getFile()); - - if (document == null) { - document = documents.get(file.getPath()); - } + if (object instanceof SystemFileContent) { + SystemFileContent file = (SystemFileContent)object; - parent += DomainPathAnalyzer.PATH_SEPARATOR - + SearchFields.ARTIFACT_FIELD - + DomainPathAnalyzer.TYPE_SEPARATOR + "jar:file:" + file.getPath() + DomainPathAnalyzer.ARCHIVE_SEPARATOR + '/' + file.getName() - + DomainPathAnalyzer.URI_SEPARATOR + file.getName(); - - document.add(new Field(SearchFields.ARTIFACT_FIELD, file.getName(), Field.Store.YES, - Field.Index.ANALYZED)); + try { + ZipFile zip = new ZipFile(file.getFile()); - ZipFileContent[] zipFiles = ZipFileContent.createZipFileContent(zip); + if (document == null) { + document = documents.get(file.getPath()); + } - for (ZipFileContent zipFile : zipFiles) { - - parentProcessor.process(parentProcessor, documents, - zipFile, document, parent); - - } - - return document; + parent += + DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.ARTIFACT_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + + "jar:file:" + + file.getPath() + + DomainPathAnalyzer.ARCHIVE_SEPARATOR + + '/' + + file.getName() + + DomainPathAnalyzer.URI_SEPARATOR + + file.getName(); - } catch (IOException e) { - // ignore file - } + document.add(new Field(SearchFields.ARTIFACT_FIELD, file.getName(), Field.Store.YES, + Field.Index.ANALYZED)); - } - - return null; + ZipFileContent[] zipFiles = ZipFileContent.createZipFileContent(zip); - } + for (ZipFileContent zipFile : zipFiles) { + + parentProcessor.process(parentProcessor, documents, zipFile, document, parent); + + } + + return document; + + } catch (IOException e) { + // ignore file + } + + } + + return null; + + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java index dff258ec4e..15f9bb6feb 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java @@ -31,296 +31,291 @@ import java.util.zip.ZipFile; */ public class ZipFileContent implements FileContent { - final private ZipFile file; + final private ZipFile file; - final private ZipEntry entry; + final private ZipEntry entry; - private FileContent[] children; + private FileContent[] children; - private ZipFileContent(ZipFile file, ZipEntry entry) { - this.file = file; - this.entry = entry; + private ZipFileContent(ZipFile file, ZipEntry entry) { + this.file = file; + this.entry = entry; - } + } - public InputStream getInputStream() throws IOException { - return this.file.getInputStream(this.entry); - } + public InputStream getInputStream() throws IOException { + return this.file.getInputStream(this.entry); + } - public String getPath() { - return this.file.getName() + DomainPathAnalyzer.ARCHIVE_SEPARATOR + '/' - + this.entry.getName(); - } + public String getPath() { + return this.file.getName() + DomainPathAnalyzer.ARCHIVE_SEPARATOR + '/' + this.entry.getName(); + } - public FileContent[] getChildren() { - return this.children; - } + public FileContent[] getChildren() { + return this.children; + } - public String getName() { - return this.entry.getName(); -// int lastSlashIndex = name.lastIndexOf('/'); -// -// if (lastSlashIndex == -1) { -// return name; -// } -// -// if (lastSlashIndex == name.length() - 1 && name.length() > 1) { -// lastSlashIndex = name.lastIndexOf('/', name.length() - 2); -// -// if (lastSlashIndex == -1) { -// return name.substring(0, name.length() - 1); -// } -// -// return name.substring(lastSlashIndex + 1, name.length() - 1); -// -// } -// -// return name.substring(lastSlashIndex + 1); + public String getName() { + return this.entry.getName(); + // int lastSlashIndex = name.lastIndexOf('/'); + // + // if (lastSlashIndex == -1) { + // return name; + // } + // + // if (lastSlashIndex == name.length() - 1 && name.length() > 1) { + // lastSlashIndex = name.lastIndexOf('/', name.length() - 2); + // + // if (lastSlashIndex == -1) { + // return name.substring(0, name.length() - 1); + // } + // + // return name.substring(lastSlashIndex + 1, name.length() - 1); + // + // } + // + // return name.substring(lastSlashIndex + 1); - } + } - public boolean isLeaf() { - return !this.entry.isDirectory(); - } + public boolean isLeaf() { + return !this.entry.isDirectory(); + } - public static ZipFileContent[] createZipFileContent(ZipFile file) { - Enumeration entries = file.entries(); + public static ZipFileContent[] createZipFileContent(ZipFile file) { + Enumeration entries = file.entries(); - if (!entries.hasMoreElements()) { - return null; - } + if (!entries.hasMoreElements()) { + return null; + } - HashMap roots = new HashMap(); + HashMap roots = new HashMap(); - do { - ZipEntry entry = entries.nextElement(); - String name = entry.getName(); + do { + ZipEntry entry = entries.nextElement(); + String name = entry.getName(); - if (name.length() > 0) { + if (name.length() > 0) { - String[] path = name.split("/"); + String[] path = name.split("/"); - ZipMap current = roots.get(path[0]); + ZipMap current = roots.get(path[0]); - if (current == null) { - current = new ZipMap(); - roots.put(path[0], current); + if (current == null) { + current = new ZipMap(); + roots.put(path[0], current); - if (path.length == 1) { - current.setEntry(file, entry); - continue; + if (path.length == 1) { + current.setEntry(file, entry); + continue; - } + } - } + } - for (int i = 1; i < path.length - 1; i++) { - ZipMap actual = current.get(path[i]); + for (int i = 1; i < path.length - 1; i++) { + ZipMap actual = current.get(path[i]); - if (actual == null) { - actual = new ZipMap(); - current.put(path[i], actual); + if (actual == null) { + actual = new ZipMap(); + current.put(path[i], actual); - } + } - current = actual; + current = actual; - } + } - ZipMap entryMap = current.get(path[path.length - 1]); + ZipMap entryMap = current.get(path[path.length - 1]); - if (entryMap == null) { - entryMap = new ZipMap(); - current.put(path[path.length - 1], entryMap); + if (entryMap == null) { + entryMap = new ZipMap(); + current.put(path[path.length - 1], entryMap); - } + } - entryMap.setEntry(file, entry); + entryMap.setEntry(file, entry); - } + } - } while (entries.hasMoreElements()); + } while (entries.hasMoreElements()); - for (ZipMap map : roots.values()) { - createZipFileContentChildren(map); - } + for (ZipMap map : roots.values()) { + createZipFileContentChildren(map); + } - ZipFileContent[] ret = new ZipFileContent[roots.size()]; - int i = 0; + ZipFileContent[] ret = new ZipFileContent[roots.size()]; + int i = 0; - for (ZipMap rootMap : roots.values()) { - ret[i++] = rootMap.zipContent; - } + for (ZipMap rootMap : roots.values()) { + ret[i++] = rootMap.zipContent; + } - return ret; + return ret; - } + } - public static ZipFileContent createZipFileContent(ZipFile file, - String filePath) { + public static ZipFileContent createZipFileContent(ZipFile file, String filePath) { - Enumeration entries = file.entries(); + Enumeration entries = file.entries(); - if (!entries.hasMoreElements()) { - return null; - } + if (!entries.hasMoreElements()) { + return null; + } - int beginIndex; - int endIndex; + int beginIndex; + int endIndex; - if (filePath.charAt(0) == '/') { - beginIndex = 1; + if (filePath.charAt(0) == '/') { + beginIndex = 1; - } else { - beginIndex = 0; - } + } else { + beginIndex = 0; + } - ZipMap root = new ZipMap(); - - if (filePath.length() > 1 - && filePath.charAt(filePath.length() - 1) == '/') { - endIndex = filePath.length() - 1; + ZipMap root = new ZipMap(); - } else { - endIndex = filePath.length(); - } + if (filePath.length() > 1 && filePath.charAt(filePath.length() - 1) == '/') { + endIndex = filePath.length() - 1; - filePath = filePath.substring(beginIndex, endIndex); - // HashMap roots = new HashMap(); + } else { + endIndex = filePath.length(); + } - do { - ZipEntry entry = entries.nextElement(); - String name = entry.getName(); + filePath = filePath.substring(beginIndex, endIndex); + // HashMap roots = new HashMap(); - if (name.length() > 0) { - - if (name.charAt(name.length() - 1) == '/') { - endIndex = 1; - - } else { - endIndex = 0; - } - - if (name.length() - endIndex == filePath.length()) { - root.setEntry(file, entry); - - } else if (filePath.length() == 0 || (name.startsWith(filePath) && name.charAt(filePath.length()) == '/')) { - - name = name.substring(filePath.length()); - String[] path = name.split("/"); + do { + ZipEntry entry = entries.nextElement(); + String name = entry.getName(); - ZipMap current = root; + if (name.length() > 0) { - // if (current == null) { - // current = new ZipMap(); - // roots.put(path[0], current); - // - // if (path.length == 1) { - // current.setEntry(file, entry); - // continue; - // - // } - // - // } + if (name.charAt(name.length() - 1) == '/') { + endIndex = 1; - if (path.length > 0) { + } else { + endIndex = 0; + } - int i; - - if (path[0].length() == 0) { - i = 1; - - } else { - i = 0; - } - - for (; i < path.length - 1; i++) { - ZipMap actual = current.get(path[i]); + if (name.length() - endIndex == filePath.length()) { + root.setEntry(file, entry); - if (actual == null) { - actual = new ZipMap(); - current.put(path[i], actual); + } else if (filePath.length() == 0 || (name.startsWith(filePath) && name.charAt(filePath.length()) == '/')) { - } + name = name.substring(filePath.length()); + String[] path = name.split("/"); - current = actual; + ZipMap current = root; - } + // if (current == null) { + // current = new ZipMap(); + // roots.put(path[0], current); + // + // if (path.length == 1) { + // current.setEntry(file, entry); + // continue; + // + // } + // + // } - ZipMap entryMap = current.get(path[path.length - 1]); + if (path.length > 0) { - if (entryMap == null) { - entryMap = new ZipMap(); - current.put(path[path.length - 1], entryMap); + int i; - } - - entryMap.setEntry(file, entry); + if (path[0].length() == 0) { + i = 1; - } + } else { + i = 0; + } - } + for (; i < path.length - 1; i++) { + ZipMap actual = current.get(path[i]); - } + if (actual == null) { + actual = new ZipMap(); + current.put(path[i], actual); - } while (entries.hasMoreElements()); + } - createZipFileContentChildren(root); + current = actual; - return root.zipContent; + } - } + ZipMap entryMap = current.get(path[path.length - 1]); - private static void createZipFileContentChildren(ZipMap map) { - ZipFileContent[] children = new ZipFileContent[map.size()]; - int i = 0; + if (entryMap == null) { + entryMap = new ZipMap(); + current.put(path[path.length - 1], entryMap); - for (ZipMap childMap : map.values()) { + } - if (childMap.zipContent == null) { - throw new RuntimeException( - "could not load zip file hierarchy for file: " - + map.zipContent.file); - } + entryMap.setEntry(file, entry); - children[i++] = childMap.zipContent; + } - createZipFileContentChildren(childMap); + } - } + } - map.zipContent.children = children; + } while (entries.hasMoreElements()); - } + createZipFileContentChildren(root); - @Override - public String toString() { - return this.file.getName() + '/' + this.entry.getName(); - } + return root.zipContent; - private static class ZipMap extends HashMap { + } - private static final long serialVersionUID = 6514645087432837480L; + private static void createZipFileContentChildren(ZipMap map) { + ZipFileContent[] children = new ZipFileContent[map.size()]; + int i = 0; - ZipFileContent zipContent; + for (ZipMap childMap : map.values()) { - void setEntry(ZipFile zipFile, ZipEntry entry) { - this.zipContent = new ZipFileContent(zipFile, entry); - } + if (childMap.zipContent == null) { + throw new RuntimeException("could not load zip file hierarchy for file: " + map.zipContent.file); + } - ZipFileContent[] getChildren() { + children[i++] = childMap.zipContent; - ZipFileContent ret[] = new ZipFileContent[this.size()]; - int i = 0; + createZipFileContentChildren(childMap); - for (ZipMap actual : this.values()) { - ret[i++] = actual.zipContent; - } + } - return ret; + map.zipContent.children = children; - } + } - } + @Override + public String toString() { + return this.file.getName() + '/' + this.entry.getName(); + } + + private static class ZipMap extends HashMap { + + private static final long serialVersionUID = 6514645087432837480L; + + ZipFileContent zipContent; + + void setEntry(ZipFile zipFile, ZipEntry entry) { + this.zipContent = new ZipFileContent(zipFile, entry); + } + + ZipFileContent[] getChildren() { + + ZipFileContent ret[] = new ZipFileContent[this.size()]; + int i = 0; + + for (ZipMap actual : this.values()) { + ret[i++] = actual.zipContent; + } + + return ret; + + } + + } } -- cgit v1.2.3