diff options
author | adrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-05 07:04:56 +0000 |
---|---|---|
committer | adrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-05 07:04:56 +0000 |
commit | 7d544d6b11dc6494170c293e6897ed6d72612d06 (patch) | |
tree | 18f24b6d896fcf0c8cfa5a6a041df082dd7672f3 /branches | |
parent | b4f758f88e8c97be870ba86080d7f0adb6dafb65 (diff) |
applying patch tuscany_2552_phillipe_ramalho_07_04_2009.patch.txt from TUSCANY-2552
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@791203 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches')
64 files changed, 2802 insertions, 248 deletions
diff --git a/branches/sca-java-1.x/modules/domain-manager/pom.xml b/branches/sca-java-1.x/modules/domain-manager/pom.xml index 786a44ca85..ba5a221ee5 100644 --- a/branches/sca-java-1.x/modules/domain-manager/pom.xml +++ b/branches/sca-java-1.x/modules/domain-manager/pom.xml @@ -3,7 +3,7 @@ * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF license f s this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at @@ -131,6 +131,13 @@ <dependency> <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution-resource</artifactId> + <version>1.6-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-contribution-java</artifactId> <version>1.6-SNAPSHOT</version> <scope>runtime</scope> @@ -143,11 +150,10 @@ <scope>runtime</scope> </dependency> - <dependency> + <dependency> <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-contribution-resource</artifactId> + <artifactId>tuscany-domain-search</artifactId> <version>1.6-SNAPSHOT</version> - <scope>runtime</scope> </dependency> <dependency> @@ -177,6 +183,12 @@ <version>1.6-SNAPSHOT</version> <scope>runtime</scope> </dependency> + + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> <dependency> <groupId>org.apache.tuscany.sca</groupId> diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java index 0b304a0854..6d13e38937 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/ContributionCollectionImpl.java @@ -97,8 +97,8 @@ import org.w3c.dom.Document; * @version $Rev$ $Date$ */ @Scope("COMPOSITE") -@Service(interfaces={ItemCollection.class, LocalItemCollection.class}) -public class ContributionCollectionImpl implements ItemCollection, LocalItemCollection { +@Service(interfaces={ItemCollection.class, LocalItemCollection.class, WorkspaceReader.class}) +public class ContributionCollectionImpl implements ItemCollection, LocalItemCollection, WorkspaceReader { private static final Logger logger = Logger.getLogger(ContributionCollectionImpl.class.getName()); @@ -486,7 +486,7 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl * * @return */ - private Workspace readWorkspace() { + Workspace readWorkspace() { String rootDirectory = domainManagerConfiguration.getRootDirectory(); Workspace workspace; @@ -652,5 +652,9 @@ public class ContributionCollectionImpl implements ItemCollection, LocalItemColl } return contributions; } + + public Workspace getWorkspace() { + return readContributions(readWorkspace()); + } } diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java index e95a0cc585..a8cc6efdd1 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java @@ -59,6 +59,7 @@ import org.apache.tuscany.sca.data.collection.Item; import org.apache.tuscany.sca.data.collection.ItemCollection; import org.apache.tuscany.sca.data.collection.LocalItemCollection; import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.apache.tuscany.sca.domain.search.DomainSearch; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.XMLSerializer; import org.osoa.sca.ServiceRuntimeException; @@ -115,7 +116,7 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte */ @Init public void initialize() throws ParserConfigurationException { - + // Create factories ExtensionPointRegistry extensionPoints = domainManagerConfiguration.getExtensionPoints(); modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); @@ -133,7 +134,7 @@ public class DeployedCompositeCollectionImpl implements ItemCollection, LocalIte public Entry<String, Item>[] getAll() { logger.fine("getAll"); - + // Return all the composites in the domain composite List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>(); Composite compositeCollection = readCompositeCollection(); diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java index d68cfa3786..04c807cba8 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/NodeProcessCollectionFacadeImpl.java @@ -39,6 +39,7 @@ import org.apache.tuscany.sca.data.collection.Item; import org.apache.tuscany.sca.data.collection.ItemCollection; import org.apache.tuscany.sca.data.collection.LocalItemCollection; import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.apache.tuscany.sca.domain.search.DomainSearch; import org.osoa.sca.ServiceRuntimeException; import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Reference; diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java new file mode 100644 index 0000000000..5a2873b35f --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/Searcher.java @@ -0,0 +1,297 @@ +package org.apache.tuscany.sca.domain.manager.impl; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Collection; + +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.data.collection.ItemCollection; +import org.apache.tuscany.sca.data.collection.LocalItemCollection; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.apache.tuscany.sca.domain.search.DomainSearch; +import org.apache.tuscany.sca.domain.search.Result; +import org.apache.tuscany.sca.domain.search.impl.ArtifactResult; +import org.apache.tuscany.sca.domain.search.impl.FileContentResult; +import org.apache.tuscany.sca.domain.search.impl.HighlightingUtil; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Scope("COMPOSITE") +@Service(interfaces = { ItemCollection.class, LocalItemCollection.class }) +public class Searcher implements ItemCollection, LocalItemCollection { + + static char[] characters = { '\u0001'/* */, '\u0003'/* */, + '\u0004'/* */, + + }; + + final private static String HTML_NEW_LINE = "<BR/>"; + + final private static String PATH_SEPARATOR = "/"; + + @Reference + public WorkspaceReader contributionCollection; + + @Reference + public DomainSearch domainSearch; + + public void delete(String key) throws NotFoundException { + System.out.println("delete"); + } + + private static void startIndentation(int size, StringWriter writer) { + writer + .write("<p style='margin-top:0em;margin-bottom:0em;padding:0em;margin-left:"); + writer.write(Integer.toString(size)); + writer.write("em'>"); + + } + + private static void endIndentation(StringWriter writer) { + writer.write("</p>"); + } + + public Item get(String key) throws NotFoundException { + System.out.println("get"); + this.domainSearch.contributionAdded(null, this.contributionCollection + .getWorkspace()); + Result[] results = this.domainSearch.parseAndSearch(key, false); + + Item item = new Item(); + item.setTitle("Results"); + + StringWriter sw = new StringWriter(); + + for (Result result : results) { + + try { + writeToHTML(0, result, sw); + + } catch (IOException e) { + // ignore result + } + + sw.write(HTML_NEW_LINE); + + } + + String contents = HighlightingUtil.replaceHighlightMarkupBy(sw + .getBuffer(), "<font color='#FF0000'>", "</font>"); + + item.setContents(replaceAll(contents, 40) + "end"); + + System.out.println(item.getContents().indexOf("@Referencevar")); + + System.out.println(item.getContents()); + + return item; + + } + + // + // private static String replaceAll(CharSequence c) { + // StringBuilder sb = new StringBuilder(); + // // HashSet<Character> set = new HashSet<Character>(); + // Arrays.sort(characters); + // // int start = 0, end = 4; + // // char[] chars = new char[end - start]; + // // System.arraycopy(characters, start, chars, 0, end - start); + // + // for (int i = 0 ; i < c.length() ; i++) { + // char actual = c.charAt(i); + // + // //if (Arrays.binarySearch(characters, actual) < 0) { + // + // if (!Character.isIdentifierIgnorable(actual)) { + // sb.append(actual); + // + // } else { + // //sb.append('0'); + // } + // + // } + // // + // // System.out.println("set-size: " + set.size()); + // // for (char character : set) { + // // System.out.print(","); + // // System.out.print((int) character); + // // System.out.print("/*" + character + "*/"); + // // + // // } + // // + // // System.out.println(); + // + // return sb.toString(); + // + // } + + private static String replaceAll(CharSequence c, int less) { + StringBuilder sb = new StringBuilder(); + // HashSet<Character> set = new HashSet<Character>(); + Arrays.sort(characters); + // int start = 0, end = 4; + // char[] chars = new char[end - start]; + // System.arraycopy(characters, start, chars, 0, end - start); + + for (int i = 0; i < c.length(); i++) { + char actual = c.charAt(i); + + // if (Arrays.binarySearch(characters, actual) < 0) { + + // if (actual != '\u000b' && actual != '\u0020' && + // actual != '\u000c' && actual != '\u0009' && + // actual != ')' && actual != '(') { + + if (actual > less || actual == '&' || actual == '#' + || actual == '\'' || actual == ' ' || actual == '%' + || actual == ':') { + sb.append(actual); + + } else { + // sb.append('0'); + } + + } + // + // System.out.println("set-size: " + set.size()); + // for (char character : set) { + // System.out.print(","); + // System.out.print((int) character); + // System.out.print("/*" + character + "*/"); + // + // } + // + // System.out.println(); + + return sb.toString(); + + } + + private static Result writeFileContentResultToHTML(int indentation, + Result result, StringWriter writer) throws IOException { + + String content = ((FileContentResult) result).getContent(); + writer.write("file:"); + + if (content != null && content.length() > 0) { + + StringEscapeUtils.escapeHtml(writer, result.getName()); + writer.write(HTML_NEW_LINE); + + startIndentation(indentation, writer); + writer.write("<span style='max-width:100%'>"); + StringEscapeUtils.escapeHtml(writer, content); + writer.write("</span>"); + endIndentation(writer); + writer.write(HTML_NEW_LINE); + + } else { + + writer.write(result.getName()); + Collection<Result> contents = result.getContents().values(); + + while (contents.size() == 1) { + result = contents.iterator().next(); + + if (result instanceof FileContentResult) { + writer.write(PATH_SEPARATOR); + writer.write(result.getName()); + + contents = result.getContents().values(); + + } else { + break; + } + + } + + if (result instanceof FileContentResult) { + FileContentResult fileResult = (FileContentResult) result; + content = fileResult.getContent(); + + if (content != null && content.length() > 0) { + + writer.write(HTML_NEW_LINE); + + startIndentation(indentation, writer); + writer.write("<span style='max-width:100%'>"); + StringEscapeUtils.escapeHtml(writer, content); + writer.write("</span>"); + endIndentation(writer); + writer.write(HTML_NEW_LINE); + + } + + } + + } + + return result; + + } + + private static void writeToHTML(int indentation, Result result, + StringWriter writer) throws IOException { + + startIndentation(indentation++, writer); + + if (result instanceof FileContentResult) { + result = writeFileContentResultToHTML(indentation, result, writer); + + } else { + + StringEscapeUtils.escapeHtml(writer, result.getClass() + .getSimpleName().substring(0, + result.getClass().getSimpleName().length() - 6)); + writer.write(':'); + StringEscapeUtils.escapeHtml(writer, result.getName()); + writer.write(HTML_NEW_LINE); + + if (result instanceof ArtifactResult) { + String location = ((ArtifactResult) result).getLocation(); + + if (location != null) { + startIndentation(indentation, writer); + writer.write("location: "); + StringEscapeUtils.escapeHtml(writer, location); + endIndentation(writer); + writer.write(HTML_NEW_LINE); + + } + + } + + } + + endIndentation(writer); + + for (Result actualResult : result.getContents().values()) { + writeToHTML(indentation, actualResult, writer); + } + + } + + public Entry<String, Item>[] getAll() { + System.out.println("getAll"); + return null; + } + + public String post(String key, Item item) { + System.out.println("post"); + return null; + } + + public void put(String key, Item item) throws NotFoundException { + System.out.println("put"); + } + + public Entry<String, Item>[] query(String queryString) { + System.out.println("query"); + return null; + } + +} diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/WorkspaceReader.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/WorkspaceReader.java new file mode 100644 index 0000000000..d4cb1d21af --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/WorkspaceReader.java @@ -0,0 +1,9 @@ +package org.apache.tuscany.sca.domain.manager.impl; + +import org.apache.tuscany.sca.workspace.Workspace; + +public interface WorkspaceReader { + + Workspace getWorkspace(); + +} diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite index ba57ea45d1..d9b0939517 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/DomainManager.composite @@ -29,6 +29,13 @@ </service> </component> + <component name="SearchPage"> + <t:implementation.widget location="search.html"/> + <service name="Widget"> + <t:binding.http uri="http://localhost:9990/ui/search"/> + </service> + </component> + <component name="HomeGadget"> <t:implementation.widget location="home-gadget.html"/> <service name="Widget"> @@ -247,6 +254,29 @@ <reference name="cloudCollection" target="CloudCollectionComponent/LocalItemCollection"/> <reference name="processCollection" target="NodeProcessCollectionComponent/LocalItemCollection"/> </component> + + <component name="SearchGadget"> + <t:implementation.widget location="search-gadget.html"/> + <service name="Widget"> + <t:binding.http uri="http://localhost:9990/ui/search-gadget"/> + </service> + <reference name="searcher" target="SearcherCollectionComponent/ItemCollection"> + <t:binding.atom/> + </reference> + + </component> + + <component name="SearcherCollectionComponent"> + <implementation.java class="org.apache.tuscany.sca.domain.manager.impl.Searcher"/> + + <service name="ItemCollection"> + <t:binding.atom uri="http://localhost:9990/search" title="Search"/> + </service> + + <reference name="domainSearch" target="DomainSearchComponent"/> + <reference name="contributionCollection" target="ContributionCollectionComponent/WorkspaceReader"/> + + </component> <component name="NodeProcessCollectionFacadeComponent"> <implementation.java class="org.apache.tuscany.sca.domain.manager.impl.NodeProcessCollectionFacadeImpl"/> @@ -258,6 +288,7 @@ <reference name="processCollection" target="NodeProcessCollectionComponent/ItemCollection"> <t:binding.atom/> </reference> + </component> <component name="NodeProcessCollectionComponent"> @@ -277,5 +308,9 @@ <component name="DomainManagerConfigurationComponent"> <implementation.java class="org.apache.tuscany.sca.domain.manager.impl.DomainManagerConfigurationImpl"/> </component> + + <component name="DomainSearchComponent"> + <implementation.java class="org.apache.tuscany.sca.domain.search.impl.DomainSearchImpl"/> + </component> </composite> diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/composite-gadget.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/composite-gadget.html index ce1039d9e5..3af9c3f725 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/composite-gadget.html +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/composite-gadget.html @@ -65,6 +65,7 @@ var gadget = gadget(window, document); if (gadget.showContributions == null) { gadget.showContributions = true; + } var domainCompositeForm = elementByID(gadget, 'domainCompositeForm'); diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html new file mode 100644 index 0000000000..df68d9751d --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search-gadget.html @@ -0,0 +1,81 @@ +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<html> + +<head> + +<title>SCA Domain - Domain Composite</title> + +<script type="text/javascript" src="../search-gadget/search-gadget.js"></script> +<script type="text/javascript" src="utils.js"></script> + + + +<link rel="stylesheet" type="text/css" href="manager.css"> + + + +</head> + +<body> + + + <div id="domainSearch"> + + <form id="domainSearchForm"> + + <p style="margin-top:1em;margin-bottom:1em;margin-left:1em;margin-right:1em"> + <input id="searchField" type="text" value="" /> <input id="searchButton" type="button" value="Search" onclick="search()" /> + </p> + + <br> + <br> + <div id="results"></div> + </form> + + </div> +</body> + +<script type="text/javascript"> + + //@Reference + var searcher = new tuscany.sca.Reference("searcher"); + + var gadget = gadget(window, document); + + function search() { + searcher.get(elementByID(gadget, 'searchField').value, searchResponse); + } + + function searchResponse(feed) { + var entries = feed.getElementsByTagName("entry"); + var content = entries[0].getElementsByTagName("content"); + + // alert(content[0].firstChild.data); + + var results = elementByID(gadget, "results"); + results.innerHTML = content[0].firstChild.data; + + } + + elementByID(gadget, 'searchButton').onclick = search + +</script> + +</html> diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search.html b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search.html new file mode 100644 index 0000000000..52309f3256 --- /dev/null +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/resources/search.html @@ -0,0 +1,66 @@ +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<html> +<head> +<title>SCA Domain - Search</title> + +<script type="text/javascript" src="utils.js"></script> + +<link rel="stylesheet" type="text/css" href="manager.css"> +</head> + +<body> + <div id="toolbarGadgetDiv"></div> + <br> + + <span class=hd1> + SCA Domain<br><br> + Domain Search <a href="/search/"><img src="icons/feed-icon.png" border="0"></a> + </span> + <br> + + <p> + <div id="searchGadgetDiv"></div> + </p> + + <iframe id="toolbarGadget" src="toolbar-gadget.html"></iframe> + <iframe id="searchGadget" src="search-gadget.html"marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe> +</body> + +<script type="text/javascript"> + var toolbarGadgetDiv = elementByID(document, 'toolbarGadgetDiv'); + var searchGadgetDiv = elementByID(document, 'searchGadgetDiv'); + + var toolbarGadget = elementByID(document, 'toolbarGadget'); + var searchGadget = elementByID(document, 'searchGadget'); + + function ongadget(win, doc) { + if (doc == content(toolbarGadget)) { + toolbarGadgetDiv.innerHTML = doc.body.innerHTML; + return toolbarGadgetDiv; + } else if (doc == content(searchGadget)) { + searchGadgetDiv.innerHTML = doc.body.innerHTML; + searchGadgetDiv.showContributions = true; + searchGadgetDiv.showComponents = true; + return searchGadgetDiv; + } + return document; + } +</script> +</html> diff --git a/branches/sca-java-1.x/modules/domain-search/pom.xml b/branches/sca-java-1.x/modules/domain-search/pom.xml index 80f6772bd0..577c3b8488 100644 --- a/branches/sca-java-1.x/modules/domain-search/pom.xml +++ b/branches/sca-java-1.x/modules/domain-search/pom.xml @@ -65,10 +65,22 @@ <version>1.6-SNAPSHOT</version> </dependency> - <dependency> + <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> - <version>2.4-SNAPSHOT</version> + <version>2.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.lucene</groupId> + <artifactId>lucene-highlighter</artifactId> + <version>2.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.lucene</groupId> + <artifactId>lucene-memory</artifactId> + <version>2.4-SNAPSHOT</version> </dependency> </dependencies> 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); diff --git a/branches/sca-java-1.x/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java b/branches/sca-java-1.x/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java index eb06ad7411..b5e77061d7 100644 --- a/branches/sca-java-1.x/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java +++ b/branches/sca-java-1.x/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java @@ -100,9 +100,11 @@ public class DomainManagerLauncher { int k = 0; try { while ((k != 'q') && (k != 'r')) { - k = System.in.read(); + // k = System.in.read(); + Thread.sleep(100); + } - } catch (IOException e) { + } catch (Exception e) { // Wait forever Object lock = new Object(); |