01: package com.technoetic.xplanner.db;
02:
03: import com.technoetic.xplanner.domain.Note;
04: import com.technoetic.xplanner.domain.SearchResult;
05: import com.technoetic.xplanner.domain.Nameable;
06:
07: import java.util.HashMap;
08: import java.util.Map;
09:
10: public class SearchResultFactory {
11: //DEBT factor the type mapping in the RelationshipMappingRegistry or similar metadata registry.
12: private Map types = new HashMap();
13: private int desiredDescriptionLines = 3;
14: private int maxSuffixLength = 20;
15:
16: public SearchResultFactory(Map types) {
17: this .types = types;
18: }
19:
20: public SearchResult convertObjectToSearchResult(Nameable titled,
21: String searchCriteria) throws Exception {
22: String resultType = convertClassToType(titled.getClass()
23: .getName());
24:
25: SearchResult searchResult = new SearchResult(titled, resultType);
26: if ("note".equals(resultType)) {
27: Note note = (Note) titled;
28: searchResult.setAttachedToId(String.valueOf(note
29: .getAttachedToId()));
30: Object objectToWhichImAttached = null;
31: objectToWhichImAttached = note.getParent();
32: Class classOfAttachedTo = objectToWhichImAttached
33: .getClass();
34: searchResult
35: .setAttachedToDomainType(convertClassToType(classOfAttachedTo
36: .getName()));
37: }
38: searchResult.populate(searchCriteria, desiredDescriptionLines,
39: maxSuffixLength);
40: return searchResult;
41: }
42:
43: private String convertClassToType(String className) {
44: return (String) types.get(className);
45: }
46:
47: public void setDesiredDescriptionLines(int desiredDescriptionLines) {
48: this .desiredDescriptionLines = desiredDescriptionLines;
49: }
50:
51: public void setMaxSuffixLength(int maxSuffixLength) {
52: this.maxSuffixLength = maxSuffixLength;
53: }
54: }
|