KickJava   Java API By Example, From Geeks To Geeks.

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


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.Projector;
26 import org.apache.slide.projector.descriptor.ValueFactoryManager;
27 import org.apache.slide.projector.value.StreamableValue;
28 import org.apache.slide.projector.value.StringValue;
29 import org.apache.slide.projector.value.URIValue;
30 import org.apache.slide.projector.value.Value;
31
32 import de.zeigermann.xml.XMLStringWriter;
33
34 public class RepositoryStore extends AbstractStore {
35     private Context context;
36     
37     public RepositoryStore(Context context) {
38         this.context = context;
39     }
40     
41     public void put(String JavaDoc key, Object JavaDoc value) throws IOException JavaDoc {
42         if ( value instanceof StreamableValue) {
43             Projector.getRepository().setResource(new URIValue(key), (StreamableValue)value, context.getCredentials());
44         } else if ( value instanceof Value ) {
45             XMLStringWriter writer = XMLStringWriter.create();
46             writer.writeXMLDeclaration();
47             ValueFactoryManager.getInstance().saveValue((Value)value, writer);
48             Projector.getRepository().setResource(new URIValue(key), new StringValue(writer.toString()), context.getCredentials());
49         } else {
50             throw new IOException JavaDoc("Could not write value to repository! Given value is '"+value+"'");
51         }
52     }
53
54     public Object JavaDoc get(String JavaDoc key) throws IOException JavaDoc {
55         return Projector.getRepository().getResource(new URIValue(key), context.getCredentials());
56     }
57
58     public void dispose(String JavaDoc key) throws IOException JavaDoc {
59         Projector.getRepository().removeResource(new URIValue(key), context.getCredentials());
60     }
61 }
Popular Tags