KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > corba > server > GenerationServerApplication


1 /**
2  * copyright 2002 2003 Laboratoire d'Informatique Paris 6 (LIP6)
3  *
4  * This file is part of ModFact.
5  *
6  * ModFact is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * at your option) any later version.
10  *
11  * ModFact is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with ModFact; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package org.objectweb.modfact.corba.server;
21
22 import org.objectweb.modfact.corba.generator.BracketGenerator;
23 import org.objectweb.modfact.corba.helper.JavaCommon;
24 import org.objectweb.modfact.corba.logging.Level;
25 import org.objectweb.modfact.corba.logging.ModFactLogger;
26 import org.omg.mof.Model.ModelElement;
27
28
29 /**
30  * This class allows the generation of the repository server main class.
31  */

32 public class GenerationServerApplication extends BracketGenerator {
33
34     /** The Java Helper. */
35     private JavaCommon javaHelper;
36
37     /** The logger. */
38     protected ModFactLogger _logger = ModFactLogger.getLogger("fr.lip6.src.mdafactory.generation.server.GenerationServerApplication");
39
40     /**
41      * The Server Application generation.
42      * @param package_ The root package.
43      * @param class_name_ The class name.
44      * @param class_name_application The application class name.
45      */

46     public void generateServerApplication(org.omg.mof.Model.Package package_, String JavaDoc class_name_, String JavaDoc class_name_application_) throws org.omg.mof.Reflective.MofError, org.omg.CORBA.TypeCodePackage.BadKind JavaDoc, org.omg.CORBA.TypeCodePackage.Bounds JavaDoc {
47         _logger.log(Level.FINE, "Server - beginning of the generation");
48         _logger.log(Level.INFO, class_name_application_ + " generation ...");
49         head(package_, class_name_application_);
50         constructors(package_.name(), class_name_application_);
51         startMethod(package_.name(), class_name_);
52         mainMethod(class_name_application_);
53         outputln("} // end class " + class_name_);
54         flushFile();
55     }
56
57     /**
58      * Server Application generation for the head.
59      * @param package_ The package.
60      * @param class_name_application_ The application class name.
61      */

62     public void head(org.omg.mof.Model.Package package_, String JavaDoc class_name_application_)
63         throws org.omg.mof.Reflective.MofError {
64         outputln("package " + javaHelper.javaPackage(package_) + ";");
65         outputln();
66         outputln("public class " + class_name_application_);
67         outputln(" extends org.objectweb.modfact.corba.service.cmdline.common.ModfactApplicationBase {");
68         outputln();
69     }
70
71     /**
72      * Server Application generation for the constructors.
73      * @param package_name_ The package name.
74      * @param class_name_application_ The application class name.
75      */

76     public void constructors(String JavaDoc package_name_, String JavaDoc class_name_application_) {
77         outputln("public " + class_name_application_ + "() {");
78         outputln("super(new org.objectweb.util.cmdline.lib.DefaultCommandLine(new java.lang.String [] {\"" + class_name_application_ + "\"},");
79         outputln(" new java.lang.String [0],");
80         outputln(" new java.lang.String [] {\"Run the " + package_name_ + " Server.\"},");
81         outputln(" true));");
82         outputln("}");
83         outputln();
84     }
85
86     /**
87      * Server Application generation for the main method.
88      * @param class_name_application_ The application class name.
89      */

90     public void mainMethod(String JavaDoc class_name_application_) throws org.omg.mof.Reflective.MofError {
91         outputln("/**");
92         outputln(" * The main method");
93         outputln(" */");
94         outputln("public static void main (java.lang.String [] args) {");
95         outputln(class_name_application_ + " application = new " + class_name_application_ + "();");
96         outputln("application.runMain(args);");
97         outputln("}");
98         outputln();
99     }
100
101     /**
102      * Server Application generation for the start method.
103      * @param package_name_ The package name.
104      * @param class_name_ The class name.
105      */

106     public void startMethod(String JavaDoc package_name_, String JavaDoc class_name_) {
107         outputln("/**");
108         outputln(" * Starts the main function");
109         outputln(" */");
110         outputln("public int start(java.lang.String[] args) {");
111         outputln(class_name_ + " server = new " + class_name_ + "(orb_);");
112         outputln("server.run();");
113         outputln("return 0;");
114         outputln("}");
115         outputln();
116     }
117
118     /* (non-Javadoc)
119      * @see org.objectweb.modfact.corba.generator.Generator#generate()
120      */

121     public void generate() throws Exception JavaDoc {
122         // TODO Auto-generated method stub
123

124     }
125
126     /* (non-Javadoc)
127      * @see org.objectweb.modfact.corba.generator.Generator#setInput(org.omg.mof.Model.ModelElement[])
128      */

129     public void setInput(ModelElement[] elt) throws Exception JavaDoc {
130         // TODO Auto-generated method stub
131

132     }
133
134     /* (non-Javadoc)
135      * @see org.objectweb.modfact.corba.generator.Generator#setLogger(org.objectweb.modfact.corba.logging.ModFactLogger)
136      */

137     public void setLogger(ModFactLogger log) throws Exception JavaDoc {
138         _logger = log;
139
140     }
141
142     /**
143      * @param common
144      */

145     public void setJavaHelper(JavaCommon common) {
146         javaHelper = common;
147     }
148
149 }
150
Popular Tags