@Bean(name = "javaNamingImpl") JavaNaming javaNamingImpl() { return new JavaNamingImpl(); }
/** * Appends a leading '_' and converts the given name to a java name. * @param name the XML name to convert * @param useKeywordSubstitutions set to true to turn on keyword substitution * @return a Java member name starting with a leading _ * @see org.castor.xml.JavaNaming#toJavaMemberName(java.lang.String,boolean) */ 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; } else { memberName = FIELD_UNDERSCORE_PREFIX + memberName; } } return memberName; } // -- toJavaMemberName
/** * 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 pacckage name is valid or not. Empty pacakge 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; }
/** * 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 * @see org.castor.xml.JavaNaming#extractFieldNameFromMethod(java.lang.reflect.Method) */ 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); } //FIELD_UNDERSCORE_PREFIX
/** * 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. * @see org.castor.xml.JavaNaming#getQualifiedFileName(java.lang.String,java.lang.String) */ public final String getQualifiedFileName(final String fileName, final String packageName) { if ((packageName == null) || (packageName.length() == 0)) { return fileName; } StringBuffer result = new StringBuffer(); result.append(packageToPath(packageName)); result.append('/'); result.append(fileName); return result.toString(); } // -- getQualifiedFileName
if (isKeyword(string)) { return false;
/** * Checks if the given pacckage name is valid or not. Empty pacakge names * are considered valid! * * @param packageName * name of package as String with periods * @return true if package name is valid * @see org.castor.xml.JavaNaming#isValidPackageName(java.lang.String) */ 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; }
public void setJavaNaming(final String javaNamingProperty) { if (javaNamingProperty == null || javaNamingProperty.length() == 0) { _javaNaming = new JavaNamingImpl(this); } else { try { Class<JavaNaming> cls = (Class<JavaNaming>) Class.forName(javaNamingProperty); _javaNaming = cls.newInstance(); } catch (Exception e) { IllegalArgumentException iae = new IllegalArgumentException("Failed to load JavaNaming: " + e); LOG.warn(iae.getMessage()); throw iae; } } }
/** * Appends a leading '_' and converts the given name to a java name. * * @param name the XML name to convert * @param useKeywordSubstitutions set to true to turn on keyword substitution * @return a Java member name starting with a leading _ */ @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; } else { memberName = FIELD_UNDERSCORE_PREFIX + memberName; } } 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 * @see org.castor.xml.JavaNaming#packageToPath(java.lang.String) */ public final String packageToPath(final String packageName) { if (packageName == null) { return packageName; } if (!isValidPackageName(packageName)) { String message = "Package name: " + packageName + " is not valid"; LOG.warn(message); throw new IllegalArgumentException(message); } return packageName.replace('.', File.separatorChar); } // -- packageToPath
public AbstractInternalContext() { _properties = XMLProperties.newInstance(); // TODO[WG]: remove once injection works _javaNaming = new JavaNamingImpl(this); }
/** * Creates an instance of {@link AbstractInternalContext}. The internal context is meant to * hold the configuration and state informations, but not necessarily retrieving * those values... */ public AbstractInternalContext() { _configuration = XMLConfiguration.newInstance(); _javaNaming = new JavaNamingImpl(); }
_javaNaming = new JavaNamingImpl(); } else { _javaNaming = new JavaNamingNGImpl();