1
/*___INFO__MARK_BEGIN__*//*************************************************************************
3
* The Contents of this file are made available subject to the terms of
4
* the Sun Industry Standards Source License Version 1.2
6
* Sun Microsystems Inc., March, 2001
9
* Sun Industry Standards Source License Version 1.2
10
* =================================================
11
* The contents of this file are subject to the Sun Industry Standards
12
* Source License Version 1.2 (the "License"); You may not use this file
13
* except in compliance with the License. You may obtain a copy of the
14
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
16
* Software provided under this License is provided on an "AS IS" basis,
17
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
18
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
19
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
20
* See the License for the specific provisions governing your rights and
21
* obligations concerning the Software.
23
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
25
* Copyright: 2001 by Sun Microsystems, Inc.
27
* All Rights Reserved.
29
************************************************************************/
30
/*___INFO__MARK_END__*/
31
package com.sun.grid.javaconv;
33
import com.sun.grid.cull.Printer;
34
import com.sun.grid.cull.template.Template;
35
import com.sun.grid.cull.template.TemplateFactory;
36
import java.beans.BeanInfo;
37
import java.beans.IntrospectionException;
39
import java.io.IOException;
40
import java.util.HashMap;
42
import java.util.logging.Logger;
47
public class JavaTemplateConverter implements JavaToJavaConverter {
49
private File outputFile;
50
private TemplateFactory fac;
51
private File templateFile;
52
private String packageName;
53
private String classpath;
54
private Printer printer;
55
private File prologFile;
56
private File epilogFile;
57
private Logger logger = Logger.getLogger("class");
59
/** Creates a new instance of JavaTemplateConverter */
60
public JavaTemplateConverter(File buildDir, String classpath, File templateFile, File outputFile, File prologFile, File epilogFile, String javaSourceVersion, String javaTargetVersion) {
61
this.templateFile = templateFile;
62
this.outputFile = outputFile;
63
fac = new TemplateFactory(buildDir, classpath, javaSourceVersion, javaTargetVersion);
64
this.prologFile = prologFile;
65
this.epilogFile = epilogFile;
69
public void convert(Class clazz) throws java.io.IOException {
70
Template template = fac.createTemplate(templateFile);
73
if (printer == null) {
74
if (!outputFile.exists() || outputFile.lastModified() < templateFile.lastModified() || (prologFile != null && outputFile.lastModified() < prologFile.lastModified()) || (epilogFile != null && outputFile.lastModified() < epilogFile.lastModified())) {
75
printer = new Printer(outputFile);
76
if (prologFile != null) {
77
logger.fine("write prolog " + prologFile);
78
printer.printFile(prologFile);
82
if (printer != null) {
83
Map<String, Object> params = new HashMap<String, Object>();
84
params.put("shortname", clazz);
85
String javaClassName = clazz.getName();
86
int index = javaClassName.lastIndexOf(".");
88
javaClassName = javaClassName.substring(index + 1);
90
params.put("shortname", javaClassName);
91
BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(clazz);
92
params.put("beanInfo", beanInfo);
93
logger.fine("writer class " + clazz.getName());
94
template.print(printer, params);
97
} catch (IntrospectionException itse) {
98
IOException e = new IOException("Introspection error: " + itse.getMessage());
104
public void finish() throws IOException {
105
if (printer != null) {
106
if (epilogFile != null) {
107
logger.fine("write epilog " + epilogFile);
108
printer.printFile(epilogFile);