@Bean(name = "javaNamingNG") JavaNaming javaNamingNGImpl() { return new JavaNamingNGImpl(); }
/** * Converts the given name to a valid Java name. * * @param name the XML name to convert * @param useKeywordSubstitutions set to true to turn on keyword substitution * @return a valid Java member name */ @Override public final String toJavaMemberName(final String name, final boolean useKeywordSubstitutions) { if (name == null) { return null; } String memberName = toJavaName(name, false); if (isKeyword(memberName) && useKeywordSubstitutions) { String mappedName = (String) SUBST.get(memberName); if (mappedName != null) { memberName = mappedName; } } return memberName; }
/** * Converts the given Package name to it's corresponding Path. The path will be a relative path. * * @param packageName the package name to convert * @return a String containing the resulting patch */ @Override public final String packageToPath(final String packageName) { if (packageName == null) { return packageName; } if (!isValidPackageName(packageName)) { String message = "Package name: " + packageName + " is not valid"; throw new IllegalArgumentException(message); } return packageName.replace('.', File.separatorChar); }
/** * Extracts the filed name part from the methods name. Mostly it cuts away the method prefix. * * @param method the Method to process * @return the extracted field name */ @Override public final String extractFieldNameFromMethod(final Method method) { if (method == null) { return null; } String fieldName = null; if (isSetMethod(method)) { fieldName = method.getName().substring(METHOD_PREFIX_SET.length()); } else if (isCreateMethod(method)) { fieldName = method.getName().substring(METHOD_PREFIX_CREATE.length()); } else if (isGetMethod(method)) { fieldName = method.getName().substring(METHOD_PREFIX_GET.length()); } else if (isIsMethod(method)) { fieldName = method.getName().substring(METHOD_PREFIX_IS.length()); } else if (isAddMethod(method)) { fieldName = method.getName().substring(METHOD_PREFIX_ADD.length()); } return toJavaMemberName(fieldName); }
/** * Qualifies the given <code>fileName</code> with the given <code>packageName</code> and returns * the resulting file path.<br> * If <code>packageName</code> is <code>null</code> or a zero-length String, this method will * return <code>fileName</code>.<br> * * @param fileName The file name to be qualified. * @param packageName The package name to be used for qualifying. * @return The qualified file path. */ @Override public final String getQualifiedFileName(final String fileName, final String packageName) { if ((packageName == null) || (packageName.length() == 0)) { return fileName; } return new StringBuilder().append(packageToPath(packageName)).append('/').append(fileName) .toString(); }
/** * Returns true if the given String matches the production of a valid Java identifier. * * @param string The String to check the production of. * @return true if the given String matches the production of a valid Java name, otherwise false. */ @Override public final boolean isValidJavaIdentifier(final String string) { if (string == null || string.length() == 0 || !Character.isJavaIdentifierStart(string.charAt(0))) { return false; } for (int i = 1; i < string.length(); i++) { char ch = string.charAt(i); if (!Character.isJavaIdentifierPart(ch)) { return false; } } return !isKeyword(string); }
/** * Checks if the given package name is valid or not. Empty package names are considered valid! * * @param packageName name of package as String with periods * @return true if package name is valid */ @Override public final boolean isValidPackageName(final String packageName) { if ((packageName == null) || (packageName.length() < 1)) { return true; } if (".".equals(packageName)) { return false; } if (packageName.startsWith(".") || (packageName.endsWith("."))) { return false; } boolean valid = true; String[] packageNameParts = packageName.split("\\."); for (int i = 0; i < packageNameParts.length; i++) { String packageNamePart = packageNameParts[i]; valid &= isValidJavaIdentifier(packageNamePart); } return valid; }
_javaNaming = new JavaNamingImpl(); } else { _javaNaming = new JavaNamingNGImpl();