001    /**
002     * ================================================
003     * LibLoader : a free Java resource loading library
004     * ================================================
005     *
006     * Project Info:  http://reporting.pentaho.org/libloader/
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     * ------------
027     * $Id: CompoundResource.java 3520 2007-10-16 10:34:47Z tmorgner $
028     * ------------
029     * (C) Copyright 2006, by Pentaho Corporation.
030     */
031    
032    package org.jfree.resourceloader;
033    
034    /**
035     * Creation-Date: 08.04.2006, 14:08:13
036     *
037     * @author Thomas Morgner
038     */
039    public class CompoundResource implements Resource
040    {
041      private ResourceKey source;
042      private DependencyCollector dependencies;
043      private Object product;
044    
045      public CompoundResource(final ResourceKey source,
046                              final DependencyCollector dependencies,
047                              final Object product)
048      {
049        if (source == null)
050        {
051          throw new NullPointerException("Source must not be null");
052        }
053        if (dependencies == null)
054        {
055          throw new NullPointerException("Dependecies must be given.");
056        }
057        if (product == null)
058        {
059          throw new NullPointerException("Product must not be null");
060        }
061        this.source = source;
062        try
063        {
064          this.dependencies = (DependencyCollector) dependencies.clone();
065        }
066        catch (CloneNotSupportedException e)
067        {
068          throw new IllegalStateException
069                  ("Clone not supported? This should not happen.");
070        }
071        this.product = product;
072      }
073    
074      public Object getResource() throws ResourceException
075      {
076        return product;
077      }
078    
079      public long getVersion(final ResourceKey key)
080      {
081        return dependencies.getVersion(key);
082      }
083    
084      /**
085       * The primary source is also included in this set. The dependencies are given
086       * as ResourceKey objects. The keys itself do not hold any state information.
087       * <p/>
088       * The dependencies do not track deep dependencies. So if Resource A depends
089       * on Resource B which depends on Resource C, then A only knows about B, not
090       * C.
091       *
092       * @return
093       */
094      public ResourceKey[] getDependencies()
095      {
096        return dependencies.getDependencies();
097      }
098    
099      public ResourceKey getSource()
100      {
101        return source;
102      }
103    }