diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java index 9e9221f8e..95a1d10b8 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java @@ -361,7 +361,8 @@ public class SourceCode { * */ public class Class extends Element { - private boolean isAbstract; + private boolean isAbstract; + private boolean isFinal; private ClassName superCls; private List interfaces = new ArrayList(); private Set fields = new TreeSet(); @@ -383,10 +384,20 @@ public class SourceCode { return this; } - public Class makeAbstract() { - isAbstract = true; - return this; - } + public Class makeAbstract() { + if (isFinal) + throw new IllegalArgumentException(_loc.get("src-invalid-modifier").toString()); + + isAbstract = true; + return this; + } + + public Class makeFinal() { + if (isAbstract) + throw new IllegalArgumentException(_loc.get("src-invalid-modifier").toString()); + isFinal = true; + return this; + } /** * Adds getters and setters to every non-public field. @@ -449,6 +460,8 @@ public class SourceCode { super.write(out, tab); if (isAbstract) out.append("abstract "); + if(isFinal) + out.append("final "); out.print("class "); out.print(type.simpleName); writeList(out, BLANK, params, PARAMS_DELIMITER, false); diff --git a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties index 812144b3d..6fd388474 100644 --- a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties +++ b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties @@ -23,3 +23,4 @@ src-invalid-type: "{0}" is not a valid type name. It must be a valid Java packag Java type or token and a valid Java identifier. src-invalid-field: "{0}" is not a valid field name. \ It must be a non-reserved Java token and a valid Java identifier. +src-invalid-modifier: Unable to declare a class as abstract and final.