001    /**
002     * ===========================================================
003     * LibRepository : a free Java content repository access layer
004     * ===========================================================
005     *
006     * Project Info:  http://jfreereport.pentaho.org/librepository/
007     *
008     * (C) Copyright 2006, by Pentaho Corporation and Contributors.
009     *
010     * This library is free software; you can redistribute it and/or modify it under the terms
011     * of the GNU Lesser General Public License as published by the Free Software Foundation;
012     * either version 2.1 of the License, or (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016     * See the GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public License along with this
019     * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020     * Boston, MA 02111-1307, USA.
021     *
022     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023     * in the United States and other countries.]
024     *
025     * ------------
026     * StreamContentLocation.java
027     * ------------
028     * (C) Copyright 2006, by Pentaho Corporation.
029     */
030    
031    package org.jfree.repository.stream;
032    
033    import org.jfree.repository.ContentCreationException;
034    import org.jfree.repository.ContentEntity;
035    import org.jfree.repository.ContentIOException;
036    import org.jfree.repository.ContentItem;
037    import org.jfree.repository.ContentLocation;
038    import org.jfree.repository.Repository;
039    
040    /**
041     * Creation-Date: 13.11.2006, 17:23:40
042     *
043     * @author Thomas Morgner
044     */
045    public class StreamContentLocation implements ContentLocation
046    {
047      private ContentItem contentItem;
048      private StreamRepository repository;
049      private static final ContentEntity[] EMPTY_CONTENT_ENTITY = new ContentEntity[0];
050    
051      public StreamContentLocation(final StreamRepository repository)
052      {
053        this.repository = repository;
054      }
055    
056      public ContentEntity[] listContents() throws ContentIOException
057      {
058        if (contentItem == null)
059        {
060          return EMPTY_CONTENT_ENTITY;
061        }
062        else
063        {
064          return new ContentEntity[]{contentItem};
065        }
066      }
067    
068      public ContentEntity getEntry(final String name) throws ContentIOException
069      {
070        if (contentItem == null)
071        {
072          throw new ContentIOException("No such item");
073        }
074        if (contentItem.getName().equals(name))
075        {
076          return contentItem;
077        }
078        throw new ContentIOException("No such item");
079      }
080    
081      public ContentItem createItem(final String name) throws ContentCreationException
082      {
083        if (contentItem == null)
084        {
085          contentItem = new StreamContentItem(name, this,
086              repository.getInputStream(), repository.getOutputStream());
087          return contentItem;
088        }
089        throw new ContentCreationException
090            ("Failed to create the item. Item already there");
091      }
092    
093      public ContentLocation createLocation(final String name)
094          throws ContentCreationException
095      {
096        throw new ContentCreationException
097            ("Failed to create the item. Item already there");
098      }
099    
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    }