1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 }
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 }