1 20 package org.apache.slide.projector.store; 21 22 import java.io.IOException ; 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 key, Object value) throws IOException { 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 ("Could not write value to repository! Given value is '"+value+"'"); 51 } 52 } 53 54 public Object get(String key) throws IOException { 55 return Projector.getRepository().getResource(new URIValue(key), context.getCredentials()); 56 } 57 58 public void dispose(String key) throws IOException { 59 Projector.getRepository().removeResource(new URIValue(key), context.getCredentials()); 60 } 61 } | Popular Tags |