Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DocumentSerializationState |
|
| 1.0;1 | ||||
DocumentSerializationState$SerializationPropertyElement |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright 2007-2008 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.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/ecl2.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.krad.util.documentserializer; | |
17 | ||
18 | import java.util.ArrayList; | |
19 | import java.util.List; | |
20 | ||
21 | /** | |
22 | * This object keeps track of most of the open tags while a document is serialized. Note that instances of this class | |
23 | * may not necessarily hold all open tags of a document while it is being serialized. For example, tags enclosing list elements | |
24 | * and map entries are not contained within here. See {@link DocumentSerializerServiceImpl} to determine when this object's state | |
25 | * is modified. | |
26 | * | |
27 | * This class's manipulators behave much like a stack, but it has random access characteristics like an array. | |
28 | */ | |
29 | public class DocumentSerializationState { | |
30 | protected class SerializationPropertyElement { | |
31 | private String elementName; | |
32 | private PropertyType propertyType; | |
33 | ||
34 | 0 | public SerializationPropertyElement(String elementName, PropertyType propertyType) { |
35 | 0 | this.elementName = elementName; |
36 | 0 | this.propertyType = propertyType; |
37 | 0 | } |
38 | ||
39 | public String getElementName() { | |
40 | 0 | return this.elementName; |
41 | } | |
42 | ||
43 | public PropertyType getPropertyType() { | |
44 | 0 | return this.propertyType; |
45 | } | |
46 | } | |
47 | ||
48 | private List<SerializationPropertyElement> pathElements; | |
49 | ||
50 | 0 | public DocumentSerializationState() { |
51 | 0 | pathElements = new ArrayList<SerializationPropertyElement>(); |
52 | 0 | } |
53 | ||
54 | /** | |
55 | * The number of property elements in this state object. | |
56 | * | |
57 | * @return | |
58 | */ | |
59 | public int numPropertyElements() { | |
60 | 0 | return pathElements.size(); |
61 | } | |
62 | ||
63 | /** | |
64 | * Adds an additional state element into this object. | |
65 | * | |
66 | * @param elementName | |
67 | * @param propertyType the type of the property when it was serialized | |
68 | */ | |
69 | public void addSerializedProperty(String elementName, PropertyType propertyType) { | |
70 | 0 | SerializationPropertyElement serializationPropertyElement = new SerializationPropertyElement(elementName, propertyType); |
71 | 0 | pathElements.add(serializationPropertyElement); |
72 | 0 | } |
73 | ||
74 | /** | |
75 | * Removes the last added serialized property | |
76 | * | |
77 | */ | |
78 | public void removeSerializedProperty() { | |
79 | 0 | pathElements.remove(pathElements.size() - 1); |
80 | 0 | } |
81 | ||
82 | /** | |
83 | * Retrieves the element name of the state element. A parameter value of 0 represents the first element that was added | |
84 | * by calling {@link #addSerializedProperty(String, PropertyType)} that hasn't been removed, and a value of | |
85 | * {@link #numPropertyElements()} - 1 represents the element last added that hasn't been removed. | |
86 | * | |
87 | * @param propertyIndex most be between 0 and the value returned by {@link #numPropertyElements()} - 1 | |
88 | * @return | |
89 | */ | |
90 | public String getElementName(int propertyIndex) { | |
91 | 0 | return pathElements.get(propertyIndex).getElementName(); |
92 | } | |
93 | ||
94 | /** | |
95 | * Retrieves the property type of the state element. A parameter value of 0 represents the first element that was added | |
96 | * by calling {@link #addSerializedProperty(String, PropertyType)} that hasn't been removed, and a value of | |
97 | * {@link #numPropertyElements()} - 1 represents the element last added that hasn't been removed. | |
98 | * | |
99 | * @param propertyIndex most be between 0 and the value returned by {@link #numPropertyElements()} - 1 | |
100 | * @return | |
101 | */ | |
102 | public PropertyType getPropertyType(int propertyIndex) { | |
103 | 0 | return pathElements.get(propertyIndex).getPropertyType(); |
104 | } | |
105 | } |