KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > search > AbstractResultSetRow


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;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.alfresco.service.cmr.repository.NodeRef;
25 import org.alfresco.service.cmr.repository.Path;
26 import org.alfresco.service.cmr.search.ResultSet;
27 import org.alfresco.service.cmr.search.ResultSetRow;
28 import org.alfresco.service.namespace.QName;
29
30 public abstract class AbstractResultSetRow implements ResultSetRow
31 {
32
33     /**
34      * The containing result set
35      */

36     private ResultSet resultSet;
37
38     /**
39      * The current position in the containing result set
40      */

41     private int index;
42
43     /**
44      * The direct properties of the current node
45      * Used by those implementations that can cache the whole set.
46      */

47
48     private Map JavaDoc<Path, Serializable JavaDoc> properties;
49
50     public AbstractResultSetRow(ResultSet resultSet, int index)
51     {
52         super();
53         this.resultSet = resultSet;
54         this.index = index;
55     }
56
57     public ResultSet getResultSet()
58     {
59         return resultSet;
60     }
61
62     public int getIndex()
63     {
64         return index;
65     }
66
67     public NodeRef getNodeRef()
68     {
69         return getResultSet().getNodeRef(getIndex());
70     }
71
72     public float getScore()
73     {
74         return getResultSet().getScore(getIndex());
75     }
76
77     public Map JavaDoc<Path, Serializable JavaDoc> getValues()
78     {
79         if (properties == null)
80         {
81             properties = new HashMap JavaDoc<Path, Serializable JavaDoc>();
82             setProperties(getDirectProperties());
83         }
84         return Collections.unmodifiableMap(properties);
85     }
86
87     protected Map JavaDoc<QName, Serializable JavaDoc> getDirectProperties()
88     {
89         return Collections.<QName, Serializable JavaDoc>emptyMap();
90     }
91     
92     protected void setProperties(Map JavaDoc<QName, Serializable JavaDoc> byQname)
93     {
94         for (QName qname : byQname.keySet())
95         {
96             Serializable JavaDoc value = byQname.get(qname);
97             Path path = new Path();
98             path.append(new Path.SelfElement());
99             path.append(new Path.AttributeElement(qname));
100             properties.put(path, value);
101         }
102     }
103     
104     public Serializable JavaDoc getValue(QName qname)
105     {
106         Path path = new Path();
107         path.append(new Path.SelfElement());
108         path.append(new Path.AttributeElement(qname));
109         return getValues().get(path);
110     }
111     
112 }
113
Popular Tags