- /**
- * 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
- * @param isUsesAugment
- * boolean true if using augment
- * @return string with valid JAVA package name
- *
- * @deprecated Use {@link #packageNameForGeneratedType(String, SchemaPath)} or
- * {@link #packageNameForAugmentedGeneratedType(String, SchemaPath)} instead.
- */
- @Deprecated
- public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath,
- final boolean isUsesAugment) {
- if (basePackageName == null) {
- throw new IllegalArgumentException("Base Package Name cannot be NULL!");
- }
- if (schemaPath == null) {
- throw new IllegalArgumentException("Schema Path cannot be NULL!");
- }
-
- final Iterable<QName> iterable = schemaPath.getPathFromRoot();
- final int size = Iterables.size(iterable);
- final int traversalSteps;
- if (isUsesAugment) {
- traversalSteps = size;
- } else {
- traversalSteps = size - 1;
- }
-
- if (traversalSteps == 0) {
- return BindingMapping.normalizePackageName(basePackageName);
- }
-
- return generateNormalizedPackageName(basePackageName, iterable, traversalSteps);
- }
-
- /**
- * 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>
- * @deprecated This method ignores typeDefinition argument and its result is only
- * <code>BindingMapping.normalizePackageName(basePackageName)</code>.
- * Aside from tests, there is not a single user in OpenDaylight codebase,
- * hence it can be considered buggy and defunct. It is scheduled for removal
- * in Boron release.
- */
- @Deprecated
- 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!");
- }
-
- return BindingMapping.normalizePackageName(basePackageName);
- }
-
- /**
- * 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.
- *
- * @deprecated Use {@link BindingMapping#getClassName(QName)} instead.
- */
- @Deprecated
- public static String parseToClassName(final 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.
- *
- * @deprecated Use {@link BindingMapping#getPropertyName(String)} instead.
- */
- @Deprecated 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 = DOT_MATCHER.removeFrom(token.trim());
- if (correctStr.isEmpty()) {
- throw new IllegalArgumentException("Name can not be empty");
- }
-
- correctStr = replaceWithCamelCase(correctStr, ' ');
- correctStr = replaceWithCamelCase(correctStr, '-');
- correctStr = replaceWithCamelCase(correctStr, '_');
-
- char firstChar = correctStr.charAt(0);
- firstChar = uppercase ? Character.toUpperCase(firstChar) : Character.toLowerCase(firstChar);
-
- if (firstChar >= '0' && firstChar <= '9') {
- return '_' + correctStr;
- } else {
- return firstChar + correctStr.substring(1);
- }
- }
-
- /**
- * Replaces all the occurrences 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(final String text, final char removalChar) {
- int toBeRemovedPos = text.indexOf(removalChar);
- if (toBeRemovedPos == -1) {
- return text;
- }
-
- final StringBuilder sb = new StringBuilder(text);
- final String toBeRemoved = String.valueOf(removalChar);
- do {
- 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");
- }
- final char replacement = Character.toUpperCase(sb.charAt(toBeRemovedPos));
- sb.setCharAt(toBeRemovedPos, replacement);
- toBeRemovedPos = sb.indexOf(toBeRemoved);
- } while (toBeRemovedPos != -1);
-
- return sb.toString();
- }
-