Code Generator for Eclipse Code
Brought to you by:
hotzst
--- a/plugin/src/ch/sahits/codegen/java/GeneratorFactory.java +++ b/plugin/src/ch/sahits/codegen/java/GeneratorFactory.java @@ -13,7 +13,7 @@ import ch.sahits.codegen.java.util.Logging; import ch.sahits.codegen.java.util.ProjectClassLoader; import ch.sahits.codegen.java.wizards.JavaCodegenNewWizard; -import ch.sahits.model.java.IGeneratedJavaDBClass; +import ch.sahits.model.java.IGeneratedJavaClass; /** * This factory method provides the correct CodeGenerator for any situation @@ -25,7 +25,7 @@ /** * Model of the class to be generated */ - private IGeneratedJavaDBClass model=null; + private IGeneratedJavaClass model=null; /** * Create the code with the use of a provided Jet-Template @@ -52,7 +52,7 @@ /** * @param _model */ - public GeneratorFactory(IGeneratedJavaDBClass _model) { + public GeneratorFactory(IGeneratedJavaClass _model) { this.model = _model; }
--- a/plugin/src/ch/sahits/codegen/java/model/ModelFactory.java +++ b/plugin/src/ch/sahits/codegen/java/model/ModelFactory.java @@ -17,6 +17,7 @@ import ch.sahits.codegen.java.input.XMLJDomParser; import ch.sahits.codegen.java.util.Logging; import ch.sahits.model.java.GeneratedJavaDBClass; +import ch.sahits.model.java.IGeneratedJavaClass; import ch.sahits.model.java.IGeneratedJavaDBClass; import ch.sahits.model.java.db.DataBaseTable; @@ -168,15 +169,36 @@ * @param inputFilePath path to the input file the model is based upon * @return generated model */ - public static IGeneratedJavaDBClass createModelWithoutDB(String typeName,String inputFilePath){ + public static IGeneratedJavaClass createModelWithoutDB(String typeName,String inputFilePath){ String extension = inputFilePath.substring(inputFilePath.lastIndexOf(".")+1).toLowerCase(); if (extension.equals("xml")){ - // open file and extract Model generator from xml file - // TODO: implement - return null; + return createModelWithoutDBFromXML(typeName, inputFilePath); } else { return createModelFromExtension(typeName, extension); } } + /** + * Create a model for a Java class without data base from an XML file + * @param typeName class name + * @param inputFilePath XML input file + * @return created model or null if there was an exception in the creation process + * @since 0.9.3 + */ + private static IGeneratedJavaClass createModelWithoutDBFromXML(String typeName,String inputFilePath){ + try { + XMLJDomParser basePaser = new XMLJDomParser(inputFilePath); + String parserName = basePaser.getParserName(); + IXMLInputFileParser parser = XMLInputParser.getParser(parserName); + parser.init(inputFilePath); + IGeneratedJavaClass model =parser.generateModel(typeName); + model.setInputFilePath(inputFilePath); + return model; + } catch (JDOMException e) { + Logging.log(e); + } catch (IOException e) { + Logging.log(e); + } + return null; + } }
--- a/plugin/src/ch/sahits/codegen/java/wizards/JavaCodegenNewWizard.java +++ b/plugin/src/ch/sahits/codegen/java/wizards/JavaCodegenNewWizard.java @@ -33,6 +33,7 @@ import ch.sahits.codegen.java.util.ProjectGeneratorClassLoader; import ch.sahits.model.db.IDBTable; import ch.sahits.model.java.EVisibility; +import ch.sahits.model.java.IGeneratedJavaClass; import ch.sahits.model.java.IGeneratedJavaDBClass; /** @@ -130,7 +131,7 @@ */ public void performFinish(IProgressMonitor monitor) throws FileNotFoundException, IOException, ClassNotFoundException, CoreException { // create a model of the data provided by the wizard - IGeneratedJavaDBClass model = initModel(); + IGeneratedJavaClass model = initModel(); // Get a generator instance int type = getComputationType(); monitor.beginTask("Creating monitor...", 1); @@ -207,9 +208,9 @@ * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") - private IGeneratedJavaDBClass initModel() throws FileNotFoundException, + private IGeneratedJavaClass initModel() throws FileNotFoundException, IOException, ClassNotFoundException { - IGeneratedJavaDBClass model; + IGeneratedJavaClass model; if (page.createWithDBInputFile()){ model = ModelFactory.createModelWithDBInputFile(page0.getTypeName(),page.getDBProduct(),page.getInputFilePath(),page0.getJavaProject()); } else if (page.createWithDBConnection()){ @@ -250,7 +251,9 @@ } model.setSrcPath(page0.getPackageFragmentRootText()); model.setInputFilePath(page.getInputFilePath()); - model.setDbProductName(page.getDBProduct()); + if (model instanceof IGeneratedJavaDBClass){ + ((IGeneratedJavaDBClass)model).setDbProductName(page.getDBProduct()); + } model.setJetFileUse(page.isTemplate()); model.setGeneratorUse(page.isGenerationSelected()); model.setJetTemplateUse(page.isJetSelected()); @@ -277,7 +280,7 @@ return model; } - private void initializeModifiers(IGeneratedJavaDBClass model) { + private void initializeModifiers(IGeneratedJavaClass model) { if (page0.isAbstract()){ model.setAbstract(true); } else {