Source for org.jfree.repository.stream.StreamContentLocation

   1: /**
   2:  * ===========================================================
   3:  * LibRepository : a free Java content repository access layer
   4:  * ===========================================================
   5:  *
   6:  * Project Info:  http://jfreereport.pentaho.org/librepository/
   7:  *
   8:  * (C) Copyright 2006, by Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  * ------------
  26:  * StreamContentLocation.java
  27:  * ------------
  28:  * (C) Copyright 2006, by Pentaho Corporation.
  29:  */
  30: 
  31: package org.jfree.repository.stream;
  32: 
  33: import org.jfree.repository.ContentCreationException;
  34: import org.jfree.repository.ContentEntity;
  35: import org.jfree.repository.ContentIOException;
  36: import org.jfree.repository.ContentItem;
  37: import org.jfree.repository.ContentLocation;
  38: import org.jfree.repository.Repository;
  39: 
  40: /**
  41:  * Creation-Date: 13.11.2006, 17:23:40
  42:  *
  43:  * @author Thomas Morgner
  44:  */
  45: public class StreamContentLocation implements ContentLocation
  46: {
  47:   private ContentItem contentItem;
  48:   private StreamRepository repository;
  49: 
  50:   public StreamContentLocation(final StreamRepository repository)
  51:   {
  52:     this.repository = repository;
  53:   }
  54: 
  55:   public ContentEntity[] listContents() throws ContentIOException
  56:   {
  57:     if (contentItem == null)
  58:     {
  59:       return new ContentEntity[0];
  60:     }
  61:     else
  62:     {
  63:       return new ContentEntity[]{contentItem};
  64:     }
  65:   }
  66: 
  67:   public ContentEntity getEntry(String name) throws ContentIOException
  68:   {
  69:     if (contentItem == null)
  70:     {
  71:       throw new ContentIOException("No such item");
  72:     }
  73:     if (contentItem.getName().equals(name))
  74:     {
  75:       return contentItem;
  76:     }
  77:     throw new ContentIOException("No such item");
  78:   }
  79: 
  80:   public ContentItem createItem(String name) throws ContentCreationException
  81:   {
  82:     if (contentItem == null)
  83:     {
  84:       contentItem = new StreamContentItem(name, this,
  85:           repository.getInputStream(), repository.getOutputStream());
  86:       return contentItem;
  87:     }
  88:     throw new ContentCreationException
  89:         ("Failed to create the item. Item already there");
  90:   }
  91: 
  92:   public ContentLocation createLocation(String name)
  93:       throws ContentCreationException
  94:   {
  95:     throw new ContentCreationException
  96:         ("Failed to create the item. Item already there");
  97:   }
  98: 
  99:   public boolean exists(final String name)
 100:   {
 101:     if (contentItem == null)
 102:     {
 103:       return false;
 104:     }
 105:     return contentItem.getName().equals(name);
 106:   }
 107: 
 108:   public String getName()
 109:   {
 110:     return "root";
 111:   }
 112: 
 113:   public Object getContentId()
 114:   {
 115:     return getName();
 116:   }
 117: 
 118:   public Object getAttribute(String domain, String key)
 119:   {
 120:     return null;
 121:   }
 122: 
 123:   public boolean setAttribute(String domain, String key, Object value)
 124:   {
 125:     return false;
 126:   }
 127: 
 128:   public ContentLocation getParent()
 129:   {
 130:     return null;
 131:   }
 132: 
 133:   public Repository getRepository()
 134:   {
 135:     return repository;
 136:   }
 137: 
 138:   public boolean delete()
 139:   {
 140:     return false;
 141:   }
 142: }