You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2009/08/17 08:24:17 UTC
svn commit: r804871 [2/3] - in
/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search:
./ impl/
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFileDocumentProcessor.java Mon Aug 17 06:24:15 2009
@@ -24,12 +24,12 @@
*/
public class DomainSearchFileDocumentProcessor extends FileDocumentProcessor {
- private static final long serialVersionUID = -2725616937948969598L;
+ private static final long serialVersionUID = -2725616937948969598L;
+
+ public DomainSearchFileDocumentProcessor() {
+ add(new ZipDocumentProcessor());
+ add(new DefaultFileDocumentProcessor());
+
+ }
- public DomainSearchFileDocumentProcessor() {
- add(new ZipDocumentProcessor());
- add(new DefaultFileDocumentProcessor());
-
- }
-
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchFormatter.java Mon Aug 17 06:24:15 2009
@@ -27,43 +27,42 @@
*/
public class DomainSearchFormatter implements Formatter {
- final public static String HIGHLIGHT_START = "\u0005\u0005\u0006";
+ final public static String HIGHLIGHT_START = "\u0005\u0005\u0006";
- final public static String HIGHLIGHT_END = "\u0006\u0005\u0005";
+ final public static String HIGHLIGHT_END = "\u0006\u0005\u0005";
- private StringBuilder sb = new StringBuilder();
+ private StringBuilder sb = new StringBuilder();
- public String highlightTerm(String originalText, TokenGroup tokenGroup) {
+ public String highlightTerm(String originalText, TokenGroup tokenGroup) {
- if (tokenGroup.getTotalScore() > 0) {
- sb.setLength(0);
-
- sb.append(HIGHLIGHT_START).append(originalText).append(
- HIGHLIGHT_END);
-
- return sb.toString();
-
- } else {
- return originalText;
- }
-
- }
-
- public static boolean isHighlighted(String text) {
- int start = text.indexOf(HIGHLIGHT_START);
- int end = text.indexOf(HIGHLIGHT_END);
-
- if (start < end && start != -1) {
- start = text.indexOf(HIGHLIGHT_START, start + 1);
-
- if (start > end || start == -1) {
- return true;
- }
-
- }
-
- return false;
-
- }
+ if (tokenGroup.getTotalScore() > 0) {
+ sb.setLength(0);
+
+ sb.append(HIGHLIGHT_START).append(originalText).append(HIGHLIGHT_END);
+
+ return sb.toString();
+
+ } else {
+ return originalText;
+ }
+
+ }
+
+ public static boolean isHighlighted(String text) {
+ int start = text.indexOf(HIGHLIGHT_START);
+ int end = text.indexOf(HIGHLIGHT_END);
+
+ if (start < end && start != -1) {
+ start = text.indexOf(HIGHLIGHT_START, start + 1);
+
+ if (start > end || start == -1) {
+ return true;
+ }
+
+ }
+
+ return false;
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchImpl.java Mon Aug 17 06:24:15 2009
@@ -52,356 +52,338 @@
@Scope("COMPOSITE")
public class DomainSearchImpl implements DomainSearch {
- @Property
- public String indexDirectoryPath;
+ @Property
+ public String indexDirectoryPath;
- private Directory dir;
+ private Directory dir;
- private Analyzer analyzer = new DomainSearchAnalyzer();
+ private Analyzer analyzer = new DomainSearchAnalyzer();
- private MultiFieldQueryParser qp = new MultiFieldQueryParser(new String[] {
- SearchFields.ARTIFACT_FIELD, SearchFields.BINDING_FIELD,
- SearchFields.COMPONENT_FIELD, SearchFields.COMPOSITE_FIELD,
- SearchFields.CONTRIBUTION_FIELD, SearchFields.EXPORTEDBY_FIELD,
- SearchFields.FILE_CONTENT_FIELD, SearchFields.IMPLEMENTS_FIELD,
- SearchFields.IMPORTEDBY_FIELD, SearchFields.INCLUDEDBY_FIELD,
- SearchFields.PROPERTY_KEY_FIELD, SearchFields.REFERENCE_FIELD,
- SearchFields.REFERENCE_INTERFACE_CALLBACK_FIELD,
- SearchFields.REFERENCE_INTERFACE_FIELD,
- SearchFields.REFERENCE_NAME_FIELD, SearchFields.SERVICE_FIELD,
- SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD,
- SearchFields.SERVICE_INTERFACE_FIELD,
- SearchFields.SERVICE_NAME_FIELD, SearchFields.TYPE_FIELD,
- SearchFields.VALUE_FIELD }, this.analyzer);
+ private MultiFieldQueryParser qp =
+ new MultiFieldQueryParser(new String[] {SearchFields.ARTIFACT_FIELD, SearchFields.BINDING_FIELD,
+ SearchFields.COMPONENT_FIELD, SearchFields.COMPOSITE_FIELD,
+ SearchFields.CONTRIBUTION_FIELD, SearchFields.EXPORTEDBY_FIELD,
+ SearchFields.FILE_CONTENT_FIELD, SearchFields.IMPLEMENTS_FIELD,
+ SearchFields.IMPORTEDBY_FIELD, SearchFields.INCLUDEDBY_FIELD,
+ SearchFields.PROPERTY_KEY_FIELD, SearchFields.REFERENCE_FIELD,
+ SearchFields.REFERENCE_INTERFACE_CALLBACK_FIELD,
+ SearchFields.REFERENCE_INTERFACE_FIELD,
+ SearchFields.REFERENCE_NAME_FIELD, SearchFields.SERVICE_FIELD,
+ SearchFields.SERVICE_INTERFACE_CALLBACK_FIELD,
+ SearchFields.SERVICE_INTERFACE_FIELD, SearchFields.SERVICE_NAME_FIELD,
+ SearchFields.TYPE_FIELD, SearchFields.VALUE_FIELD}, this.analyzer);
- public DomainSearchImpl() {
- this.qp.setAllowLeadingWildcard(true);
+ public DomainSearchImpl() {
+ this.qp.setAllowLeadingWildcard(true);
- }
+ }
- private Directory getIndexDirectory() throws IOException {
+ private Directory getIndexDirectory() throws IOException {
- if (this.dir == null) {
+ if (this.dir == null) {
- if (this.indexDirectoryPath == null
- || this.indexDirectoryPath.length() == 0) {
- this.dir = new RAMDirectory();
+ if (this.indexDirectoryPath == null || this.indexDirectoryPath.length() == 0) {
+ this.dir = new RAMDirectory();
- } else {
+ } else {
- try {
- this.dir = new FSDirectory(
- new File(this.indexDirectoryPath),
- new SimpleFSLockFactory(this.indexDirectoryPath));
+ try {
+ this.dir =
+ new FSDirectory(new File(this.indexDirectoryPath),
+ new SimpleFSLockFactory(this.indexDirectoryPath));
- } catch (IOException e) {
- System.err.println("Could not open index at "
- + this.indexDirectoryPath);
+ } catch (IOException e) {
+ System.err.println("Could not open index at " + this.indexDirectoryPath);
- throw e;
+ throw e;
- }
+ }
- }
+ }
- }
+ }
- return this.dir;
+ return this.dir;
- }
+ }
- @AllowsPassByReference
- public void contributionAdded(Contribution contribution) {
+ @AllowsPassByReference
+ public void contributionAdded(Contribution contribution) {
- IndexWriter indexWriter = null;
+ IndexWriter indexWriter = null;
- try {
- indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer,
- IndexWriter.MaxFieldLength.UNLIMITED);
+ try {
+ indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
- contributionAdded(contribution, indexWriter);
+ contributionAdded(contribution, indexWriter);
- indexWriter.commit();
+ indexWriter.commit();
- } catch (Exception e) {
+ } catch (Exception e) {
- if (indexWriter != null) {
+ if (indexWriter != null) {
- try {
- indexWriter.rollback();
+ try {
+ indexWriter.rollback();
- } catch (Exception e1) {
- // ignore exception
- }
+ } catch (Exception e1) {
+ // ignore exception
+ }
- }
+ }
- throw new RuntimeException("Problem while indexing!", e);
+ throw new RuntimeException("Problem while indexing!", e);
- } finally {
+ } finally {
- if (indexWriter != null) {
+ if (indexWriter != null) {
- try {
- indexWriter.close();
+ try {
+ indexWriter.close();
- } catch (Exception e) {
- // ignore exception
- }
+ } catch (Exception e) {
+ // ignore exception
+ }
- }
+ }
- }
+ }
- }
+ }
- @AllowsPassByReference
- public void contributionRemoved(Contribution contribution) {
+ @AllowsPassByReference
+ public void contributionRemoved(Contribution contribution) {
- IndexWriter indexWriter = null;
+ IndexWriter indexWriter = null;
- try {
- indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer,
- IndexWriter.MaxFieldLength.UNLIMITED);
+ if (indexExists()) {
- contributionRemoved(contribution, indexWriter);
+ try {
+ indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
- indexWriter.commit();
+ contributionRemoved(contribution, indexWriter);
- } catch (Exception e) {
+ indexWriter.commit();
- if (indexWriter != null) {
+ } catch (Exception e) {
- try {
- indexWriter.rollback();
+ if (indexWriter != null) {
- } catch (Exception e1) {
- // ignore exception
- }
+ try {
+ indexWriter.rollback();
- }
+ } catch (Exception e1) {
+ // ignore exception
+ }
- throw new RuntimeException("Problem while indexing!", e);
+ }
- } finally {
+ throw new RuntimeException("Problem while indexing!", e);
- if (indexWriter != null) {
+ } finally {
- try {
- indexWriter.close();
+ if (indexWriter != null) {
- } catch (Exception e) {
- // ignore exception
- }
+ try {
+ indexWriter.close();
- }
+ } catch (Exception e) {
+ // ignore exception
+ }
- }
+ }
- }
+ }
- private void contributionRemoved(Contribution contribution,
- IndexWriter indexWriter) throws CorruptIndexException, IOException {
+ }
- String contributionURI = contribution.getURI();
- StringBuilder sb = new StringBuilder(SearchFields.PARENT_FIELD);
- sb.append(":\"");
- sb.append(DomainPathAnalyzer.PATH_START);
- sb.append(contributionURI);
- sb.append("\" OR ");
- sb.append(SearchFields.CONTRIBUTION_FIELD);
- sb.append(":\"");
- sb.append(contributionURI);
- sb.append('"');
+ }
- try {
- Query query = this.qp.parse(sb.toString());
- indexWriter.deleteDocuments(query);
+ private void contributionRemoved(Contribution contribution, IndexWriter indexWriter) throws CorruptIndexException,
+ IOException {
- } catch (ParseException e) {
- throw new RuntimeException("Could not parse query: "
- + sb.toString(), e);
- }
+ String contributionURI = contribution.getURI();
+ StringBuilder sb = new StringBuilder(SearchFields.PARENT_FIELD);
+ sb.append(":\"");
+ sb.append(DomainPathAnalyzer.PATH_START);
+ sb.append(contributionURI);
+ sb.append("\" OR ");
+ sb.append(SearchFields.CONTRIBUTION_FIELD);
+ sb.append(":\"");
+ sb.append(contributionURI);
+ sb.append('"');
- }
+ try {
+ Query query = this.qp.parse(sb.toString());
+ indexWriter.deleteDocuments(query);
- private void contributionAdded(Contribution contribution,
- IndexWriter indexWriter) throws CorruptIndexException, IOException {
+ } catch (ParseException e) {
+ throw new RuntimeException("Could not parse query: " + sb.toString(), e);
+ }
- DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap();
- DocumentMap docs = new DocumentMap();
+ }
- try {
- docProcessors.process(docProcessors, docs, contribution, null, "");
+ private void contributionAdded(Contribution contribution, IndexWriter indexWriter) throws CorruptIndexException,
+ IOException {
- } catch (Exception e) {
- e.printStackTrace();
- }
+ DomainSearchDocumentProcessorsMap docProcessors = new DomainSearchDocumentProcessorsMap();
+ DocumentMap docs = new DocumentMap();
- FileWriter writer = new FileWriter("indexed.txt");
- for (Document doc : docs.values()) {
- org.apache.lucene.document.Document luceneDoc = doc
- .createLuceneDocument();
- writer.write(luceneDoc.toString());
- writer.write('\n');
- writer.write('\n');
- indexWriter.addDocument(luceneDoc);
+ try {
+ docProcessors.process(docProcessors, docs, contribution, null, "");
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
- writer.close();
+ FileWriter writer = new FileWriter("indexed.txt");
+ for (Document doc : docs.values()) {
+ org.apache.lucene.document.Document luceneDoc = doc.createLuceneDocument();
+ writer.write(luceneDoc.toString());
+ writer.write('\n');
+ writer.write('\n');
+ indexWriter.addDocument(luceneDoc);
- // BufferedReader consoleReader = new BufferedReader(
- // new InputStreamReader(System.in));
- //
- // while (true) {
- // System.out.print("query: ");
- // String queryString = consoleReader.readLine();
- //
- // if (queryString.equals("exit")) {
- // break;
- // }
- //
- // parseAndSearch(queryString, false);
- //
- // }
+ }
- }
+ writer.close();
- @AllowsPassByReference
- public void contributionUpdated(Contribution oldContribution,
- Contribution contribution) {
+ // BufferedReader consoleReader = new BufferedReader(
+ // new InputStreamReader(System.in));
+ //
+ // while (true) {
+ // System.out.print("query: ");
+ // String queryString = consoleReader.readLine();
+ //
+ // if (queryString.equals("exit")) {
+ // break;
+ // }
+ //
+ // parseAndSearch(queryString, false);
+ //
+ // }
- IndexWriter indexWriter = null;
+ }
- try {
- indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer,
- IndexWriter.MaxFieldLength.UNLIMITED);
+ @AllowsPassByReference
+ public void contributionUpdated(Contribution oldContribution, Contribution contribution) {
- contributionRemoved(oldContribution, indexWriter);
- contributionAdded(contribution, indexWriter);
+ IndexWriter indexWriter = null;
- indexWriter.commit();
+ try {
+ indexWriter = new IndexWriter(getIndexDirectory(), this.analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
- } catch (Exception e) {
+ contributionRemoved(oldContribution, indexWriter);
+ contributionAdded(contribution, indexWriter);
- if (indexWriter != null) {
+ indexWriter.commit();
- try {
- indexWriter.rollback();
+ } catch (Exception e) {
- } catch (Exception e1) {
- // ignore exception
- }
+ if (indexWriter != null) {
- }
+ try {
+ indexWriter.rollback();
- throw new RuntimeException("Problem while indexing!", e);
+ } catch (Exception e1) {
+ // ignore exception
+ }
- } finally {
+ }
- if (indexWriter != null) {
+ throw new RuntimeException("Problem while indexing!", e);
- try {
- indexWriter.close();
+ } finally {
- } catch (Exception e) {
- // ignore exception
- }
+ if (indexWriter != null) {
- }
+ try {
+ indexWriter.close();
- }
+ } catch (Exception e) {
+ // ignore exception
+ }
- }
+ }
- public Result[] parseAndSearch(String searchQuery, final boolean highlight)
- throws Exception {
+ }
- final IndexSearcher searcher = new IndexSearcher(getIndexDirectory());
+ }
- DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor(
- new DomainSearchResultFactory());
+ public Result[] parseAndSearch(String searchQuery, final boolean highlight) throws Exception {
- final Query query = qp.parse(searchQuery);
- System.out.println("query: " + searchQuery);
+ final IndexSearcher searcher = new IndexSearcher(getIndexDirectory());
- TopDocs topDocs = searcher.search(query, 1000);
+ DomainSearchResultProcessor resultProcessor = new DomainSearchResultProcessor(new DomainSearchResultFactory());
- int indexed = 0;
- HashSet<String> set = new HashSet<String>();
- for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
- org.apache.lucene.document.Document luceneDocument = searcher
- .doc(scoreDoc.doc);
+ final Query query = qp.parse(searchQuery);
+ System.out.println("query: " + searchQuery);
- resultProcessor.process(luceneDocument, null);
+ TopDocs topDocs = searcher.search(query, 1000);
- indexed++;
- set.add(luceneDocument.toString());
+ int indexed = 0;
+ HashSet<String> set = new HashSet<String>();
+ for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
+ org.apache.lucene.document.Document luceneDocument = searcher.doc(scoreDoc.doc);
- System.out.println(luceneDocument);
+ resultProcessor.process(luceneDocument, null);
- }
+ indexed++;
+ set.add(luceneDocument.toString());
- /*
- * searcher.search(query, new HitCollector() {
- *
- * @Override public void collect(int doc, float score) { try {
- * org.apache.lucene.document.Document document = searcher .doc(doc);
- *
- * luceneDocuments.put(doc, document);
- *
- * System.out.println(doc);
- *
- * } catch (CorruptIndexException e) { // TODO Auto-generated catch
- * block e.printStackTrace(); } catch (IOException e) { // TODO
- * Auto-generated catch block e.printStackTrace(); } }
- *
- * });
- */
+ System.out.println(luceneDocument);
- System.out.println("indexed = " + indexed);
- System.out.println("set.size() = " + set.size());
+ }
- Result[] results = resultProcessor.createResultRoots();
+ /*
+ * searcher.search(query, new HitCollector() {
+ * @Override public void collect(int doc, float score) { try {
+ * org.apache.lucene.document.Document document = searcher .doc(doc);
+ * luceneDocuments.put(doc, document); System.out.println(doc); } catch
+ * (CorruptIndexException e) { // TODO Auto-generated catch block
+ * e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated
+ * catch block e.printStackTrace(); } } });
+ */
- if (highlight) {
+ System.out.println("indexed = " + indexed);
+ System.out.println("set.size() = " + set.size());
- for (Result result : results) {
- HighlightingUtil.highlightResult(result, query);
- }
+ Result[] results = resultProcessor.createResultRoots();
- }
+ if (highlight) {
- return results;
+ for (Result result : results) {
+ HighlightingUtil.highlightResult(result, query);
+ }
- }
+ }
- public Result[] search(Query searchQuery, boolean hightlight) {
- // TODO Auto-generated method stub
- return null;
- }
+ return results;
- public String highlight(String field, String text, String searchQuery)
- throws Exception {
- final Query query = qp.parse(searchQuery);
+ }
- return HighlightingUtil.highlight(field, query, text);
+ public Result[] search(Query searchQuery, boolean hightlight) {
+ // TODO Auto-generated method stub
+ return null;
+ }
- }
+ public String highlight(String field, String text, String searchQuery) throws Exception {
+ final Query query = qp.parse(searchQuery);
- public boolean indexExists() {
+ return HighlightingUtil.highlight(field, query, text);
- if ((this.indexDirectoryPath == null || this.indexDirectoryPath
- .length() == 0)
- && this.dir == null) {
+ }
- return false;
+ public boolean indexExists() {
- } else {
- return this.dir != null || IndexReader.indexExists(new File(this.indexDirectoryPath));
- }
+ if ((this.indexDirectoryPath == null || this.indexDirectoryPath.length() == 0) && this.dir == null) {
- }
+ return false;
+
+ } else {
+ return this.dir != null || IndexReader.indexExists(new File(this.indexDirectoryPath));
+ }
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchModuleActivator.java Mon Aug 17 06:24:15 2009
@@ -26,17 +26,17 @@
* @version $Rev$ $Date$
*/
public class DomainSearchModuleActivator implements ModuleActivator {
-
- public DomainSearchModuleActivator() {
- // empty constructor
- }
- public void start(ExtensionPointRegistry registry) {
- registry.addExtensionPoint(new DefaultSearchContributionListenerExtensionPoint());
- }
+ public DomainSearchModuleActivator() {
+ // empty constructor
+ }
- public void stop(ExtensionPointRegistry registry) {
- // does nothing
- }
+ public void start(ExtensionPointRegistry registry) {
+ registry.addExtensionPoint(new DefaultSearchContributionListenerExtensionPoint());
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ // does nothing
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultFactory.java Mon Aug 17 06:24:15 2009
@@ -24,17 +24,17 @@
*/
public class DomainSearchResultFactory extends PriorityFieldListResultFactory {
- private static final long serialVersionUID = -7421799172738469027L;
+ private static final long serialVersionUID = -7421799172738469027L;
- public DomainSearchResultFactory() {
- add(SearchFields.COMPOSITE_FIELD);
- add(SearchFields.COMPONENT_FIELD);
- add(SearchFields.COMPONENT_TYPE_FIELD);
- add(SearchFields.CONTRIBUTION_FIELD);
- add(SearchFields.BINDING_FIELD);
- add(SearchFields.FILE_CONTENT_FIELD);
- add(SearchFields.ARTIFACT_FIELD);
-
- }
+ public DomainSearchResultFactory() {
+ add(SearchFields.COMPOSITE_FIELD);
+ add(SearchFields.COMPONENT_FIELD);
+ add(SearchFields.COMPONENT_TYPE_FIELD);
+ add(SearchFields.CONTRIBUTION_FIELD);
+ add(SearchFields.BINDING_FIELD);
+ add(SearchFields.FILE_CONTENT_FIELD);
+ add(SearchFields.ARTIFACT_FIELD);
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/DomainSearchResultProcessor.java Mon Aug 17 06:24:15 2009
@@ -27,15 +27,14 @@
*/
public class DomainSearchResultProcessor extends ResultProcessorList {
- private static final long serialVersionUID = 792292814333612713L;
+ private static final long serialVersionUID = 792292814333612713L;
- public DomainSearchResultProcessor(
- ResultFactory<? extends Result> resultFactory) {
-
- super(new DomainSearchResultFactory());
-
- add(new FileContentResultProcessor());
-
- }
+ public DomainSearchResultProcessor(ResultFactory<? extends Result> resultFactory) {
+
+ super(new DomainSearchResultFactory());
+
+ add(new FileContentResultProcessor());
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContent.java Mon Aug 17 06:24:15 2009
@@ -26,15 +26,15 @@
* @version $Rev$ $Date$
*/
public interface FileContent {
-
- String getPath();
-
- String getName();
-
- FileContent[] getChildren();
-
- boolean isLeaf();
-
- InputStream getInputStream() throws IOException;
+
+ String getPath();
+
+ String getName();
+
+ FileContent[] getChildren();
+
+ boolean isLeaf();
+
+ InputStream getInputStream() throws IOException;
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileContentResultProcessor.java Mon Aug 17 06:24:15 2009
@@ -33,76 +33,73 @@
*/
public class FileContentResultProcessor implements ResultProcessor {
- public Result process(Document document, Result result) {
+ public Result process(Document document, Result result) {
- if (document.getFieldable(SearchFields.FILE_CONTENT_FIELD) != null) {
- Reader reader;
+ if (document.getFieldable(SearchFields.FILE_CONTENT_FIELD) != null) {
+ Reader reader;
- ParentField parentField = new ParentField(document
- .get(SearchFields.PARENT_FIELD));
+ ParentField parentField = new ParentField(document.get(SearchFields.PARENT_FIELD));
- int lastParentElementIndex = parentField.getElementsCount() - 1;
- String parentURI;
+ int lastParentElementIndex = parentField.getElementsCount() - 1;
+ String parentURI;
- if (SearchFields.ARTIFACT_FIELD.equals(parentField
- .getElementType(lastParentElementIndex))) {
- parentURI = parentField.getElementURI(lastParentElementIndex);
+ if (SearchFields.ARTIFACT_FIELD.equals(parentField.getElementType(lastParentElementIndex))) {
+ parentURI = parentField.getElementURI(lastParentElementIndex);
- // if (parentURI.startsWith("jar:")) {
+ // if (parentURI.startsWith("jar:")) {
- try {
- reader = new InputStreamReader(new URL(parentURI)
- .openStream());
+ try {
+ reader = new InputStreamReader(new URL(parentURI).openStream());
- } catch (IOException e) {
- return result;
- }
+ } catch (IOException e) {
+ return result;
+ }
- // } else {
- //
- // try {
- // reader = new InputStreamReader(new FileInputStream(
- // new File(parentURI + (parentURI.length() > 0 ? "/" : "") +
- // name)));
- //
- // } catch (FileNotFoundException e) {
- // return result;
- // }
- //
- // }
+ // } else {
+ //
+ // try {
+ // reader = new InputStreamReader(new FileInputStream(
+ // new File(parentURI + (parentURI.length() > 0 ? "/" : "") +
+ // name)));
+ //
+ // } catch (FileNotFoundException e) {
+ // return result;
+ // }
+ //
+ // }
- try {
+ try {
- StringBuilder sb = new StringBuilder();
- int c;
+ StringBuilder sb = new StringBuilder();
+ int c;
- // TODO: load the chars into an array buffer instead of one
- // at a
- // time
- while ((c = reader.read()) != -1) {
- char character = (char) c;
+ // TODO: load the chars into an array buffer instead of one
+ // at a
+ // time
+ while ((c = reader.read()) != -1) {
+ char character = (char)c;
- if (!Character.isIdentifierIgnorable(character)) {
- sb.append(character);
- }
+ if (!Character.isIdentifierIgnorable(character)) {
+ sb.append(character);
+ }
- }
+ }
- result.setValue(sb.toString());
+ result.setValue(sb.toString());
- } catch (Exception e) {
- // ignore content loading, TODO: maybe it should return an
- // error
- // message as the content
+ } catch (Exception e) {
+ // ignore content loading, TODO: maybe it should return an
+ // error
+ // message as the content
- }
+ }
- }
+ }
- }
+ }
- return result;
+ return result;
- }
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/FileDocumentProcessor.java Mon Aug 17 06:24:15 2009
@@ -27,81 +27,82 @@
*
* @version $Rev$ $Date$
*/
-public class FileDocumentProcessor extends LinkedList<DocumentProcessor>
- implements DocumentProcessor {
+public class FileDocumentProcessor extends LinkedList<DocumentProcessor> implements DocumentProcessor {
- private static final long serialVersionUID = 7843338343970738591L;
+ private static final long serialVersionUID = 7843338343970738591L;
- public Document process(DocumentProcessor parentProcessor,
- DocumentMap documents, Object object, Document doc, String parent) {
+ public Document process(DocumentProcessor parentProcessor,
+ DocumentMap documents,
+ Object object,
+ Document doc,
+ String parent) {
- if (object instanceof FileContent) {
- FileContent file = (FileContent) object;
+ if (object instanceof FileContent) {
+ FileContent file = (FileContent)object;
- if (!file.isLeaf()) {
+ if (!file.isLeaf()) {
- if (doc == null) {
- doc = documents.get(SearchFields.FILE_CONTENT_FIELD + file.getPath());
- }
+ if (doc == null) {
+ doc = documents.get(SearchFields.FILE_CONTENT_FIELD + file.getPath());
+ }
- //FileContent[] files = file.getChildren();
+ // FileContent[] files = file.getChildren();
-// for (FileContent childFile : files) {
-// // Document fileDoc = parentProcessor.process(
-// // parentProcessor, documents, childFile, null,
-// // parent);
-//
-// Document fileDoc = null;
-//
-// fileDoc = process(this, documents, childFile, null, parent);
-//
-// if (fileDoc == null) {
-// continue;
-// }
-//
-// fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
-// Field.Store.YES, Field.Index.ANALYZED));
-//
-// }
+ // for (FileContent childFile : files) {
+ // // Document fileDoc = parentProcessor.process(
+ // // parentProcessor, documents, childFile, null,
+ // // parent);
+ //
+ // Document fileDoc = null;
+ //
+ // fileDoc = process(this, documents, childFile, null, parent);
+ //
+ // if (fileDoc == null) {
+ // continue;
+ // }
+ //
+ // fileDoc.add(new Field(SearchFields.PARENT_FIELD, parent,
+ // Field.Store.YES, Field.Index.ANALYZED));
+ //
+ // }
- return doc;
+ return doc;
- } else {
+ } else {
- for (DocumentProcessor processor : this) {
- Document newDoc = processor.process(this, documents, file,
- doc, parent);
+ for (DocumentProcessor processor : this) {
+ Document newDoc = processor.process(this, documents, file, doc, parent);
- if (newDoc != null) {
- return newDoc;
- }
+ if (newDoc != null) {
+ return newDoc;
+ }
- }
+ }
- }
+ }
- }
+ }
- return doc;
+ return doc;
- }
+ }
- public Object getDocumentKey(Object object) {
+ public Object getDocumentKey(Object object) {
- if (object instanceof FileContent) {
- FileContent file = (FileContent) object;
- String path = file.getPath();
+ if (object instanceof FileContent) {
+ FileContent file = (FileContent)object;
+ String path = file.getPath();
- if (path != null && path.length() == 0) {
- return null;
- }
+ if (path != null && path.length() == 0) {
+ return null;
+ }
- return SearchFields.FILE_CONTENT_FIELD + path;
+ return SearchFields.FILE_CONTENT_FIELD + path;
- }
+ }
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException();
- }
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/HighlightingUtil.java Mon Aug 17 06:24:15 2009
@@ -37,151 +37,152 @@
* @version $Rev$ $Date$
*/
final public class HighlightingUtil {
-
- public static void highlightResult(Result result, Query query) {
- highlightResult(result, query, new SimpleFragmenter(70));
- }
-
- public static void highlightResult(Result result, Query query, Fragmenter fragmenter) {
- Map<String, Result> contents = result.getContents();
-
- if (contents != null) {
-
- for (Result content : contents.values()) {
- highlightResult(content, query, fragmenter);
- }
-
- }
-
- try {
- String highlightedText = HighlightingUtil.bestFragmentHighlighted(
- result.getField(), query, result.getValue(), fragmenter);
-
- // checks if something was highlighted before resetting the value
- if (highlightedText != null && highlightedText.length() > 0) {
- result.setValue(highlightedText);
- }
-
- } catch (IOException e) {
- // ignore highlighting
- }
-
- }
-
- public static String highlight(String field, Query query, String text) throws IOException {
- String highlightedText = bestFragmentHighlighted(field, query, text, new NullFragmenter());
-
- if (highlightedText == null || text.length() >= highlightedText.length()) {
- return text;
- }
-
- return highlightedText;
-
- }
-
- public static String bestFragmentHighlighted(String field, Query query, String text) throws IOException {
- return bestFragmentHighlighted(field, query, text, new SimpleFragmenter(100));
- }
-
- public static String bestFragmentHighlighted(String field, Query query, String text, Fragmenter fragmenter) throws IOException {
- CachingTokenFilter tokenStream = new CachingTokenFilter(new DomainSearchAnalyzer().tokenStream(
- field, new StringReader(text)));
-
- Highlighter highlighter = new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, field, tokenStream, ""));
- highlighter.setTextFragmenter(fragmenter);
- tokenStream.reset();
-
- try {
- return highlighter.getBestFragments(tokenStream, text, 2, " ... ");
-
- } catch (InvalidTokenOffsetsException e) {
-
- // could not create fragments, return empty string
- return "";
-
- }
-
- }
-
- public static String replaceHighlightMarkupBy(CharSequence text,
- String startHighlight, String endHighlight) {
- StringBuilder sb = new StringBuilder();
- int start = 0;
- int end = 0;
-
- for (int i = 0; i < text.length(); i++) {
- char c = text.charAt(i);
-
- if (start > 0) {
-
- if (c == DomainSearchFormatter.HIGHLIGHT_START.charAt(start)) {
- start++;
-
- if (start == DomainSearchFormatter.HIGHLIGHT_START.length()) {
- sb.append(startHighlight);
- start = 0;
-
- }
-
- } else {
-
- for (int j = 0; j < start; j++) {
- sb.append(DomainSearchFormatter.HIGHLIGHT_START.charAt(j));
- }
-
- start = 0;
-
- }
-
- } else if (end > 0) {
-
- if (c == DomainSearchFormatter.HIGHLIGHT_END.charAt(end)) {
- end++;
-
- if (end == DomainSearchFormatter.HIGHLIGHT_END.length()) {
- sb.append(endHighlight);
- end = 0;
-
- }
-
- } else {
-
- for (int j = 0; j < end; j++) {
- sb.append(DomainSearchFormatter.HIGHLIGHT_END.charAt(j));
- }
-
- end = 0;
-
- }
-
- } else if (c == DomainSearchFormatter.HIGHLIGHT_START.charAt(0)) {
- start = 1;
-
- } else if (c == DomainSearchFormatter.HIGHLIGHT_END.charAt(0)) {
- end = 1;
-
- } else {
- sb.append(c);
- }
-
- }
-
- if (start > 0) {
-
- for (int j = 0; j < start; j++) {
- sb.append(DomainSearchFormatter.HIGHLIGHT_START.charAt(j));
- }
-
- } else if (end > 0) {
-
- for (int j = 0; j < start; j++) {
- sb.append(DomainSearchFormatter.HIGHLIGHT_END.charAt(j));
- }
-
- }
-
- return sb.toString();
- }
+ public static void highlightResult(Result result, Query query) {
+ highlightResult(result, query, new SimpleFragmenter(70));
+ }
+
+ public static void highlightResult(Result result, Query query, Fragmenter fragmenter) {
+ Map<String, Result> contents = result.getContents();
+
+ if (contents != null) {
+
+ for (Result content : contents.values()) {
+ highlightResult(content, query, fragmenter);
+ }
+
+ }
+
+ try {
+ String highlightedText =
+ HighlightingUtil.bestFragmentHighlighted(result.getField(), query, result.getValue(), fragmenter);
+
+ // checks if something was highlighted before resetting the value
+ if (highlightedText != null && highlightedText.length() > 0) {
+ result.setValue(highlightedText);
+ }
+
+ } catch (IOException e) {
+ // ignore highlighting
+ }
+
+ }
+
+ public static String highlight(String field, Query query, String text) throws IOException {
+ String highlightedText = bestFragmentHighlighted(field, query, text, new NullFragmenter());
+
+ if (highlightedText == null || text.length() >= highlightedText.length()) {
+ return text;
+ }
+
+ return highlightedText;
+
+ }
+
+ public static String bestFragmentHighlighted(String field, Query query, String text) throws IOException {
+ return bestFragmentHighlighted(field, query, text, new SimpleFragmenter(100));
+ }
+
+ public static String bestFragmentHighlighted(String field, Query query, String text, Fragmenter fragmenter)
+ throws IOException {
+ CachingTokenFilter tokenStream =
+ new CachingTokenFilter(new DomainSearchAnalyzer().tokenStream(field, new StringReader(text)));
+
+ Highlighter highlighter =
+ new Highlighter(new DomainSearchFormatter(), new SpanScorer(query, field, tokenStream, ""));
+ highlighter.setTextFragmenter(fragmenter);
+ tokenStream.reset();
+
+ try {
+ return highlighter.getBestFragments(tokenStream, text, 2, " ... ");
+
+ } catch (InvalidTokenOffsetsException e) {
+
+ // could not create fragments, return empty string
+ return "";
+
+ }
+
+ }
+
+ public static String replaceHighlightMarkupBy(CharSequence text, String startHighlight, String endHighlight) {
+ StringBuilder sb = new StringBuilder();
+ int start = 0;
+ int end = 0;
+
+ for (int i = 0; i < text.length(); i++) {
+ char c = text.charAt(i);
+
+ if (start > 0) {
+
+ if (c == DomainSearchFormatter.HIGHLIGHT_START.charAt(start)) {
+ start++;
+
+ if (start == DomainSearchFormatter.HIGHLIGHT_START.length()) {
+ sb.append(startHighlight);
+ start = 0;
+
+ }
+
+ } else {
+
+ for (int j = 0; j < start; j++) {
+ sb.append(DomainSearchFormatter.HIGHLIGHT_START.charAt(j));
+ }
+
+ start = 0;
+
+ }
+
+ } else if (end > 0) {
+
+ if (c == DomainSearchFormatter.HIGHLIGHT_END.charAt(end)) {
+ end++;
+
+ if (end == DomainSearchFormatter.HIGHLIGHT_END.length()) {
+ sb.append(endHighlight);
+ end = 0;
+
+ }
+
+ } else {
+
+ for (int j = 0; j < end; j++) {
+ sb.append(DomainSearchFormatter.HIGHLIGHT_END.charAt(j));
+ }
+
+ end = 0;
+
+ }
+
+ } else if (c == DomainSearchFormatter.HIGHLIGHT_START.charAt(0)) {
+ start = 1;
+
+ } else if (c == DomainSearchFormatter.HIGHLIGHT_END.charAt(0)) {
+ end = 1;
+
+ } else {
+ sb.append(c);
+ }
+
+ }
+
+ if (start > 0) {
+
+ for (int j = 0; j < start; j++) {
+ sb.append(DomainSearchFormatter.HIGHLIGHT_START.charAt(j));
+ }
+
+ } else if (end > 0) {
+
+ for (int j = 0; j < start; j++) {
+ sb.append(DomainSearchFormatter.HIGHLIGHT_END.charAt(j));
+ }
+
+ }
+
+ return sb.toString();
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingAnalyzer.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingAnalyzer.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingAnalyzer.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingAnalyzer.java Mon Aug 17 06:24:15 2009
@@ -31,19 +31,18 @@
*/
public class NamingAnalyzer extends Analyzer {
- public TokenStream tokenStream(String fieldName, Reader reader) {
- return new NamingTokenizer(reader);
- }
+ public TokenStream tokenStream(String fieldName, Reader reader) {
+ return new NamingTokenizer(reader);
+ }
- public TokenStream reusableTokenStream(String fieldName, Reader reader)
- throws IOException {
- Tokenizer tokenizer = (Tokenizer) getPreviousTokenStream();
- if (tokenizer == null) {
- tokenizer = new NamingTokenizer(reader);
- setPreviousTokenStream(tokenizer);
- } else
- tokenizer.reset(reader);
- return tokenizer;
- }
+ public TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException {
+ Tokenizer tokenizer = (Tokenizer)getPreviousTokenStream();
+ if (tokenizer == null) {
+ tokenizer = new NamingTokenizer(reader);
+ setPreviousTokenStream(tokenizer);
+ } else
+ tokenizer.reset(reader);
+ return tokenizer;
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizer.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizer.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizer.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/NamingTokenizer.java Mon Aug 17 06:24:15 2009
@@ -30,120 +30,120 @@
*/
public class NamingTokenizer extends Tokenizer {
- private int offset = 0, bufferIndex = 0, dataLen = 0;
- private static final int MAX_WORD_LEN = 255;
- private static final int IO_BUFFER_SIZE = 4096;
- private final char[] ioBuffer = new char[IO_BUFFER_SIZE];
-
- public NamingTokenizer(Reader reader) {
- super(reader);
- }
-
- @Override
- public Token next(Token reusableToken) throws IOException {
- assert reusableToken != null;
- reusableToken.clear();
- int length = 0;
- int start = bufferIndex;
- char[] buffer = reusableToken.termBuffer();
-
- boolean lowercaseCharFound = false;
- boolean digitFound = false;
-
- while (true) {
-
- if (bufferIndex >= dataLen) {
- offset += dataLen;
- int incr;
-
- if (lowercaseCharFound || length == 0) {
- incr = 0;
-
- } else {
- incr = 2;
- ioBuffer[0] = ioBuffer[bufferIndex - 1];
- ioBuffer[1] = ioBuffer[bufferIndex];
-
- }
-
- dataLen = input.read(ioBuffer, incr, ioBuffer.length - incr);
- if (dataLen == -1) {
- if (length > 0)
- break;
- else
- return null;
- }
- bufferIndex = incr;
- dataLen += incr;
-
- }
-
- final char c = ioBuffer[bufferIndex++];
- boolean breakChar = true;
-
- if (Character.isDigit(c)) {
-
- if (digitFound || length == 0) {
- breakChar = false;
- digitFound = true;
-
- } else {
- bufferIndex--;
- }
-
- // TODO: normalize accent, it does not index accents for now
- } else if (c >= 65 && c<= 90 || c >= 97 && c<= 122) {
-
- if (digitFound) {
- bufferIndex--;
-
- } else if (Character.isLowerCase(c)) {
-
- if (!(lowercaseCharFound || length <= 1)) {
- length--;
- bufferIndex -= 2;
-
- } else {
- lowercaseCharFound = true;
- breakChar = false;
-
- }
-
- } else if (!lowercaseCharFound) { // && uppercase
- breakChar = false;
-
- } else {
- bufferIndex--;
- }
-
- }
-
- if (!breakChar) {
-
- if (length == 0) // start of token
- start = offset + bufferIndex - 1;
- else if (length == buffer.length)
- buffer = reusableToken.resizeTermBuffer(1 + length);
-
- buffer[length++] = Character.toLowerCase(c); // buffer it, normalized
-
- if (length == MAX_WORD_LEN) // buffer overflow!
- break;
-
- } else if (length > 0) {// at non-Letter w/ chars
-
-
- break; // return 'em
-
- }
-
- }
-
- reusableToken.setTermLength(length);
- reusableToken.setStartOffset(start);
- reusableToken.setEndOffset(start + length);
-
- return reusableToken;
-
- }
+ private int offset = 0, bufferIndex = 0, dataLen = 0;
+ private static final int MAX_WORD_LEN = 255;
+ private static final int IO_BUFFER_SIZE = 4096;
+ private final char[] ioBuffer = new char[IO_BUFFER_SIZE];
+
+ public NamingTokenizer(Reader reader) {
+ super(reader);
+ }
+
+ @Override
+ public Token next(Token reusableToken) throws IOException {
+ assert reusableToken != null;
+ reusableToken.clear();
+ int length = 0;
+ int start = bufferIndex;
+ char[] buffer = reusableToken.termBuffer();
+
+ boolean lowercaseCharFound = false;
+ boolean digitFound = false;
+
+ while (true) {
+
+ if (bufferIndex >= dataLen) {
+ offset += dataLen;
+ int incr;
+
+ if (lowercaseCharFound || length == 0) {
+ incr = 0;
+
+ } else {
+ incr = 2;
+ ioBuffer[0] = ioBuffer[bufferIndex - 1];
+ ioBuffer[1] = ioBuffer[bufferIndex];
+
+ }
+
+ dataLen = input.read(ioBuffer, incr, ioBuffer.length - incr);
+ if (dataLen == -1) {
+ if (length > 0)
+ break;
+ else
+ return null;
+ }
+ bufferIndex = incr;
+ dataLen += incr;
+
+ }
+
+ final char c = ioBuffer[bufferIndex++];
+ boolean breakChar = true;
+
+ if (Character.isDigit(c)) {
+
+ if (digitFound || length == 0) {
+ breakChar = false;
+ digitFound = true;
+
+ } else {
+ bufferIndex--;
+ }
+
+ // TODO: normalize accent, it does not index accents for now
+ } else if (c >= 65 && c <= 90 || c >= 97 && c <= 122) {
+
+ if (digitFound) {
+ bufferIndex--;
+
+ } else if (Character.isLowerCase(c)) {
+
+ if (!(lowercaseCharFound || length <= 1)) {
+ length--;
+ bufferIndex -= 2;
+
+ } else {
+ lowercaseCharFound = true;
+ breakChar = false;
+
+ }
+
+ } else if (!lowercaseCharFound) { // && uppercase
+ breakChar = false;
+
+ } else {
+ bufferIndex--;
+ }
+
+ }
+
+ if (!breakChar) {
+
+ if (length == 0) // start of token
+ start = offset + bufferIndex - 1;
+ else if (length == buffer.length)
+ buffer = reusableToken.resizeTermBuffer(1 + length);
+
+ buffer[length++] = Character.toLowerCase(c); // buffer it,
+ // normalized
+
+ if (length == MAX_WORD_LEN) // buffer overflow!
+ break;
+
+ } else if (length > 0) {// at non-Letter w/ chars
+
+ break; // return 'em
+
+ }
+
+ }
+
+ reusableToken.setTermLength(length);
+ reusableToken.setStartOffset(start);
+ reusableToken.setEndOffset(start + length);
+
+ return reusableToken;
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ParentField.java Mon Aug 17 06:24:15 2009
@@ -29,178 +29,178 @@
*/
public class ParentField implements Serializable {
- private static final long serialVersionUID = -2090538050273088026L;
+ private static final long serialVersionUID = -2090538050273088026L;
- final private List<ParentFieldElement> elements;
+ final private List<ParentFieldElement> elements;
- public ParentField(String parentFieldValue) {
- int length = parentFieldValue.length();
+ 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 || c == DomainPathAnalyzer.PATH_START) {
-
- if (sb.length() > 0 || element != null) {
-
- if (element == null) {
- element = new ParentFieldElement();
- }
-
- if (element.type == null) {
- element.type = "";
- }
-
- if (element.uri == null) {
- element.uri = element.name = sb.toString();
-
- } else {
- element.name = sb.toString();
- }
-
- sb.setLength(0);
- this.elements.add(element);
- element = null;
-
- }
-
- } else if (c == DomainPathAnalyzer.TYPE_SEPARATOR) {
-
- if (element == null) {
- element = new ParentFieldElement();
- }
-
- element.type = sb.toString();
-
- sb.setLength(0);
-
- } else if (c == DomainPathAnalyzer.URI_SEPARATOR) {
-
- if (element == null) {
- element = new ParentFieldElement();
- }
-
- element.uri = sb.toString();
-
- sb.setLength(0);
-
- } else {
- sb.append(c);
- }
-
- }
-
- if (sb.length() > 0 || element != null) {
-
- if (element == null) {
- element = new ParentFieldElement();
- }
-
- if (element.type == null) {
- element.type = "";
- }
-
- if (element.uri == null) {
- element.uri = element.name = sb.toString();
-
- } else {
- element.name = sb.toString();
- }
-
- sb.setLength(0);
- this.elements.add(element);
- element = null;
-
- }
-
- }
-
- public static String getURIPath(ParentField parentField) {
- return getURIPath(parentField, System.getProperty("file.separator"));
- }
-
- public static String getURIPath(ParentField parentField, String pathSeparator) {
- StringBuilder sb = new StringBuilder();
- sb.append(pathSeparator);
- int elementsCount = parentField.getElementsCount();
-
- for (int i = 0 ; i < elementsCount ; i++) {
- sb.append(parentField.getElementName(i));
- sb.append(pathSeparator);
-
- }
-
- if (sb.length() > pathSeparator.length()) {
- sb.setLength(sb.length() - pathSeparator.length());
- }
-
- return sb.toString();
-
- }
-
- public static int getParentElementsCount(String parent) {
- int length = parent.length();
-
- if (length == 0) {
- return 0;
- }
-
- boolean pathSeparatorBefore = true;
- int count = 1;
-
- for (int i = 0; i < length - 1; i++) {
- char c = parent.charAt(i);
-
- if (c == DomainPathAnalyzer.PATH_SEPARATOR && !pathSeparatorBefore) {
- pathSeparatorBefore = true;
- count++;
-
- } else {
- pathSeparatorBefore = false;
- }
-
- }
-
- return count;
-
- }
-
- public int getElementsCount() {
- return this.elements.size();
- }
-
- public String getElementType(int index) {
- return this.elements.get(index).type;
- }
-
- public String getElementURI(int index) {
- return this.elements.get(index).uri;
- }
-
- public String getElementName(int index) {
- return this.elements.get(index).name;
- }
-
- final private static class ParentFieldElement {
+ if (length == 0) {
+ this.elements = Collections.emptyList();
- String type;
+ return;
- String uri;
+ }
- String name;
+ 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 || c == DomainPathAnalyzer.PATH_START) {
+
+ if (sb.length() > 0 || element != null) {
+
+ if (element == null) {
+ element = new ParentFieldElement();
+ }
+
+ if (element.type == null) {
+ element.type = "";
+ }
+
+ if (element.uri == null) {
+ element.uri = element.name = sb.toString();
+
+ } else {
+ element.name = sb.toString();
+ }
+
+ sb.setLength(0);
+ this.elements.add(element);
+ element = null;
+
+ }
+
+ } else if (c == DomainPathAnalyzer.TYPE_SEPARATOR) {
+
+ if (element == null) {
+ element = new ParentFieldElement();
+ }
+
+ element.type = sb.toString();
+
+ sb.setLength(0);
+
+ } else if (c == DomainPathAnalyzer.URI_SEPARATOR) {
+
+ if (element == null) {
+ element = new ParentFieldElement();
+ }
+
+ element.uri = sb.toString();
+
+ sb.setLength(0);
+
+ } else {
+ sb.append(c);
+ }
+
+ }
+
+ if (sb.length() > 0 || element != null) {
+
+ if (element == null) {
+ element = new ParentFieldElement();
+ }
+
+ if (element.type == null) {
+ element.type = "";
+ }
+
+ if (element.uri == null) {
+ element.uri = element.name = sb.toString();
+
+ } else {
+ element.name = sb.toString();
+ }
+
+ sb.setLength(0);
+ this.elements.add(element);
+ element = null;
+
+ }
+
+ }
+
+ public static String getURIPath(ParentField parentField) {
+ return getURIPath(parentField, System.getProperty("file.separator"));
+ }
+
+ public static String getURIPath(ParentField parentField, String pathSeparator) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(pathSeparator);
+ int elementsCount = parentField.getElementsCount();
+
+ for (int i = 0; i < elementsCount; i++) {
+ sb.append(parentField.getElementName(i));
+ sb.append(pathSeparator);
+
+ }
+
+ if (sb.length() > pathSeparator.length()) {
+ sb.setLength(sb.length() - pathSeparator.length());
+ }
+
+ return sb.toString();
+
+ }
+
+ public static int getParentElementsCount(String parent) {
+ int length = parent.length();
+
+ if (length == 0) {
+ return 0;
+ }
+
+ boolean pathSeparatorBefore = true;
+ int count = 1;
+
+ for (int i = 0; i < length - 1; i++) {
+ char c = parent.charAt(i);
+
+ if (c == DomainPathAnalyzer.PATH_SEPARATOR && !pathSeparatorBefore) {
+ pathSeparatorBefore = true;
+ count++;
+
+ } else {
+ pathSeparatorBefore = false;
+ }
+
+ }
+
+ return count;
+
+ }
+
+ public int getElementsCount() {
+ return this.elements.size();
+ }
+
+ public String getElementType(int index) {
+ return this.elements.get(index).type;
+ }
+
+ public String getElementURI(int index) {
+ return this.elements.get(index).uri;
+ }
+
+ public String getElementName(int index) {
+ return this.elements.get(index).name;
+ }
+
+ final private static class ParentFieldElement {
+
+ String type;
+
+ String uri;
+
+ String name;
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PriorityFieldListResultFactory.java Mon Aug 17 06:24:15 2009
@@ -29,30 +29,30 @@
* @version $Rev$ $Date$
*/
public class PriorityFieldListResultFactory extends LinkedList<String> implements ResultFactory<Result> {
-
- private static final long serialVersionUID = 6806221945324235828L;
- public PriorityFieldListResultFactory() {
- // empty constructor
- }
-
- public Result createResult(Document document) {
-
- for (String field : this) {
- String value = document.get(field);
-
- if (value != null) {
- return new ResultImpl(field, value);
- }
-
- }
-
- return null;
-
- }
-
- public Result createResult(String field, String value) {
- return new ResultImpl(field, value);
- }
+ private static final long serialVersionUID = 6806221945324235828L;
+
+ public PriorityFieldListResultFactory() {
+ // empty constructor
+ }
+
+ public Result createResult(Document document) {
+
+ for (String field : this) {
+ String value = document.get(field);
+
+ if (value != null) {
+ return new ResultImpl(field, value);
+ }
+
+ }
+
+ return null;
+
+ }
+
+ public Result createResult(String field, String value) {
+ return new ResultImpl(field, value);
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/PropertyDocumentProcessor.java Mon Aug 17 06:24:15 2009
@@ -31,54 +31,58 @@
*/
public class PropertyDocumentProcessor implements DocumentProcessor {
- public Document process(DocumentProcessor parentProcessor,
- DocumentMap documents, Object object, Document doc, String parent) {
+ public Document process(DocumentProcessor parentProcessor,
+ DocumentMap documents,
+ Object object,
+ Document doc,
+ String parent) {
- if (object instanceof Property) {
- Property property = (Property) object;
- String name = property.getName();
+ if (object instanceof Property) {
+ Property property = (Property)object;
+ String name = property.getName();
- if (name != null && name.length() > 0) {
+ if (name != null && name.length() > 0) {
- if (doc == null) {
- doc = documents.get(name);
- }
+ if (doc == null) {
+ doc = documents.get(name);
+ }
- Object value = property.getValue();
+ Object value = property.getValue();
- if (value.getClass().isArray()) {
- int arraySize = Array.getLength(value);
+ if (value.getClass().isArray()) {
+ int arraySize = Array.getLength(value);
- for (int i = 0; i < arraySize; i++) {
- Object arrayValue = Array.get(value, i);
+ for (int i = 0; i < arraySize; i++) {
+ Object arrayValue = Array.get(value, i);
- doc.add(new Field(SearchFields.VALUE_FIELD, arrayValue.toString(),
- Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(new Field(SearchFields.VALUE_FIELD, arrayValue.toString(), Field.Store.YES,
+ Field.Index.ANALYZED));
- }
+ }
- } else {
+ } else {
- doc.add(new Field(SearchFields.VALUE_FIELD, value.toString(),
- Field.Store.YES, Field.Index.ANALYZED));
+ doc
+ .add(new Field(SearchFields.VALUE_FIELD, value.toString(), Field.Store.YES,
+ Field.Index.ANALYZED));
- }
-
- return doc == null ? FAKE_DOCUMENT : doc;
+ }
- } else {
- return FAKE_DOCUMENT;
- }
+ return doc == null ? FAKE_DOCUMENT : doc;
- }
+ } else {
+ return FAKE_DOCUMENT;
+ }
- throw new IllegalArgumentException();
+ }
- }
+ throw new IllegalArgumentException();
- public Object getDocumentKey(Object object) {
- // TODO Auto-generated method stub
- return null;
- }
+ }
+
+ public Object getDocumentKey(Object object) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultImpl.java Mon Aug 17 06:24:15 2009
@@ -33,253 +33,238 @@
*/
final public class ResultImpl implements Result {
- private static final long serialVersionUID = 7084570994751217396L;
+ private static final long serialVersionUID = 7084570994751217396L;
- private Result container;
+ private Result container;
- private HashMap<String, Result> contents;
+ private HashMap<String, Result> contents;
- private String value;
-
- private String field;
+ private String value;
- public ResultImpl() {
- // empty constructor
- }
+ private String field;
- public ResultImpl(String field, String value) {
- setValue(value);
- setField(field);
-
- }
-
- public String getField() {
- return this.field;
- }
-
- public void setField(String field) {
- this.field = field;
- }
+ public ResultImpl() {
+ // empty constructor
+ }
- public Result getContainer() {
- return this.container;
- }
+ public ResultImpl(String field, String value) {
+ setValue(value);
+ setField(field);
- public Map<String, Result> getContents() {
+ }
- if (this.contents == null) {
- return Collections.emptyMap();
- }
+ public String getField() {
+ return this.field;
+ }
- return Collections.unmodifiableMap(this.contents);
+ public void setField(String field) {
+ this.field = field;
+ }
- }
+ public Result getContainer() {
+ return this.container;
+ }
- public String getValue() {
- return this.value;
- }
+ public Map<String, Result> getContents() {
- public void setContainer(Result container) {
+ if (this.contents == null) {
+ return Collections.emptyMap();
+ }
- if (container != this.container) {
-
- if (this.container != null) {
- this.container.removeContent(this);
- }
+ return Collections.unmodifiableMap(this.contents);
- this.container = container;
+ }
- if (container != null) {
- container.addContent(this);
- }
+ public String getValue() {
+ return this.value;
+ }
- }
+ public void setContainer(Result container) {
- }
+ if (container != this.container) {
- @Override
- public boolean equals(Object obj) {
+ if (this.container != null) {
+ this.container.removeContent(this);
+ }
- if (obj instanceof Result) {
- Result artifactResult = (Result) obj;
+ this.container = container;
- if (artifactResult.getValue() == this.value || this.value != null
- && this.value.equals(artifactResult.getValue())) {
+ if (container != null) {
+ container.addContent(this);
+ }
- if (artifactResult.getContainer() == this.container
- || this.container != null
- && this.container.equals(artifactResult.getContainer())) {
+ }
- Map<String, Result> contents = artifactResult.getContents();
+ }
- if (this.contents == null) {
- return contents.isEmpty();
+ @Override
+ public boolean equals(Object obj) {
- } else if (this.contents.equals(contents)) {
- return true;
- }
+ if (obj instanceof Result) {
+ Result artifactResult = (Result)obj;
- }
+ if (artifactResult.getValue() == this.value || this.value != null
+ && this.value.equals(artifactResult.getValue())) {
- }
+ if (artifactResult.getContainer() == this.container || this.container != null
+ && this.container.equals(artifactResult.getContainer())) {
- }
+ Map<String, Result> contents = artifactResult.getContents();
- return false;
+ if (this.contents == null) {
+ return contents.isEmpty();
- }
+ } else if (this.contents.equals(contents)) {
+ return true;
+ }
- public void addContent(Result artifactResult) {
- internalGetContents().put(artifactResult.getValue(), artifactResult);
-
- if (artifactResult.getContainer() != this) {
- artifactResult.setContainer(this);
- }
+ }
- }
+ }
- private HashMap<String, Result> internalGetContents() {
+ }
- if (this.contents == null) {
- this.contents = new HashMap<String, Result>();
- }
+ return false;
- return this.contents;
+ }
- }
+ public void addContent(Result artifactResult) {
+ internalGetContents().put(artifactResult.getValue(), artifactResult);
- public void removeContent(Result artifactResult) {
+ if (artifactResult.getContainer() != this) {
+ artifactResult.setContainer(this);
+ }
- if (this.contents != null) {
- this.contents.remove(artifactResult);
+ }
- artifactResult.setContainer(null);
+ private HashMap<String, Result> internalGetContents() {
- if (this.contents.isEmpty()) {
- this.contents = null;
- }
+ if (this.contents == null) {
+ this.contents = new HashMap<String, Result>();
+ }
- }
+ return this.contents;
- }
+ }
- @Override
- public int hashCode() {
- int hash = 11;
+ public void removeContent(Result artifactResult) {
- hash = hash * 31
- + (this.container == null ? 7 : this.container.hashCode());
- hash = hash
- * 31
- + (this.contents == null || this.contents.isEmpty() ? 13
- : this.contents.hashCode());
- hash = hash * 31 + (this.value == null ? 17 : this.value.hashCode());
+ if (this.contents != null) {
+ this.contents.remove(artifactResult);
- return hash;
+ artifactResult.setContainer(null);
- }
+ if (this.contents.isEmpty()) {
+ this.contents = null;
+ }
- public void setValue(String value) {
- this.value = value;
- }
+ }
- public String toString() {
- StringBuilder sb = new StringBuilder("<");
- Result container = getContainer();
-
- sb.append(getClass().getName()).append(" name='").append(getValue())
- .append("' container='").append(container != null ? container.getValue() : null).append("'>\n");
+ }
- Method[] methods = getClass().getMethods();
+ @Override
+ public int hashCode() {
+ int hash = 11;
- for (Method method : methods) {
- String methodName = method.getName();
+ hash = hash * 31 + (this.container == null ? 7 : this.container.hashCode());
+ hash = hash * 31 + (this.contents == null || this.contents.isEmpty() ? 13 : this.contents.hashCode());
+ hash = hash * 31 + (this.value == null ? 17 : this.value.hashCode());
- if (method.getReturnType() != void.class) {
+ return hash;
- if (method.getParameterTypes().length == 0) {
+ }
- if (methodName.startsWith("get")
- && !"getName".equals(methodName)
- && !"getContainer".equals(methodName)) {
+ public void setValue(String value) {
+ this.value = value;
+ }
- try {
- Object returnedObj = method.invoke(this);
+ public String toString() {
+ StringBuilder sb = new StringBuilder("<");
+ Result container = getContainer();
- sb.append('\t');
+ sb.append(getClass().getName()).append(" name='").append(getValue()).append("' container='")
+ .append(container != null ? container.getValue() : null).append("'>\n");
- if (returnedObj instanceof Map<?, ?>) {
+ Method[] methods = getClass().getMethods();
- sb.append("<collection type='").append(
- returnedObj.getClass()
- .getGenericInterfaces()[1])
- .append("'>\n");
+ for (Method method : methods) {
+ String methodName = method.getName();
- for (Object obj : ((Map<?, ?>) returnedObj).values()) {
+ if (method.getReturnType() != void.class) {
- sb.append("\t\t").append(obj.toString())
- .append("\n");
+ if (method.getParameterTypes().length == 0) {
- }
+ if (methodName.startsWith("get") && !"getName".equals(methodName)
+ && !"getContainer".equals(methodName)) {
- sb.append("\t</collection>\n");
+ try {
+ Object returnedObj = method.invoke(this);
- } else if (returnedObj instanceof Collection<?>) {
+ sb.append('\t');
- sb.append("<collection type='").append(
- returnedObj.getClass()
- .getGenericInterfaces()[0])
- .append("'>\n");
+ if (returnedObj instanceof Map<?, ?>) {
- for (Object obj : (Collection<?>) returnedObj) {
+ sb.append("<collection type='")
+ .append(returnedObj.getClass().getGenericInterfaces()[1]).append("'>\n");
- sb.append("\t\t").append(obj.toString())
- .append("\n");
+ for (Object obj : ((Map<?, ?>)returnedObj).values()) {
- }
+ sb.append("\t\t").append(obj.toString()).append("\n");
- sb.append("\t</collection>\n");
+ }
- } else if (returnedObj.getClass().isArray()) {
+ sb.append("\t</collection>\n");
- sb.append("<array type='").append(
- returnedObj.getClass()
- .getComponentType())
- .append("'>\n");
-
- int length = Array.getLength(returnedObj);
+ } else if (returnedObj instanceof Collection<?>) {
- for (int i = 0 ; i < length ; i++) {
+ sb.append("<collection type='")
+ .append(returnedObj.getClass().getGenericInterfaces()[0]).append("'>\n");
- sb.append("\t\t").append(Array.get(returnedObj, i).toString())
- .append("\n");
+ for (Object obj : (Collection<?>)returnedObj) {
- }
+ sb.append("\t\t").append(obj.toString()).append("\n");
- sb.append("\t</array>\n");
+ }
- } else {
-
- sb.append('\t').append(returnedObj).append('\n');
-
- }
+ sb.append("\t</collection>\n");
- } catch (Throwable e) {
- // ignore exceptions and don't print the object
- }
+ } 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("</").append(getClass().getName()).append(">");
+ sb.append("\t\t").append(Array.get(returnedObj, i).toString()).append("\n");
- return sb.toString();
+ }
+
+ 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();
+
+ }
- }
-
}