YANG typedefs generation as class with extends key word
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / controller / sal / java / api / generator / GeneratorUtil.java
index ec908560e4108ced2b832b57887b1afce26d91bf..0e2da819371cf7b962ba0eba39fa980e1e66bdbd 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.sal.java.api.generator;
 import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -27,12 +28,12 @@ public final class GeneratorUtil {
 
     public static String createIfcDeclaration(final GeneratedType genType, final String indent,
             final Map<String, String> availableImports) {
-        return createFileDeclaration(IFC, genType, indent, availableImports, false);
+        return createFileDeclaration(IFC, genType, indent, availableImports, false, false);
     }
 
     public static String createClassDeclaration(final GeneratedTransferObject genTransferObject, final String indent,
-            final Map<String, String> availableImports, boolean isIdentity) {
-        return createFileDeclaration(CLASS, genTransferObject, indent, availableImports, isIdentity);
+            final Map<String, String> availableImports, boolean isIdentity, boolean isInnerClass) {
+        return createFileDeclaration(CLASS, genTransferObject, indent, availableImports, isIdentity, isInnerClass);
     }
 
     public static String createPackageDeclaration(final String packageName) {
@@ -40,7 +41,7 @@ public final class GeneratorUtil {
     }
 
     private static String createFileDeclaration(final String type, final GeneratedType genType, final String indent,
-            final Map<String, String> availableImports, boolean isIdentity) {
+            final Map<String, String> availableImports, boolean isIdentity, boolean innerClass) {
         final StringBuilder builder = new StringBuilder();
         final String currentPkg = genType.getPackageName();
 
@@ -52,13 +53,15 @@ public final class GeneratorUtil {
             builder.append(NL);
         }
 
-        if (isIdentity) {
+        if (innerClass) {
+            builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP + type + GAP + genType.getName() + GAP);
+        } else if (isIdentity) {
             if (!(CLASS.equals(type))) {
                 throw new IllegalArgumentException("'identity' has to be generated as a class");
             }
-            builder.append(PUBLIC + GAP + ABSTRACT + GAP + type + GAP + genType.getName() + GAP);
+            builder.append(indent + PUBLIC + GAP + ABSTRACT + GAP + type + GAP + genType.getName() + GAP);
         } else {
-            builder.append(PUBLIC + GAP + type + GAP + genType.getName() + GAP);
+            builder.append(indent + PUBLIC + GAP + type + GAP + genType.getName() + GAP);
         }
 
         if (genType instanceof GeneratedTransferObject) {
@@ -149,26 +152,9 @@ public final class GeneratorUtil {
         builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP);
         builder.append(getExplicitType(constant.getType(), availableImports, currentPkg) + GAP + constant.getName());
         builder.append(GAP + "=" + GAP);
-        final Object constValue = constant.getValue();
 
         if (constant.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
-            if (constant.getName() == null || constant.getType() == null || constant.getValue() == null)
-                throw new IllegalArgumentException();
-            if (constValue instanceof List) {
-                builder.append("Arrays.asList" + LB);
-                final List<?> constantValues = (List<?>) constValue;
-                int stringsCount = 0;
-                for (Object value : constantValues) {
-                    if (value instanceof String) {
-                        if (stringsCount > 0) {
-                            builder.append(COMMA);
-                        }
-                        stringsCount++;
-                        builder.append(DOUBLE_QUOTE + (String) value + DOUBLE_QUOTE);
-                    }
-                }
-                builder.append(RB);
-            }
+            return "";
         } else {
             builder.append(constant.getValue());
         }
@@ -222,9 +208,9 @@ public final class GeneratorUtil {
 
         createComment(builder, comment, indent);
         builder.append(NL);
-        builder.append(indent);
 
         if (!method.getAnnotations().isEmpty()) {
+            builder.append(indent);
             final List<AnnotationType> annotations = method.getAnnotations();
             appendAnnotations(builder, annotations);
             builder.append(NL);
@@ -246,78 +232,352 @@ public final class GeneratorUtil {
         return builder.toString();
     }
 
-    public static String createConstructor(GeneratedTransferObject genTransferObject, final String indent,
-            final Map<String, String> availableImports, boolean isIdentity) {
-        final StringBuilder builder = new StringBuilder();
+    public static String createConstructor(final GeneratedTransferObject genTransferObject, final String indent,
+            final Map<String, String> availableImports, final boolean isIdentity, final boolean oneConstructor) {
+        if (genTransferObject == null) {
+            throw new IllegalArgumentException("Generated transfer object can't be null");
+        }
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        if (availableImports == null) {
+            throw new IllegalArgumentException("Map of available imports can't be null");
+        }
+        GeneratedTransferObject genTOTopParent = getTopParrentTransportObject(genTransferObject);
+        final List<GeneratedProperty> ctorProperties = resolveReadOnlyPropertiesFromTO(genTransferObject
+                .getProperties());
+        final List<GeneratedProperty> ctorPropertiesAllParents = getPropertiesOfAllParents(genTransferObject
+                .getExtends());
 
         final String currentPkg = genTransferObject.getPackageName();
-        final List<GeneratedProperty> properties = genTransferObject.getProperties();
-        final List<GeneratedProperty> ctorParams = new ArrayList<GeneratedProperty>();
+        final String className = genTransferObject.getName();
+
+        String constructorPart = "";
+        if (oneConstructor) {
+            if (genTOTopParent != genTransferObject && genTOTopParent.isUnionType()) {
+                constructorPart = createConstructorForEveryParentProperty(indent, isIdentity, ctorProperties,
+                        ctorPropertiesAllParents, availableImports, currentPkg, className);
+
+            } else {
+                constructorPart = createOneConstructor(indent, isIdentity, ctorProperties, ctorPropertiesAllParents,
+                        availableImports, currentPkg, className);
+            }
+
+        } else { // union won't be extended
+            constructorPart = createConstructorForEveryProperty(indent, isIdentity, ctorProperties,
+                    ctorPropertiesAllParents, availableImports, currentPkg, className);
+        }
+
+        return constructorPart;
+    }
+
+    private static String createOneConstructor(final String indent, boolean isIdentity,
+            final List<GeneratedProperty> properties, final List<GeneratedProperty> propertiesAllParents,
+            final Map<String, String> availableImports, final String currentPkg, final String className) {
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        if (properties == null) {
+            throw new IllegalArgumentException("List of generated properties can't be null");
+        }
+        if (propertiesAllParents == null) {
+            throw new IllegalArgumentException(
+                    "List of generated properties of all parent transport objects can't be null");
+        }
+        if (availableImports == null) {
+            throw new IllegalArgumentException("Map of available imports can't be null");
+        }
+        if (currentPkg == null) {
+            throw new IllegalArgumentException("String with current package can't be null");
+        }
+        if (className == null) {
+            throw new IllegalArgumentException("String with class name can't be null");
+        }
+
+        final StringBuilder builder = new StringBuilder();
+
+        List<GeneratedProperty> propertiesAll = new ArrayList<GeneratedProperty>(properties);
+        propertiesAll.addAll(propertiesAllParents);
+
+        builder.append(createConstructorDeclarationToLeftParenthesis(className, indent, isIdentity));
+        builder.append(createMethodPropertiesDeclaration(propertiesAll, availableImports, currentPkg, COMMA + GAP));
+        builder.append(createConstructorDeclarationFromRightParenthesis());
+        builder.append(createConstructorSuper(propertiesAllParents, indent));
+        builder.append(createClassPropertiesInitialization(propertiesAll, indent));
+        builder.append(createConstructorClosingPart(indent));
+        return builder.toString();
+    }
+
+    private static String createConstructorForEveryParentProperty(final String indent, final boolean isIdentity,
+            final List<GeneratedProperty> properties, final List<GeneratedProperty> propertiesAllParents,
+            final Map<String, String> availableImports, final String currentPkg, final String className) {
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        if (properties == null) {
+            throw new IllegalArgumentException("List of generated properties can't be null");
+        }
+        if (propertiesAllParents == null) {
+            throw new IllegalArgumentException(
+                    "List of generated properties of all parent transport objects can't be null");
+        }
+        if (availableImports == null) {
+            throw new IllegalArgumentException("Map of available imports can't be null");
+        }
+        if (currentPkg == null) {
+            throw new IllegalArgumentException("String with current package can't be null");
+        }
+        if (className == null) {
+            throw new IllegalArgumentException("String with class name can't be null");
+        }
+        final StringBuilder builder = new StringBuilder();
+        GeneratedProperty parentProperty;
+        Iterator<GeneratedProperty> parentPropertyIterator = propertiesAllParents.iterator();
+
+        do {
+            parentProperty = null;
+            if (parentPropertyIterator.hasNext()) {
+                parentProperty = parentPropertyIterator.next();
+            }
+
+            List<GeneratedProperty> propertiesAndParentProperties = new ArrayList<GeneratedProperty>();
+            if (parentProperty != null) {
+                propertiesAndParentProperties.add(parentProperty);
+            }
+            propertiesAndParentProperties.addAll(properties);
+
+            builder.append(createConstructorDeclarationToLeftParenthesis(className, indent, isIdentity));
+            builder.append(createMethodPropertiesDeclaration(propertiesAndParentProperties, availableImports,
+                    currentPkg, COMMA + GAP));
+            builder.append(createConstructorDeclarationFromRightParenthesis());
+            builder.append(createConstructorSuper(parentProperty, indent));
+            builder.append(createClassPropertiesInitialization(properties, indent));
+            builder.append(createConstructorClosingPart(indent));
+        } while (parentPropertyIterator.hasNext());
+
+        return builder.toString();
+    }
+
+    private static String createConstructorForEveryProperty(final String indent, final boolean isIdentity,
+            final List<GeneratedProperty> properties, final List<GeneratedProperty> propertiesAllParents,
+            final Map<String, String> availableImports, final String currentPkg, final String className) {
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        if (properties == null) {
+            throw new IllegalArgumentException("List of generated properties can't be null");
+        }
+        if (propertiesAllParents == null) {
+            throw new IllegalArgumentException(
+                    "List of generated properties of all parent transport objects can't be null");
+        }
+        if (availableImports == null) {
+            throw new IllegalArgumentException("Map of available imports can't be null");
+        }
+        if (currentPkg == null) {
+            throw new IllegalArgumentException("String with current package can't be null");
+        }
+        if (className == null) {
+            throw new IllegalArgumentException("String with class name can't be null");
+        }
+
+        final StringBuilder builder = new StringBuilder();
+
+        GeneratedProperty property;
+        Iterator<GeneratedProperty> propertyIterator = properties.iterator();
+
+        do {
+            property = null;
+            if (propertyIterator.hasNext()) {
+                property = propertyIterator.next();
+            }
+
+            List<GeneratedProperty> propertyAndTopParentProperties = new ArrayList<GeneratedProperty>();
+            if (property != null) {
+                propertyAndTopParentProperties.add(property);
+            }
+            propertyAndTopParentProperties.addAll(propertiesAllParents);
+
+            builder.append(createConstructorDeclarationToLeftParenthesis(className, indent, isIdentity));
+            builder.append(createMethodPropertiesDeclaration(propertyAndTopParentProperties, availableImports,
+                    currentPkg, COMMA + GAP));
+            builder.append(createConstructorDeclarationFromRightParenthesis());
+            builder.append(createConstructorSuper(propertiesAllParents, indent));
+            builder.append(createClassPropertyInitialization(property, indent));
+            builder.append(createConstructorClosingPart(indent));
+        } while (propertyIterator.hasNext());
+
+        return builder.toString();
+    }
+
+    /**
+     * The method selects from input list of properties only those which have
+     * read only attribute set to true.
+     * 
+     * @param properties
+     *            contains list of properties of generated transfer object
+     * @return subset of <code>properties</code> which have read only attribute
+     *         set to true
+     */
+    private static List<GeneratedProperty> resolveReadOnlyPropertiesFromTO(List<GeneratedProperty> properties) {
+        List<GeneratedProperty> readOnlyProperties = new ArrayList<GeneratedProperty>();
         if (properties != null) {
             for (final GeneratedProperty property : properties) {
                 if (property.isReadOnly()) {
-                    ctorParams.add(property);
+                    readOnlyProperties.add(property);
                 }
             }
         }
+        return readOnlyProperties;
+    }
+
+    private static String createMethodPropertiesDeclaration(final List<GeneratedProperty> parameters,
+            final Map<String, String> availableImports, final String currentPkg, final String parameterSeparator) {
+        StringBuilder builder = new StringBuilder();
+        if (parameters == null) {
+            throw new IllegalArgumentException("List of generated properties can't be null");
+        }
+        if (availableImports == null) {
+            throw new IllegalArgumentException("Map of available imports can't be null");
+        }
+        if (currentPkg == null) {
+            throw new IllegalArgumentException("String with current package can't be null");
+        }
+        if (parameterSeparator == null) {
+            throw new IllegalArgumentException("String with separator of parameters can't be null");
+        }
+
+        for (final GeneratedProperty parameter : parameters) {
+            builder.append(createMethodPropertyDeclaration(parameter, availableImports, currentPkg));
+            builder.append(parameterSeparator);
+        }
+        if (!parameters.isEmpty()) {
+            builder = builder.delete(builder.length() - parameterSeparator.length(), builder.length());
+        }
+        return builder.toString();
+    }
 
+    private static String createConstructorDeclarationToLeftParenthesis(final String className, final String indent,
+            final boolean isIdentity) {
+        if (className == null) {
+            throw new IllegalArgumentException("String with class name can't be null");
+        }
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        final StringBuilder builder = new StringBuilder();
         builder.append(indent);
         builder.append(isIdentity ? PROTECTED : PUBLIC);
         builder.append(GAP);
-        builder.append(genTransferObject.getName());
+        builder.append(className);
         builder.append(LB);
+        return builder.toString();
+    }
 
-        if (!ctorParams.isEmpty()) {
-            builder.append(getExplicitType(ctorParams.get(0).getReturnType(), availableImports, currentPkg));
-            builder.append(" ");
-            builder.append(ctorParams.get(0).getName());
-            for (int i = 1; i < ctorParams.size(); ++i) {
-                final GeneratedProperty param = ctorParams.get(i);
-                builder.append(", ");
-                builder.append(getExplicitType(param.getReturnType(), availableImports, currentPkg));
-                builder.append(GAP);
-                builder.append(param.getName());
-            }
+    private static String createConstructorDeclarationFromRightParenthesis() {
+        final StringBuilder builder = new StringBuilder();
+        builder.append(RB + GAP + LCB + NL);
+        return builder.toString();
+    }
+
+    private static String createConstructorSuper(final List<GeneratedProperty> propertiesAllParents, final String indent) {
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
         }
-        builder.append(RB + GAP + LCB + NL + indent + TAB + "super();" + NL);
-        if (!ctorParams.isEmpty()) {
-            for (final GeneratedProperty property : ctorParams) {
-                builder.append(indent);
-                builder.append(TAB);
-                builder.append("this.");
-                builder.append(property.getName());
-                builder.append(" = ");
-                builder.append(property.getName());
-                builder.append(SC);
-                builder.append(NL);
-            }
+        if (propertiesAllParents == null) {
+            throw new IllegalArgumentException("List of all parent's properties can't be null");
+        }
+        StringBuilder builder = new StringBuilder();
+        builder.append(indent + TAB + "super(");
+        String propertySeparator = COMMA + GAP;
+        for (GeneratedProperty superProperty : propertiesAllParents) {
+            builder.append(superProperty.getName());
+            builder.append(propertySeparator);
+        }
+        if (!propertiesAllParents.isEmpty()) {
+            builder = builder.delete(builder.length() - propertySeparator.length(), builder.length());
         }
-        List<Constant> consts = genTransferObject.getConstantDefinitions();
-        for (Constant con : consts) {
-            if (con.getName() == null || con.getType() == null || con.getValue() == null)
-                continue;
-            if (con.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
-                Object values = con.getValue();
-                if (values instanceof List) {
-                    for (Object regEx : (List<?>) values) {
-                        if (regEx instanceof String) {
-                            builder.append(indent + TAB + "for (String regEx : " + TypeConstants.PATTERN_CONSTANT_NAME
-                                    + ") {" + NL);
-                            builder.append(indent + TAB + TAB + "this." + MEMBER_PATTERN_LIST
-                                    + ".add(Pattern.compile(regEx))" + SC + NL);
-                            builder.append(indent + TAB + RCB + NL);
-
-                            break;
-                        }
-                    }
 
-                }
-            }
+        builder.append(");" + NL);
+        return builder.toString();
+    }
 
+    private static String createConstructorSuper(final GeneratedProperty parentProperty, final String indent) {
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        if (parentProperty == null) {
+            throw new IllegalArgumentException("Parent property can't be null");
+        }
+        StringBuilder builder = new StringBuilder();
+        if (parentProperty != null) {
+            builder.append(indent + TAB + "super(");
+            builder.append(parentProperty.getName());
+            builder.append(");" + NL);
         }
+        return builder.toString();
+    }
 
+    private static String createConstructorClosingPart(final String indent) {
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        final StringBuilder builder = new StringBuilder();
         builder.append(indent);
         builder.append(RCB);
+        builder.append(NL + NL);
+        return builder.toString();
+    }
+
+    private static String createClassPropertiesInitialization(final List<GeneratedProperty> properties,
+            final String indent) {
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        if (properties == null) {
+            throw new IllegalArgumentException("List of generated class properties can't be null");
+        }
+        final StringBuilder builder = new StringBuilder();
+        for (final GeneratedProperty property : properties) {
+            createClassPropertyInitialization(property, indent);
+        }
+        return builder.toString();
+    }
+
+    private static String createClassPropertyInitialization(final GeneratedProperty property, final String indent) {
+        if (indent == null) {
+            throw new IllegalArgumentException("String with indent can't be null");
+        }
+        if (property == null) {
+            throw new IllegalArgumentException("List of generated class properties can't be null");
+        }
+        final StringBuilder builder = new StringBuilder();
+        builder.append(indent);
+        builder.append(TAB);
+        builder.append("this.");
+        builder.append(property.getName());
+        builder.append(" = ");
+        builder.append(property.getName());
+        builder.append(SC);
+        builder.append(NL);
+        return builder.toString();
+    }
+
+    private static String createMethodPropertyDeclaration(final GeneratedProperty property,
+            final Map<String, String> availableImports, final String currentPkg) {
+        if (property == null) {
+            throw new IllegalArgumentException("Generated property can't be null");
+        }
+        if (availableImports == null) {
+            throw new IllegalArgumentException("Map of available imports can't be null");
+        }
+        if (currentPkg == null) {
+            throw new IllegalArgumentException("String with current package can't be null");
+        }
+        final StringBuilder builder = new StringBuilder();
+        builder.append(getExplicitType(property.getReturnType(), availableImports, currentPkg));
+        builder.append(GAP);
+        builder.append(property.getName());
         return builder.toString();
     }
 
@@ -543,6 +803,9 @@ public final class GeneratorUtil {
                     builder.append(type.getName());
                 }
             }
+            if (type.equals(Types.voidType())) {
+                return "void";
+            }
             if (type instanceof ParameterizedType) {
                 final ParameterizedType pType = (ParameterizedType) type;
                 final Type[] pTypes = pType.getActualTypeArguments();
@@ -550,9 +813,6 @@ public final class GeneratorUtil {
                 builder.append(getParameters(pTypes, imports, currentPkg));
                 builder.append(">");
             }
-            if (builder.toString().equals("Void")) {
-                return "void";
-            }
             return builder.toString();
         }
     }
@@ -568,10 +828,17 @@ public final class GeneratorUtil {
             }
 
             String wildcardParam = "";
-            if (t instanceof WildcardType) {
-                wildcardParam = "? extends ";
+            if (t.equals(Types.voidType())) {
+                builder.append("java.lang.Void" + separator);
+                continue;
+            } else {
+
+                if (t instanceof WildcardType) {
+                    wildcardParam = "? extends ";
+                }
+
+                builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg) + separator);
             }
-            builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg) + separator);
         }
         return builder.toString();
     }
@@ -584,12 +851,18 @@ public final class GeneratorUtil {
         }
     }
 
-    public static Map<String, String> createImports(final GeneratedType genType) {
+    public static Map<String, String> createImports(GeneratedType genType) {
         if (genType == null) {
             throw new IllegalArgumentException("Generated Type cannot be NULL!");
         }
-
         final Map<String, String> imports = new LinkedHashMap<>();
+        List<GeneratedType> childGeneratedTypes = genType.getEnclosedTypes();
+        if (!childGeneratedTypes.isEmpty()) {
+            for (GeneratedType genTypeChild : childGeneratedTypes) {
+                imports.putAll(createImports(genTypeChild));
+            }
+        }
+
         final List<Constant> constants = genType.getConstantDefinitions();
         final List<MethodSignature> methods = genType.getMethodDefinitions();
         final List<Type> impl = genType.getImplements();
@@ -644,6 +917,18 @@ public final class GeneratorUtil {
         return imports;
     }
 
+    public static Map<String, String> createChildImports(GeneratedType genType) {
+        Map<String, String> childImports = new LinkedHashMap<>();
+        List<GeneratedType> childGeneratedTypes = genType.getEnclosedTypes();
+        if (!childGeneratedTypes.isEmpty()) {
+            for (GeneratedType genTypeChild : childGeneratedTypes) {
+                createChildImports(genTypeChild);
+                childImports.put(genTypeChild.getName(), genTypeChild.getPackageName());
+            }
+        }
+        return childImports;
+    }
+
     private static void putTypeIntoImports(final GeneratedType parentGenType, final Type type,
             final Map<String, String> imports) {
         if (parentGenType == null) {
@@ -686,12 +971,20 @@ public final class GeneratorUtil {
         }
     }
 
-    public static List<String> createImportLines(final Map<String, String> imports) {
+    public static List<String> createImportLines(final Map<String, String> imports,
+            final Map<String, String> innerTypeImports) {
         final List<String> importLines = new ArrayList<>();
 
         for (Map.Entry<String, String> entry : imports.entrySet()) {
             final String typeName = entry.getKey();
             final String packageName = entry.getValue();
+            if (innerTypeImports != null) {
+                String innerTypePackageName = innerTypeImports.get(typeName);
+                if (innerTypePackageName != null) {
+                    if (innerTypePackageName.equals(packageName))
+                        continue;
+                }
+            }
             importLines.add("import " + packageName + "." + typeName + SC);
         }
         return importLines;
@@ -709,4 +1002,95 @@ public final class GeneratorUtil {
         }
         return false;
     }
+
+    /**
+     * The method returns reference to highest (top parent) Generated Transfer
+     * Object.
+     * 
+     * @param childTransportObject
+     *            is generated transfer object which can be extended by other
+     *            generated transfer object
+     * @return in first case that <code>childTransportObject</code> isn't
+     *         extended then <code>childTransportObject</code> is returned. In
+     *         second case the method is recursive called until first case.
+     */
+    private static GeneratedTransferObject getTopParrentTransportObject(GeneratedTransferObject childTransportObject) {
+        if (childTransportObject == null) {
+            throw new IllegalArgumentException("Parameter childTransportObject can't be null.");
+        }
+        if (childTransportObject.getExtends() == null) {
+            return childTransportObject;
+        } else {
+            return getTopParrentTransportObject(childTransportObject.getExtends());
+        }
+    }
+
+    /**
+     * The method returns the list of the properties of all extending generated
+     * transfer object from <code>genTO</code> to highest parent generated
+     * transfer object
+     * 
+     * @param genTO
+     * @return the list of all properties from actual to highest parent
+     *         generated transfer object. In case when extension exists the
+     *         method is recursive called.
+     */
+    private static List<GeneratedProperty> getPropertiesOfAllParents(GeneratedTransferObject genTO) {
+        List<GeneratedProperty> propertiesOfAllParents = new ArrayList<GeneratedProperty>();
+        if (genTO != null) {
+            final List<GeneratedProperty> allPropertiesOfTO = genTO.getProperties();
+            List<GeneratedProperty> readOnlyPropertiesOfTO = resolveReadOnlyPropertiesFromTO(allPropertiesOfTO);
+            propertiesOfAllParents.addAll(readOnlyPropertiesOfTO);
+            if (genTO.getExtends() != null) {
+                propertiesOfAllParents.addAll(getPropertiesOfAllParents(genTO.getExtends()));
+            }
+        }
+        return propertiesOfAllParents;
+    }
+
+    public static String createStaticInicializationBlock(GeneratedTransferObject genTransferObject, String indent) {
+
+        final StringBuilder builder = new StringBuilder();
+
+        List<Constant> constants = genTransferObject.getConstantDefinitions();
+        for (Constant constant : constants) {
+            if (constant.getName() == null || constant.getType() == null || constant.getValue() == null) {
+                continue;
+            }
+            if (constant.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
+                final Object constValue = constant.getValue();
+                List<String> regularExpressions = new ArrayList<>();
+                if (constValue instanceof List) {
+                    builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP + "List<String>" + GAP
+                            + TypeConstants.PATTERN_CONSTANT_NAME + GAP + "=" + GAP + "Arrays.asList" + LB);
+                    final List<?> constantValues = (List<?>) constValue;
+                    int stringsCount = 0;
+                    for (Object value : constantValues) {
+                        if (value instanceof String) {
+                            if (stringsCount > 0) {
+                                builder.append(COMMA);
+                            }
+                            stringsCount++;
+                            regularExpressions.add((String) value);
+                            builder.append(DOUBLE_QUOTE + (String) value + DOUBLE_QUOTE);
+                        }
+                    }
+                    builder.append(RB + SC + NL);
+                }
+                builder.append(indent + PRIVATE + GAP + STATIC + GAP + FINAL + GAP + "List<Pattern>" + GAP
+                        + MEMBER_PATTERN_LIST + GAP + ASSIGN + GAP + "new ArrayList<Pattern>()" + GAP + SC + NL + NL);
+
+                if (!regularExpressions.isEmpty()) {
+                    builder.append(indent + STATIC + LCB + NL);
+                    builder.append(indent + TAB + "for (String regEx : " + TypeConstants.PATTERN_CONSTANT_NAME + ") {"
+                            + NL);
+                    builder.append(indent + TAB + TAB + MEMBER_PATTERN_LIST + ".add(Pattern.compile(regEx))" + SC + NL);
+                    builder.append(indent + TAB + RCB + NL);
+                    builder.append(indent + RCB + NL + NL);
+                }
+
+            }
+        }
+        return builder.toString();
+    }
 }