KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientContentStore.java,v 1.2 2004/07/28 09:34:05 ib Exp $
3  * $Revision: 1.2 $
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.content.NodeRevisionContent;
28 import org.apache.slide.content.NodeRevisionDescriptor;
29 import org.apache.slide.content.RevisionAlreadyExistException;
30 import org.apache.slide.content.RevisionNotFoundException;
31 import org.apache.slide.store.ContentStore;
32
33
34 /**
35  */

36 public class TransientContentStore extends AbstractTransientStore implements
37       ContentStore
38 {
39    // FIXME: should we clone the content byte array?
40

41    public NodeRevisionContent retrieveRevisionContent(Uri uri,
42          NodeRevisionDescriptor revisionDescriptor)
43          throws ServiceAccessException, RevisionNotFoundException
44    {
45       VersionedUriKey key = new VersionedUriKey(uri,
46             revisionDescriptor.getRevisionNumber());
47       debug("retrieveRevisionContent {0}", key);
48       
49       byte[] content = (byte[])get(key);
50       if (content != null) {
51          NodeRevisionContent revisionContent = new NodeRevisionContent();
52          revisionContent.setContent(content);
53          return revisionContent;
54       } else {
55          throw new RevisionNotFoundException(uri.toString(),
56                revisionDescriptor.getRevisionNumber());
57       }
58    }
59
60    public void createRevisionContent(Uri uri,
61          NodeRevisionDescriptor revisionDescriptor,
62          NodeRevisionContent revisionContent) throws ServiceAccessException,
63          RevisionAlreadyExistException
64    {
65       VersionedUriKey key = new VersionedUriKey(uri,
66             revisionDescriptor.getRevisionNumber());
67       debug("createRevisionContent {0}", key);
68       
69       byte[] content = (byte[])get(key);
70       if (content == null) {
71          put(key, revisionContent.getContentBytes());
72       } else {
73          throw new RevisionAlreadyExistException(uri.toString(),
74                revisionDescriptor.getRevisionNumber());
75       }
76    }
77    
78    public void storeRevisionContent(Uri uri,
79          NodeRevisionDescriptor revisionDescriptor,
80          NodeRevisionContent revisionContent) throws ServiceAccessException,
81          RevisionNotFoundException
82    {
83       VersionedUriKey key = new VersionedUriKey(uri,
84             revisionDescriptor.getRevisionNumber());
85       debug("storeRevisionContent {0}", key);
86      
87       byte[] content = (byte[])get(key);
88       if (content != null) {
89          put(key, revisionContent.getContentBytes());
90       } else {
91          throw new RevisionNotFoundException(uri.toString(),
92                revisionDescriptor.getRevisionNumber());
93       }
94    }
95
96    public void removeRevisionContent(Uri uri,
97          NodeRevisionDescriptor revisionDescriptor)
98          throws ServiceAccessException
99    {
100       VersionedUriKey key = new VersionedUriKey(uri,
101             revisionDescriptor.getRevisionNumber());
102       debug("storeRevisionContent {0}", key);
103       
104       remove(key);
105    }
106 }
107
Popular Tags