KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > search > impl > lucene > LuceneResultSetRow


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.search.impl.lucene;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.alfresco.model.ContentModel;
23 import org.alfresco.repo.search.AbstractResultSetRow;
24 import org.alfresco.service.cmr.repository.ChildAssociationRef;
25 import org.alfresco.service.cmr.repository.NodeRef;
26 import org.alfresco.service.cmr.repository.Path;
27 import org.alfresco.service.namespace.QName;
28 import org.apache.lucene.document.Document;
29 import org.apache.lucene.document.Field;
30
31 /**
32  * A row in a result set. Created on the fly.
33  *
34  * @author Andy Hind
35  *
36  */

37 public class LuceneResultSetRow extends AbstractResultSetRow
38 {
39     /**
40      * The current document - cached so we do not get it for each value
41      */

42     private Document document;
43
44     /**
45      * Wrap a position in a lucene Hits class with node support
46      *
47      * @param resultSet
48      * @param position
49      */

50     public LuceneResultSetRow(LuceneResultSet resultSet, int index)
51     {
52         super(resultSet, index);
53     }
54
55     /**
56      * Support to cache the document for this row
57      *
58      * @return
59      */

60     public Document getDocument()
61     {
62         if (document == null)
63         {
64             document = ((LuceneResultSet) getResultSet()).getDocument(getIndex());
65         }
66         return document;
67     }
68
69     /*
70      * ResultSetRow implementation
71      */

72
73     protected Map JavaDoc<QName, Serializable JavaDoc> getDirectProperties()
74     {
75         LuceneResultSet lrs = (LuceneResultSet) getResultSet();
76         return lrs.getNodeService().getProperties(lrs.getNodeRef(getIndex()));
77     }
78
79     public Serializable JavaDoc getValue(Path path)
80     {
81         // TODO: implement path base look up against the document or via the
82
// node service
83
throw new UnsupportedOperationException JavaDoc();
84     }
85
86     public QName getQName()
87     {
88         Field field = getDocument().getField("QNAME");
89         if (field != null)
90         {
91             String JavaDoc qname = field.stringValue();
92             if((qname == null) || (qname.length() == 0))
93             {
94                 return null;
95             }
96             else
97             {
98                return QName.createQName(qname);
99             }
100         }
101         else
102         {
103             return null;
104         }
105     }
106
107     public QName getPrimaryAssocTypeQName()
108     {
109         
110         Field field = getDocument().getField("PRIMARYASSOCTYPEQNAME");
111         if (field != null)
112         {
113             String JavaDoc qname = field.stringValue();
114             return QName.createQName(qname);
115         }
116         else
117         {
118             return ContentModel.ASSOC_CHILDREN;
119         }
120     }
121
122     public ChildAssociationRef getChildAssocRef()
123     {
124         Field field = getDocument().getField("PRIMARYPARENT");
125         String JavaDoc primaryParent = null;
126         if (field != null)
127         {
128             primaryParent = field.stringValue();
129         }
130         NodeRef childNodeRef = getNodeRef();
131         NodeRef parentNodeRef = primaryParent == null ? null : new NodeRef(primaryParent);
132         return new ChildAssociationRef(getPrimaryAssocTypeQName(), parentNodeRef, getQName(), childNodeRef);
133     }
134
135 }
136
Popular Tags