KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > store > FormStore


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

20 package org.apache.slide.projector.store;
21
22 import java.io.IOException JavaDoc;
23
24 import org.apache.slide.projector.Context;
25 import org.apache.slide.projector.Store;
26 import org.apache.slide.projector.value.MapValue;
27
28 public class FormStore extends AbstractStore {
29     private Context context;
30     private Store store;
31     
32     public FormStore(Context context, Store store) {
33         this.context = context;
34         this.store = store;
35     }
36
37     public void put(String JavaDoc key, Object JavaDoc value) throws IOException JavaDoc {
38         MapValue domain = getDomain();
39         domain.getMap().put(key, value);
40     }
41
42     public Object JavaDoc get(String JavaDoc key) throws IOException JavaDoc {
43         return getDomain().getMap().get(key);
44     }
45
46     public void dispose(String JavaDoc key) throws IOException JavaDoc {
47         getDomain().getMap().remove(key);
48     }
49
50     public void clear() throws IOException JavaDoc {
51         String JavaDoc domain = context.getProcess().toString();
52         store.dispose(domain);
53     }
54     
55     public MapValue getDomain() throws IOException JavaDoc {
56         String JavaDoc domain = context.getProcess().toString();
57         MapValue mapResource = (MapValue)store.get(domain);
58         if ( mapResource == null ) {
59             mapResource = new MapValue();
60             store.put(domain, mapResource);
61             return mapResource;
62         } else {
63             return mapResource;
64         }
65     }
66 }
Popular Tags