/** * Searches for the property with the specified key in this property map. If the key is not * found in this property map, the parent property map, and its parents, recursively, are then * checked. * <br/> * If the key maps to any object value, it will be returned as is. If the property is not found, * <code>null</code> will be returned. * * @param key Property key. * @return Object in this property map with the specified key value. */ public final Object getObject(final String key) { return get(key); }
/** * Construct a configuration with given parent. Application and domain class loaders will be * initialized to the ones of the parent. * * @param parent Parent configuration. */ protected Configuration(final Configuration parent) { _applicationClassLoader = parent.getApplicationClassLoader(); _domainClassLoader = parent.getDomainClassLoader(); _parent = parent; }
/** * @see org.castor.xml.InternalContext#getLoadPackageMapping() */ public Boolean getLoadPackageMapping() { return _configuration.getBoolean(XMLConfiguration.LOAD_PACKAGE_MAPPING); }
/** * Load common user configuration from classpath root and current working directory. * <br/> * First it loads default configuration contained in Castor JAR. This gets overwritten * by a configuration found on Java library directory. If no configuration could be found * until that point a ConfigurationException will be thrown. At last an overriding * configuration is loaded from root of classpath or, if that could not be found, from * local working directory. * * @param filename Name of the configuration file. */ protected void loadUserProperties(final String filename) { Properties properties = new Properties(); // Get common configuration from the classpath root, ignore if not found. boolean onClasspathRoot = loadFromClassPath(properties, "/" + filename); // If not found on classpath root, either it doesn't exist, or "." is not part of // the classpath, try looking at local working directory. if (!onClasspathRoot) { loadFromWorkingDirectory(properties, filename); } _map.putAll(properties); }
Boolean validation = _configuration.getBoolean(XMLConfiguration.PARSER_VALIDATION); Boolean namespaces = _configuration.getBoolean(XMLConfiguration.NAMESPACES); String readerClassName = _configuration.getString(XMLConfiguration.PARSER); _configuration.getString(XMLConfiguration.PARSER_FEATURES, features), _configuration.getString(XMLConfiguration.PARSER_FEATURES_DISABLED, ""), validation.booleanValue(), namespaces.booleanValue(),
/** * @see org.castor.xml.InternalContext#getStringProperty(java.lang.String) */ public String getStringProperty(final String propertyName) { return _configuration.getString(propertyName); }
/** * Load modul configuration from default locations. * <br/> * First it loads default configuration contained in Castor JAR. This gets overwritten * by a configuration found on Java library directory. If no configuration could be found * until that point a ConfigurationException will be thrown. * * @param path Path to the default configuration to load. * @param filename Name of the configuration file. */ protected void loadDefaultProperties(final String path, final String filename) { Properties properties = new Properties(); // Get detault configuration from the Castor JAR. boolean inCastorJar = loadFromClassPath(properties, path + filename); // Get overriding configuration from the Java library directory, ignore if not // found. If found merge existing properties. boolean inJavaLibDir = loadFromJavaHome(properties, filename); // Couldn't find configuration in Castor jar nor Java library directory. if (!inCastorJar && !inJavaLibDir) { throw new ConfigurationException("Failed to load configuration: " + filename); } _map.putAll(properties); }
/** * Load properties with given filename from local working directory and merge them into * the given properties. * * @param properties Properties to merge the loaded ones into. * @param filename Name of the properties file to load from local working directory. * @return <code>true</code> if properties could be loaded, <code>false</code> otherwise. */ private boolean loadFromWorkingDirectory(final Properties properties, final String filename) { return loadFromFile(properties, new File(filename)); }
/** * @see org.castor.xml.InternalContext#getProperty(java.lang.String) */ public Object getProperty(final String propertyName) { return _configuration.getObject(propertyName); }
/** * Creates an instance of this registry, loading the mapping loader * factories from the castor.properties file. * @param config Configuration. */ public MappingLoaderRegistry(final Configuration config) { Object[] objects = config.getObjectArray( CoreConfiguration.MAPPING_LOADER_FACTORIES, getClass().getClassLoader()); for (int i = 0; i < objects.length; i++) { _mappingLoaderFactories.add(objects[i]); } }
public static Parser getParser(final Configuration configuration, final String features) { Parser parser = null; Boolean validation = configuration.getBoolean(XMLConfiguration.PARSER_VALIDATION); Boolean namespaces = configuration.getBoolean(XMLConfiguration.NAMESPACES); String parserClassName = configuration.getString(XMLConfiguration.PARSER); if ((parserClassName == null) || (parserClassName.length() == 0)) { SAXParser saxParser = XMLParserUtils.getSAXParser(validation.booleanValue(), namespaces.booleanValue()); XMLReader xmlReader = (XMLReader) parser; XMLParserUtils.setFeaturesOnXmlReader( configuration.getString(XMLConfiguration.PARSER_FEATURES, features), configuration.getString(XMLConfiguration.PARSER_FEATURES_DISABLED, ""), validation.booleanValue(), namespaces.booleanValue(),
/** * @see org.castor.xml.InternalContext#getPrimitiveNodeType() */ public NodeType getPrimitiveNodeType() { if (_primitiveNodeType != null) { return _primitiveNodeType; } String prop = _configuration.getString(XMLConfiguration.PRIMITIVE_NODE_TYPE, null); if (prop == null) { return null; } _primitiveNodeType = NodeType.getNodeType(prop); return _primitiveNodeType; } //-- getPrimitiveNodeType
/** * Load properties with given filename from Java library directory and merge them into * the given properties. * * @param properties Properties to merge the loaded ones into. * @param filename Name of the properties file to load from Java library directory. * @return <code>true</code> if properties could be loaded, <code>false</code> otherwise. */ private boolean loadFromJavaHome(final Properties properties, final String filename) { try { String javaHome = System.getProperty("java.home"); if (javaHome == null) { return false; } return loadFromFile(properties, new File(new File(javaHome, "lib"), filename)); } catch (SecurityException ex) { LOG.warn("Security policy prevented access to system property 'java.home'.", ex); return false; } }
/** * Searches for the property with the specified key in this property map. If the key is not * found in this property map, the parent property map, and its parents, recursively, are then * checked. * <br/> * If the key maps to any object value, it will be returned as is. If the property is not found, * <code>null</code> will be returned. * * @param key Key of the property to get from configuration. * @return Object in this property map with the specified key value. */ protected synchronized Object get(final String key) { Object value = _map.get(key); if ((value == null) && (_parent != null)) { value = _parent.get(key); } return value; }
/** * @see org.castor.xml.InternalContext#getOutputFormat() */ public static OutputFormat getOutputFormat(final Configuration configuration) { boolean indent = configuration.getBoolean(XMLConfiguration.USE_INDENTATION, false); OutputFormat format = getSerializerFactory( configuration.getString( XMLConfiguration.SERIALIZER_FACTORY)) .getOutputFormat(); format.setMethod(OutputFormat.XML); format.setIndenting(indent); // There is a bad interaction between the indentation and the // setPreserveSpace option. The indentated output is strangely indented. if (!indent) { format.setPreserveSpace(true); } return format; } //-- getOutputFormat
/** * @see org.castor.xml.InternalContext#getUseIntrospector() */ public Boolean getUseIntrospector() { return _configuration.getBoolean(XMLConfiguration.USE_INTROSPECTION); }
tokenizer = new StringTokenizer(configuration.getString(XMLConfiguration.COLLECTION_HANDLERS_FOR_JAVA_11_OR_12, ""), ", ");
/** * Searches for the property with the specified key in this property map. If the key is not * found in this property map, the parent property map, and its parents, recursively, are then * checked. * <br/> * If the key maps to a string value that is not empty, it will be returned as is. In all other * cases the given default value will be returned. * * @param key Property key. * @param defaultValue Default value. * @return String value in this property map with the specified key value. */ public final String getString(final String key, final String defaultValue) { Object objectValue = get(key); if ((objectValue instanceof String) && !"".equals(objectValue)) { return (String) objectValue; } return defaultValue; }
/** * @see org.castor.xml.InternalContext#getBooleanProperty(java.lang.String) */ public Boolean getBooleanProperty(final String propertyName) { return _configuration.getBoolean(propertyName); }
/** * @see org.castor.xml.InternalContext#getRegExpEvaluator() */ public RegExpEvaluator getRegExpEvaluator() { if (_regExpEvaluator != null) { return _regExpEvaluator; } String regExpEvalClassName = _configuration.getString(XMLConfiguration.REG_EXP_CLASS_NAME); if ((regExpEvalClassName == null) || (regExpEvalClassName.length() == 0)) { _regExpEvaluator = null; } else { try { Class regExpEvalClass = Class.forName(regExpEvalClassName); _regExpEvaluator = (RegExpEvaluator) regExpEvalClass.newInstance(); } catch (ClassNotFoundException e) { throw new RuntimeException( Messages.format("conf.failedInstantiateRegExp", regExpEvalClassName, e)); } catch (InstantiationException e) { throw new RuntimeException( Messages.format("conf.failedInstantiateRegExp", regExpEvalClassName, e)); } catch (IllegalAccessException e) { throw new RuntimeException( Messages.format("conf.failedInstantiateRegExp", regExpEvalClassName, e)); } } return _regExpEvaluator; } // -- getRegExpEvaluator