Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornhauge2008-10-22 12:09:16 -0400
committernhauge2008-10-22 12:09:16 -0400
commitc2cc567e138b2ea374228a56f42cdabd4e59d641 (patch)
treea608d69e138b908e4c69298b2b905641b84ca76d
parent5962ffe815d9afcfedb3f728e678722887fec275 (diff)
downloadwebtools.dali-c2cc567e138b2ea374228a56f42cdabd4e59d641.tar.gz
webtools.dali-c2cc567e138b2ea374228a56f42cdabd4e59d641.tar.xz
webtools.dali-c2cc567e138b2ea374228a56f42cdabd4e59d641.zip
250619 - Make .JETEmitter project optional
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/.jetproperties4
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/.project6
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF2
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java166
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java126
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java255
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java57
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/templates/annotated_entity.javajet2
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/templates/entity.javajet2
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/templates/idClass.javajet2
10 files changed, 603 insertions, 19 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/.jetproperties b/jpa/plugins/org.eclipse.jpt.ui/.jetproperties
new file mode 100644
index 0000000000..2907c83a43
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/.jetproperties
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<jet-settings>
+ <template-container>templates</template-container> <source-container>src</source-container>
+</jet-settings>
diff --git a/jpa/plugins/org.eclipse.jpt.ui/.project b/jpa/plugins/org.eclipse.jpt.ui/.project
index 50ef9e3305..f1b147fd81 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/.project
+++ b/jpa/plugins/org.eclipse.jpt.ui/.project
@@ -6,6 +6,11 @@
</projects>
<buildSpec>
<buildCommand>
+ <name>org.eclipse.emf.codegen.JETBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
@@ -22,6 +27,7 @@
</buildCommand>
</buildSpec>
<natures>
+ <nature>org.eclipse.emf.codegen.jet.IJETNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
diff --git a/jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF
index 6216941a12..5ee940e08f 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.jpt.ui;singleton:=true
-Bundle-Version: 2.0.101.qualifier
+Bundle-Version: 2.0.102.qualifier
Bundle-Activator: org.eclipse.jpt.ui.JptUiPlugin
Bundle-ClassPath: .
Bundle-Localization: plugin
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java
new file mode 100644
index 0000000000..5dfd091bc4
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java
@@ -0,0 +1,166 @@
+package org.eclipse.jpt.ui.internal.wizards.entity;
+
+import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*;
+import java.util.*;
+
+public class AnnotatedEntityTemplate
+{
+ protected static String nl;
+ public static synchronized AnnotatedEntityTemplate create(String lineSeparator)
+ {
+ nl = lineSeparator;
+ AnnotatedEntityTemplate result = new AnnotatedEntityTemplate();
+ nl = null;
+ return result;
+ }
+
+ public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+ protected final String TEXT_1 = "package ";
+ protected final String TEXT_2 = ";";
+ protected final String TEXT_3 = NL;
+ protected final String TEXT_4 = NL + "import ";
+ protected final String TEXT_5 = ";";
+ protected final String TEXT_6 = NL + NL + "/**" + NL + " * Entity implementation class for Entity: ";
+ protected final String TEXT_7 = NL + " *" + NL + " */";
+ protected final String TEXT_8 = NL;
+ protected final String TEXT_9 = "(name=\"";
+ protected final String TEXT_10 = "\")";
+ protected final String TEXT_11 = NL + "@Table(name=\"";
+ protected final String TEXT_12 = "\")";
+ protected final String TEXT_13 = NL;
+ protected final String TEXT_14 = NL + "@IdClass(";
+ protected final String TEXT_15 = ".class)";
+ protected final String TEXT_16 = NL + "public class ";
+ protected final String TEXT_17 = " extends ";
+ protected final String TEXT_18 = " implements ";
+ protected final String TEXT_19 = ", ";
+ protected final String TEXT_20 = " {" + NL + "" + NL + "\t";
+ protected final String TEXT_21 = " " + NL + "\t@Id";
+ protected final String TEXT_22 = NL + "\tprivate ";
+ protected final String TEXT_23 = " ";
+ protected final String TEXT_24 = ";";
+ protected final String TEXT_25 = NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "" + NL + "\tpublic ";
+ protected final String TEXT_26 = "() {" + NL + "\t\tsuper();" + NL + "\t}";
+ protected final String TEXT_27 = " " + NL + "\t@Id ";
+ protected final String TEXT_28 = " " + NL + "\tpublic ";
+ protected final String TEXT_29 = " get";
+ protected final String TEXT_30 = "() {" + NL + "\t\treturn this.";
+ protected final String TEXT_31 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set";
+ protected final String TEXT_32 = "(";
+ protected final String TEXT_33 = " ";
+ protected final String TEXT_34 = ") {" + NL + "\t\tthis.";
+ protected final String TEXT_35 = " = ";
+ protected final String TEXT_36 = ";" + NL + "\t}";
+ protected final String TEXT_37 = NL + " " + NL + "}";
+ protected final String TEXT_38 = NL;
+
+ public String generate(Object argument)
+ {
+ final StringBuffer stringBuffer = new StringBuffer();
+ CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument;
+if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") {
+ stringBuffer.append(TEXT_1);
+ stringBuffer.append(model.getJavaPackageName());
+ stringBuffer.append(TEXT_2);
+ }
+ stringBuffer.append(TEXT_3);
+ Collection<String> imports = model.getImports(false);
+for (String anImport : imports) {
+ stringBuffer.append(TEXT_4);
+ stringBuffer.append(anImport);
+ stringBuffer.append(TEXT_5);
+ }
+ stringBuffer.append(TEXT_6);
+ stringBuffer.append(model.getEntityName());
+ stringBuffer.append(TEXT_7);
+ stringBuffer.append(TEXT_8);
+ stringBuffer.append(model.getArtifactType());
+ String ENTITY_NAME = model.getEntityName();
+if (model.isEntityNameSet()) {
+ stringBuffer.append(TEXT_9);
+ stringBuffer.append(ENTITY_NAME);
+ stringBuffer.append(TEXT_10);
+ }
+ if (model.isTableNameSet()) {
+ stringBuffer.append(TEXT_11);
+ stringBuffer.append(model.getTableName());
+ stringBuffer.append(TEXT_12);
+ }
+ stringBuffer.append(TEXT_13);
+ stringBuffer.append(model.getInheritanceStrategy());
+ if (model.isCompositePK()) {
+ stringBuffer.append(TEXT_14);
+ stringBuffer.append(model.getIdClassName());
+ stringBuffer.append(TEXT_15);
+ }
+ stringBuffer.append(TEXT_16);
+ stringBuffer.append(model.getClassName());
+ String superClass = model.getSuperclassName();
+ if (! "".equals(superClass)) {
+ stringBuffer.append(TEXT_17);
+ stringBuffer.append(superClass);
+ }
+
+ List<String> interfaces = model.getInterfaces();
+ if (interfaces.size()>0) {
+ stringBuffer.append(TEXT_18);
+ }
+ for (int i=0; i<interfaces.size(); i++) {
+ String INTERFACE = (String) interfaces.get(i);
+ if (i>0) {
+ stringBuffer.append(TEXT_19);
+ }
+ stringBuffer.append(INTERFACE);
+ }
+ stringBuffer.append(TEXT_20);
+ List<EntityRow> fields = model.getEntityFields();
+ List<String> pkFields = model.getPKFields();
+ for (EntityRow entity : fields) {
+ String NAME = entity.getName();
+ if (pkFields.contains(NAME) && model.isFieldAccess()) {
+
+ stringBuffer.append(TEXT_21);
+ }
+ stringBuffer.append(TEXT_22);
+ stringBuffer.append(entity.getType());
+ stringBuffer.append(TEXT_23);
+ stringBuffer.append(entity.getName());
+ stringBuffer.append(TEXT_24);
+ }
+ stringBuffer.append(TEXT_25);
+ stringBuffer.append(model.getClassName());
+ stringBuffer.append(TEXT_26);
+
+ fields = model.getEntityFields();
+ if (fields != null) for (int i=0; i<fields.size(); i++) {
+ EntityRow field = (EntityRow) fields.get(i);
+ String TYPE = field.getType();
+ String NAME = field.getName();
+ String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1);
+ if (pkFields.contains(NAME) && !model.isFieldAccess()) {
+
+ stringBuffer.append(TEXT_27);
+ }
+ stringBuffer.append(TEXT_28);
+ stringBuffer.append(TYPE);
+ stringBuffer.append(TEXT_29);
+ stringBuffer.append(METHOD);
+ stringBuffer.append(TEXT_30);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_31);
+ stringBuffer.append(METHOD);
+ stringBuffer.append(TEXT_32);
+ stringBuffer.append(TYPE);
+ stringBuffer.append(TEXT_33);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_34);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_35);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_36);
+ }
+ stringBuffer.append(TEXT_37);
+ stringBuffer.append(TEXT_38);
+ return stringBuffer.toString();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java
new file mode 100644
index 0000000000..a5309c4a95
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java
@@ -0,0 +1,126 @@
+package org.eclipse.jpt.ui.internal.wizards.entity;
+
+import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*;
+import java.util.*;
+
+public class EntityTemplate
+{
+ protected static String nl;
+ public static synchronized EntityTemplate create(String lineSeparator)
+ {
+ nl = lineSeparator;
+ EntityTemplate result = new EntityTemplate();
+ nl = null;
+ return result;
+ }
+
+ public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+ protected final String TEXT_1 = "package ";
+ protected final String TEXT_2 = ";";
+ protected final String TEXT_3 = NL;
+ protected final String TEXT_4 = NL + "import ";
+ protected final String TEXT_5 = ";";
+ protected final String TEXT_6 = NL + NL + "/**" + NL + " * Entity implementation class for Entity: ";
+ protected final String TEXT_7 = NL + " *" + NL + " */" + NL + "public class ";
+ protected final String TEXT_8 = " extends ";
+ protected final String TEXT_9 = " implements ";
+ protected final String TEXT_10 = ", ";
+ protected final String TEXT_11 = " {" + NL + "" + NL + "\t";
+ protected final String TEXT_12 = " " + NL + "\tprivate ";
+ protected final String TEXT_13 = " ";
+ protected final String TEXT_14 = ";";
+ protected final String TEXT_15 = NL + "\tprivate static final long serialVersionUID = 1L;\t" + NL + "\tpublic ";
+ protected final String TEXT_16 = "() {" + NL + "\t\tsuper();" + NL + "\t} " + NL + "\t";
+ protected final String TEXT_17 = " " + NL + "\tpublic ";
+ protected final String TEXT_18 = " get";
+ protected final String TEXT_19 = "() {" + NL + " \t\treturn this.";
+ protected final String TEXT_20 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set";
+ protected final String TEXT_21 = "(";
+ protected final String TEXT_22 = " ";
+ protected final String TEXT_23 = ") {" + NL + "\t\tthis.";
+ protected final String TEXT_24 = " = ";
+ protected final String TEXT_25 = ";" + NL + "\t}" + NL + "\t";
+ protected final String TEXT_26 = NL + " " + NL + "}";
+ protected final String TEXT_27 = NL;
+
+ public String generate(Object argument)
+ {
+ final StringBuffer stringBuffer = new StringBuffer();
+ CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument;
+if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") {
+ stringBuffer.append(TEXT_1);
+ stringBuffer.append(model.getJavaPackageName());
+ stringBuffer.append(TEXT_2);
+ }
+ stringBuffer.append(TEXT_3);
+ Collection<String> imports = model.getImports(false);
+for (String anImport : imports) {
+ stringBuffer.append(TEXT_4);
+ stringBuffer.append(anImport);
+ stringBuffer.append(TEXT_5);
+ }
+ stringBuffer.append(TEXT_6);
+ stringBuffer.append(model.getEntityName());
+ stringBuffer.append(TEXT_7);
+ stringBuffer.append(model.getClassName());
+ String superClass = model.getSuperclassName();
+ if (! "".equals(superClass)) {
+ stringBuffer.append(TEXT_8);
+ stringBuffer.append(superClass);
+ }
+
+ List<String> interfaces = model.getInterfaces();
+ if (interfaces.size()>0) {
+ stringBuffer.append(TEXT_9);
+ }
+ for (int i=0; i<interfaces.size(); i++) {
+ String INTERFACE = (String) interfaces.get(i);
+ if (i>0) {
+ stringBuffer.append(TEXT_10);
+ }
+ stringBuffer.append(INTERFACE);
+ }
+ stringBuffer.append(TEXT_11);
+ List<EntityRow> fields = model.getEntityFields();
+ for (EntityRow entity : fields) {
+
+ stringBuffer.append(TEXT_12);
+ stringBuffer.append(entity.getType());
+ stringBuffer.append(TEXT_13);
+ stringBuffer.append(entity.getName());
+ stringBuffer.append(TEXT_14);
+ }
+ stringBuffer.append(TEXT_15);
+ stringBuffer.append(model.getClassName());
+ stringBuffer.append(TEXT_16);
+
+ fields = model.getEntityFields();
+ if (fields != null) for (int i=0; i<fields.size(); i++) {
+ EntityRow field = (EntityRow) fields.get(i);
+ String TYPE = field.getType();
+ String NAME = field.getName();
+ String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1);
+
+ stringBuffer.append(TEXT_17);
+ stringBuffer.append(TYPE);
+ stringBuffer.append(TEXT_18);
+ stringBuffer.append(METHOD);
+ stringBuffer.append(TEXT_19);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_20);
+ stringBuffer.append(METHOD);
+ stringBuffer.append(TEXT_21);
+ stringBuffer.append(TYPE);
+ stringBuffer.append(TEXT_22);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_23);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_24);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_25);
+ }
+ stringBuffer.append(TEXT_26);
+ stringBuffer.append(TEXT_27);
+ return stringBuffer.toString();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java
new file mode 100644
index 0000000000..1ea33feaff
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java
@@ -0,0 +1,255 @@
+package org.eclipse.jpt.ui.internal.wizards.entity;
+
+import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*;
+import java.util.*;
+
+public class IdClassTemplate
+{
+ protected static String nl;
+ public static synchronized IdClassTemplate create(String lineSeparator)
+ {
+ nl = lineSeparator;
+ IdClassTemplate result = new IdClassTemplate();
+ nl = null;
+ return result;
+ }
+
+ public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+ protected final String TEXT_1 = "package ";
+ protected final String TEXT_2 = ";";
+ protected final String TEXT_3 = NL;
+ protected final String TEXT_4 = NL + "import ";
+ protected final String TEXT_5 = ";";
+ protected final String TEXT_6 = NL + NL + "/**" + NL + " * ID class for entity: ";
+ protected final String TEXT_7 = NL + " *" + NL + " */ " + NL + "public class ";
+ protected final String TEXT_8 = " ";
+ protected final String TEXT_9 = " implements ";
+ protected final String TEXT_10 = ", ";
+ protected final String TEXT_11 = " { " + NL + " " + NL + "\t";
+ protected final String TEXT_12 = " " + NL + "\tprivate ";
+ protected final String TEXT_13 = " ";
+ protected final String TEXT_14 = ";";
+ protected final String TEXT_15 = NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "" + NL + "\tpublic ";
+ protected final String TEXT_16 = "() {}" + NL + "" + NL + "\t";
+ protected final String TEXT_17 = NL + NL + "\tpublic ";
+ protected final String TEXT_18 = " get";
+ protected final String TEXT_19 = "() {" + NL + "\t\treturn this.";
+ protected final String TEXT_20 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set";
+ protected final String TEXT_21 = "(";
+ protected final String TEXT_22 = " ";
+ protected final String TEXT_23 = ") {" + NL + "\t\tthis.";
+ protected final String TEXT_24 = " = ";
+ protected final String TEXT_25 = ";" + NL + "\t}" + NL + "\t";
+ protected final String TEXT_26 = NL + " " + NL + "\t/*" + NL + "\t * @see java.lang.Object#equals(Object)" + NL + "\t */\t" + NL + "\tpublic boolean equals(Object o) {" + NL + "\t\tif (o == this) {" + NL + "\t\t\treturn true;" + NL + "\t\t}" + NL + "\t\tif (!(o instanceof ";
+ protected final String TEXT_27 = ")) {" + NL + "\t\t\treturn false;" + NL + "\t\t}" + NL + "\t\t";
+ protected final String TEXT_28 = " other = (";
+ protected final String TEXT_29 = ") o;" + NL + "\t\treturn true";
+ protected final String TEXT_30 = NL + "\t\t\t&& ";
+ protected final String TEXT_31 = "() == other.";
+ protected final String TEXT_32 = "()";
+ protected final String TEXT_33 = NL + "\t\t\t&& (Double.doubleToLongBits(";
+ protected final String TEXT_34 = "()) == Double.doubleToLongBits(other.";
+ protected final String TEXT_35 = "()))";
+ protected final String TEXT_36 = NL + "\t\t\t&& (Float.floatToIntBits(";
+ protected final String TEXT_37 = "()) == Float.floatToIntBits(other.";
+ protected final String TEXT_38 = "()))";
+ protected final String TEXT_39 = NL + "\t\t\t&& (";
+ protected final String TEXT_40 = "() == null ? other.";
+ protected final String TEXT_41 = "() == null : ";
+ protected final String TEXT_42 = "().equals(other.";
+ protected final String TEXT_43 = "()))";
+ protected final String TEXT_44 = ";" + NL + "\t}" + NL + "\t" + NL + "\t/*\t " + NL + "\t * @see java.lang.Object#hashCode()" + NL + "\t */\t" + NL + "\tpublic int hashCode() {" + NL + "\t\tfinal int prime = 31;" + NL + "\t\tint result = 1;";
+ protected final String TEXT_45 = NL + "\t\tresult = prime * result + (";
+ protected final String TEXT_46 = "() ? 1 : 0);";
+ protected final String TEXT_47 = NL + "\t\tresult = prime * result + ";
+ protected final String TEXT_48 = "();";
+ protected final String TEXT_49 = NL + "\t\tresult = prime * result + ((int) ";
+ protected final String TEXT_50 = "());";
+ protected final String TEXT_51 = NL + "\t\tresult = prime * result + ((int) (";
+ protected final String TEXT_52 = "() ^ (";
+ protected final String TEXT_53 = "() >>> 32)));";
+ protected final String TEXT_54 = NL + "\t\tresult = prime * result + ((int) (Double.doubleToLongBits(";
+ protected final String TEXT_55 = "() ) ^ (Double.doubleToLongBits(";
+ protected final String TEXT_56 = "()) >>> 32)));";
+ protected final String TEXT_57 = NL + "\t\tresult = prime * result + Float.floatToIntBits(";
+ protected final String TEXT_58 = "());";
+ protected final String TEXT_59 = NL + "\t\tresult = prime * result + (";
+ protected final String TEXT_60 = "() == null ? 0 : ";
+ protected final String TEXT_61 = "().hashCode());";
+ protected final String TEXT_62 = NL + "\t\treturn result;" + NL + "\t}" + NL + " " + NL + " " + NL + "}";
+ protected final String TEXT_63 = NL;
+
+ public String generate(Object argument)
+ {
+ final StringBuffer stringBuffer = new StringBuffer();
+ CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument;
+if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") {
+ stringBuffer.append(TEXT_1);
+ stringBuffer.append(model.getJavaPackageName());
+ stringBuffer.append(TEXT_2);
+ }
+ stringBuffer.append(TEXT_3);
+ Collection<String> imports = model.getImports(true);
+for (String anImport : imports) {
+ stringBuffer.append(TEXT_4);
+ stringBuffer.append(anImport);
+ stringBuffer.append(TEXT_5);
+ }
+ stringBuffer.append(TEXT_6);
+ stringBuffer.append(model.getClassName());
+ stringBuffer.append(TEXT_7);
+ stringBuffer.append(model.getIdClassName());
+ stringBuffer.append(TEXT_8);
+ List<String> interfaces = model.getInterfaces();
+ if (interfaces.size()>0) {
+ stringBuffer.append(TEXT_9);
+ }
+ for (int i=0; i<interfaces.size(); i++) {
+ String INTERFACE = (String) interfaces.get(i);
+ if (i>0) {
+ stringBuffer.append(TEXT_10);
+ }
+ stringBuffer.append(INTERFACE);
+ }
+ stringBuffer.append(TEXT_11);
+ List<EntityRow> fields = model.getEntityFields();
+ List<String> pkFields = model.getPKFields();
+ for (int i=0; i<fields.size(); i++) {
+ EntityRow entity = (EntityRow) fields.get(i);
+ if (!pkFields.contains(entity.getName())) {
+ continue;
+ }
+
+ stringBuffer.append(TEXT_12);
+ stringBuffer.append(entity.getType());
+ stringBuffer.append(TEXT_13);
+ stringBuffer.append(entity.getName());
+ stringBuffer.append(TEXT_14);
+ }
+ stringBuffer.append(TEXT_15);
+ stringBuffer.append(model.getIdClassName());
+ stringBuffer.append(TEXT_16);
+
+ fields = model.getEntityFields();
+ if (fields != null) for (int i=0; i<fields.size(); i++) {
+ EntityRow field = (EntityRow) fields.get(i);
+ String TYPE = field.getType();
+ String NAME = field.getName();
+ if (!pkFields.contains(NAME)) {
+ continue;
+ }
+ String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1);
+
+ stringBuffer.append(TEXT_17);
+ stringBuffer.append(TYPE);
+ stringBuffer.append(TEXT_18);
+ stringBuffer.append(METHOD);
+ stringBuffer.append(TEXT_19);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_20);
+ stringBuffer.append(METHOD);
+ stringBuffer.append(TEXT_21);
+ stringBuffer.append(TYPE);
+ stringBuffer.append(TEXT_22);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_23);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_24);
+ stringBuffer.append(NAME);
+ stringBuffer.append(TEXT_25);
+ }
+ stringBuffer.append(TEXT_26);
+ stringBuffer.append(model.getIdClassName());
+ stringBuffer.append(TEXT_27);
+ stringBuffer.append(model.getIdClassName());
+ stringBuffer.append(TEXT_28);
+ stringBuffer.append(model.getIdClassName());
+ stringBuffer.append(TEXT_29);
+ if (fields != null) for (int i=0; i<fields.size(); i++) {
+ EntityRow field = (EntityRow) fields.get(i);
+ String NAME = field.getName();
+ if (!pkFields.contains(NAME)) {
+ continue;
+ }
+ String TYPE = field.getType();
+ String GET_METHOD = "get" + NAME.substring(0,1).toUpperCase() + NAME.substring(1);
+ if (TYPE.equals("boolean") || TYPE.equals("byte") || TYPE.equals("char") || TYPE.equals("short") || TYPE.equals("int") || TYPE.equals("long")) {
+ stringBuffer.append(TEXT_30);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_31);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_32);
+ } else if (TYPE.equals("double")) {
+ stringBuffer.append(TEXT_33);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_34);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_35);
+ } else if (TYPE.equals("float")) {
+ stringBuffer.append(TEXT_36);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_37);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_38);
+ } else {
+ stringBuffer.append(TEXT_39);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_40);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_41);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_42);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_43);
+ }
+ }
+ stringBuffer.append(TEXT_44);
+ if (fields != null) for (int i=0; i<fields.size(); i++) {
+ EntityRow field = (EntityRow) fields.get(i);
+ String NAME = field.getName();
+ if (!pkFields.contains(NAME)) {
+ continue;
+ }
+ String TYPE = field.getType();
+ String GET_METHOD = "get" + NAME.substring(0,1).toUpperCase() + NAME.substring(1);
+ if (TYPE.equals("boolean")) {
+ stringBuffer.append(TEXT_45);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_46);
+ } else if (TYPE.equals("int")) {
+ stringBuffer.append(TEXT_47);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_48);
+ } else if (TYPE.equals("byte") || TYPE.equals("char") || TYPE.equals("short")) {
+ stringBuffer.append(TEXT_49);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_50);
+ } else if (TYPE.equals("long")) {
+ stringBuffer.append(TEXT_51);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_52);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_53);
+ } else if (TYPE.equals("double")) {
+ stringBuffer.append(TEXT_54);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_55);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_56);
+ } else if (TYPE.equals("float")) {
+ stringBuffer.append(TEXT_57);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_58);
+ } else {
+ stringBuffer.append(TEXT_59);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_60);
+ stringBuffer.append(GET_METHOD);
+ stringBuffer.append(TEXT_61);
+ }
+ }
+ stringBuffer.append(TEXT_62);
+ stringBuffer.append(TEXT_63);
+ return stringBuffer.toString();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
index e93ab339d8..45645a338d 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
@@ -11,6 +11,8 @@
***********************************************************************/
package org.eclipse.jpt.ui.internal.wizards.entity.data.operation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -30,8 +32,10 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.codegen.jet.JETEmitter;
import org.eclipse.emf.codegen.jet.JETException;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -64,12 +68,17 @@ import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef;
import org.eclipse.jpt.core.resource.persistence.XmlPersistence;
import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
import org.eclipse.jpt.ui.JptUiPlugin;
+import org.eclipse.jpt.ui.internal.wizards.entity.AnnotatedEntityTemplate;
+import org.eclipse.jpt.ui.internal.wizards.entity.EntityTemplate;
import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg;
+import org.eclipse.jpt.ui.internal.wizards.entity.IdClassTemplate;
import org.eclipse.jpt.ui.internal.wizards.entity.data.model.CreateEntityTemplateModel;
import org.eclipse.jst.common.internal.annotations.controller.AnnotationsController;
import org.eclipse.jst.common.internal.annotations.controller.AnnotationsControllerManager;
import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
+import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
import org.eclipse.jst.j2ee.internal.project.WTPJETEmitter;
+import org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditProviderOperation;
import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
@@ -107,7 +116,11 @@ public class NewEntityClassOperation extends AbstractDataModelOperation {
protected static final String BUILDER_ID = "builderId"; //$NON-NLS-1$
private static final String EMPTY_STRING = "";//$NON-NLS-1$
private static final String SINGLE_TABLE = "SINGLE_TABLE";//$NON-NLS-1$
-
+
+ /**
+ * Method name of template implementation classes.
+ */
+ protected static final String GENERATE_METHOD = "generate"; //$NON-NLS-1$
/**
* This is the constructor which should be used when creating a NewEntityClassOperation.
@@ -202,21 +215,23 @@ public class NewEntityClassOperation extends AbstractDataModelOperation {
* @throws WFTWrappedException
*/
protected void generateUsingTemplates(IProgressMonitor monitor, IPackageFragment fragment) throws WFTWrappedException, CoreException {
- // Create the filter template model
+ // Create the entity template model
CreateEntityTemplateModel tempModel = createTemplateModel();
IProject project = getTargetProject();
String entityClassSource = null;
String idClassSource = null;
- // Using the WTPJetEmitter, generate the java source based on the filter template model
+ // Generate the java source based on the entity template models
try {
if (tempModel.isArtifactsAnnotated()) {
- entityClassSource = generateTemplateSource(tempModel, monitor, ANNOTATED_ENTITY_TEMPLATE_FILE);
+ AnnotatedEntityTemplate tempImpl = AnnotatedEntityTemplate.create(null);
+ entityClassSource = generateTemplateSource(tempModel, ANNOTATED_ENTITY_TEMPLATE_FILE, tempImpl, monitor);
} else {
- entityClassSource = generateTemplateSource(tempModel, monitor, ENTITY_TEMPLATE_FILE);
+ EntityTemplate tempImpl = EntityTemplate.create(null);
+ entityClassSource = generateTemplateSource(tempModel, ENTITY_TEMPLATE_FILE, tempImpl, monitor);
}
if (tempModel.isCompositePK()) {
- idClassSource = generateTemplateSource(tempModel, monitor, IDCLASS_TEMPLATE_FILE);
-
+ IdClassTemplate tempImpl = IdClassTemplate.create(null);
+ idClassSource = generateTemplateSource(tempModel, IDCLASS_TEMPLATE_FILE, tempImpl, monitor);
}
} catch (Exception e) {
throw new WFTWrappedException(e);
@@ -288,19 +303,31 @@ public class NewEntityClassOperation extends AbstractDataModelOperation {
* java.lang.Object[])
* @see CreateEntityTemplateModel
*
- * @param tempModel
+ * @param templateModel
* @param monitor
* @param template_file
* @return String the source for the java file
* @throws JETException
+ * @throws NoSuchMethodException
+ * @throws SecurityException
+ * @throws InvocationTargetException
+ * @throws IllegalAccessException
*/
- private String generateTemplateSource(CreateEntityTemplateModel tempModel, IProgressMonitor monitor, String template_file) throws JETException {
- URL templateURL = FileLocator.find(JptUiPlugin.getPlugin().getBundle(), new Path(template_file), null);
- cleanUpOldEmitterProject();
- WTPJETEmitter emitter = new WTPJETEmitter(templateURL.toString(), this.getClass().getClassLoader());
- emitter.setIntelligentLinkingEnabled(true);
- emitter.addVariable(WTP_CUSTOMIZATION_PLUGIN, JptUiPlugin.PLUGIN_ID);
- return emitter.generate(monitor, new Object[] { tempModel });
+ private String generateTemplateSource(CreateEntityTemplateModel templateModel, String templateFile, Object templateImpl, IProgressMonitor monitor)
+ throws JETException, SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ Preferences preferences = J2EEPlugin.getDefault().getPluginPreferences();
+ boolean dynamicTranslation = preferences.getBoolean(J2EEPlugin.DYNAMIC_TRANSLATION_OF_JET_TEMPLATES_PREF_KEY);
+ if (dynamicTranslation) {
+ URL templateURL = FileLocator.find(JptUiPlugin.getPlugin().getBundle(), new Path(templateFile), null);
+ cleanUpOldEmitterProject();
+ WTPJETEmitter emitter = new WTPJETEmitter(templateURL.toString(), this.getClass().getClassLoader());
+ emitter.setIntelligentLinkingEnabled(true);
+ emitter.addVariable(WTP_CUSTOMIZATION_PLUGIN, JptUiPlugin.PLUGIN_ID);
+ return emitter.generate(monitor, new Object[] { templateModel });
+ } else {
+ Method method = templateImpl.getClass().getMethod(GENERATE_METHOD, new Class[] { Object.class });
+ return (String) method.invoke(templateImpl, templateModel);
+ }
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.ui/templates/annotated_entity.javajet b/jpa/plugins/org.eclipse.jpt.ui/templates/annotated_entity.javajet
index c6c61531b6..a2c7d1df1f 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/templates/annotated_entity.javajet
+++ b/jpa/plugins/org.eclipse.jpt.ui/templates/annotated_entity.javajet
@@ -1,4 +1,4 @@
-<%@ jet package="org.eclipse.jpt.ui"
+<%@ jet package="org.eclipse.jpt.ui.internal.wizards.entity"
imports="org.eclipse.jpt.ui.internal.wizards.entity.data.model.* java.util.* "
class="AnnotatedEntityTemplate"
%>
diff --git a/jpa/plugins/org.eclipse.jpt.ui/templates/entity.javajet b/jpa/plugins/org.eclipse.jpt.ui/templates/entity.javajet
index 77cb6ffb13..f58231c1b0 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/templates/entity.javajet
+++ b/jpa/plugins/org.eclipse.jpt.ui/templates/entity.javajet
@@ -1,4 +1,4 @@
-<%@ jet package="org.eclipse.jpt.ui"
+<%@ jet package="org.eclipse.jpt.ui.internal.wizards.entity"
imports="org.eclipse.jpt.ui.internal.wizards.entity.data.model.* java.util.* "
class="EntityTemplate"
%>
diff --git a/jpa/plugins/org.eclipse.jpt.ui/templates/idClass.javajet b/jpa/plugins/org.eclipse.jpt.ui/templates/idClass.javajet
index 1baadd89ac..7997344b4f 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/templates/idClass.javajet
+++ b/jpa/plugins/org.eclipse.jpt.ui/templates/idClass.javajet
@@ -1,4 +1,4 @@
-<%@ jet package="org.eclipse.jpt.ui"
+<%@ jet package="org.eclipse.jpt.ui.internal.wizards.entity"
imports="org.eclipse.jpt.ui.internal.wizards.entity.data.model.* java.util.* "
class="IdClassTemplate"
%>

Back to the top