View Javadoc

1   /*
2    * Copyright (c) 2003 Peter Antman, Teknik i Media  <peter.antman@tim.se>
3    *
4    * $Id: CachedStreamFactory.java,v 1.1.1.1 2004/05/19 12:07:30 pra Exp $
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version
10   * 
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package org.backsource.utils.io;
21  import java.util.Properties;
22  
23  import org.backsource.utils.lang.Factory;
24  /***
25   * Factory for CachedStream implementation.
26   *
27   * <p>The factory follows the pattern from JXAP and {@link org.backsource.utils.lang.Factory}, which means that the factory is used to get an implementing factory: from which the CachedStream is gotten. {@link #FACTORY_PROPERTY} defines the name of the property.</p>
28   *
29   * @author <a href="mailto:pra@tim.se">Peter Antman</a>
30   * @version $Revision: 1.1.1.1 $
31   */
32  
33  public abstract class CachedStreamFactory extends Factory {
34     /***
35      * The property name/key to use when configuring the factory: <b>org.backsource.utils.io.CachedStreamFactory</b>.
36      */
37     public static final String FACTORY_PROPERTY = "org.backsource.utils.io.CachedStreamFactory";
38     protected CachedStreamFactory (){
39        
40     }
41     /***
42      * Get the system configured CachedStreamFactory.
43      *
44      * <p>See {@link org.backsource.utils.lang.Factory} to understand how the search order is used and how to configure a custom factory.The default is ByteCachedStream.A reverse search order is used!</p>
45      */
46     public static CachedStreamFactory newInstance() throws ClassNotFoundException {
47        return newInstance(null,true);
48     }
49     
50     /***
51      * Get the possibly locally configured CachedStreamFactory.
52      *
53      * <p>See {@link org.backsource.utils.lang.Factory} to understand how the search order is used and how to configure a custom factory.The default is ByteCachedStream.</p>
54      * @param clazz the full classname of the factory to use, may be null.
55      * @param reversedOrder search in reverse order according to Factory.
56      */
57     public static CachedStreamFactory newInstance(String clazz, boolean reversedOrder) throws ClassNotFoundException {
58        Properties env = null;
59        if ( clazz != null) {
60           env = new Properties();
61           env.setProperty(FACTORY_PROPERTY,clazz);
62        } // end of if ()
63        return (CachedStreamFactory)findInstance(FACTORY_PROPERTY, env, ByteCachedStreamFactory.class.getName(),reversedOrder);
64        
65     }
66     
67     /***
68      * Get the CachedStream implementation.
69      */
70     public abstract CachedStream getCachedStream();
71  
72  }// CachedStreamFactory