diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/CommonUtil.java b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/CommonUtil.java
deleted file mode 100644
index 147acf64cf..0000000000
--- a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/CommonUtil.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.devonfw.cobigen.templates.devon4j.utils;
-
-import java.lang.reflect.Field;
-import java.util.Collection;
-
-import org.apache.commons.lang3.ClassUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class provides utility for all objects that inherit from it
- *
- */
-public class CommonUtil {
-
- /**
- * The constructor.
- */
- public CommonUtil() {
-
- // Empty for CobiGen to automatically instantiate it
- }
-
- /**
- * Logger for this class
- */
- protected static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class);
-
- /**
- * Checks whether the class given by the full qualified name is an enum
- *
- * @param className full qualified class name
- * @return true
if the class is an enum, false
otherwise
- */
- public boolean isEnum(String className) {
-
- try {
- return ClassUtils.getClass(className).isEnum();
- } catch (ClassNotFoundException e) {
- LOG.warn("{}: Could not find {}", e.getMessage(), className);
- return false;
- }
- }
-
- /**
- * @param pojoClass {@link Class} the class object of the pojo
- * @param fieldName {@link String} the name of the field
- * @return true if the field is an instance of java.utils.Collections
- * @throws NoSuchFieldException indicating something awfully wrong in the used model
- * @throws SecurityException if the field cannot be accessed.
- */
- public boolean isCollection(Class> pojoClass, String fieldName) throws NoSuchFieldException, SecurityException {
-
- if (pojoClass == null) {
- return false;
- }
-
- Field field = pojoClass.getDeclaredField(fieldName);
- if (field == null) {
- field = pojoClass.getField(fieldName);
- }
- if (field == null) {
- return false;
- } else {
- return Collection.class.isAssignableFrom(field.getType());
- }
-
- }
-
-}
diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java
index 943c0bf66b..f1bb367ccc 100644
--- a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java
+++ b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java
@@ -3,15 +3,23 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.Map;
import org.apache.commons.lang3.ClassUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Provides type operations, mainly checks and casts for Java Primitives, to be used in the templates
*
*/
-public class JavaUtil extends CommonUtil {
+public class JavaUtil {
+
+ /**
+ * Logger for this class
+ */
+ private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class);
/**
* The constructor.
@@ -54,7 +62,7 @@ public String boxJavaPrimitives(Class> pojoClass, String fieldName) throws NoS
if (pojoClass == null) {
throw new IllegalAccessError(
- "Class object is null. Cannot generate template as it might obviously depend on reflection.");
+ "Class object is null. Cannot generate template as it might obviously depend on reflection.");
}
if (equalsJavaPrimitive(pojoClass, fieldName)) {
@@ -114,7 +122,7 @@ public boolean equalsJavaPrimitiveOrWrapper(String simpleType) {
* @throws SecurityException if the field cannot be accessed.
*/
public boolean equalsJavaPrimitive(Class> pojoClass, String fieldName)
- throws NoSuchFieldException, SecurityException {
+ throws NoSuchFieldException, SecurityException {
if (pojoClass == null) {
return false;
@@ -161,10 +169,10 @@ public boolean equalsJavaPrimitiveIncludingArrays(String simpleType) {
* @throws SecurityException if the field cannot be accessed.
*/
public boolean equalsJavaPrimitiveIncludingArrays(Class> pojoClass, String fieldName)
- throws NoSuchFieldException, SecurityException {
+ throws NoSuchFieldException, SecurityException {
return equalsJavaPrimitive(pojoClass, fieldName) || (pojoClass.getDeclaredField(fieldName).getType().isArray()
- && pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive());
+ && pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive());
}
/**
@@ -198,7 +206,7 @@ public String castJavaPrimitives(String simpleType, String varName) throws Class
* @throws SecurityException if the field cannot be accessed.
*/
public String castJavaPrimitives(Class> pojoClass, String fieldName)
- throws NoSuchFieldException, SecurityException {
+ throws NoSuchFieldException, SecurityException {
if (equalsJavaPrimitive(pojoClass, fieldName)) {
return String.format("((%1$s)%2$s)", boxJavaPrimitives(pojoClass, fieldName), fieldName);
@@ -207,6 +215,31 @@ public String castJavaPrimitives(Class> pojoClass, String fieldName)
}
}
+ /**
+ * @param pojoClass {@link Class} the class object of the pojo
+ * @param fieldName {@link String} the name of the field
+ * @return true if the field is an instance of java.utils.Collections
+ * @throws NoSuchFieldException indicating something awefully wrong in the used model
+ * @throws SecurityException if the field cannot be accessed.
+ */
+ public boolean isCollection(Class> pojoClass, String fieldName) throws NoSuchFieldException, SecurityException {
+
+ if (pojoClass == null) {
+ return false;
+ }
+
+ Field field = pojoClass.getDeclaredField(fieldName);
+ if (field == null) {
+ field = pojoClass.getField(fieldName);
+ }
+ if (field == null) {
+ return false;
+ } else {
+ return Collection.class.isAssignableFrom(field.getType());
+ }
+
+ }
+
/**
* Returns the Ext Type to a given java type
*
@@ -301,7 +334,7 @@ public String getReturnType(Class> pojoClass, String methodName) throws NoSuch
if (pojoClass == null) {
throw new IllegalAccessError(
- "Class object is null. Cannot generate template as it might obviously depend on reflection.");
+ "Class object is null. Cannot generate template as it might obviously depend on reflection.");
}
String s = "-";
Method method = findMethod(pojoClass, methodName);
@@ -324,11 +357,11 @@ public String getReturnType(Class> pojoClass, String methodName) throws NoSuch
*/
@SuppressWarnings("unchecked")
public String getReturnTypeOfMethodAnnotatedWith(Class> pojoClass, String annotatedClassName)
- throws ClassNotFoundException {
+ throws ClassNotFoundException {
if (pojoClass == null) {
throw new IllegalAccessError(
- "Class object is null. Cannot generate template as it might obviously depend on reflection.");
+ "Class object is null. Cannot generate template as it might obviously depend on reflection.");
}
Method[] methods = pojoClass.getDeclaredMethods();
@@ -381,7 +414,7 @@ private Method findMethod(Class> pojoClass, String methodName) {
if (pojoClass == null) {
throw new IllegalAccessError(
- "Class object is null. Cannot generate template as it might obviously depend on reflection.");
+ "Class object is null. Cannot generate template as it might obviously depend on reflection.");
}
for (Method m : pojoClass.getMethods()) {
if (m.getName().equals(methodName)) {
@@ -391,6 +424,22 @@ private Method findMethod(Class> pojoClass, String methodName) {
return null;
}
+ /**
+ * Checks whether the class given by the full qualified name is an enum
+ *
+ * @param className full qualified class name
+ * @return true
if the class is an enum, false
otherwise
+ */
+ public boolean isEnum(String className) {
+
+ try {
+ return ClassUtils.getClass(className).isEnum();
+ } catch (ClassNotFoundException e) {
+ LOG.warn("{}: Could not find {}", e.getMessage(), className);
+ return false;
+ }
+ }
+
/**
* Returns the first enum value of an enum class
*
diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java
index 2c266f034c..2795d835b1 100644
--- a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java
+++ b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java
@@ -7,7 +7,7 @@
* Provides operations to identify and process SQL specific information
*
*/
-public class SQLUtil extends CommonUtil {
+public class SQLUtil {
private static int DEFAULT_FIELD_LENGTH = 255;