/** * Construct an instance of CacheFactoryRegistry that uses given properties * to get required configuration properties. * * @param properties The properties. */ public CacheFactoryRegistry(final AbstractProperties properties) { Object[] objects = properties.getObjectArray( CPAProperties.CACHE_FACTORIES, properties.getApplicationClassLoader()); for (int i = 0; i < objects.length; i++) { CacheFactory factory = (CacheFactory) objects[i]; _cacheFactories.put(factory.getCacheType(), factory); } }
@Override public Boolean getBooleanProperty(final String propertyName) { return _properties.getBoolean(propertyName); }
@Override public String getStringProperty(final String propertyName) { return _properties.getString(propertyName); }
/** * Construct properties with given parent. Application and domain class loaders will be * initialized to the ones of the parent. * * @param parent Parent properties. */ protected AbstractProperties(final AbstractProperties parent) { _applicationClassLoader = parent.getApplicationClassLoader(); _domainClassLoader = parent.getDomainClassLoader(); _parent = parent; }
private void setPropertyInternal(final String propertyName, final Object value) { Object oldValue = this._properties.getObject(propertyName); if (oldValue == null) { if (value != null) { this._properties.put(propertyName, value); this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, value); } } else { if (!oldValue.equals(value)) { this._properties.put(propertyName, value); this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, value); } } }
@Override public XMLReader getXMLReader(final String features) { XMLReader reader = null; Boolean validation = _properties.getBoolean(XMLProperties.PARSER_VALIDATION); Boolean namespaces = _properties.getBoolean(XMLProperties.NAMESPACES); String readerClassName = _properties.getString(XMLProperties.PARSER); if (readerClassName == null || readerClassName.length() == 0) { SAXParser saxParser = XMLParserUtils.getSAXParser(validation.booleanValue(), namespaces.booleanValue()); if (saxParser != null) { try { reader = saxParser.getXMLReader(); } catch (SAXException e) { LOG.error(Messages.format("conf.configurationError", e)); } } } if (reader == null) { if ((readerClassName == null) || (readerClassName.length() == 0) || (readerClassName.equalsIgnoreCase("xerces"))) { readerClassName = "org.apache.xerces.parsers.SAXParser"; } reader = XMLParserUtils.instantiateXMLReader(readerClassName); } XMLParserUtils.setFeaturesOnXmlReader( _properties.getString(XMLProperties.PARSER_FEATURES, features), _properties.getString(XMLProperties.PARSER_FEATURES_DISABLED, ""), validation.booleanValue(), namespaces.booleanValue(), reader); return reader; }
boolean userPropertiesLoaded = loadFromClassPath(properties, "/" + filename); userPropertiesLoaded = loadFromWorkingDirectory(properties, filename); if (file.exists()) { LOG.info("Loading custom Castor properties from " + file.getAbsolutePath()); userPropertiesLoaded = loadFromFile(properties, file); } else { LOG.warn(file.getAbsolutePath() + " is not a valid file.");
/** * 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); }
/** * Creates an instance of this registry, loading the mapping loader factories from the * castor.properties file. * * @param properties Properties. */ public MappingLoaderRegistry(final AbstractProperties properties) { Object[] objects = properties.getObjectArray(CoreProperties.MAPPING_LOADER_FACTORIES, getClass().getClassLoader()); for (Object mappingLoaderFactory : objects) { _mappingLoaderFactories.add((MappingLoaderFactory) mappingLoaderFactory); } }
/** * Load module properties from default locations. <br/> * First it loads default properties contained in Castor JAR. This gets overwritten by a * properties found on Java library directory. If no properties could be found until that point a * PropertiesException will be thrown. * * @param path Path to the default properties to load. * @param filename Name of the properties file. */ protected void loadDefaultProperties(final String path, final String filename) { Properties properties = new Properties(); // Get default properties from the Castor JAR. boolean inCastorJar = loadFromClassPath(properties, path + filename); // Get overriding properties from the Java library directory, ignore if not // found. If found merge existing properties. boolean inJavaLibDir = loadFromJavaHome(properties, filename); // Couldn't find properties in Castor jar nor Java library directory. if (!inCastorJar && !inJavaLibDir) { throw new PropertiesException("Failed to load properties: " + 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)); }
@Override public Object getProperty(final String propertyName) { return _properties.getObject(propertyName); }
/** * {@inheritDoc} */ public final void configure(final AbstractProperties properties) { _lobBufferSize = properties.getInteger( CPAProperties.LOB_BUFFER_SIZE, DEFAULT_LOB_BUFFER_SIZE); if (LOG.isDebugEnabled()) { LOG.debug("Using lobBufferSize: " + _lobBufferSize); } }
public static Parser getParser(final AbstractProperties properties, final String features) { Parser parser = null; Boolean validation = properties.getBoolean(XMLProperties.PARSER_VALIDATION); Boolean namespaces = properties.getBoolean(XMLProperties.NAMESPACES); String parserClassName = properties.getString(XMLProperties.PARSER); if ((parserClassName == null) || (parserClassName.length() == 0)) { SAXParser saxParser = XMLReader xmlReader = (XMLReader) parser; XMLParserUtils.setFeaturesOnXmlReader( properties.getString(XMLProperties.PARSER_FEATURES, features), properties.getString(XMLProperties.PARSER_FEATURES_DISABLED, ""), validation.booleanValue(), namespaces.booleanValue(), xmlReader);
/** * 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 properties. * @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; }
/** * 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; } }
/** * Create a new registry instance of key generator factories. The registry will be initialized * with all key generator factories specified through <b>KEYGENERATOR_FACTORIES</b> property * of given properties. * * @param properties The properties to use. */ public KeyGeneratorFactoryRegistry(final AbstractProperties properties) { Object[] objects = properties.getObjectArray( CPAProperties.KEYGENERATOR_FACTORIES, properties.getApplicationClassLoader()); for (int i = 0; i < objects.length; i++) { KeyGeneratorFactory factory = (KeyGeneratorFactory) objects[i]; _factories.put(factory.getKeyGeneratorName(), factory); } }
@Override public Boolean getLoadPackageMapping() { return _properties.getBoolean(XMLProperties.LOAD_PACKAGE_MAPPING); }
/** * @see org.castor.xml.InternalContext#getOutputFormat() */ public static OutputFormat getOutputFormat(final AbstractProperties properties) { boolean indent = properties.getBoolean(XMLProperties.USE_INDENTATION, false); String version = properties.getString(XMLProperties.XML_VERSION, "1.0"); OutputFormat format = getSerializerFactory(properties.getString(XMLProperties.SERIALIZER_FACTORY)) .getOutputFormat(); format.setMethod(OutputFormat.XML); format.setVersion(version); 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
@Override public NodeType getPrimitiveNodeType() { if (_primitiveNodeType != null) { return _primitiveNodeType; } String prop = _properties.getString(XMLProperties.PRIMITIVE_NODE_TYPE, null); if (prop == null) { return null; } _primitiveNodeType = NodeType.getNodeType(prop); return _primitiveNodeType; }