KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > xml > FactoryMethods


1 /*
2  * Copyright 2002-2005 the original author or authors.
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
17 package org.springframework.beans.factory.xml;
18
19 import java.util.Collections JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.springframework.beans.TestBean;
23
24 /**
25  * Test class for Spring's ability to create objects using static
26  * factory methods, rather than constructors.
27  *
28  * @author Rod Johnson
29  */

30 public class FactoryMethods {
31     
32     public static FactoryMethods defaultInstance() {
33         TestBean tb = new TestBean();
34         tb.setName("defaultInstance");
35         return new FactoryMethods(tb, "default", 0);
36     }
37     
38     /**
39      * Note that overloaded methods are supported.
40      */

41     public static FactoryMethods newInstance(TestBean tb) {
42         return new FactoryMethods(tb, "default", 0);
43     }
44     
45     public static FactoryMethods newInstance(TestBean tb, int num, String JavaDoc name) {
46         if (name == null) {
47             throw new IllegalStateException JavaDoc("Should never be called with null value");
48         }
49         return new FactoryMethods(tb, name, num);
50     }
51     
52     public static FactoryMethods newInstance(TestBean tb, int num, Integer JavaDoc something) {
53         if (something != null) {
54             throw new IllegalStateException JavaDoc("Should never be called with non-null value");
55         }
56         return new FactoryMethods(tb, null, num);
57     }
58
59     public static List JavaDoc listInstance() {
60         return Collections.EMPTY_LIST;
61     }
62
63
64     private int num = 0;
65     private String JavaDoc name = "default";
66     private TestBean tb;
67     private String JavaDoc stringValue;
68
69
70     /**
71      * Constructor is private: not for use outside this class,
72      * even by IoC container.
73      */

74     private FactoryMethods(TestBean tb, String JavaDoc name, int num) {
75         this.tb = tb;
76         this.name = name;
77         this.num = num;
78     }
79     
80     public void setStringValue(String JavaDoc stringValue) {
81         this.stringValue = stringValue;
82     }
83     
84     public String JavaDoc getStringValue() {
85         return this.stringValue;
86     }
87     
88     public TestBean getTestBean() {
89         return this.tb;
90     }
91     
92     public int getNum() {
93         return num;
94     }
95     
96     public String JavaDoc getName() {
97         return name;
98     }
99     
100     /**
101      * Set via Setter Injection once instance is created
102      */

103     public void setName(String JavaDoc name) {
104         this.name = name;
105     }
106
107 }
108
Popular Tags