| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ViewIndex |
|
| 1.3333333333333333;1.333 |
| 1 | /* | |
| 2 | * Copyright 2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 1.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl1.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.kns.uif.container; | |
| 17 | ||
| 18 | import java.io.Serializable; | |
| 19 | import java.util.HashMap; | |
| 20 | import java.util.HashSet; | |
| 21 | import java.util.List; | |
| 22 | import java.util.Map; | |
| 23 | import java.util.Set; | |
| 24 | ||
| 25 | import org.kuali.rice.kns.uif.field.AttributeField; | |
| 26 | import org.kuali.rice.kns.uif.field.Field; | |
| 27 | import org.kuali.rice.kns.uif.field.GroupField; | |
| 28 | import org.kuali.rice.kns.uif.util.ComponentUtils; | |
| 29 | ||
| 30 | /** | |
| 31 | * Holds field indexes of a <code>View</code> instance for retrieval | |
| 32 | * | |
| 33 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 34 | */ | |
| 35 | public class ViewIndex implements Serializable { | |
| 36 | private static final long serialVersionUID = 4700818801272201371L; | |
| 37 | ||
| 38 | private Set<AttributeField> attributeFields; | |
| 39 | private Map<String, AttributeField> attributeFieldIndex; | |
| 40 | ||
| 41 | private Set<CollectionGroup> collections; | |
| 42 | private Map<String, CollectionGroup> collectionsIndex; | |
| 43 | ||
| 44 | 0 | public ViewIndex() { |
| 45 | 0 | attributeFields = new HashSet<AttributeField>(); |
| 46 | 0 | collections = new HashSet<CollectionGroup>(); |
| 47 | 0 | } |
| 48 | ||
| 49 | /** | |
| 50 | * Creates the field indexes based on the currently held fields | |
| 51 | * | |
| 52 | * <p> | |
| 53 | * <code>AttributeField</code> instances are indexed by the attribute path. | |
| 54 | * This is useful for retrieving the AttributeField based on the incoming | |
| 55 | * request parameter | |
| 56 | * </p> | |
| 57 | * | |
| 58 | * <p> | |
| 59 | * <code>CollectionGroup</code> instances are indexed by the collection | |
| 60 | * path. This is useful for retrieving the CollectionGroup based on the | |
| 61 | * incoming request parameter | |
| 62 | * </p> | |
| 63 | */ | |
| 64 | public void index() { | |
| 65 | 0 | attributeFieldIndex = new HashMap<String, AttributeField>(); |
| 66 | 0 | for (AttributeField field : attributeFields) { |
| 67 | 0 | attributeFieldIndex.put(field.getBindingInfo().getBindingPath(), field); |
| 68 | } | |
| 69 | ||
| 70 | 0 | collectionsIndex = new HashMap<String, CollectionGroup>(); |
| 71 | 0 | for (CollectionGroup collection : collections) { |
| 72 | 0 | collectionsIndex.put(collection.getBindingInfo().getBindingPath(), collection); |
| 73 | } | |
| 74 | 0 | } |
| 75 | ||
| 76 | /** | |
| 77 | * Retrieves a <code>AttributeField</code> instance from the index | |
| 78 | * | |
| 79 | * @param attributePath | |
| 80 | * - full path of the attribute (from the form) | |
| 81 | * @return AttributeField instance for the path or Null if not found | |
| 82 | */ | |
| 83 | public AttributeField getAttributeFieldByPath(String attributePath) { | |
| 84 | 0 | return attributeFieldIndex.get(attributePath); |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Set of <code>AttributeField</code> instances that are held in the index | |
| 89 | * | |
| 90 | * @return Set<AttributeField> | |
| 91 | */ | |
| 92 | public Set<AttributeField> getAttributeFields() { | |
| 93 | 0 | return this.attributeFields; |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * Setter for the AttributeField set | |
| 98 | * | |
| 99 | * @param attributeFields | |
| 100 | */ | |
| 101 | public void setAttributeFields(Set<AttributeField> attributeFields) { | |
| 102 | 0 | this.attributeFields = attributeFields; |
| 103 | 0 | } |
| 104 | ||
| 105 | /** | |
| 106 | * Adds an <code>AttributeField</code> instance to the Set of fields to | |
| 107 | * index | |
| 108 | * | |
| 109 | * @param field | |
| 110 | * - AttributeField instance to index | |
| 111 | */ | |
| 112 | public void addAttributeField(AttributeField field) { | |
| 113 | 0 | attributeFields.add(field); |
| 114 | 0 | } |
| 115 | ||
| 116 | /** | |
| 117 | * Adds any <code>AttributeField</code> instances to the Set of fields to | |
| 118 | * index. If the field is a <code>GroupField</code> it is recursively | |
| 119 | * checked for attribute field items | |
| 120 | * | |
| 121 | * @param fields | |
| 122 | * - List of fields instances to add | |
| 123 | */ | |
| 124 | public void addFields(List<? extends Field> fields) { | |
| 125 | 0 | for (Field field : fields) { |
| 126 | 0 | if (field instanceof AttributeField) { |
| 127 | 0 | attributeFields.add((AttributeField) field); |
| 128 | } | |
| 129 | 0 | else if (field instanceof GroupField) { |
| 130 | 0 | List<? extends Field> groupFields = ComponentUtils.getComponentsOfType(((GroupField) field).getItems(), |
| 131 | Field.class); | |
| 132 | 0 | addFields(groupFields); |
| 133 | 0 | } |
| 134 | } | |
| 135 | 0 | } |
| 136 | ||
| 137 | /** | |
| 138 | * Gets the Map that contains attribute field indexing information. The Map | |
| 139 | * key points to an attribute binding path, and the Map value is the | |
| 140 | * <code>AttributeField</code> instance | |
| 141 | * | |
| 142 | * @return Map<String, AttributeField> attribute fields index map | |
| 143 | */ | |
| 144 | public Map<String, AttributeField> getAttributeFieldIndex() { | |
| 145 | 0 | return this.attributeFieldIndex; |
| 146 | } | |
| 147 | ||
| 148 | /** | |
| 149 | * Setter for the attribute fields index map | |
| 150 | * | |
| 151 | * @param attributeFieldIndex | |
| 152 | */ | |
| 153 | public void setAttributeFieldIndex(Map<String, AttributeField> attributeFieldIndex) { | |
| 154 | 0 | this.attributeFieldIndex = attributeFieldIndex; |
| 155 | 0 | } |
| 156 | ||
| 157 | /** | |
| 158 | * Set of <code>CollectionGroup</code> instances that are held in the index | |
| 159 | * | |
| 160 | * @return Set<CollectionGroup> | |
| 161 | */ | |
| 162 | public Set<CollectionGroup> getCollections() { | |
| 163 | 0 | return this.collections; |
| 164 | } | |
| 165 | ||
| 166 | /** | |
| 167 | * Setter for the Set of <code>CollectionGroup</code> instances | |
| 168 | * | |
| 169 | * @param collections | |
| 170 | */ | |
| 171 | public void setCollections(Set<CollectionGroup> collections) { | |
| 172 | 0 | this.collections = collections; |
| 173 | 0 | } |
| 174 | ||
| 175 | /** | |
| 176 | * Adds a <code>CollectionGroup</code> instances to the set of collections | |
| 177 | * to index | |
| 178 | * | |
| 179 | * @param collectionGroup | |
| 180 | * - collection group instance to index | |
| 181 | */ | |
| 182 | public void addCollection(CollectionGroup collectionGroup) { | |
| 183 | 0 | collections.add(collectionGroup); |
| 184 | 0 | } |
| 185 | ||
| 186 | /** | |
| 187 | * Gets the Map that contains collection indexing information. The Map key | |
| 188 | * gives the binding path to the collection, and the Map value givens the | |
| 189 | * <code>CollectionGroup</code> instance | |
| 190 | * | |
| 191 | * @return Map<String, CollectionGroup> collection index map | |
| 192 | */ | |
| 193 | public Map<String, CollectionGroup> getCollectionsIndex() { | |
| 194 | 0 | return this.collectionsIndex; |
| 195 | } | |
| 196 | ||
| 197 | /** | |
| 198 | * Setter for the collections index map | |
| 199 | * | |
| 200 | * @param collectionsIndex | |
| 201 | */ | |
| 202 | public void setCollectionsIndex(Map<String, CollectionGroup> collectionsIndex) { | |
| 203 | 0 | this.collectionsIndex = collectionsIndex; |
| 204 | 0 | } |
| 205 | ||
| 206 | /** | |
| 207 | * Retrieves a <code>CollectionGroup</code> instance from the index | |
| 208 | * | |
| 209 | * @param collectionPath | |
| 210 | * - full path of the collection (from the form) | |
| 211 | * @return CollectionGroup instance for the collection path or Null if not | |
| 212 | * found | |
| 213 | */ | |
| 214 | public CollectionGroup getCollectionGroupByPath(String collectionPath) { | |
| 215 | 0 | return collectionsIndex.get(collectionPath); |
| 216 | } | |
| 217 | ||
| 218 | } |