KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > store > mem > TransientNodeStore


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientNodeStore.java,v 1.3 2004/07/28 09:34:05 ib Exp $
3  * $Revision: 1.3 $
4  * $Date: 2004/07/28 09:34:05 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23 package org.apache.slide.store.mem;
24
25 import org.apache.slide.common.ServiceAccessException;
26 import org.apache.slide.common.Uri;
27 import org.apache.slide.store.NodeStore;
28 import org.apache.slide.structure.ObjectAlreadyExistsException;
29 import org.apache.slide.structure.ObjectNode;
30 import org.apache.slide.structure.ObjectNotFoundException;
31
32
33 /**
34  * NodeStore that stores ObjectNodes in transient memory.
35  *
36  */

37 public class TransientNodeStore extends AbstractTransientStore implements
38       NodeStore
39 {
40    // Note: we don't clone ObjectNodes because ExtendedStore clones
41

42    public ObjectNode retrieveObject(Uri uri) throws ServiceAccessException,
43          ObjectNotFoundException
44    {
45       debug("retrieveObject {0}", uri);
46       ObjectNode node = (ObjectNode)get(uri.toString());
47       if (node != null) {
48          return node;
49       } else {
50          throw new ObjectNotFoundException(uri);
51       }
52    }
53
54    public void storeObject(Uri uri, ObjectNode object)
55          throws ServiceAccessException, ObjectNotFoundException
56    {
57       debug("storeObejct {0}", uri);
58       ObjectNode node = (ObjectNode)get(uri.toString());
59       if (node != null) {
60          put(uri.toString(), object);
61       } else {
62          throw new ObjectNotFoundException(uri);
63       }
64    }
65
66    public void createObject(Uri uri, ObjectNode object)
67          throws ServiceAccessException, ObjectAlreadyExistsException
68    {
69       debug("createObject {0}", uri);
70       ObjectNode node = (ObjectNode)get(uri.toString());
71       if (node == null) {
72          put(uri.toString(), object);
73       } else {
74          throw new ObjectAlreadyExistsException(uri.toString());
75       }
76    }
77
78    public void removeObject(Uri uri, ObjectNode object)
79          throws ServiceAccessException, ObjectNotFoundException
80    {
81       debug("removeObject {0}", uri);
82       ObjectNode node = (ObjectNode)get(uri.toString());
83       if (node != null) {
84          remove(uri.toString());
85       } else {
86          throw new ObjectNotFoundException(uri);
87       }
88    }
89 }
90
Popular Tags