%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.om.page.impl.FragmentPreferenceList |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.om.page.impl; |
|
18 | ||
19 | import java.util.AbstractList; |
|
20 | import java.util.List; |
|
21 | import org.apache.jetspeed.page.impl.DatabasePageManagerUtils; |
|
22 | ||
23 | /** |
|
24 | * FragmentPreferenceList |
|
25 | * |
|
26 | * @author <a href="mailto:rwatler@apache.org">Randy Watler</a> |
|
27 | * @version $Id$ |
|
28 | */ |
|
29 | class FragmentPreferenceList extends AbstractList |
|
30 | { |
|
31 | private FragmentImpl fragment; |
|
32 | ||
33 | private List removedPreferences; |
|
34 | ||
35 | FragmentPreferenceList(FragmentImpl fragment) |
|
36 | { |
|
37 | 0 | super(); |
38 | 0 | this.fragment = fragment; |
39 | 0 | } |
40 | ||
41 | /** |
|
42 | * validatePreferenceForAdd |
|
43 | * |
|
44 | * Validates preference to be added to this list. |
|
45 | * |
|
46 | * @param preference preference to add |
|
47 | * @return list element to add |
|
48 | */ |
|
49 | private FragmentPreferenceImpl validatePreferenceForAdd(FragmentPreferenceImpl preference) |
|
50 | { |
|
51 | // only non-null definitions supported |
|
52 | 0 | if (preference == null) |
53 | { |
|
54 | 0 | throw new NullPointerException("Unable to add null to list."); |
55 | } |
|
56 | // make sure element is unique |
|
57 | 0 | if (fragment.accessPreferences().contains(preference)) |
58 | { |
|
59 | 0 | throw new IllegalArgumentException("Unable to add duplicate entry to list: " + preference.getName()); |
60 | } |
|
61 | // retrieve from removed list to reuse |
|
62 | // previously removed element copying |
|
63 | // security constraint defs |
|
64 | 0 | if (removedPreferences != null) |
65 | { |
|
66 | 0 | int removedIndex = removedPreferences.indexOf(preference); |
67 | 0 | if (removedIndex >= 0) |
68 | { |
|
69 | 0 | FragmentPreferenceImpl addPreference = preference; |
70 | 0 | preference = (FragmentPreferenceImpl)removedPreferences.remove(removedIndex); |
71 | // TODO: move this logic to copy methods on implementations |
|
72 | 0 | preference.setReadOnly(addPreference.isReadOnly()); |
73 | 0 | preference.setValueList(addPreference.getValueList()); |
74 | } |
|
75 | } |
|
76 | 0 | return preference; |
77 | } |
|
78 | ||
79 | /** |
|
80 | * getRemovedPreferences |
|
81 | * |
|
82 | * @return removed preferences tracking collection |
|
83 | */ |
|
84 | private List getRemovedPreferences() |
|
85 | { |
|
86 | 0 | if (removedPreferences == null) |
87 | { |
|
88 | 0 | removedPreferences = DatabasePageManagerUtils.createList(); |
89 | } |
|
90 | 0 | return removedPreferences; |
91 | } |
|
92 | ||
93 | /* (non-Javadoc) |
|
94 | * @see java.util.List#add(int,java.lang.Object) |
|
95 | */ |
|
96 | public void add(int index, Object element) |
|
97 | { |
|
98 | // implement for modifiable AbstractList: |
|
99 | // validate index |
|
100 | 0 | if ((index < 0) || (index > fragment.accessPreferences().size())) |
101 | { |
|
102 | 0 | throw new IndexOutOfBoundsException("Unable to add to list at index: " + index); |
103 | } |
|
104 | // verify preference |
|
105 | 0 | FragmentPreferenceImpl preference = validatePreferenceForAdd((FragmentPreferenceImpl)element); |
106 | // add to underlying ordered list |
|
107 | 0 | fragment.accessPreferences().add(index, preference); |
108 | 0 | } |
109 | ||
110 | /* (non-Javadoc) |
|
111 | * @see java.util.List#get(int) |
|
112 | */ |
|
113 | public Object get(int index) |
|
114 | { |
|
115 | // implement for modifiable AbstractList |
|
116 | 0 | return fragment.accessPreferences().get(index); |
117 | } |
|
118 | ||
119 | /* (non-Javadoc) |
|
120 | * @see java.util.List#remove(int) |
|
121 | */ |
|
122 | public Object remove(int index) |
|
123 | { |
|
124 | // implement for modifiable AbstractList: |
|
125 | // save removed element |
|
126 | 0 | FragmentPreferenceImpl removed = (FragmentPreferenceImpl)fragment.accessPreferences().remove(index); |
127 | 0 | if (removed != null) |
128 | { |
|
129 | 0 | getRemovedPreferences().add(removed); |
130 | } |
|
131 | 0 | return removed; |
132 | } |
|
133 | ||
134 | /* (non-Javadoc) |
|
135 | * @see java.util.List#set(int,java.lang.Object) |
|
136 | */ |
|
137 | public Object set(int index, Object element) |
|
138 | { |
|
139 | // implement for modifiable AbstractList: |
|
140 | // verify preference |
|
141 | 0 | FragmentPreferenceImpl newPreference = validatePreferenceForAdd((FragmentPreferenceImpl)element); |
142 | // set in underlying ordered list |
|
143 | 0 | FragmentPreferenceImpl preference = (FragmentPreferenceImpl)fragment.accessPreferences().set(index, newPreference); |
144 | // save replaced element |
|
145 | 0 | getRemovedPreferences().add(preference); |
146 | // return constraints ref |
|
147 | 0 | return preference; |
148 | } |
|
149 | ||
150 | /* (non-Javadoc) |
|
151 | * @see java.util.List#size() |
|
152 | */ |
|
153 | public int size() |
|
154 | { |
|
155 | // implement for modifiable AbstractList |
|
156 | 0 | return fragment.accessPreferences().size(); |
157 | } |
|
158 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |