Implemented range validation (Bug 178).
[mdsal.git] / code-generator / binding-generator-util / src / main / java / org / opendaylight / yangtools / binding / generator / util / BindingGeneratorUtil.java
index e4e532fba91a22b0f8b8a4207e3f0ab3baf96feb..6e961701e907549ee6071a9535fc03191f4329d1 100644 (file)
-package org.opendaylight.yangtools.binding.generator.util;\r
-\r
-import java.text.DateFormat;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Arrays;\r
-import java.util.Calendar;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.model.api.Module;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
-\r
-/**\r
- * Contains the methods for converting strings to valid JAVA language strings\r
- * (package names, class names, attribute names).\r
- * \r
- * \r
- */\r
-public final class BindingGeneratorUtil {\r
-\r
-    private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyMMdd");\r
-    \r
-    /**\r
-     * Array of strings values which represents JAVA reserved words.\r
-     */\r
-    private static final String[] SET_VALUES = new String[] { "abstract", "assert", "boolean", "break", "byte", "case",\r
-            "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends",\r
-            "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",\r
-            "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",\r
-            "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",\r
-            "true", "try", "void", "volatile", "while" };\r
-\r
-    /**\r
-     * Impossible to instantiate this class. All of the methods or attributes\r
-     * are static.\r
-     */\r
-    private BindingGeneratorUtil() {\r
-    }\r
-\r
-    /**\r
-     * Hash set of words which are reserved in JAVA language.\r
-     */\r
-    private static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(Arrays.asList(SET_VALUES));\r
-\r
-    /**\r
-     * Converts string <code>packageName</code> to valid JAVA package name.\r
-     * \r
-     * If some words of package name are digits of JAVA reserved words they are\r
-     * prefixed with underscore character.\r
-     * \r
-     * @param packageName\r
-     *            string which contains words separated by point.\r
-     * @return package name which contains words separated by point.\r
-     */\r
-    private static String validateJavaPackage(final String packageName) {\r
-        if (packageName != null) {\r
-            final String[] packNameParts = packageName.split("\\.");\r
-            if (packNameParts != null) {\r
-                final StringBuilder builder = new StringBuilder();\r
-                for (int i = 0; i < packNameParts.length; ++i) {\r
-                    final String packNamePart = packNameParts[i];\r
-                    if (Character.isDigit(packNamePart.charAt(0))) {\r
-                        packNameParts[i] = "_" + packNamePart;\r
-                    } else if (JAVA_RESERVED_WORDS.contains(packNamePart)) {\r
-                        packNameParts[i] = "_" + packNamePart;\r
-                    }\r
-                    if (i > 0) {\r
-                        builder.append(".");\r
-                    }\r
-                    builder.append(packNameParts[i]);\r
-                }\r
-                return builder.toString();\r
-            }\r
-        }\r
-        return packageName;\r
-    }\r
-\r
-    /**\r
-     * Converts <code>parameterName</code> to valid JAVA parameter name.\r
-     * \r
-     * If the <code>parameterName</code> is one of the JAVA reserved words then\r
-     * it is prefixed with underscore character.\r
-     * \r
-     * @param parameterName\r
-     *            string with the parameter name\r
-     * @return string with the admissible parameter name\r
-     */\r
-    public static String validateParameterName(final String parameterName) {\r
-        if (parameterName != null && JAVA_RESERVED_WORDS.contains(parameterName)) {\r
-            return "_" + parameterName;\r
-        }\r
-        return parameterName;\r
-    }\r
-\r
-    /**\r
-     * Converts module name to valid JAVA package name.\r
-     * \r
-     * The package name consists of:\r
-     * <ul>\r
-     * <li>prefix - <i>org.opendaylight.yang.gen.v</i></li>\r
-     * <li>module YANG version - <i>org.opendaylight.yang.gen.v</i></li>\r
-     * <li>module namespace - invalid characters are replaced with dots</li>\r
-     * <li>revision prefix - <i>.rev</i></li>\r
-     * <li>revision - YYYYMMDD (MM and DD aren't spread to the whole length)</li>\r
-     * </ul>\r
-     * \r
-     * @param module\r
-     *            module which contains data about namespace and revision date\r
-     * @return string with the valid JAVA package name\r
-     * @throws IllegalArgumentException\r
-     *             if the revision date of the <code>module</code> equals\r
-     *             <code>null</code>\r
-     */\r
-    public static String moduleNamespaceToPackageName(final Module module) {\r
-        final StringBuilder packageNameBuilder = new StringBuilder();\r
-\r
-        if (module.getRevision() == null) {\r
-            throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!");\r
-        }\r
-        packageNameBuilder.append("org.opendaylight.yang.gen.v");\r
-        packageNameBuilder.append(module.getYangVersion());\r
-        packageNameBuilder.append(".");\r
-\r
-        String namespace = module.getNamespace().toString();\r
-        namespace = namespace.replace("://", ".");\r
-        namespace = namespace.replace("/", ".");\r
-        namespace = namespace.replace(":", ".");\r
-        namespace = namespace.replace("-", ".");\r
-        namespace = namespace.replace("@", ".");\r
-        namespace = namespace.replace("$", ".");\r
-        namespace = namespace.replace("#", ".");\r
-        namespace = namespace.replace("'", ".");\r
-        namespace = namespace.replace("*", ".");\r
-        namespace = namespace.replace("+", ".");\r
-        namespace = namespace.replace(",", ".");\r
-        namespace = namespace.replace(";", ".");\r
-        namespace = namespace.replace("=", ".");\r
-\r
-        packageNameBuilder.append(namespace);\r
-        packageNameBuilder.append(".rev");\r
-        packageNameBuilder.append(DATE_FORMAT.format(module.getRevision()));\r
-        \r
-        return validateJavaPackage(packageNameBuilder.toString());\r
-    }\r
-\r
-    /**\r
-     * Creates package name from specified <code>basePackageName</code> (package\r
-     * name for module) and <code>schemaPath</code>.\r
-     * \r
-     * Resulting package name is concatenation of <code>basePackageName</code>\r
-     * and all local names of YANG nodes which are parents of some node for\r
-     * which <code>schemaPath</code> is specified.\r
-     * \r
-     * @param basePackageName\r
-     *            string with package name of the module\r
-     * @param schemaPath\r
-     *            list of names of YANG nodes which are parents of some node +\r
-     *            name of this node\r
-     * @return string with valid JAVA package name\r
-     */\r
-    public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath) {\r
-        if (basePackageName == null) {\r
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");\r
-        }\r
-        if (schemaPath == null) {\r
-            throw new IllegalArgumentException("Schema Path cannot be NULL!");\r
-        }\r
-\r
-        final StringBuilder builder = new StringBuilder();\r
-        builder.append(basePackageName);\r
-        final List<QName> pathToNode = schemaPath.getPath();\r
-        final int traversalSteps = (pathToNode.size() - 1);\r
-        for (int i = 0; i < traversalSteps; ++i) {\r
-            builder.append(".");\r
-            String nodeLocalName = pathToNode.get(i).getLocalName();\r
-\r
-            nodeLocalName = nodeLocalName.replace(":", ".");\r
-            nodeLocalName = nodeLocalName.replace("-", ".");\r
-            builder.append(nodeLocalName);\r
-        }\r
-        return validateJavaPackage(builder.toString());\r
-    }\r
-\r
-    /**\r
-     * Generates the package name for type definition from\r
-     * <code>typeDefinition</code> and <code>basePackageName</code>.\r
-     * \r
-     * @param basePackageName\r
-     *            string with the package name of the module\r
-     * @param typeDefinition\r
-     *            type definition for which the package name will be generated *\r
-     * @return string with valid JAVA package name\r
-     * @throws IllegalArgumentException\r
-     *             <ul>\r
-     *             <li>if <code>basePackageName</code> equals <code>null</code></li>\r
-     *             <li>if <code>typeDefinition</code> equals <code>null</code></li>\r
-     *             </ul>\r
-     */\r
-    public static String packageNameForTypeDefinition(final String basePackageName,\r
-            final TypeDefinition<?> typeDefinition) {\r
-        if (basePackageName == null) {\r
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");\r
-        }\r
-        if (typeDefinition == null) {\r
-            throw new IllegalArgumentException("Type Definition reference cannot be NULL!");\r
-        }\r
-\r
-        final StringBuilder builder = new StringBuilder();\r
-        builder.append(basePackageName);\r
-        return validateJavaPackage(builder.toString());\r
-    }\r
-\r
-    /**\r
-     * Converts <code>token</code> to string which is in accordance with best\r
-     * practices for JAVA class names.\r
-     * \r
-     * @param token\r
-     *            string which contains characters which should be converted to\r
-     *            JAVA class name\r
-     * @return string which is in accordance with best practices for JAVA class\r
-     *         name.\r
-     */\r
-    public static String parseToClassName(String token) {\r
-        String correctStr = token.replace(".", "");\r
-        correctStr = parseToCamelCase(correctStr);\r
-\r
-        // make first char upper-case\r
-        char first = Character.toUpperCase(correctStr.charAt(0));\r
-        if (first >= '0' && first <= '9') {\r
-\r
-            correctStr = "_" + correctStr;\r
-        } else {\r
-            correctStr = first + correctStr.substring(1);\r
-        }\r
-        return correctStr;\r
-    }\r
-\r
-    /**\r
-     * Converts <code>token</code> to string which is in accordance with best\r
-     * practices for JAVA parameter names.\r
-     * \r
-     * @param token\r
-     *            string which contains characters which should be converted to\r
-     *            JAVA parameter name\r
-     * @return string which is in accordance with best practices for JAVA\r
-     *         parameter name.\r
-     */\r
-    public static String parseToValidParamName(final String token) {\r
-        final String validToken = token.replace(".", "");\r
-        String correctStr = parseToCamelCase(validToken);\r
-\r
-        // make first char lower-case\r
-        char first = Character.toLowerCase(correctStr.charAt(0));\r
-        correctStr = first + correctStr.substring(1);\r
-        return validateParameterName(correctStr);\r
-    }\r
-\r
-    /**\r
-     * Converts <code>token</code> to capital letters and removes invalid\r
-     * characters.\r
-     * \r
-     * @param token\r
-     *            string with characters which should be conversed to capital\r
-     * @return string with capital letters\r
-     */\r
-    public static String convertToCapitalLetters(final String token) {\r
-        String convertedStr = token.replace(" ", "_");\r
-        convertedStr = convertedStr.replace(".", "_");\r
-        convertedStr = convertedStr.toUpperCase();\r
-        return convertedStr;\r
-    }\r
-\r
-    /**\r
-     * \r
-     * Converts string <code>token</code> to the cammel case format.\r
-     * \r
-     * @param token\r
-     *            string which should be converted to the cammel case format\r
-     * @return string in the cammel case format\r
-     * @throws IllegalArgumentException\r
-     *             <ul>\r
-     *             <li>if <code>token</code> without white spaces is empty</li>\r
-     *             <li>if <code>token</code> equals null</li>\r
-     *             </ul>\r
-     */\r
-    private static String parseToCamelCase(String token) {\r
-        if (token == null) {\r
-            throw new IllegalArgumentException("Name can not be null");\r
-        }\r
-\r
-        String correctStr = token.trim();\r
-        if (correctStr.isEmpty()) {\r
-            throw new IllegalArgumentException("Name can not be emty");\r
-        }\r
-\r
-        correctStr = replaceWithCamelCase(correctStr, ' ');\r
-        correctStr = replaceWithCamelCase(correctStr, '-');\r
-        correctStr = replaceWithCamelCase(correctStr, '_');\r
-        return correctStr;\r
-    }\r
-\r
-    /**\r
-     * Replaces all the occurances of the <code>removalChar</code> in the\r
-     * <code>text</code> with empty string and converts following character to\r
-     * upper case.\r
-     * \r
-     * @param text\r
-     *            string with source text which should be converted\r
-     * @param removalChar\r
-     *            character which is sought in the <code>text</code>\r
-     * @return string which doesn't contain <code>removalChar</code> and has\r
-     *         following characters converted to upper case\r
-     * @throws IllegalArgumentException\r
-     *             if the length of the returning string has length 0\r
-     */\r
-    private static String replaceWithCamelCase(String text, char removalChar) {\r
-        StringBuilder sb = new StringBuilder(text);\r
-        String toBeRemoved = String.valueOf(removalChar);\r
-\r
-        int toBeRemovedPos = sb.indexOf(toBeRemoved);\r
-        while (toBeRemovedPos != -1) {\r
-            sb.replace(toBeRemovedPos, toBeRemovedPos + 1, "");\r
-            // check if 'toBeRemoved' character is not the only character in\r
-            // 'text'\r
-            if (sb.length() == 0) {\r
-                throw new IllegalArgumentException("The resulting string can not be empty");\r
-            }\r
-            String replacement = String.valueOf(sb.charAt(toBeRemovedPos)).toUpperCase();\r
-            sb.setCharAt(toBeRemovedPos, replacement.charAt(0));\r
-            toBeRemovedPos = sb.indexOf(toBeRemoved);\r
-        }\r
-        return sb.toString();\r
-    }\r
-}\r
+package org.opendaylight.yangtools.binding.generator.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
+import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.TypeMemberBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+
+/**
+ * Contains the methods for converting strings to valid JAVA language strings
+ * (package names, class names, attribute names).
+ *
+ *
+ */
+public final class BindingGeneratorUtil {
+
+    private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyMMdd");
+
+    /**
+     * Array of strings values which represents JAVA reserved words.
+     */
+    private static final String[] SET_VALUES = new String[] { "abstract", "assert", "boolean", "break", "byte", "case",
+            "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends",
+            "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
+            "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",
+            "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",
+            "true", "try", "void", "volatile", "while" };
+
+    /**
+     * Impossible to instantiate this class. All of the methods or attributes
+     * are static.
+     */
+    private BindingGeneratorUtil() {
+    }
+
+    /**
+     * Hash set of words which are reserved in JAVA language.
+     */
+    private static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(Arrays.asList(SET_VALUES));
+
+    /**
+     * Converts string <code>packageName</code> to valid JAVA package name.
+     *
+     * If some words of package name are digits of JAVA reserved words they are
+     * prefixed with underscore character.
+     *
+     * @param packageName
+     *            string which contains words separated by point.
+     * @return package name which contains words separated by point.
+     */
+    private static String validateJavaPackage(final String packageName) {
+        if (packageName != null) {
+            final String[] packNameParts = packageName.toLowerCase().split("\\.");
+            if (packNameParts != null) {
+                final StringBuilder builder = new StringBuilder();
+                for (int i = 0; i < packNameParts.length; ++i) {
+                    final String packNamePart = packNameParts[i];
+                    if (Character.isDigit(packNamePart.charAt(0))) {
+                        packNameParts[i] = "_" + packNamePart;
+                    } else if (JAVA_RESERVED_WORDS.contains(packNamePart)) {
+                        packNameParts[i] = "_" + packNamePart;
+                    }
+                    if (i > 0) {
+                        builder.append(".");
+                    }
+                    builder.append(packNameParts[i]);
+                }
+                return builder.toString();
+            }
+        }
+        return packageName;
+    }
+
+    /**
+     * Converts <code>parameterName</code> to valid JAVA parameter name.
+     *
+     * If the <code>parameterName</code> is one of the JAVA reserved words then
+     * it is prefixed with underscore character.
+     *
+     * @param parameterName
+     *            string with the parameter name
+     * @return string with the admissible parameter name
+     */
+    public static String resolveJavaReservedWordEquivalency(final String parameterName) {
+        if (parameterName != null && JAVA_RESERVED_WORDS.contains(parameterName)) {
+            return "_" + parameterName;
+        }
+        return parameterName;
+    }
+
+    /**
+     * Converts module name to valid JAVA package name.
+     *
+     * The package name consists of:
+     * <ul>
+     * <li>prefix - <i>org.opendaylight.yang.gen.v</i></li>
+     * <li>module YANG version - <i>org.opendaylight.yang.gen.v</i></li>
+     * <li>module namespace - invalid characters are replaced with dots</li>
+     * <li>revision prefix - <i>.rev</i></li>
+     * <li>revision - YYYYMMDD (MM and DD aren't spread to the whole length)</li>
+     * </ul>
+     *
+     * @param module
+     *            module which contains data about namespace and revision date
+     * @return string with the valid JAVA package name
+     * @throws IllegalArgumentException
+     *             if the revision date of the <code>module</code> equals
+     *             <code>null</code>
+     */
+    public static String moduleNamespaceToPackageName(final Module module) {
+        final StringBuilder packageNameBuilder = new StringBuilder();
+
+        if (module.getRevision() == null) {
+            throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!");
+        }
+        packageNameBuilder.append("org.opendaylight.yang.gen.v");
+        packageNameBuilder.append(module.getYangVersion());
+        packageNameBuilder.append(".");
+
+        String namespace = module.getNamespace().toString();
+        namespace = namespace.replace("://", ".");
+        namespace = namespace.replace("/", ".");
+        namespace = namespace.replace(":", ".");
+        namespace = namespace.replace("-", ".");
+        namespace = namespace.replace("@", ".");
+        namespace = namespace.replace("$", ".");
+        namespace = namespace.replace("#", ".");
+        namespace = namespace.replace("'", ".");
+        namespace = namespace.replace("*", ".");
+        namespace = namespace.replace("+", ".");
+        namespace = namespace.replace(",", ".");
+        namespace = namespace.replace(";", ".");
+        namespace = namespace.replace("=", ".");
+
+        packageNameBuilder.append(namespace);
+        packageNameBuilder.append(".rev");
+        packageNameBuilder.append(DATE_FORMAT.format(module.getRevision()));
+
+        return validateJavaPackage(packageNameBuilder.toString());
+    }
+
+    /**
+     * Creates package name from specified <code>basePackageName</code> (package
+     * name for module) and <code>schemaPath</code>.
+     *
+     * Resulting package name is concatenation of <code>basePackageName</code>
+     * and all local names of YANG nodes which are parents of some node for
+     * which <code>schemaPath</code> is specified.
+     *
+     * @param basePackageName
+     *            string with package name of the module
+     * @param schemaPath
+     *            list of names of YANG nodes which are parents of some node +
+     *            name of this node
+     * @return string with valid JAVA package name
+     */
+    public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath) {
+        if (basePackageName == null) {
+            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+        }
+        if (schemaPath == null) {
+            throw new IllegalArgumentException("Schema Path cannot be NULL!");
+        }
+
+        final StringBuilder builder = new StringBuilder();
+        builder.append(basePackageName);
+        final List<QName> pathToNode = schemaPath.getPath();
+        final int traversalSteps = (pathToNode.size() - 1);
+        for (int i = 0; i < traversalSteps; ++i) {
+            builder.append(".");
+            String nodeLocalName = pathToNode.get(i).getLocalName();
+
+            nodeLocalName = nodeLocalName.replace(":", ".");
+            nodeLocalName = nodeLocalName.replace("-", ".");
+            builder.append(nodeLocalName);
+        }
+        return validateJavaPackage(builder.toString());
+    }
+
+    /**
+     * Generates the package name for type definition from
+     * <code>typeDefinition</code> and <code>basePackageName</code>.
+     *
+     * @param basePackageName
+     *            string with the package name of the module
+     * @param typeDefinition
+     *            type definition for which the package name will be generated *
+     * @return string with valid JAVA package name
+     * @throws IllegalArgumentException
+     *             <ul>
+     *             <li>if <code>basePackageName</code> equals <code>null</code></li>
+     *             <li>if <code>typeDefinition</code> equals <code>null</code></li>
+     *             </ul>
+     */
+    public static String packageNameForTypeDefinition(final String basePackageName,
+            final TypeDefinition<?> typeDefinition) {
+        if (basePackageName == null) {
+            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+        }
+        if (typeDefinition == null) {
+            throw new IllegalArgumentException("Type Definition reference cannot be NULL!");
+        }
+
+        final StringBuilder builder = new StringBuilder();
+        builder.append(basePackageName);
+        return validateJavaPackage(builder.toString());
+    }
+
+    /**
+     * Converts <code>token</code> to string which is in accordance with best
+     * practices for JAVA class names.
+     *
+     * @param token
+     *            string which contains characters which should be converted to
+     *            JAVA class name
+     * @return string which is in accordance with best practices for JAVA class
+     *         name.
+     */
+    public static String parseToClassName(String token) {
+        return parseToCamelCase(token, true);
+    }
+
+    /**
+     * Converts <code>token</code> to string which is in accordance with best
+     * practices for JAVA parameter names.
+     *
+     * @param token
+     *            string which contains characters which should be converted to
+     *            JAVA parameter name
+     * @return string which is in accordance with best practices for JAVA
+     *         parameter name.
+     */
+    public static String parseToValidParamName(final String token) {
+        return resolveJavaReservedWordEquivalency(parseToCamelCase(token, false));
+    }
+
+    /**
+     *
+     * Converts string <code>token</code> to the cammel case format.
+     *
+     * @param token
+     *            string which should be converted to the cammel case format
+     * @param uppercase
+     *            boolean value which says whether the first character of the
+     *            <code>token</code> should|shuldn't be uppercased
+     * @return string in the cammel case format
+     * @throws IllegalArgumentException
+     *             <ul>
+     *             <li>if <code>token</code> without white spaces is empty</li>
+     *             <li>if <code>token</code> equals null</li>
+     *             </ul>
+     */
+
+    private static String parseToCamelCase(final String token, final boolean uppercase) {
+        if (token == null) {
+            throw new IllegalArgumentException("Name can not be null");
+        }
+
+        String correctStr = token.trim();
+        correctStr = correctStr.replace(".", "");
+
+        if (correctStr.isEmpty()) {
+            throw new IllegalArgumentException("Name can not be emty");
+        }
+
+        correctStr = replaceWithCamelCase(correctStr, ' ');
+        correctStr = replaceWithCamelCase(correctStr, '-');
+        correctStr = replaceWithCamelCase(correctStr, '_');
+
+        String firstChar = correctStr.substring(0, 1);
+        if (uppercase) {
+            firstChar = firstChar.toUpperCase();
+        } else {
+            firstChar = firstChar.toLowerCase();
+        }
+
+        if (firstChar.matches("[0-9]")) {
+            correctStr = "_" + correctStr;
+        } else {
+            correctStr = firstChar + correctStr.substring(1);
+        }
+        return correctStr;
+    }
+
+    /**
+     * Replaces all the occurances of the <code>removalChar</code> in the
+     * <code>text</code> with empty string and converts following character to
+     * upper case.
+     *
+     * @param text
+     *            string with source text which should be converted
+     * @param removalChar
+     *            character which is sought in the <code>text</code>
+     * @return string which doesn't contain <code>removalChar</code> and has
+     *         following characters converted to upper case
+     * @throws IllegalArgumentException
+     *             if the length of the returning string has length 0
+     */
+    private static String replaceWithCamelCase(String text, char removalChar) {
+        StringBuilder sb = new StringBuilder(text);
+        String toBeRemoved = String.valueOf(removalChar);
+
+        int toBeRemovedPos = sb.indexOf(toBeRemoved);
+        while (toBeRemovedPos != -1) {
+            sb.replace(toBeRemovedPos, toBeRemovedPos + 1, "");
+            // check if 'toBeRemoved' character is not the only character in
+            // 'text'
+            if (sb.length() == 0) {
+                throw new IllegalArgumentException("The resulting string can not be empty");
+            }
+            String replacement = String.valueOf(sb.charAt(toBeRemovedPos)).toUpperCase();
+            sb.setCharAt(toBeRemovedPos, replacement.charAt(0));
+            toBeRemovedPos = sb.indexOf(toBeRemoved);
+        }
+        return sb.toString();
+    }
+
+    public static long computeDefaultSUID(GeneratedTOBuilderImpl to) {
+        try {
+            ByteArrayOutputStream bout = new ByteArrayOutputStream();
+            DataOutputStream dout = new DataOutputStream(bout);
+
+            dout.writeUTF(to.getName());
+            dout.writeInt(to.isAbstract() ? 3 : 7);
+
+            List<Type> impl = to.getImplementsTypes();
+            Collections.sort(impl, new Comparator<Type>() {
+                @Override
+                public int compare(Type o1, Type o2) {
+                    return o1.getFullyQualifiedName().compareTo(o2.getFullyQualifiedName());
+                }
+            });
+            for (Type ifc : impl) {
+                dout.writeUTF(ifc.getFullyQualifiedName());
+            }
+
+            Comparator<TypeMemberBuilder<?>> comparator = new Comparator<TypeMemberBuilder<?>>() {
+                @Override
+                public int compare(TypeMemberBuilder<?> o1, TypeMemberBuilder<?> o2) {
+                    return o1.getName().compareTo(o2.getName());
+                }
+            };
+
+            List<GeneratedPropertyBuilder> props = to.getProperties();
+            Collections.sort(props, comparator);
+            for (GeneratedPropertyBuilder gp : props) {
+                dout.writeUTF(gp.getName());
+            }
+
+            List<MethodSignatureBuilder> methods = to.getMethodDefinitions();
+            Collections.sort(methods, comparator);
+            for (MethodSignatureBuilder m : methods) {
+                if (!(m.getAccessModifier().equals(AccessModifier.PRIVATE))) {
+                    dout.writeUTF(m.getName());
+                    dout.write(m.getAccessModifier().ordinal());
+                }
+            }
+
+            dout.flush();
+
+            MessageDigest md = MessageDigest.getInstance("SHA");
+            byte[] hashBytes = md.digest(bout.toByteArray());
+            long hash = 0;
+            for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) {
+                hash = (hash << 8) | (hashBytes[i] & 0xFF);
+            }
+            return hash;
+        } catch (IOException ex) {
+            throw new InternalError();
+        } catch (NoSuchAlgorithmException ex) {
+            throw new SecurityException(ex.getMessage());
+        }
+    }
+
+    public static Restrictions getRestrictions(TypeDefinition<?> type) {
+        final List<LengthConstraint> length = new ArrayList<>();
+        final List<PatternConstraint> pattern = new ArrayList<>();
+        final List<RangeConstraint> range = new ArrayList<>();
+
+        if (type instanceof ExtendedType) {
+            ExtendedType ext = (ExtendedType)type;
+            TypeDefinition<?> base = ext.getBaseType();
+            length.addAll(ext.getLengthConstraints());
+            pattern.addAll(ext.getPatternConstraints());
+            range.addAll(ext.getRangeConstraints());
+
+            if (base instanceof IntegerTypeDefinition && range.isEmpty()) {
+                range.addAll(((IntegerTypeDefinition)base).getRangeConstraints());
+            } else if (base instanceof UnsignedIntegerTypeDefinition && range.isEmpty()) {
+                range.addAll(((UnsignedIntegerTypeDefinition)base).getRangeConstraints());
+            } else if (base instanceof DecimalTypeDefinition && range.isEmpty()) {
+                range.addAll(((DecimalTypeDefinition)base).getRangeConstraints());
+            }
+
+        }
+
+        return new Restrictions() {
+            @Override
+            public List<RangeConstraint> getRangeConstraints() {
+                return range;
+            }
+            @Override
+            public List<PatternConstraint> getPatternConstraints() {
+                return pattern;
+            }
+            @Override
+            public List<LengthConstraint> getLengthConstraints() {
+                return length;
+            }
+            @Override
+            public boolean isEmpty() {
+                return range.isEmpty() && pattern.isEmpty() && length.isEmpty();
+            }
+        };
+    }
+
+}