KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openuss > presentation > layoutformatter > LayoutFormatterFactory


1 /**
2  * Title: OpenUSS - Open Source University Support System
3  * Description: Layout Formatter
4  * Copyright: Copyright (c) B. Lofi Dewanto
5  * Company: University of Muenster
6  * @author B. Lofi Dewanto
7  * @version 1.0
8  */

9 package org.openuss.presentation.layoutformatter;
10
11 import java.lang.reflect.*;
12
13
14 /**
15  * The interface for layout formatter factory.
16  *
17  * @author B. Lofi Dewanto
18  * @version 1.0
19  */

20 public class LayoutFormatterFactory {
21     /**
22      * Gets the layout formatter.
23      *
24      * @return the layout formatter implementation.
25      */

26     public static LayoutFormatter getLayoutFormatter(Object JavaDoc stateObject,
27                                                      String JavaDoc fullClassNameLayout)
28                                               throws Exception JavaDoc {
29         // Depends on the stateObject create the layout formatter
30
Class JavaDoc objectClass = Class.forName(fullClassNameLayout);
31
32         // Get the constructor
33
Class JavaDoc myOwner = Class.forName("java.lang.Object");
34         Class JavaDoc[] parameterTypes = new Class JavaDoc[1];
35         parameterTypes[0] = myOwner;
36
37         Constructor objectConstructor = objectClass.getConstructor(
38                                                 parameterTypes);
39
40         // Create the object with the constructor
41
Object JavaDoc[] initArgs = new Object JavaDoc[1];
42         initArgs[0] = stateObject;
43
44         LayoutFormatter layoutFormatter = (LayoutFormatter) objectConstructor.newInstance(
45                                                   initArgs);
46
47         return layoutFormatter;
48     }
49 }
Popular Tags