diff options
author | adrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-06 09:18:42 +0000 |
---|---|---|
committer | adrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-06 09:18:42 +0000 |
commit | 8f34ff7c71819472d7b2f023b8ecb04da97d2655 (patch) | |
tree | efe54ad5daf1f6aa176abab2641bfdf007f167d9 /branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java | |
parent | 6a9f8b2718697d444e4413166465cf2c5f1ef533 (diff) |
-applying patch tuscany_2552_phillipe_ramalho_06_04_2009.patch from TUSCANY-2552
-adding domain-search to modules/pom.xml
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@782215 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java new file mode 100644 index 0000000000..86e0e98f95 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ContributionDocumentProcessor.java @@ -0,0 +1,120 @@ +package org.apache.tuscany.sca.domain.search.impl; + +import org.apache.lucene.document.Field; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.domain.search.DocumentMap; +import org.apache.tuscany.sca.domain.search.DocumentProcessor; +import org.apache.tuscany.sca.domain.search.DocumentProcessorsMap; + +public class ContributionDocumentProcessor implements DocumentProcessor { + + public Document process(DocumentProcessorsMap processors, + DocumentMap documents, Object object, Document doc, String parent) { + + if (object instanceof Contribution) { + Contribution contribution = (Contribution) object; + String uri = contribution.getURI(); + + if (uri != null) { + + if (uri.length() == 0) { + uri = null; + + } else { + parent += DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.CONTRIBUTION_FIELD + DomainPathAnalyzer.TYPE_SEPARATOR + uri; + } + + } + + if (uri != null && doc == null) { + doc = documents.get(uri); + + doc.add(new Field(SearchFields.CONTRIBUTION_FIELD, uri, + Field.Store.YES, Field.Index.ANALYZED)); + + } else { + doc = FAKE_DOCUMENT; + } + + for (Artifact artifact : contribution.getArtifacts()) { + Document artifactDoc = processors.process(processors, + documents, artifact, null, parent); + + if (uri != null) { + + artifactDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + +// for (Import imprt : contribution.getImports()) { +// Document importDoc = processors.process(processors, documents, +// imprt, null); +// +// if (uri != null) { +// +// importDoc.add(new Field(SearchFields.IMPORTEDBY_FIELD, uri, +// Field.Store.YES, Field.Index.ANALYZED)); +// +// } +// +// } +// +// for (Export export : contribution.getExports()) { +// Document exportDoc = processors.process(processors, documents, +// export, null); +// +// if (uri != null) { +// +// exportDoc.add(new Field(SearchFields.EXPORTEDBY_FIELD, uri, +// Field.Store.YES, Field.Index.ANALYZED)); +// +// } +// +// } + + for (Composite composite : contribution.getDeployables()) { + Document compositeDoc = processors.process(processors, + documents, composite, null, parent); + + if (uri != null) { + + compositeDoc.add(new Field(SearchFields.PARENT_FIELD, parent, + Field.Store.YES, Field.Index.ANALYZED)); + + } + + } + + return doc; + + } + + throw new IllegalArgumentException(); + + } + + public Object getDocumentKey(Object object) { + + if (object instanceof Contribution) { + Contribution contribution = (Contribution) object; + String uri = contribution.getURI(); + + if (uri != null && uri.length() == 0) { + return null; + } + + return uri; + + } + + throw new IllegalArgumentException(); + + } + +} |