1 17 package org.alfresco.repo.search; 18 19 import java.io.Serializable ; 20 import java.util.Collections ; 21 import java.util.HashMap ; 22 import java.util.Map ; 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 36 private ResultSet resultSet; 37 38 41 private int index; 42 43 47 48 private Map <Path, Serializable > 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 <Path, Serializable > getValues() 78 { 79 if (properties == null) 80 { 81 properties = new HashMap <Path, Serializable >(); 82 setProperties(getDirectProperties()); 83 } 84 return Collections.unmodifiableMap(properties); 85 } 86 87 protected Map <QName, Serializable > getDirectProperties() 88 { 89 return Collections.<QName, Serializable >emptyMap(); 90 } 91 92 protected void setProperties(Map <QName, Serializable > byQname) 93 { 94 for (QName qname : byQname.keySet()) 95 { 96 Serializable 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 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 |