diff options
Diffstat (limited to 'branches/sca-java-1.x/modules/domain-search/src')
52 files changed, 2268 insertions, 235 deletions
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 6a3de9e8c9..269b9a8aae 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 @@ -6,7 +6,7 @@ public interface DocumentProcessor { final public static Document FAKE_DOCUMENT = new Document(); - Document process(DocumentProcessorsMap processors, DocumentMap documents, Object object, Document document, String parent); + 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 19c9e51d8d..d7d35474bd 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 @@ -77,7 +77,7 @@ public class DocumentProcessorsMap extends } - public Document process(DocumentProcessorsMap processors, + public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document document, String parent) { LinkedList<DocumentProcessor> processorsList; @@ -102,7 +102,7 @@ public class DocumentProcessorsMap extends } for (DocumentProcessor processor : processorsList) { - processor.process(processors, documents, object, document, parent); + processor.process(parentProcessor, documents, object, document, parent); } return document; 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 3d26b08d8a..bc347d8cbe 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 @@ -1,5 +1,6 @@ package org.apache.tuscany.sca.domain.search; +import org.apache.lucene.search.Query; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.service.ContributionRepository; import org.osoa.sca.annotations.Remotable; @@ -7,7 +8,9 @@ import org.osoa.sca.annotations.Remotable; @Remotable public interface DomainSearch { + Result[] parseAndSearch(String searchQuery, boolean highlight); + Result[] search(Query searchQuery, boolean hightlight); /** * Notifies the listener that a contribution has been added. 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 new file mode 100644 index 0000000000..9713b7e79d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/Result.java @@ -0,0 +1,22 @@ +package org.apache.tuscany.sca.domain.search; + +import java.io.Serializable; +import java.util.Map; + +public interface Result extends Serializable { + + String getName(); + + void setName(String name); + + Result getContainer(); + + Map<String, Result> getContents(); + + void addContent(Result artifactResult); + + void removeContent(Result artifactResult); + + void setContainer(Result container); + +} 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 new file mode 100644 index 0000000000..073dda6c78 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultFactory.java @@ -0,0 +1,15 @@ +package org.apache.tuscany.sca.domain.search; + +import org.apache.lucene.document.Document; + +public interface ResultFactory<T extends Result> { + + String getType(); + + String getName(Document document); + + T createResult(String name); + + 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 new file mode 100644 index 0000000000..0a2935cde7 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/ResultProcessor.java @@ -0,0 +1,10 @@ +package org.apache.tuscany.sca.domain.search; + +import org.apache.lucene.document.Document; +import org.apache.lucene.search.Query; + +public interface ResultProcessor { + + Result process(Document document, Query query, Result result); + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java index 815f0a20c7..ade97aaaeb 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactDocumentProcessor.java @@ -1,44 +1,63 @@ package org.apache.tuscany.sca.domain.search.impl; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + import org.apache.lucene.document.Field; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; public class ArtifactDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, - DocumentMap documents, Object object, Document document, String parent) { + public Document process(DocumentProcessor parentProcessor, + DocumentMap documents, Object object, Document document, + String parent) { if (object instanceof Artifact) { Artifact artifact = (Artifact) object; String uri = artifact.getURI(); - + if (uri != null && uri.length() == 0) { uri = null; } - + if (uri != null) { - - parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.ARTIFACT_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; - + + parent += DomainPathAnalyzer.PATH_SEPARATOR + + SearchFields.ARTIFACT_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + if (document == null) { document = documents.get(uri); } - + document.add(new Field(SearchFields.ARTIFACT_FIELD, uri, Field.Store.YES, Field.Index.ANALYZED)); - + } - + if (document != null) { + + String location = artifact.getLocation(); - document.add(new Field(SearchFields.LOCATION_FIELD, artifact.getLocation(), + document.add(new Field(SearchFields.LOCATION_FIELD, location, Field.Store.YES, Field.Index.ANALYZED)); - + + try { + Document fileDoc = parentProcessor.process(parentProcessor, + documents, new SystemFileContent(new File(new URL(location).getFile())), document, parent); + + fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } catch (MalformedURLException e) { + // ignore file + } + } - + return document == null ? FAKE_DOCUMENT : document; } @@ -48,21 +67,21 @@ public class ArtifactDocumentProcessor implements DocumentProcessor { } public Object getDocumentKey(Object obj) { - + if (obj instanceof Artifact) { Artifact artifact = (Artifact) obj; String uri = artifact.getURI(); - + if (uri != null && uri.length() == 0) { return null; } - + return uri; - + } - + throw new IllegalArgumentException(); - + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResult.java new file mode 100644 index 0000000000..ace9fde093 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResult.java @@ -0,0 +1,25 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class ArtifactResult extends ResultImpl { + + private static final long serialVersionUID = 7418036586148544103L; + + private String location; + + public ArtifactResult() { + // empty constructor + } + + public ArtifactResult(String name) { + super(name); + } + + public void setLocation(String location) { + this.location = location; + } + + public String getLocation() { + return this.location; + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResultProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResultProcessor.java new file mode 100644 index 0000000000..700e823161 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ArtifactResultProcessor.java @@ -0,0 +1,55 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.tuscany.sca.domain.search.Result; +import org.apache.tuscany.sca.domain.search.ResultFactory; +import org.apache.tuscany.sca.domain.search.ResultProcessor; + +import org.apache.lucene.document.Document; +import org.apache.lucene.search.Query; + +public class ArtifactResultProcessor implements ResultProcessor { + + public Result process(Document document, Query query, Result result) { + + if (result instanceof ArtifactResult) { + String location = document.get(SearchFields.LOCATION_FIELD); + ((ArtifactResult) result).setLocation(location); + + } + + return result; + + } + + public static class ArtifactResultFactory implements ResultFactory<ArtifactResult> { + + public ArtifactResultFactory() { + // empty constructor + } + + public ArtifactResult createResult(String name) { + return new ArtifactResult(name); + } + + public String getName(Document document) { + return document.get(SearchFields.ARTIFACT_FIELD); + } + + public String getType() { + return SearchFields.ARTIFACT_FIELD; + } + + public ArtifactResult createResult(Document document) { + String name = getName(document); + + if (name != null) { + return createResult(name); + } + + return null; + + } + + } + +} 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 5d01bec389..f2eb360c4b 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 @@ -4,11 +4,10 @@ import org.apache.lucene.document.Field; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; public class BindingDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, + public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document document, String parent) { if (object instanceof Binding) { @@ -55,5 +54,5 @@ public class BindingDocumentProcessor implements DocumentProcessor { throw new IllegalArgumentException(); } - + } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResult.java new file mode 100644 index 0000000000..7a2654f05b --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResult.java @@ -0,0 +1,11 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class BindingResult extends ResultImpl { + + private static final long serialVersionUID = 8393058630593239377L; + + public BindingResult(String name) { + super(name); + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResultFactory.java new file mode 100644 index 0000000000..f88548344f --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/BindingResultFactory.java @@ -0,0 +1,36 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Document; +import org.apache.tuscany.sca.domain.search.ResultFactory; + +public class BindingResultFactory implements ResultFactory<BindingResult> { + + public BindingResultFactory() { + // empty constructor + } + + public BindingResult createResult(String name) { + return new BindingResult(name); + } + + public String getType() { + return SearchFields.BINDING_FIELD; + } + + public String getName(Document document) { + return document.get(getType()); + } + + public BindingResult createResult(Document document) { + String name = getName(document); + + if (name != null) { + return createResult(name); + } + + return null; + + + } + +} 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 284791118a..ac7ffbe5b9 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 @@ -7,13 +7,13 @@ import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; +import org.apache.tuscany.sca.domain.search.Result; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; public class ComponentDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, + public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document doc, String parent) { if (object instanceof Component) { @@ -33,7 +33,7 @@ public class ComponentDocumentProcessor implements DocumentProcessor { doc = documents.get(uri); } - parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPONENT_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + 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)); @@ -81,10 +81,10 @@ public class ComponentDocumentProcessor implements DocumentProcessor { } for (ComponentReference reference : component.getReferences()) { - Document serviceDoc = documents.get(uri + ':' + Document referenceDoc = documents.get(uri + ':' + reference.getName()); - serviceDoc.add(new Field(SearchFields.REFERENCE_NAME_FIELD, + referenceDoc.add(new Field(SearchFields.REFERENCE_NAME_FIELD, reference.getName(), Field.Store.YES, Field.Index.ANALYZED)); @@ -96,7 +96,7 @@ public class ComponentDocumentProcessor implements DocumentProcessor { for (Operation operation : interfaceContract .getInterface().getOperations()) { - serviceDoc.add(new Field( + referenceDoc.add(new Field( SearchFields.REFERENCE_INTERFACE_FIELD, operation.getName(), Field.Store.YES, Field.Index.ANALYZED)); @@ -106,7 +106,7 @@ public class ComponentDocumentProcessor implements DocumentProcessor { for (Operation operation : interfaceContract .getCallbackInterface().getOperations()) { - serviceDoc + referenceDoc .add(new Field( SearchFields.REFERENCE_INTERFACE_CALLBACK_FIELD, operation.getName(), @@ -117,26 +117,26 @@ public class ComponentDocumentProcessor implements DocumentProcessor { } - serviceDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + referenceDoc.add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); } } - Document implementationDoc = processors.process(processors, + Document implementationDoc = parentProcessor.process(parentProcessor, documents, component.getImplementation(), null, parent); if (uri != null && implementationDoc != null) { - implementationDoc.add(new Field(SearchFields.IMPLEMENTS_FIELD, + implementationDoc.add(new Field(SearchFields.PARENT_FIELD, uri, Field.Store.YES, Field.Index.ANALYZED)); - + } for (ComponentProperty componentProperty : component .getProperties()) { - Document propertyDoc = processors.process(processors, + Document propertyDoc = parentProcessor.process(parentProcessor, documents, componentProperty.getProperty(), null, parent); if (uri != null) { @@ -176,4 +176,17 @@ public class ComponentDocumentProcessor implements DocumentProcessor { } + public Result processDocument(org.apache.lucene.document.Document document, Result result) { + String componentName = document.get(SearchFields.COMPONENT_FIELD); + + if (componentName != null) { + + + + } + + return null; + + } + } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResult.java new file mode 100644 index 0000000000..012715a7ea --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResult.java @@ -0,0 +1,16 @@ +package org.apache.tuscany.sca.domain.search.impl; + + +public class ComponentResult extends ResultImpl { + + private static final long serialVersionUID = -2171168107785499573L; + + public ComponentResult() { + // empty constructor + } + + public ComponentResult(String name) { + super(name); + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResultFactory.java new file mode 100644 index 0000000000..61e734d725 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentResultFactory.java @@ -0,0 +1,35 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Document; +import org.apache.tuscany.sca.domain.search.ResultFactory; + +public class ComponentResultFactory implements ResultFactory<ComponentResult> { + + public ComponentResultFactory() { + // empty constructor + } + + public ComponentResult createResult(String name) { + return new ComponentResult(name); + } + + public String getName(Document document) { + return document.get(getType()); + } + + public String getType() { + return SearchFields.COMPONENT_FIELD; + } + + public ComponentResult createResult(Document document) { + String name = getName(document); + + if (name != null) { + return createResult(name); + } + + 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 b110ce769d..68453fcb0b 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 @@ -7,13 +7,12 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; public class ComponentTypeDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, + public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document doc, String parent) { if (object instanceof ComponentType) { @@ -131,7 +130,7 @@ public class ComponentTypeDocumentProcessor implements DocumentProcessor { } for (Property property : componentType.getProperties()) { - Document propertyDoc = processors.process(processors, + Document propertyDoc = parentProcessor.process(parentProcessor, documents, property, null, parent); if (uri != null) { diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResult.java new file mode 100644 index 0000000000..bc7112cf47 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResult.java @@ -0,0 +1,15 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class ComponentTypeResult extends ResultImpl { + + private static final long serialVersionUID = 3767144511814116732L; + + public ComponentTypeResult() { + // empty constructor + } + + public ComponentTypeResult(String name) { + super(name); + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResultFactory.java new file mode 100644 index 0000000000..d486870078 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ComponentTypeResultFactory.java @@ -0,0 +1,36 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Document; +import org.apache.tuscany.sca.domain.search.ResultFactory; + +public class ComponentTypeResultFactory implements + ResultFactory<ComponentTypeResult> { + + public ComponentTypeResultFactory() { + // empty constructor + } + + public String getName(Document document) { + return document.get(getType()); + } + + public String getType() { + return SearchFields.COMPONENT_TYPE_FIELD; + } + + public ComponentTypeResult createResult(String name) { + return new ComponentTypeResult(name); + } + + public ComponentTypeResult createResult(Document document) { + String name = getName(document); + + if (name != null) { + return createResult(name); + } + + return null; + + } + +} 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 27e1e9b087..f28d876d2e 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 @@ -7,11 +7,10 @@ import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; public class CompositeDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, + public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document doc, String parent) { if (object instanceof Composite) { @@ -25,15 +24,16 @@ public class CompositeDocumentProcessor implements DocumentProcessor { uri = null; } else if (doc == null) { - doc = documents.get(uri); - parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPOSITE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; - + doc = documents.get(uri); + } + + if (uri != null) { + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.COMPOSITE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + composite.getURI() + DomainPathAnalyzer.URI_SEPARATOR + composite.getName(); } for (Component component : composite.getComponents()) { - - Document componentDoc = processors.process(processors, + Document componentDoc = parentProcessor.process(parentProcessor, documents, component, null, parent); if (uri != null) { @@ -47,13 +47,13 @@ public class CompositeDocumentProcessor implements DocumentProcessor { if (uri != null) { - doc.add(new Field(SearchFields.COMPOSITE_FIELD, uri.toString(), + doc.add(new Field(SearchFields.COMPOSITE_FIELD, uri, Field.Store.YES, Field.Index.ANALYZED)); } for (Composite include : composite.getIncludes()) { - Document compositeDoc = processors.process(processors, + Document compositeDoc = parentProcessor.process(parentProcessor, documents, include, null, parent); if (uri != null) { @@ -66,7 +66,7 @@ public class CompositeDocumentProcessor implements DocumentProcessor { } for (Component component : composite.getComponents()) { - Document componentDoc = processors.process(processors, + Document componentDoc = parentProcessor.process(parentProcessor, documents, component, null, parent); if (uri != null) { @@ -102,5 +102,5 @@ public class CompositeDocumentProcessor implements DocumentProcessor { throw new IllegalArgumentException(); } - + } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResult.java new file mode 100644 index 0000000000..8dd96de288 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResult.java @@ -0,0 +1,15 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class CompositeResult extends ResultImpl { + + private static final long serialVersionUID = -4651241874173649592L; + + public CompositeResult() { + // empty constructor + } + + public CompositeResult(String name) { + super(name); + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResultFactory.java new file mode 100644 index 0000000000..9b4acefc8c --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/CompositeResultFactory.java @@ -0,0 +1,35 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Document; +import org.apache.tuscany.sca.domain.search.ResultFactory; + +public class CompositeResultFactory implements ResultFactory<CompositeResult> { + + public CompositeResultFactory() { + // empty constructor + } + + public CompositeResult createResult(String name) { + return new CompositeResult(name); + } + + public String getName(Document document) { + return document.get(getType()); + } + + public String getType() { + return SearchFields.COMPOSITE_FIELD; + } + + public CompositeResult createResult(Document document) { + String name = getName(document); + + if (name != null) { + return createResult(name); + } + + return null; + + } + +} 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 86e0e98f95..615a84b6dc 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 @@ -7,31 +7,35 @@ import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; +import org.apache.tuscany.sca.domain.search.Result; public class ContributionDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, + 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 (uri != null) { - + if (uri.length() == 0) { uri = null; - + } else { - parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.CONTRIBUTION_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + + parent += DomainPathAnalyzer.PATH_SEPARATOR + + SearchFields.CONTRIBUTION_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + } - + } - + if (uri != null && doc == null) { doc = documents.get(uri); - + doc.add(new Field(SearchFields.CONTRIBUTION_FIELD, uri, Field.Store.YES, Field.Index.ANALYZED)); @@ -40,52 +44,56 @@ public class ContributionDocumentProcessor implements DocumentProcessor { } for (Artifact artifact : contribution.getArtifacts()) { - Document artifactDoc = processors.process(processors, + Document artifactDoc = parentProcessor.process(parentProcessor, documents, artifact, null, parent); if (uri != null) { - artifactDoc.add(new Field(SearchFields.PARENT_FIELD, parent, - Field.Store.YES, Field.Index.ANALYZED)); + artifactDoc.add(new Field(SearchFields.PARENT_FIELD, + parent, Field.Store.YES, Field.Index.ANALYZED)); } } -// for (Import imprt : contribution.getImports()) { -// Document importDoc = processors.process(processors, documents, -// imprt, null); -// -// if (uri != null) { -// -// importDoc.add(new Field(SearchFields.IMPORTEDBY_FIELD, uri, -// Field.Store.YES, Field.Index.ANALYZED)); -// -// } -// -// } -// -// for (Export export : contribution.getExports()) { -// Document exportDoc = processors.process(processors, documents, -// export, null); -// -// if (uri != null) { -// -// exportDoc.add(new Field(SearchFields.EXPORTEDBY_FIELD, uri, -// Field.Store.YES, Field.Index.ANALYZED)); -// -// } -// -// } - - for (Composite composite : contribution.getDeployables()) { - Document compositeDoc = processors.process(processors, - documents, composite, null, parent); - - if (uri != null) { - - compositeDoc.add(new Field(SearchFields.PARENT_FIELD, parent, - Field.Store.YES, Field.Index.ANALYZED)); + // 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 (Composite composite : contribution.getDeployables()) { + Document compositeDoc = parentProcessor.process(parentProcessor, + documents, composite, null, parent); + + if (uri != null) { + + compositeDoc.add(new Field(SearchFields.PARENT_FIELD, + parent, Field.Store.YES, Field.Index.ANALYZED)); + + } } @@ -100,21 +108,42 @@ public class ContributionDocumentProcessor implements DocumentProcessor { } public Object getDocumentKey(Object object) { - + if (object instanceof Contribution) { Contribution contribution = (Contribution) object; String uri = contribution.getURI(); - + if (uri != null && uri.length() == 0) { return null; } - + return uri; - + } - + throw new IllegalArgumentException(); - + + } + + public Result processDocument(org.apache.lucene.document.Document document, + Result result) { + String contributionName = document.get(SearchFields.CONTRIBUTION_FIELD); + + if (contributionName != null) { + + if (result == null) { + result = new ContributionResult(contributionName); + + } else if (!(result instanceof ContributionResult)) { + throw new IllegalArgumentException(); + } + + result.setName(contributionName); + + } + + return result; + } } diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResult.java new file mode 100644 index 0000000000..f4abc62319 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResult.java @@ -0,0 +1,15 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class ContributionResult extends ArtifactResult { + + private static final long serialVersionUID = 4508196828816188213L; + + public ContributionResult() { + // empty constructor + } + + public ContributionResult(String name) { + super(name); + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResultFactory.java new file mode 100644 index 0000000000..c2ac77ed43 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionResultFactory.java @@ -0,0 +1,36 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Document; +import org.apache.tuscany.sca.domain.search.ResultFactory; + +public class ContributionResultFactory implements + ResultFactory<ContributionResult> { + + public ContributionResultFactory() { + // empty constructor + } + + public ContributionResult createResult(String name) { + return new ContributionResult(name); + } + + public String getName(Document document) { + return document.get(SearchFields.CONTRIBUTION_FIELD); + } + + public String getType() { + return SearchFields.CONTRIBUTION_FIELD; + } + + public ContributionResult createResult(Document document) { + String name = getName(document); + + if (name != null) { + return createResult(name); + } + + return null; + + } + +} 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 new file mode 100644 index 0000000000..d4a23693d4 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DefaultFileDocumentProcessor.java @@ -0,0 +1,63 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.domain.search.DocumentMap; +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_FIELD, file.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + doc.add(new Field(SearchFields.FILE_CONTENT_FIELD, reader)); + + 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/DirectoryDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java index 95d008250b..b25e292322 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DirectoryDocumentProcessor.java @@ -5,11 +5,10 @@ import java.io.File; import org.apache.lucene.document.Field; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; public class DirectoryDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, + public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document doc, String parent) { if (object instanceof File) { @@ -25,7 +24,7 @@ public class DirectoryDocumentProcessor implements DocumentProcessor { File[] files = file.listFiles(); for (File childFile : files) { - Document fileDoc = processors.process(processors, documents, childFile, null, parent); + Document fileDoc = parentProcessor.process(parentProcessor, documents, childFile, null, parent); fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); 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 8a1aac2cd5..02cf097874 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 @@ -3,29 +3,52 @@ package org.apache.tuscany.sca.domain.search.impl; import java.util.Collection; import java.util.Collections; import java.util.Hashtable; +import java.util.LinkedList; import org.apache.lucene.document.Fieldable; public class Document { private Hashtable<String, Hashtable<String, Fieldable>> fieldablesTable = new Hashtable<String, Hashtable<String, Fieldable>>(); + + private Hashtable<String, LinkedList<Fieldable>> readerMap = new Hashtable<String, LinkedList<Fieldable>>();; public Document() { // empty constructor } public void add(Fieldable fieldable) { - Hashtable<String, Fieldable> fieldables = this.fieldablesTable - .get(fieldable.name()); + + String strValue = fieldable.stringValue(); + + if (strValue != null) { + + Hashtable<String, Fieldable> fieldables = this.fieldablesTable + .get(fieldable.name()); + + if (fieldables == null) { + fieldables = new Hashtable<String, Fieldable>(); + this.fieldablesTable.put(fieldable.name(), fieldables); - if (fieldables == null) { - fieldables = new Hashtable<String, Fieldable>(); - this.fieldablesTable.put(fieldable.name(), fieldables); + } + + fieldables.put(strValue, fieldable); + + } else { + + LinkedList<Fieldable> fieldables = this.readerMap + .get(fieldable.name()); + + if (fieldables == null) { + fieldables = new LinkedList<Fieldable>(); + this.readerMap.put(fieldable.name(), fieldables); + } + + fieldables.add(fieldable); + } - fieldables.put(fieldable.stringValue(), fieldable); - } public org.apache.lucene.document.Document createLuceneDocument() { @@ -39,6 +62,14 @@ public class Document { } + for (LinkedList<Fieldable> fieldables : this.readerMap.values()) { + + for (Fieldable fieldable : fieldables) { + doc.add(fieldable); + } + + } + return doc; } @@ -50,7 +81,7 @@ public class Document { return fieldables.keySet(); } - return Collections.EMPTY_LIST; + return Collections.emptyList(); } 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 9255f49eef..b17d22d68a 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 @@ -14,6 +14,8 @@ public class DomainPathAnalyzer extends Analyzer { final public static char TYPE_SEPARATOR = '\u0002'; + final public static char URI_SEPARATOR = '\u0003'; + static class DomainPathTokenizer extends Tokenizer { private int offset = 0, bufferIndex = 0, dataLen = 0; @@ -21,25 +23,28 @@ public class DomainPathAnalyzer extends Analyzer { 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; public DomainPathTokenizer(Reader reader) { super(reader); } - + @Override public void reset() throws IOException { super.reset(); - + typeCharFound = false; - + uriCharFound = false; + } - + @Override public void reset(Reader input) throws IOException { super.reset(input); - + + uriCharFound = false; typeCharFound = false; - + } @Override @@ -52,7 +57,7 @@ public class DomainPathAnalyzer extends Analyzer { boolean lowercaseCharFound = false; boolean digitFound = false; - + while (true) { if (bufferIndex >= dataLen) { @@ -94,15 +99,17 @@ public class DomainPathAnalyzer extends Analyzer { } else { bufferIndex--; } - + typeCharFound = false; + uriCharFound = false; - } else if (c == TYPE_SEPARATOR && !typeCharFound) { + } else if (c == TYPE_SEPARATOR && !typeCharFound + || c == URI_SEPARATOR && !uriCharFound) { length = 0; breakChar = false; lowercaseCharFound = false; digitFound = false; - + } else { if (Character.isDigit(c)) { @@ -154,12 +161,18 @@ public class DomainPathAnalyzer extends Analyzer { if (c == TYPE_SEPARATOR && !typeCharFound) { typeCharFound = true; - + + } else if (c == URI_SEPARATOR && !uriCharFound) { + typeCharFound = true; + } else { - buffer[length++] = Character.toLowerCase(c); // buffer it, normalized + buffer[length++] = Character.toLowerCase(c); // buffer + // it, + // normalized } - - if (length == MAX_WORD_LEN || (breakChar && length > 0)) // buffer overflow! + + if (length == MAX_WORD_LEN || (breakChar && length > 0)) // buffer + // overflow! break; } else if (length > 0) {// at non-Letter w/ chars 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 66c2898ebd..4aeb431964 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 @@ -1,5 +1,7 @@ package org.apache.tuscany.sca.domain.search.impl; +import java.io.File; + import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentType; @@ -21,6 +23,7 @@ public class DomainSearchDocumentProcessorsMap extends DocumentProcessorsMap { addDocumentProcessor(Binding.class, new BindingDocumentProcessor()); addDocumentProcessor(Component.class, new ComponentDocumentProcessor()); addDocumentProcessor(Composite.class, new CompositeDocumentProcessor()); + addDocumentProcessor(File.class, new DomainSearchFileDocumentProcessor()); } 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 new file mode 100644 index 0000000000..2675de4807 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java @@ -0,0 +1,13 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class DomainSearchFileDocumentProcessor extends FileDocumentProcessor { + + private static final long serialVersionUID = -2725616937948969598L; + + 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 new file mode 100644 index 0000000000..2537066b92 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java @@ -0,0 +1,30 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.search.highlight.Formatter; +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; + } + + } + +} 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 56b375685b..332bd249e1 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 @@ -1,8 +1,6 @@ package org.apache.tuscany.sca.domain.search.impl; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.util.List; import org.apache.lucene.analysis.Analyzer; @@ -21,91 +19,65 @@ import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.service.ContributionRepository; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DomainSearch; +import org.apache.tuscany.sca.domain.search.Result; import org.osoa.sca.annotations.AllowsPassByReference; +import org.osoa.sca.annotations.Scope; +@Scope("COMPOSITE") public class DomainSearchImpl implements DomainSearch { + private Directory dir = new RAMDirectory(); + + private Analyzer analyzer = new DomainSearchAnalyzer(); + + public DomainSearchImpl() { + // empty constructor + } + @AllowsPassByReference public void contributionAdded(ContributionRepository repository, Contribution contribution) { System.out.println("contributionAdded:"); System.out.println(repository); System.out.println(contribution); - + try { - Directory dir = new RAMDirectory(); - Analyzer analyzer = new DomainSearchAnalyzer(); - IndexWriter indexWriter = new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); - DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap(); - DocumentMap docs = new DocumentMap(); - - docProcessors.process(docProcessors, docs, contribution, null, ""); - - for (Document doc : docs.values()) { - indexWriter.addDocument(doc.createLuceneDocument()); - } - - indexWriter.close(); - - final IndexSearcher searcher = new IndexSearcher(dir); - BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in)); - QueryParser qp = new QueryParser("", analyzer); - - qp.setAllowLeadingWildcard(true); - - while (true) { - System.out.print("query: "); - String queryString = consoleReader.readLine(); - - if (queryString.equals("exit")) { - break; - } - + IndexWriter indexWriter = new IndexWriter(dir, analyzer, + IndexWriter.MaxFieldLength.UNLIMITED); + + try { + DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap(); + DocumentMap docs = new DocumentMap(); + try { - Query query = qp.parse(queryString); - - searcher.search(query, new HitCollector() { - - @Override - public void collect(int doc, float score) { - try { - org.apache.lucene.document.Document document = searcher.doc(doc); - List<?> fields = document.getFields(); - System.out.println("---------"); - System.out.println("doc = " + doc); - - for (Object obj : fields) { - Field field = (Field) obj; - String[] values = document.getValues(field.name()); - System.out.println(field); - - for (String value : values) { - System.out.println("\t" + value); - } - - } - - } catch (CorruptIndexException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - }); - - } catch (ParseException e) { - System.out.println(e.getMessage()); + docProcessors.process(docProcessors, docs, contribution, null, ""); + } catch (Exception e) { + e.printStackTrace(); } - - System.out.println(); - + + for (Document doc : docs.values()) { + indexWriter.addDocument(doc.createLuceneDocument()); + } + + } finally { + indexWriter.close(); } - - - + + // 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); + // + // } + } catch (CorruptIndexException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -116,7 +88,7 @@ public class DomainSearchImpl implements DomainSearch { // TODO Auto-generated catch block e.printStackTrace(); } - + } public void contributionRemoved(ContributionRepository repository, @@ -124,17 +96,100 @@ public class DomainSearchImpl implements DomainSearch { 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); - + + } + + @SuppressWarnings("deprecation") + public Result[] parseAndSearch(String searchQuery, boolean highlight) { + + try { + final IndexSearcher searcher = new IndexSearcher(dir); + final DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor( + new DomainSearchResultFactory()); + + QueryParser qp = new QueryParser("", analyzer); + + qp.setAllowLeadingWildcard(true); + + try { + final Query query = qp.parse(searchQuery); + + searcher.search(query, new HitCollector() { + + @Override + public void collect(int doc, float score) { + try { + org.apache.lucene.document.Document document = searcher + .doc(doc); + + resultProcessor.process(document, query, null); + + List<?> fields = document.getFields(); + System.out.println("---------"); + System.out.println("doc = " + doc); + + for (Object obj : fields) { + Field field = (Field) obj; + String[] values = document.getValues(field + .name()); + System.out.println(field); + + for (String value : values) { + System.out.println("\t" + value); + } + + } + + } catch (CorruptIndexException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + }); + + } catch (ParseException e) { + System.out.println(e.getMessage()); + } + + Result[] results = resultProcessor.getResultRoots(); + + // for (Result result : results) { + // System.out.println(result); + // } + + System.out.println(); + + return results; + + } catch (CorruptIndexException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + return null; + + } + + public Result[] search(Query searchQuery, boolean hightlight) { + // 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/DomainSearchResultFactory.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java new file mode 100644 index 0000000000..f20d2bb586 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java @@ -0,0 +1,18 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class DomainSearchResultFactory extends ResultFactoryList { + + private static final long serialVersionUID = -7421799172738469027L; + + public DomainSearchResultFactory() { + add(new ContributionResultFactory()); + add(new CompositeResultFactory()); + add(new ComponentResultFactory()); + add(new ComponentTypeResultFactory()); + add(new ArtifactResultProcessor.ArtifactResultFactory()); + add(new BindingResultFactory()); + add(new FileContentResultProcessor.FileContentResultFactory()); + + } + +} 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 new file mode 100644 index 0000000000..760f9a6bc2 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java @@ -0,0 +1,20 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.tuscany.sca.domain.search.Result; +import org.apache.tuscany.sca.domain.search.ResultFactory; + +public class DomainSearchResultProcessor extends ResultProcessorList { + + private static final long serialVersionUID = 792292814333612713L; + + public DomainSearchResultProcessor( + ResultFactory<? extends Result> resultFactory) { + + super(new DomainSearchResultFactory()); + + add(new ArtifactResultProcessor()); + 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 new file mode 100644 index 0000000000..8b57080551 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java @@ -0,0 +1,18 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.IOException; +import java.io.InputStream; + +public interface FileContent { + + 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/FileContentResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResult.java new file mode 100644 index 0000000000..1e5d3aec7a --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResult.java @@ -0,0 +1,25 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class FileContentResult extends ResultImpl { + + private static final long serialVersionUID = 950227008096181276L; + + private String content; + + public FileContentResult() { + // empty constructor + } + + public FileContentResult(String name) { + super(name); + } + + public void setContent(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + +} 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 new file mode 100644 index 0000000000..e20a170e19 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java @@ -0,0 +1,116 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.lucene.document.Document; +import org.apache.lucene.search.Query; +import org.apache.tuscany.sca.domain.search.Result; +import org.apache.tuscany.sca.domain.search.ResultFactory; +import org.apache.tuscany.sca.domain.search.ResultProcessor; + +public class FileContentResultProcessor implements ResultProcessor { + + public static class FileContentResultFactory implements + ResultFactory<FileContentResult> { + + public FileContentResultFactory() { + // empty constructor + } + + public FileContentResult createResult(String name) { + return new FileContentResult(name); + } + + public String getName(Document document) { + return document.get(SearchFields.FILE_FIELD); + } + + public String getType() { + return SearchFields.FILE_FIELD; + } + + public FileContentResult createResult(Document document) { + String name = getName(document); + + if (name != null) { + return createResult(name); + } + + return null; + + } + + } + + public Result process(Document document, Query query, Result result) { + + if (result instanceof FileContentResult) { + FileContentResult fileContentResult = (FileContentResult) result; + Reader reader; + + ParentField parentField = new ParentField(document + .get(SearchFields.PARENT_FIELD)); + String parentURI = parentField.getElementURI(parentField + .getElementsCount() - 1); + String name = document.get(SearchFields.FILE_FIELD); + + if (name == null) { + return result; + } + + if (parentURI.indexOf(ZipDocumentProcessor.ARCHIVE_SEPARATOR) != -1) { + String[] locations = parentURI.split(Character + .toString(ZipDocumentProcessor.ARCHIVE_SEPARATOR)); + + try { + ZipFile zip = new ZipFile(new File(locations[0])); + + // TODO: normalize the entry path and check if the entry still exists + ZipEntry entry = zip.getEntry(locations[1].substring(1) + name); + + Enumeration<? extends ZipEntry> entries = zip.entries(); + + while (entries.hasMoreElements()) System.out.println(entries.nextElement().getName()); + + reader = new InputStreamReader(zip.getInputStream(entry)); + + } catch (IOException e) { + return result; + } + + } else { + + try { + reader = new InputStreamReader(new FileInputStream( + new File(parentURI + '/' + name))); + + } catch (FileNotFoundException e) { + return result; + } + + } + + try { + fileContentResult.setContent(HighlightingUtil + .bestFragmentHighlighted(query, reader)); + + } catch (IOException e) { + // ignore content loading, TODO: maybe it return an error + // message as the content + } + + } + + 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 27eb52d659..138c9c42e9 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 @@ -1,50 +1,86 @@ package org.apache.tuscany.sca.domain.search.impl; -import java.io.File; +import java.util.LinkedList; import org.apache.lucene.document.Field; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; -public class FileDocumentProcessor implements DocumentProcessor { +public class FileDocumentProcessor extends LinkedList<DocumentProcessor> + implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, + private static final long serialVersionUID = 7843338343970738591L; + + public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document doc, String parent) { - if (object instanceof File) { - File file = (File) object; - documents.get(file.getAbsoluteFile()); - - if (file.isFile()) { - doc.add(new Field(SearchFields.DIRECTORY_FIELD, file.getAbsolutePath(), - Field.Store.YES, Field.Index.ANALYZED)); - - parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.FILE_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + file.getName(); - - File[] files = file.listFiles(); - - for (File childFile : files) { - Document fileDoc = processors.process(processors, documents, childFile, null, parent); - + if (object instanceof FileContent) { + FileContent file = (FileContent) object; + + if (!file.isLeaf()) { + + if (doc == null) { + doc = documents.get(file.getPath()); + } + + doc.add(new Field(SearchFields.DIRECTORY_FIELD, file + .getPath(), Field.Store.YES, + Field.Index.ANALYZED)); + + parent += DomainPathAnalyzer.PATH_SEPARATOR + + SearchFields.FILE_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + file.getPath() + + DomainPathAnalyzer.URI_SEPARATOR + file.getName(); + + FileContent[] files = file.getChildren(); + + for (FileContent childFile : files) { + Document fileDoc = parentProcessor.process(parentProcessor, + documents, childFile, null, parent); + fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent, Field.Store.YES, Field.Index.ANALYZED)); - + } + return doc; + + } else { + + for (DocumentProcessor processor : this) { + Document newDoc = processor.process(this, documents, + object, doc, parent); + + if (newDoc != null) { + return newDoc; + } + + } + } - - return doc; } - - throw new IllegalArgumentException(); + + return doc; } public Object getDocumentKey(Object object) { - // TODO Auto-generated method stub - return null; + + if (object instanceof FileContent) { + FileContent file = (FileContent) 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/HighlightingUtil.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java new file mode 100644 index 0000000000..0703438125 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java @@ -0,0 +1,132 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; + +import org.apache.lucene.analysis.CachingTokenFilter; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.highlight.Highlighter; +import org.apache.lucene.search.highlight.InvalidTokenOffsetsException; +import org.apache.lucene.search.highlight.SimpleFragmenter; +import org.apache.lucene.search.highlight.SpanScorer; + +final public class HighlightingUtil { + + public static String bestFragmentHighlighted(Query query, Reader reader) throws IOException { + StringBuilder sb = new StringBuilder(); + int c; + + // TODO: load the chars into a buffer instead of one at a time + while ((c = reader.read()) != -1) { + char character = (char) c; + + if (!Character.isIdentifierIgnorable(character)) { + sb.append(character); + } + + } + + String text = sb.toString(); + + CachingTokenFilter tokenStream = new CachingTokenFilter(new NamingAnalyzer().tokenStream( + SearchFields.FILE_CONTENT_FIELD, new StringReader(text))); + + Highlighter highlighter = new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, SearchFields.FILE_CONTENT_FIELD, tokenStream, "")); + highlighter.setTextFragmenter(new SimpleFragmenter(100)); + 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/ParentField.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java new file mode 100644 index 0000000000..11885909e1 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java @@ -0,0 +1,184 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class ParentField implements Serializable { + + private static final long serialVersionUID = -2090538050273088026L; + + final private List<ParentFieldElement> elements; + + public ParentField(String parentFieldValue) { + int length = parentFieldValue.length(); + + if (length == 0) { + this.elements = Collections.emptyList(); + + return; + + } + + this.elements = new ArrayList<ParentFieldElement>(); + + ParentFieldElement element = null; + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < length ; i++) { + char c = parentFieldValue.charAt(i); + + if (c == DomainPathAnalyzer.PATH_SEPARATOR) { + + 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/PropertyDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java index 0a0ff9ceeb..30885dca0e 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 @@ -6,11 +6,10 @@ import org.apache.lucene.document.Field; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.domain.search.DocumentMap; import org.apache.tuscany.sca.domain.search.DocumentProcessor; -import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; public class PropertyDocumentProcessor implements DocumentProcessor { - public Document process(DocumentProcessorsMap processors, + public Document process(DocumentProcessor parentProcessor, DocumentMap documents, Object object, Document doc, String parent) { if (object instanceof Property) { diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyResult.java new file mode 100644 index 0000000000..361279e62d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyResult.java @@ -0,0 +1,20 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class PropertyResult extends ResultImpl { + + private static final long serialVersionUID = 5744678253277504237L; + + private String[] values; + + public PropertyResult(String name, String... values) { + super(name); + + this.values = values; + + } + + public String[] getValues() { + return this.values.clone(); + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ReferenceResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ReferenceResult.java new file mode 100644 index 0000000000..fbd724ce2d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ReferenceResult.java @@ -0,0 +1,27 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class ReferenceResult extends ResultImpl { + + private static final long serialVersionUID = -2846199490484466090L; + + private String[] operations; + + private String[] callbackOperations; + + public ReferenceResult(String name, String[] operations, String[] callbackOperations) { + super(name); + + this.operations = operations; + this.callbackOperations = callbackOperations; + + } + + public String[] getOperations() { + return this.operations.clone(); + } + + public String[] getCallbackOperations() { + return this.callbackOperations.clone(); + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultFactoryList.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultFactoryList.java new file mode 100644 index 0000000000..c2a4edc7f0 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultFactoryList.java @@ -0,0 +1,55 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.util.LinkedList; + +import org.apache.lucene.document.Document; +import org.apache.tuscany.sca.domain.search.Result; +import org.apache.tuscany.sca.domain.search.ResultFactory; + +public class ResultFactoryList extends LinkedList<ResultFactory<? extends Result>> implements ResultFactory<Result> { + + private static final long serialVersionUID = 6806221945324235828L; + + public ResultFactoryList() { + // empty constructor + } + + public Result createResult(Document document) { + + for (ResultFactory<? extends Result> resultFactory : this) { + Result result = resultFactory.createResult(document); + + if (result != null) { + return result; + } + + } + + return null; + + } + + public Result createResult(String name) { + return null; + } + + public String getName(Document document) { + + for (ResultFactory<? extends Result> resultFactory : this) { + String name = resultFactory.getName(document); + + if (name != null) { + return name; + } + + } + + return null; + + } + + public String getType() { + return ""; + } + +} 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 new file mode 100644 index 0000000000..aef4a8e53c --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java @@ -0,0 +1,251 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.lang.reflect.Array; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.domain.search.Result; + +public abstract class ResultImpl implements Result { + + private static final long serialVersionUID = 7084570994751217396L; + + private Result container; + + private HashMap<String, Result> contents; + + private String name; + + public ResultImpl() { + // empty constructor + } + + public ResultImpl(String name) { + this.name = name; + } + + public Result getContainer() { + return this.container; + } + + public Map<String, Result> getContents() { + + if (this.contents == null) { + return Collections.emptyMap(); + } + + return Collections.unmodifiableMap(this.contents); + + } + + public String getName() { + return this.name; + } + + public void setContainer(Result container) { + + if (container != this.container) { + + if (this.container != null) { + this.container.removeContent(this); + } + + this.container = container; + + if (container != null) { + container.addContent(this); + } + + } + + } + + @Override + public boolean equals(Object obj) { + + if (obj instanceof Result) { + Result artifactResult = (Result) obj; + + if (artifactResult.getName() == this.name || this.name != null + && this.name.equals(artifactResult.getName())) { + + if (artifactResult.getContainer() == this.container + || this.container != null + && this.container.equals(artifactResult.getContainer())) { + + Map<String, Result> contents = artifactResult.getContents(); + + if (this.contents == null) { + return contents.isEmpty(); + + } else if (this.contents.equals(contents)) { + return true; + } + + } + + } + + } + + return false; + + } + + public void addContent(Result artifactResult) { + internalGetContents().put(artifactResult.getName(), artifactResult); + + if (artifactResult.getContainer() != this) { + artifactResult.setContainer(this); + } + + } + + private HashMap<String, Result> internalGetContents() { + + if (this.contents == null) { + this.contents = new HashMap<String, Result>(); + } + + return this.contents; + + } + + public void removeContent(Result artifactResult) { + + if (this.contents != null) { + this.contents.remove(artifactResult); + + artifactResult.setContainer(null); + + if (this.contents.isEmpty()) { + this.contents = null; + } + + } + + } + + @Override + public int hashCode() { + int hash = 11; + + 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.name == null ? 17 : this.name.hashCode()); + + return hash; + + } + + public void setName(String name) { + this.name = name; + } + + public String toString() { + StringBuilder sb = new StringBuilder("<"); + Result container = getContainer(); + + sb.append(getClass().getName()).append(" name='").append(getName()) + .append("' container='").append(container != null ? container.getName() : null).append("'>\n"); + + Method[] methods = getClass().getMethods(); + + for (Method method : methods) { + String methodName = method.getName(); + + if (method.getReturnType() != void.class) { + + if (method.getParameterTypes().length == 0) { + + if (methodName.startsWith("get") + && !"getName".equals(methodName) + && !"getContainer".equals(methodName)) { + + try { + Object returnedObj = method.invoke(this); + + sb.append('\t'); + + if (returnedObj instanceof Map<?, ?>) { + + sb.append("<collection type='").append( + returnedObj.getClass() + .getGenericInterfaces()[1]) + .append("'>\n"); + + for (Object obj : ((Map<?, ?>) returnedObj).values()) { + + sb.append("\t\t").append(obj.toString()) + .append("\n"); + + } + + sb.append("\t</collection>\n"); + + } else if (returnedObj instanceof Collection<?>) { + + sb.append("<collection type='").append( + returnedObj.getClass() + .getGenericInterfaces()[0]) + .append("'>\n"); + + for (Object obj : (Collection<?>) returnedObj) { + + sb.append("\t\t").append(obj.toString()) + .append("\n"); + + } + + sb.append("\t</collection>\n"); + + } else if (returnedObj.getClass().isArray()) { + + sb.append("<array type='").append( + returnedObj.getClass() + .getComponentType()) + .append("'>\n"); + + int length = Array.getLength(returnedObj); + + for (int i = 0 ; i < length ; i++) { + + sb.append("\t\t").append(Array.get(returnedObj, i).toString()) + .append("\n"); + + } + + sb.append("\t</array>\n"); + + } else { + + sb.append('\t').append(returnedObj).append('\n'); + + } + + } catch (Throwable e) { + // ignore exceptions and don't print the object + } + + } + + } + + } + + } + + sb.append("</").append(getClass().getName()).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 new file mode 100644 index 0000000000..e186bdd6d0 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java @@ -0,0 +1,148 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.util.HashMap; +import java.util.LinkedList; + +import org.apache.lucene.document.Document; +import org.apache.lucene.search.Query; +import org.apache.tuscany.sca.domain.search.Result; +import org.apache.tuscany.sca.domain.search.ResultFactory; +import org.apache.tuscany.sca.domain.search.ResultProcessor; + +public class ResultProcessorList extends LinkedList<ResultProcessor> implements ResultProcessor { + + private static final long serialVersionUID = 7147307292452694895L; + + private ResultFactoryList resultFactoryList; + + private HashMap<String, ResultHashMap> resultRoots = new HashMap<String, ResultHashMap>(); + + public ResultProcessorList(ResultFactoryList resultFactoryList) { + this.resultFactoryList = resultFactoryList; + } + + public Result process(Document document, Query query, Result result) { + + if (result == null) { + result = this.resultFactoryList.createResult(document); + } + + if (result == null) { + return null; + } + + ResultHashMap resultHashMap; + + String parent = document.get(SearchFields.PARENT_FIELD); + + if (parent == null) { + resultHashMap = new ResultHashMap(result); + resultRoots.put(result.getName(), resultHashMap); + + } else { + + ParentField parentField = new ParentField(parent); + HashMap<String, ResultHashMap> current = this.resultRoots; + Result currentResult = null; + int elementsCount = parentField.getElementsCount(); + + for (int i = 0 ; i < elementsCount ; i++) { + String actualURI = parentField.getElementURI(i); + String type = parentField.getElementType(i); + + if (actualURI.length() > 0) { + ResultHashMap actualResultHashMap = current.get(actualURI); + + if (actualResultHashMap == null) { + ResultHashMap aux = new ResultHashMap(type, parentField.getElementName(i)); + + if (current.put(actualURI, aux) == null && currentResult != null) { + currentResult.addContent(aux.result); + } + + current = aux; + currentResult = aux.result; + + } else { + current = actualResultHashMap; + currentResult = actualResultHashMap.result; + + } + + } + + } + + resultHashMap = current.get(result.getName()); + + if (resultHashMap == null) { + resultHashMap = new ResultHashMap(result); + current.put(result.getName(), resultHashMap); + + if (currentResult != null) { + currentResult.addContent(result); + } + + } + + } + + for (ResultProcessor processor : this) { + result = processor.process(document, query, result); + } + + resultHashMap.result = result; + + return result; + + } + + public Result[] getResultRoots() { + int size = this.resultRoots.size(); + + if (size == 0) { + return new Result[0]; + } + + Result[] res = new Result[size]; + + int i = 0; + for (ResultHashMap resultHashMap : this.resultRoots.values()) { + res[i++] = resultHashMap.result; + } + + return res; + + } + + private Result createResult(String type, String name) { + + for (ResultFactory<? extends Result> actualResultFactory : this.resultFactoryList) { + + if (type.equals(actualResultFactory.getType())) { + return actualResultFactory.createResult(name); + } + + } + + throw new IllegalArgumentException(); + + } + + private class ResultHashMap extends HashMap<String, ResultHashMap> { + + private static final long serialVersionUID = 7982561264440904411L; + + Result result; + + ResultHashMap(String type, String name) { + this.result = 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 fbb0af8dd8..5d0a60ccd6 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 @@ -51,5 +51,7 @@ public interface SearchFields { final public static String 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/ServiceResult.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ServiceResult.java new file mode 100644 index 0000000000..fd9d980137 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ServiceResult.java @@ -0,0 +1,27 @@ +package org.apache.tuscany.sca.domain.search.impl; + +public class ServiceResult extends ResultImpl { + + private static final long serialVersionUID = -2846199490484466090L; + + private String[] operations; + + private String[] callbackOperations; + + public ServiceResult(String name, String[] operations, String[] callbackOperations) { + super(name); + + this.operations = operations; + this.callbackOperations = callbackOperations; + + } + + public String[] getOperations() { + return this.operations.clone(); + } + + public String[] getCallbackOperations() { + return this.callbackOperations.clone(); + } + +} 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 new file mode 100644 index 0000000000..9ce20bdea1 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java @@ -0,0 +1,44 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class SystemFileContent extends File implements FileContent { + + private static final long serialVersionUID = -8337926886777467728L; + + final boolean leaf; + + final private File file; + + public SystemFileContent(File file) { + super(file.getPath()); + + this.leaf = !file.isDirectory(); + this.file = file; + + } + + public InputStream getInputStream() throws IOException { + return new FileInputStream(this); + } + + 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; + } + +} 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 new file mode 100644 index 0000000000..3f3112dd60 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java @@ -0,0 +1,77 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.File; +import java.io.IOException; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import org.apache.lucene.document.Field; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; + +public class ZipDocumentProcessor implements DocumentProcessor { + + final public static char ARCHIVE_SEPARATOR = '\u0004'; + + 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 document, + String parent) { + + if (object instanceof SystemFileContent) { + SystemFileContent file = (SystemFileContent) object; + + try { + ZipFile zip = new ZipFile(file); + + if (document == null) { + document = documents.get(file.getPath()); + } + + parent += DomainPathAnalyzer.PATH_SEPARATOR + + SearchFields.FILE_FIELD + + DomainPathAnalyzer.TYPE_SEPARATOR + file.getPath() + ARCHIVE_SEPARATOR + + DomainPathAnalyzer.URI_SEPARATOR + file.getName(); + + document.add(new Field(SearchFields.FILE_FIELD, file.getName(), Field.Store.YES, + Field.Index.ANALYZED)); + + 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 new file mode 100644 index 0000000000..10aea9fa9e --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java @@ -0,0 +1,188 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.tuscany.sca.domain.search.DocumentProcessor; + +public class ZipFileContent implements FileContent { + + final private ZipFile file; + + final private ZipEntry entry; + + private FileContent[] children; + + private ZipFileContent(ZipFile file, ZipEntry entry) { + this.file = file; + this.entry = entry; + + } + + public InputStream getInputStream() throws IOException { + return this.file.getInputStream(this.entry); + } + + public String getPath() { + return this.file.getName() + ZipDocumentProcessor.ARCHIVE_SEPARATOR + '/' + this.entry.getName(); + } + + public FileContent[] getChildren() { + return this.children; + } + + public String getName() { + String name = 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 static ZipFileContent[] createZipFileContent(ZipFile file) { + Enumeration<? extends ZipEntry> entries = file.entries(); + + if (!entries.hasMoreElements()) { + return null; + } + + HashMap<String, ZipMap> roots = new HashMap<String, ZipMap>(); + + do { + ZipEntry entry = entries.nextElement(); + String name = entry.getName(); + + if (name.length() > 0) { + + String[] path = name.split("/"); + + ZipMap current = roots.get(path[0]); + + if (current == null) { + current = new ZipMap(); + roots.put(path[0], current); + + if (path.length == 1) { + current.setEntry(file, entry); + continue; + + } + + } + + 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); + + } + + current = actual; + + } + + ZipMap entryMap = current.get(path[path.length - 1]); + + if (entryMap == null) { + entryMap = new ZipMap(); + current.put(path[path.length - 1], entryMap); + + } + + entryMap.setEntry(file, entry); + + } + + } while (entries.hasMoreElements()); + + for (ZipMap map : roots.values()) { + createZipFileContentChildren(map); + } + + ZipFileContent[] ret = new ZipFileContent[roots.size()]; + int i = 0; + + for (ZipMap rootMap : roots.values()) { + ret[i++] = rootMap.zipContent; + } + + return ret; + + } + + private static void createZipFileContentChildren(ZipMap map) { + ZipFileContent[] children = new ZipFileContent[map.size()]; + int i = 0; + + for (ZipMap childMap : map.values()) { + + if (childMap.zipContent == null) { + throw new RuntimeException("could not load zip file hierarchy for file: " + map.zipContent.file); + } + + children[i++] = childMap.zipContent; + + createZipFileContentChildren(childMap); + + } + + map.zipContent.children = children; + + } + + @Override + public String toString() { + return this.file.getName() + '/' + this.entry.getName(); + } + + private static class ZipMap extends HashMap<String, ZipMap> { + + 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; + + } + + } + +} diff --git a/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java b/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java index 54a84f0b49..4cb81a1961 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java +++ b/branches/sca-java-1.x/modules/domain-search/src/test/java/org/apache/tuscany/sca/domain/search/impl/DomainPathAnalyzerTestCase.java @@ -16,7 +16,7 @@ public class DomainPathAnalyzerTestCase extends TestCase { Tokenizer tokenizer = new DomainPathAnalyzer.DomainPathTokenizer(new StringReader( DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.CONTRIBUTION_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + "123tuscany" + DomainPathAnalyzer.TYPE_SEPARATOR + "SCA" + - DomainPathAnalyzer.PATH_SEPARATOR + DomainPathAnalyzer.TYPE_SEPARATOR + "TuscanySCA" + DomainPathAnalyzer.TYPE_SEPARATOR + "123")); + DomainPathAnalyzer.PATH_SEPARATOR + DomainPathAnalyzer.TYPE_SEPARATOR + "TuscanySCA" + DomainPathAnalyzer.TYPE_SEPARATOR + "321" + DomainPathAnalyzer.URI_SEPARATOR + "123")); assertNextToken(Character.toString(DomainPathAnalyzer.PATH_SEPARATOR), tokenizer); assertNextToken("123", tokenizer); |