KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > record > PropertyPersistenceStrategySourceImpl


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.record;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.hivemind.ApplicationRuntimeException;
25 import org.apache.tapestry.IRequestCycle;
26 import org.apache.tapestry.engine.ServiceEncoding;
27
28 /**
29  * Implementation of the <code>tapestry.persist.PropertyPersistenceStrategySource</code> service.
30  * Allows access to other services, that implement the
31  * {@link org.apache.tapestry.record.PropertyPersistenceStrategy} interface.
32  *
33  * @author Howard M. Lewis Ship
34  * @since 4.0
35  */

36 public class PropertyPersistenceStrategySourceImpl implements PropertyPersistenceStrategySource
37 {
38     // Set from tapestry.props.PersistenceStrategy
39
private List JavaDoc _contributions;
40
41     private Map JavaDoc _strategies = new HashMap JavaDoc();
42
43     public void initializeService()
44     {
45         Iterator JavaDoc i = _contributions.iterator();
46         while (i.hasNext())
47         {
48             PropertyPersistenceStrategyContribution c = (PropertyPersistenceStrategyContribution) i
49                     .next();
50
51             _strategies.put(c.getName(), c.getStrategy());
52         }
53     }
54
55     public PropertyPersistenceStrategy getStrategy(String JavaDoc name)
56     {
57         if (!_strategies.containsKey(name))
58             throw new ApplicationRuntimeException(RecordMessages.unknownPersistenceStrategy(name));
59
60         return (PropertyPersistenceStrategy) _strategies.get(name);
61     }
62
63     public Collection JavaDoc getAllStoredChanges(String JavaDoc pageName, IRequestCycle cycle)
64     {
65         Collection JavaDoc result = new ArrayList JavaDoc();
66
67         Iterator JavaDoc i = _strategies.values().iterator();
68
69         while (i.hasNext())
70         {
71             PropertyPersistenceStrategy s = (PropertyPersistenceStrategy) i.next();
72
73             result.addAll(s.getStoredChanges(pageName, cycle));
74         }
75
76         return result;
77     }
78
79     public void discardAllStoredChanged(String JavaDoc pageName, IRequestCycle cycle)
80     {
81         Iterator JavaDoc i = _strategies.values().iterator();
82
83         while (i.hasNext())
84         {
85             PropertyPersistenceStrategy s = (PropertyPersistenceStrategy) i.next();
86
87             s.discardStoredChanges(pageName, cycle);
88         }
89     }
90
91     public void addParametersForPersistentProperties(ServiceEncoding encoding, IRequestCycle cycle)
92     {
93         Iterator JavaDoc i = _strategies.values().iterator();
94
95         while (i.hasNext())
96         {
97             PropertyPersistenceStrategy s = (PropertyPersistenceStrategy) i.next();
98
99             s.addParametersForPersistentProperties(encoding, cycle);
100         }
101     }
102
103     public void setContributions(List JavaDoc contributions)
104     {
105         _contributions = contributions;
106     }
107 }
Popular Tags