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:   private static final ContentEntity[] EMPTY_CONTENT_ENTITY = new ContentEntity[0];
  50: 
  51:   public StreamContentLocation(final StreamRepository repository)
  52:   {
  53:     this.repository = repository;
  54:   }
  55: 
  56:   public ContentEntity[] listContents() throws ContentIOException
  57:   {
  58:     if (contentItem == null)
  59:     {
  60:       return EMPTY_CONTENT_ENTITY;
  61:     }
  62:     else
  63:     {
  64:       return new ContentEntity[]{contentItem};
  65:     }
  66:   }
  67: 
  68:   public ContentEntity getEntry(final String name) throws ContentIOException
  69:   {
  70:     if (contentItem == null)
  71:     {
  72:       throw new ContentIOException("No such item");
  73:     }
  74:     if (contentItem.getName().equals(name))
  75:     {
  76:       return contentItem;
  77:     }
  78:     throw new ContentIOException("No such item");
  79:   }
  80: 
  81:   public ContentItem createItem(final String name) throws ContentCreationException
  82:   {
  83:     if (contentItem == null)
  84:     {
  85:       contentItem = new StreamContentItem(name, this,
  86:           repository.getInputStream(), repository.getOutputStream());
  87:       return contentItem;
  88:     }
  89:     throw new ContentCreationException
  90:         ("Failed to create the item. Item already there");
  91:   }
  92: 
  93:   public ContentLocation createLocation(final String name)
  94:       throws ContentCreationException
  95:   {
  96:     throw new ContentCreationException
  97:         ("Failed to create the item. Item already there");
  98:   }
  99: 
 100:   public boolean exists(final String name)
 101:   {
 102:     if (contentItem == null)
 103:     {
 104:       return false;
 105:     }
 106:     return contentItem.getName().equals(name);
 107:   }
 108: 
 109:   public String getName()
 110:   {
 111:     return "root";
 112:   }
 113: 
 114:   public Object getContentId()
 115:   {
 116:     return getName();
 117:   }
 118: 
 119:   public Object getAttribute(final String domain, final String key)
 120:   {
 121:     return null;
 122:   }
 123: 
 124:   public boolean setAttribute(final String domain, final String key, final Object value)
 125:   {
 126:     return false;
 127:   }
 128: 
 129:   public ContentLocation getParent()
 130:   {
 131:     return null;
 132:   }
 133: 
 134:   public Repository getRepository()
 135:   {
 136:     return repository;
 137:   }
 138: 
 139:   public boolean delete()
 140:   {
 141:     return false;
 142:   }
 143: }