001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.util.loader;
028:
029: import java.io.File;
030: import java.io.FileWriter;
031:
032: /**
033: * Usage interne.
034: * Générateur de classe java.
035: *
036: * @author Thierry Badard & Arnaud Braun
037: * @version 1.0
038: *
039: */
040:
041: class JavaGenerator {
042:
043: private static FileWriter fw;
044: private static String className;
045: private static String javaFilePath;
046: private static String extentClassName;
047: private static String packageName;
048:
049: public JavaGenerator(String path, String ClassName,
050: String ExtentClassName, String PackageName) {
051: className = ClassName.substring(ClassName.lastIndexOf('.') + 1); // pour enlever le prefixe du nom de package
052: extentClassName = ExtentClassName;
053: packageName = PackageName;
054: try {
055: File thePath = new File(path);
056: File dirFile = new File(thePath, PackageName.replace('.',
057: '/'));
058: dirFile.mkdirs();
059: File javaFile = new File(dirFile, className + ".java");
060: javaFilePath = javaFile.getPath();
061: } catch (Exception e) {
062: System.out.println(className);
063: e.printStackTrace();
064: }
065: }
066:
067: public void writeHeader() {
068: String line1 = "package " + packageName + ";\n";
069: String line2 = "\n";
070: String line4 = "\n";
071: String line5 = "/** Classe geographique. Classe generee automatiquement par le chargeur de la plate-forme GeOxygene*/\n";
072: String line6 = "\n";
073: String line7 = "public class " + className + " extends "
074: + extentClassName;
075: String line8 = " {\n\n";
076: try {
077: fw = new FileWriter(javaFilePath);
078: fw.write(line1);
079: fw.write(line2);
080: fw.write(line4);
081: fw.write(line5);
082: fw.write(line6);
083: fw.write(line7);
084: fw.write(line8);
085: fw.close();
086: } catch (Exception e) {
087: System.out.println(className);
088: e.printStackTrace();
089: }
090: }
091:
092: public void writeBottom() {
093: String line1 = "}\n";
094: try {
095: fw = new FileWriter(javaFilePath, true);
096: fw.write(line1);
097: fw.close();
098: } catch (Exception e) {
099: System.out.println(className);
100: e.printStackTrace();
101: }
102: }
103:
104: public void writeField(String type, String name) {
105: String str1 = " protected " + type + " " + name + ";\n";
106: String str2 = " public " + type + " get"
107: + name.substring(0, 1).toUpperCase()
108: + name.substring(1) + "() {return this." + name
109: + "; }\n";
110: String str3 = " public void set"
111: + name.substring(0, 1).toUpperCase()
112: + name.substring(1) + " (" + type + " ";
113: String str4 = name.substring(0, 1).toUpperCase()
114: + name.substring(1) + ") {" + name + " = "
115: + name.substring(0, 1).toUpperCase()
116: + name.substring(1) + "; }\n";
117: String str5 = "\n";
118: try {
119: fw = new FileWriter(javaFilePath, true);
120: fw.write(str1);
121: fw.write(str2);
122: fw.write(str3);
123: fw.write(str4);
124: fw.write(str5);
125: fw.close();
126: } catch (Exception e) {
127: System.out.println(className);
128: e.printStackTrace();
129: }
130: }
131:
132: }
|