1 /*
2 * Copyright 2012 Oracle Corporation. All Rights Reserved.
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 com.fatwire.gst.foundation.controller.action.support;
17
18 import COM.FutureTense.Interfaces.ICS;
19
20 import com.fatwire.gst.foundation.controller.action.Factory;
21
22 /**
23 * Factory that reads the producer methods of the passed in class names.
24 *
25 * @author Dolf Dijkstra
26 *
27 */
28 public class ClassBasedFactory extends BaseFactory {
29
30 private Class<?>[] clx;
31
32 /**
33 * @param ics
34 * @param parent the parent factory
35 * @param classnames the names of the classes that hold the factory methods
36 */
37 public ClassBasedFactory(ICS ics, Factory parent, String... classnames) {
38 this(ics, parent, Thread.currentThread().getContextClassLoader(), classnames);
39 }
40
41 /**
42 * @param ics
43 * @param parent the parent factory
44 * @param classLoader the classloader to load the classes of
45 * @param classnames the names of the classes that hold the factory methods
46 */
47 public ClassBasedFactory(ICS ics, Factory parent, ClassLoader classLoader, String... classnames) {
48 super(ics, parent);
49 clx = new Class[classnames.length];
50 for (int i = 0; i < classnames.length; i++) {
51 try {
52 clx[i] = classLoader.loadClass(classnames[i]);
53 } catch (ClassNotFoundException e) {
54 throw new RuntimeException(e.getMessage());
55 }
56 }
57
58 }
59
60 @Override
61 protected Class<?>[] factoryClasses(ICS ics) {
62 return super.factoryClasses(ics);
63 }
64
65 }