KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > functors > FactoryTransformer


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.functors;
17
18 import java.io.Serializable JavaDoc;
19
20 import org.apache.commons.collections.Factory;
21 import org.apache.commons.collections.Transformer;
22
23 /**
24  * Transformer implementation that calls a Factory and returns the result.
25  *
26  * @since Commons Collections 3.0
27  * @version $Revision: 1.6 $ $Date: 2004/05/16 11:36:31 $
28  *
29  * @author Stephen Colebourne
30  */

31 public class FactoryTransformer implements Transformer, Serializable JavaDoc {
32
33     /** Serial version UID */
34     static final long serialVersionUID = -6817674502475353160L;
35
36     /** The factory to wrap */
37     private final Factory iFactory;
38
39     /**
40      * Factory method that performs validation.
41      *
42      * @param factory the factory to call, not null
43      * @return the <code>factory</code> transformer
44      * @throws IllegalArgumentException if the factory is null
45      */

46     public static Transformer getInstance(Factory factory) {
47         if (factory == null) {
48             throw new IllegalArgumentException JavaDoc("Factory must not be null");
49         }
50         return new FactoryTransformer(factory);
51     }
52
53     /**
54      * Constructor that performs no validation.
55      * Use <code>getInstance</code> if you want that.
56      *
57      * @param factory the factory to call, not null
58      */

59     public FactoryTransformer(Factory factory) {
60         super();
61         iFactory = factory;
62     }
63
64     /**
65      * Transforms the input by ignoring the input and returning the result of
66      * calling the decorated factory.
67      *
68      * @param input the input object to transform
69      * @return the transformed result
70      */

71     public Object JavaDoc transform(Object JavaDoc input) {
72         return iFactory.create();
73     }
74
75     /**
76      * Gets the factory.
77      *
78      * @return the factory
79      * @since Commons Collections 3.1
80      */

81     public Factory getFactory() {
82         return iFactory;
83     }
84
85 }
86
Popular Tags