openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r406215 [1/10] - in /incubator/openjpa/trunk/openjpa-lib: ./ java/ java/org/ java/org/apache/ java/org/apache/openjpa/ java/org/apache/openjpa/lib/ java/org/apache/openjpa/lib/conf/ java/org/apache/openjpa/lib/jdbc/ java/org/apache/openjpa/...
Date Sun, 14 May 2006 03:26:02 GMT
Author: pcl
Date: Sat May 13 20:25:56 2006
New Revision: 406215

URL: http://svn.apache.org/viewcvs?rev=406215&view=rev
Log:
Some core utility classes. These are all JDK1.3-safe. I have not committed required libraries; we'll need to set up our build + lib infrastructure. To compile this codebase, you'll need serp, commons collections, commons lang, log4j, commons logging, jdbc3 stubs, and the xml apis to be available.

Added:
    incubator/openjpa/trunk/openjpa-lib/
    incubator/openjpa/trunk/openjpa-lib/java/
    incubator/openjpa/trunk/openjpa-lib/java/org/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/BooleanValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurable.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configuration.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurations.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/DoubleValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/FileValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/GenericConfigurable.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/IntValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/NoneConfigurationProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ObjectValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/PluginListValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/PluginValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/StringListValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/StringValue.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Value.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ValueListener.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/package.html   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/AbstractJDBCListener.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ConfiguringConnectionDecorator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ConnectionDecorator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ConnectionRequestInfo.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DataSourceLogs.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DecoratingDataSource.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DelegatingCallableStatement.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DelegatingConnection.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DelegatingDataSource.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DelegatingDatabaseMetaData.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DelegatingPreparedStatement.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DelegatingResultSet.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/DelegatingStatement.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEvent.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/JDBCListener.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/ReportingSQLException.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/SQLFormatter.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/jdbc/package.html   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/AbstractLog.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/CommonsLogFactory.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/Log4JLogFactory.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/LogFactory.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/LogFactoryImpl.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/LogOutputStream.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/MultiLogFactory.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/NoneLogFactory.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/log/package.html   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/CFMetaDataSerializer.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/ClassAnnotationMetaDataFilter.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/ClassArgParser.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/ClassMetaDataIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/ClasspathMetaDataIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/MetaDataFilter.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/MetaDataIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/MetaDataIteratorChain.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/MetaDataParser.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/MetaDataSerializer.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/ResourceMetaDataIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/SourceTracker.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/SourceTrackers.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/SuffixMetaDataFilter.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/URLMetaDataIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/meta/package.html   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/AbstractListIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/AbstractResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/EagerResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/ListResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/RandomAccessResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/ResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/ResultListIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/ResultObjectProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/ResultObjectProviderIterator.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/SimpleResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/SoftRandomAccessResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/WindowResultList.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/rop/package.html   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/AbstractEventManager.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/Base16Encoder.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/BytecodeWriter.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/Closeable.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/CodeFormat.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/ConcurrentHashMap.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/EfficientEmptyReferenceMap.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/ExpirationNotifyingReferenceMap.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/Files.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/FormatPreservingProperties.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/JavaVersions.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/Localizer.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/MultiClassLoader.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/Options.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/ParameterTemplate.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/ParseException.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/ReferenceSet.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/ResourceBundleProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/Services.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/SimpleRegex.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/SimpleResourceBundleProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/StreamResourceBundleProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/StringDistance.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/ThreadLock.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/TypedProperties.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/ZipResourceBundleProvider.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/util/package.html   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/xml/
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/xml/Commentable.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/xml/DocTypeReader.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/xml/Location.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/xml/ValidatingErrorHandler.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/xml/XMLFactory.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/xml/XMLWriter.java   (with props)
    incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/xml/package.html   (with props)
    incubator/openjpa/trunk/openjpa-lib/resources/
    incubator/openjpa/trunk/openjpa-lib/resources/org/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/conf/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/conf/localizer.properties   (with props)
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/jdbc/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/jdbc/localizer.properties   (with props)
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/log/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/log/localizer.properties   (with props)
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/meta/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/meta/localizer.properties   (with props)
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/rop/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/rop/localizer.properties   (with props)
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/util/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/util/localizer.properties   (with props)
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/xml/
    incubator/openjpa/trunk/openjpa-lib/resources/org/apache/openjpa/lib/xml/localizer.properties   (with props)

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/BooleanValue.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/BooleanValue.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/BooleanValue.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/BooleanValue.java Sat May 13 20:25:56 2006
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+/**
+ *	A boolean {@link Value}.
+ *
+ *	@author	Marc Prud'hommeaux
+ */
+public class BooleanValue
+	extends Value
+{
+ 	private boolean value;
+
+
+	public BooleanValue (String prop)
+	{
+		super (prop);
+		setAliasListComprehensive (true);
+	}
+
+
+	public Class getValueType ()
+	{
+		return boolean.class;
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public void set (boolean value)
+	{
+		boolean oldValue = this.value;
+		this.value = value;
+		if (oldValue != value)
+			valueChanged ();
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public boolean get ()
+	{
+		return value;
+	}
+
+
+	protected String getInternalString ()
+	{
+		return String.valueOf (value);
+	}
+
+
+	protected void setInternalString (String val)
+	{
+		set (Boolean.valueOf (val).booleanValue ());
+	}
+
+
+	protected void setInternalObject (Object obj)
+	{
+		if (obj == null)
+			set (false);
+		else
+			set (((Boolean) obj).booleanValue ());
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/BooleanValue.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurable.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurable.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurable.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurable.java Sat May 13 20:25:56 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+/**
+ *	<p>This interface provides a mechanism for notifying interested
+ *	objects when configuration events occur. It provides an object
+ *	with the opportunity to set itself up for configuration and to
+ *	perform any necessary post-configuration.</p>
+ *
+ *	@author	Patrick Linskey
+ */
+public interface Configurable
+{
+	/**
+	 *	Invoked prior to setting bean properties. 
+	 */
+	public void setConfiguration (Configuration conf);
+
+
+	/**
+	 *	Invoked before bean property configuration is begun on this object.
+	 */
+	public void startConfiguration ();
+
+
+	/**
+	 *	Invoked upon completion of bean property configuration for this object.
+	 */
+	public void endConfiguration ();
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurable.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configuration.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configuration.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configuration.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configuration.java Sat May 13 20:25:56 2006
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+import java.beans.*;
+import java.io.*;
+import java.util.*;
+
+import org.apache.openjpa.lib.log.*;
+import org.apache.openjpa.lib.util.Closeable; 
+
+
+/**
+ *	<p>Interface for generic configuration objects.  Includes the ability
+ *	to write configuration to and from {@link Properties} instances.</p>
+ *
+ *	@author Marc Prud'hommeaux
+ *	@author Abe White
+ */
+public interface Configuration
+	extends BeanInfo, Serializable, Closeable, Cloneable
+{
+	/**
+	 *	Attribute of returned {@link Value} property descriptors listing 
+	 *	recognized values for the property.
+	 */
+	public static final String ATTRIBUTE_ALLOWED_VALUES = "allowedValues";
+
+	/**
+	 *	Attribute of the returned {@link Value} property descriptors naming 
+	 *	the property's type or category.
+	 */	
+	public static final String ATTRIBUTE_TYPE = "propertyType";
+
+	/**
+	 *	Attribute of the returned {@link Value} property descriptors naming 
+	 *	the property' hierarchical category.
+	 */	
+	public static final String ATTRIBUTE_CATEGORY = "propertyCategory";
+
+	/**
+	 *	Attribute of the returned {@link Value} property descriptors naming 
+	 *	the property's ordering in its category.
+	 */	
+	public static final String ATTRIBUTE_ORDER = "propertyCategoryOrder";
+
+
+	/**
+	 *	Return the product name.  Defaults to <code>solarmetric</code>.
+	 */
+	public String getProductName ();
+
+
+	/**
+	 *	The log factory. If no log factory has been set explicitly,
+ 	 *	this method will create one.
+	 */
+	public LogFactory getLogFactory ();
+
+
+	/**
+	 * 	 The log factory.
+	 */
+	public void setLogFactory (LogFactory factory);
+
+
+	/**
+	 *	Log plugin setting.
+	 */
+	public String getLog ();
+
+
+	/**
+	 *	Log plugin setting.
+	 */
+	public void setLog (String log);
+
+
+	/**
+	 *	Return the log for the given category.
+	 *
+	 *	@see	#getLogFactory
+	 */
+	public Log getLog (String category);
+
+
+	/**
+	 *	Return the log to use for configuration messages.
+	 */
+	public Log getConfigurationLog ();
+
+
+	/**
+	 *	Return the log to use for management messages.
+	 */
+	public Log getManagementLog ();
+
+
+	/**
+	 *	Return the log to use for profiling messages.
+	 */
+	public Log getProfilingLog ();
+
+
+	/**
+	 *	Return the {@link Value} for the given property, or null if none.
+	 */
+	public Value getValue (String property);
+
+
+	/**
+	 *	Return the set of all {@link Value}s.
+	 */
+	public Value[] getValues ();
+
+
+	/**
+	 *	A properties representation of this Configuration.
+	 *	Note that changes made to this properties object will
+	 *	not be automatically reflected in this Configuration object.
+	 *
+	 *	@param storeDefaults if true, then properties will be written
+	 * 						out even if they match the default value
+	 * 						for a property
+	 */
+	public Properties toProperties (boolean storeDefaults);
+
+
+	/**
+	 *	Set this Configuration via the given map.  Any keys missing from
+	 *	the given map will not be set. Note that changes made to this map 
+	 *	will not be automatically reflected in this Configuration object.
+	 *
+	 *	IMPORTANT: If the map contains instantiated objects (rather than 
+	 *	string values), only the string representation of those objects
+	 *	are considered in this configuration's <code>equals</code> and 
+	 *	<code>hashCode</code> methods.   If the object's property has no
+	 *	string form (such as an {@link ObjectValue}), the object is not
+	 *	part of the equality and hashing calculations.
+	 */
+	public void fromProperties (Map map);
+
+
+	/** 
+	 *  Adds a listener for any property changes.  The property events fired
+	 * 	will <b>not</b> include the old value.
+	 *  
+	 *  @param  listener  	the listener to receive notification
+	 *  					of property changes
+	 */
+	public void addPropertyChangeListener (PropertyChangeListener listener);
+
+
+	/** 
+	 *  Removes a listener for any property changes.
+	 *  
+	 *  @param  listener  the listener to remove
+	 */
+	public void removePropertyChangeListener (PropertyChangeListener listener);
+
+
+	/**
+	 *	Lock down the configuration's state.  Attempting to set state on a
+	 *	read-only configuration results in an exception.
+	 */
+	public void setReadOnly (boolean readOnly);
+
+
+	/**
+	 *	Return true if this configuration is immutable.
+	 */
+	public boolean isReadOnly ();
+
+
+	/**
+	 *	Free the resources used by this object.
+	 */
+	public void close ();
+
+
+	/**
+	 *	Return a copy of this configuration.
+	 */
+	public Object clone ();
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configuration.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java Sat May 13 20:25:56 2006
@@ -0,0 +1,900 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+import java.awt.*;
+import java.beans.*;
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+import java.util.List;
+
+import org.apache.commons.lang.*;
+
+import org.apache.openjpa.lib.log.*;
+import org.apache.openjpa.lib.util.*;
+
+import serp.util.*;
+
+
+/**
+ *  <p>Default implementation of the {@link Configuration} interface.
+ *	Subclasses can choose to obtain configuration 
+ *	information from JNDI, Properties, a Bean-builder, etc.  This class
+ *	provides base configuration functionality, including serialization,
+ *	the <code>equals</code> and <code>hashCode</code> contracts, and default
+ *	property loading.</p>
+ *
+ *	<p>Subclasses should be sure to pass in <code>false</code> to the
+ *	constructor when they call it, then call {@link #loadDefaults} themselves 
+ *	if they want to load default properties.  Otherwise, their field 
+ *	initializations will overwrite the defaults that were loaded.</p>
+ *
+ *	<p>Property descriptors for {@link Value} instances are constructed from 
+ *	the {@link Localizer} for the package of the configuration class. The 
+ *	following localized strings will be used for describing a value, where
+ *	<em>name</em> is the last token of the value's property string:
+ *  <ul>
+ *  <li><em>name</em>-name: The name that will be displayed for the
+ * 		option in a user interface; required.</li>
+ *  <li><em>name</em>-desc: A brief description of the option; required.</li>
+ *  <li><em>name</em>-type: The type or category name for this option; 
+ *		required.</li>
+ *  <li><em>name</em>-expert: True if this is an expert option, false 
+ *		otherwise; defaults to false.</li>
+ *	<li><em>name</em>-values: Set of expected or common values, excluding 
+ *		alias keys; optional.</li>
+ *	<li><em>name</em>-interface: The class name of an interface whose 
+ *		discoverable implementations should be included in the set of expected 
+ *		or common values; optional.</li>	
+ *  <li><em>name</em>-cat: The hierarchical category for the property
+ *  	name, separated by ".".
+ *  <li><em>name</em>-displayorder: The order in which the property should
+ *  	be displayer.</li>
+ *  </ul></p>
+ *
+ *	@author	Abe White
+ */
+public class ConfigurationImpl
+	implements Configuration, Externalizable, ValueListener
+{
+	private static final Localizer _loc = Localizer.forPackage 
+		(ConfigurationImpl.class);
+
+	protected final PluginValue logFactoryPlugin;
+
+	private boolean 	_readOnly	= false;
+	private Properties	_props		= null;
+	private boolean		_defaults	= false;
+	private final List	_vals 		= new ArrayList ();
+
+	// property listener helper
+	private PropertyChangeSupport _changeSupport = null;
+
+	// cache descriptors
+	private PropertyDescriptor[] _pds = null;
+	private MethodDescriptor[] _mds = null;
+
+
+	/**
+	 *	Default constructor.  Attempts to load default properties through
+	 *	system's configured {@link ConfigurationProvider}s.
+	 */
+	public ConfigurationImpl ()
+	{
+		this (true);
+	}
+
+
+	/**
+	 *	Constructor.
+ 	 *
+	 *	@param	loadDefaults	whether to attempt to load the default
+	 *							properties
+	 */
+	public ConfigurationImpl (boolean loadDefaults)
+	{
+		logFactoryPlugin = addPlugin ("org.apache.openjpa.lib.Log", true);
+		String[] aliases = new String[] {
+			"true", "org.apache.openjpa.lib.log.LogFactoryImpl",
+			"commons", "org.apache.openjpa.lib.log.CommonsLogFactory",	
+			"log4j", "org.apache.openjpa.lib.log.Log4JLogFactory",	
+			"none", "org.apache.openjpa.lib.log.NoneLogFactory",
+			"false", "org.apache.openjpa.lib.log.NoneLogFactory",	
+		};
+		logFactoryPlugin.setAliases (aliases);
+		logFactoryPlugin.setDefault (aliases[0]);
+		logFactoryPlugin.setClassName (aliases[1]);
+
+		if (loadDefaults)
+			loadDefaults ();
+	}
+
+
+	/**
+	 *	Automatically load default values from the system's 
+	 *	{@link ConfigurationProvider}s, and from System properties.
+	 */
+	public synchronized boolean loadDefaults ()
+	{
+		ConfigurationProvider provider = Configurations.loadDefaults 
+			(getClass ().getClassLoader ());
+		if (provider != null)
+			provider.setInto (this);
+
+		// load system properties; let them override any others
+		try
+		{
+			fromProperties (new HashMap (System.getProperties ()));
+		}
+		catch (SecurityException se)
+		{
+			// security manager might disallow this
+		}
+
+		_defaults = true;
+		if (provider == null)
+		{
+			Log log = getConfigurationLog ();
+			if (log.isTraceEnabled ())
+				log.trace (_loc.get ("no-providers"));
+			return false;
+		}
+		return true;
+	}
+
+
+	public String getProductName ()
+	{
+		return "solarmetric";
+	}
+
+
+	public LogFactory getLogFactory ()
+	{
+		synchronized (logFactoryPlugin)
+		{
+			if (logFactoryPlugin.get () == null)
+				logFactoryPlugin.instantiate (LogFactory.class, this);
+		}
+		return (LogFactory) logFactoryPlugin.get ();
+	}
+
+
+	public void setLogFactory (LogFactory logFactory)
+	{
+		assertNotReadOnly ();
+		logFactoryPlugin.set (logFactory);	
+	}
+
+
+	public String getLog ()
+	{
+		return logFactoryPlugin.getString ();
+	}
+
+
+	public void setLog (String log)
+	{
+		assertNotReadOnly ();
+		logFactoryPlugin.setString (log);
+	}
+
+
+	public Log getLog (String category)
+	{
+		return getLogFactory ().getLog (category);
+	}
+
+
+	/**
+	 *	Returns the logging channel <code>org.apache.openjpa.lib.Runtime</code> by
+	 *	default.
+	 */
+	public Log getConfigurationLog ()
+	{
+		return getLog ("org.apache.openjpa.lib.Runtime");
+	}
+
+
+	/**
+	 *	Returns the logging channel <code>org.apache.openjpa.lib.Manage</code> by
+	 *	default.
+	 */
+	public Log getManagementLog ()
+	{
+		return getLog ("org.apache.openjpa.lib.Manage");
+	}
+
+
+	/**
+	 *	Returns the logging channel <code>org.apache.openjpa.lib.Profile</code> by
+	 *	default.
+	 */
+	public Log getProfilingLog ()
+	{
+		return getLog ("org.apache.openjpa.lib.Profile");
+	}
+
+
+	public Value[] getValues ()
+	{
+		return (Value[]) _vals.toArray (new Value[_vals.size ()]);
+	}
+
+
+	public Value getValue (String property)
+	{
+		if (property == null)
+			return null;
+
+		Value val;
+		for (int i = 0; i < _vals.size (); i++)
+		{
+			val = (Value) _vals.get (i);
+			if (val.getProperty ().equals (property))
+				return val;
+		}
+		return null;
+	}
+
+
+	public void setReadOnly (boolean readOnly)
+	{
+		_readOnly = readOnly;
+	}
+
+
+	public boolean isReadOnly ()
+	{
+		return _readOnly;
+	}
+
+
+	public synchronized void addPropertyChangeListener 
+		(PropertyChangeListener listener)
+	{
+		if (_changeSupport == null)
+			_changeSupport = new PropertyChangeSupport (this); 
+		_changeSupport.addPropertyChangeListener (listener);
+	}
+
+
+	public void removePropertyChangeListener (PropertyChangeListener listener)
+	{
+		if (_changeSupport != null)
+			_changeSupport.removePropertyChangeListener (listener);
+	}
+
+
+	public void valueChanged (Value val)
+	{
+		if (_changeSupport == null && _props == null)
+			return;
+
+		String newString = val.getString ();
+		if (_changeSupport != null)
+			_changeSupport.firePropertyChange (val.getProperty (), null, 
+				newString);
+
+		// keep cached props up to date
+		if (_props != null)
+		{
+			if (newString == null)
+				_props.remove (val.getProperty ());
+			else if (_props.containsKey (val.getProperty ())
+				|| val.getDefault () == null
+				|| !val.getDefault ().equals (newString))
+				_props.put (val.getProperty (), newString);
+		}
+	}
+
+
+	public void close ()
+	{
+	}
+
+
+	///////////////////////////
+	// BeanInfo implementation
+	///////////////////////////
+
+
+	public BeanInfo[] getAdditionalBeanInfo ()
+	{
+		return new BeanInfo[0];
+	}
+
+
+	public BeanDescriptor getBeanDescriptor ()
+	{
+		return new BeanDescriptor (getClass ());
+	}
+
+
+	public int getDefaultEventIndex ()
+	{
+		return 0;
+	}
+
+
+	public int getDefaultPropertyIndex ()
+	{
+		return 0;
+	}
+
+
+	public EventSetDescriptor[] getEventSetDescriptors ()
+	{
+		return new EventSetDescriptor[0];
+	}
+
+
+	public Image getIcon (int kind)
+	{
+		return null;
+	}
+
+
+	public synchronized MethodDescriptor[] getMethodDescriptors ()
+	{
+		if (_mds != null)
+			return _mds;
+		PropertyDescriptor[] pds = getPropertyDescriptors ();
+		_mds = new MethodDescriptor[pds.length * 2];
+		for (int i = 0; i < pds.length; i++)
+		{
+			_mds[i * 2] = new MethodDescriptor (pds[i].getWriteMethod ());
+			_mds[(i * 2) + 1] = new MethodDescriptor (pds[i].getReadMethod ());
+		}
+		return _mds;
+	}
+
+
+	public synchronized PropertyDescriptor[] getPropertyDescriptors ()
+	{
+		if (_pds != null)
+			return _pds;
+
+		_pds = new PropertyDescriptor[_vals.size ()];
+		List failures = null;
+		Value val;
+		for (int i = 0; i < _vals.size (); i++)
+		{
+			val = (Value) _vals.get (i);
+			try
+			{
+				_pds[i] = getPropertyDescriptor (val);
+			}
+			catch (MissingResourceException mre)
+			{
+				if (failures == null)
+					failures = new ArrayList ();
+
+				failures.add (val.getProperty ());
+			}
+			catch (IntrospectionException ie)
+			{
+				if (failures == null)
+					failures = new ArrayList ();
+
+				failures.add (val.getProperty ());
+			}
+		}
+		if (failures != null)
+			throw new ParseException (_loc.get ("invalid-property-descriptors",
+				failures));
+
+		return _pds;
+	}
+
+
+	/**
+	 *	Create a property descriptor for the given value.
+	 */
+	private PropertyDescriptor getPropertyDescriptor (Value val)
+		throws IntrospectionException
+	{
+		String prop = val.getProperty ();
+		prop = prop.substring (prop.lastIndexOf ('.') + 1);
+
+		// set up property descriptor
+		PropertyDescriptor pd = new PropertyDescriptor 
+			(Introspector.decapitalize (prop), getClass ());
+		pd.setDisplayName (findLocalized (prop + "-name", true));
+		pd.setShortDescription (findLocalized (prop + "-desc", true));
+		pd.setExpert ("true".equals (findLocalized (prop + "-expert", false)));
+
+		try
+		{
+			pd.setReadMethod (getClass ().getMethod ("get" 
+				+ StringUtils.capitalize (prop), (Class[]) null));
+			pd.setWriteMethod (getClass ().getMethod ("set" 
+				+ StringUtils.capitalize (prop), new Class[] 
+				{pd.getReadMethod ().getReturnType ()}));
+		}
+		catch (Throwable t) 
+		{
+			throw new IntrospectionException (t.toString ());
+		}
+
+	
+		String type = findLocalized (prop + "-type", true);
+		if (type != null)
+			pd.setValue (ATTRIBUTE_TYPE, type);
+
+		String cat = findLocalized (prop + "-cat", false);
+		if (cat != null)
+			pd.setValue (ATTRIBUTE_CATEGORY, cat);
+
+		String order = findLocalized (prop + "-displayorder", false);
+		if (order != null)
+			pd.setValue (ATTRIBUTE_ORDER, order);
+		
+		// collect allowed values from aliase keys, listed values, and
+		// interface implementors
+		Collection allowed = new TreeSet ();
+		List aliases = Collections.EMPTY_LIST;
+		if (val.getAliases () != null)
+		{
+			aliases = Arrays.asList (val.getAliases ());
+			for (int i = 0; i < aliases.size (); i += 2)
+				allowed.add (aliases.get (i));
+		}
+		String[] vals = Strings.split (findLocalized (prop 
+			+ "-values", false), ",", 0);
+		for (int i = 0; i < vals.length; i++)
+			if (!aliases.contains (vals[i]))
+				allowed.add (vals[i]);
+		try
+		{
+			Class intf = Class.forName (findLocalized (prop 
+				+ "-interface", true), false, getClass ().getClassLoader ());
+			String[] impls = Services.getImplementors (intf);
+			for (int i = 0; i < impls.length; i++)
+				if (!aliases.contains (impls[i]))
+					allowed.add (impls[i]);
+		}
+		catch (Exception e)
+		{
+		}
+		if (!allowed.isEmpty ())
+			pd.setValue (ATTRIBUTE_ALLOWED_VALUES, (String[]) allowed.toArray
+				(new String[allowed.size ()]));
+
+		return pd;
+	}
+
+
+	/**
+	 *	Find the given localized string, or return null if not found.
+	 */
+	private String findLocalized (String key, boolean fatal)
+	{
+		// find the localizer package that contains this key
+		Localizer loc = null;
+		for (Class cls = getClass (); cls != Object.class;
+			cls = cls.getSuperclass ())
+		{
+			loc = Localizer.forPackage (cls);
+			try
+			{
+				return loc.getFatal (key);
+			}
+			catch (MissingResourceException mse)
+			{
+			}
+		}
+
+		if (fatal)
+			throw new MissingResourceException (key,
+				getClass ().getName (), key);
+		return null;
+	}
+
+
+	////////////////
+	// To/from maps
+	////////////////
+
+
+	public synchronized Properties toProperties (boolean storeDefaults)
+	{
+		// clone properties before making any modifications; we need to keep
+		// the internal properties instance consistent to maintain equals and
+		// hashcode contracts
+		Properties clone;
+		if (_props == null)
+			clone = new Properties ();
+		else
+			clone = (Properties) _props.clone ();
+
+		// if no existing properties or the properties should contain entries
+		// with default values, add values to properties
+		if (_props == null || storeDefaults)
+		{
+			Value val;
+			String str;
+			for (int i = 0; i < _vals.size (); i++)
+			{
+				// if key in existing properties, we already know value is up 
+				// to date
+				val = (Value) _vals.get (i);
+				if (_props != null && _props.containsKey (val.getProperty ()))
+					continue;
+
+				str = val.getString ();
+				if (str != null && (storeDefaults 
+					|| !str.equals (val.getDefault ())))
+					clone.put (val.getProperty (), str);
+			}
+			if (_props == null)
+				_props = (Properties) clone.clone ();
+		}
+		return clone;
+	}
+
+
+	public synchronized void fromProperties (Map map)
+	{
+		if (map == null || map.isEmpty ())
+			return;
+		assertNotReadOnly ();
+
+		// if the only previous call was to load defaults, forget them.
+		// this way we preserve the original formatting of the user's props
+		// instead of the defaults.  this is important for caching on
+		// configuration objects
+		if (_defaults)
+		{
+			_props = null;
+			_defaults = false;
+		}
+		
+		Map remaining = new HashMap (map);
+		Value val;
+		Object set;
+		for (int i = 0; i < _vals.size (); i++)
+		{
+			val = (Value) _vals.get (i);
+			set = map.get (val.getProperty ());
+			if (set == null)
+				continue;
+
+			if (set instanceof String)
+			{
+				if (!StringUtils.equals ((String) set, val.getString ()))
+					val.setString ((String) set);
+			}
+			else
+				val.setObject (set);
+
+			remaining.remove (val.getProperty ());
+		}
+
+		// cache properties
+		if (_props == null && map instanceof Properties)
+			_props = (Properties) map;
+
+		// convention is to point product at a resource with the 
+		// <product>.properties System property; remove that property so we
+		// we don't warn about it
+		remaining.remove (getProductName () + ".properties");
+
+		// now warn if there are any remaining properties that there
+		// is an unhandled prop
+		Map.Entry entry;
+		for (Iterator itr = remaining.entrySet ().iterator (); itr.hasNext ();)
+		{
+			entry = (Map.Entry) itr.next ();
+			if (entry.getKey () != null)
+				warnInvalidProperty ((String) entry.getKey ());
+		}
+	}
+
+
+	/** 
+	 *  Issue a warning that the specified property is not valid.
+	 */
+	private void warnInvalidProperty (String propName)
+	{
+		if (!isInvalidProperty (propName))
+			return;
+		Log log = getConfigurationLog ();
+		if (log == null || !log.isWarnEnabled ())
+			return;
+
+		// try to find the closest string to the invalid property
+		// so that we can provide a hint in case of a misspelling
+		String closest = StringDistance.getClosestLevenshteinDistance
+			(propName, new PropertyList (), 15);
+
+		if (closest == null)
+			log.warn (_loc.get ("invalid-property", propName));
+		else
+			log.warn (_loc.get ("invalid-property-hint", propName, closest));
+	}
+
+
+	/** 
+	 *  Returns true if the specified property name should raise a warning
+	 *  if it is not found in the list of known properties.
+	 */
+	protected boolean isInvalidProperty (String propName)
+	{
+		// by default, we don't warn on any properties, since we don't
+		// know what property pattern will be used for the base config
+		return false;
+	}
+
+
+	/**
+	 *	This method loads the named resource as a properties file.  It is
+	 *	useful for auto-configuration tools so users can specify a
+	 *	<code>properties</code> value with the name of a resource.
+	 */
+	public void setProperties (String resourceName)
+		throws IOException
+	{
+		Configurations.load (resourceName, getClass ().getClassLoader ()).
+			setInto (this);
+	}
+
+
+	/**
+	 *	This method loads the named file as a properties file.  It is
+	 *	useful for auto-configuration tools so users can specify a
+	 *	<code>propertiesFile</code> value with the name of a file.
+	 */
+	public void setPropertiesFile (File file)
+		throws IOException
+	{
+		Configurations.load (file, getClass ().getClassLoader ()).
+			setInto (this);
+	}
+
+
+	/////////////
+	// Utilities
+	/////////////
+
+
+	/**
+	 *	Checks if the configuration is read only and if so throws an
+	 *	exception, otherwise returns silently.  
+	 *	Implementations	should call this method before setting any state.
+	 */
+	protected void assertNotReadOnly ()
+	{
+		if (isReadOnly ())
+			throw new IllegalStateException (_loc.get ("read-only"));
+	}
+
+
+	/**
+	 *	Performs an equality check based on the properties returned from
+	 *	{@link #toProperties}. 
+	 */
+	public boolean equals (Object other)
+	{
+		if (other == this)
+			return true;
+		if (other == null)
+			return false;
+		if (!getClass ().equals (other.getClass ()))
+			return false;
+		
+		// compare properties
+		ConfigurationImpl conf = (ConfigurationImpl) other;
+		Properties p1 = (_props == null) ? toProperties (false) : _props;
+		Properties p2 = (conf._props == null) ? conf.toProperties (false)
+			: conf._props;
+		return p1.equals (p2);
+	}
+
+
+	/**
+	 *	Computes hash code based on the properties returned from
+	 *	{@link #toProperties}.
+	 */
+	public int hashCode ()
+	{
+		if (_props != null)
+			return _props.hashCode ();
+		return toProperties (false).hashCode ();
+	}
+
+
+	/**
+	 *	Implementation of the {@link Externalizable} interface to read from
+	 *	the properties written by {@link #writeExternal}.
+	 */
+	public void readExternal (ObjectInput in)
+		throws IOException, ClassNotFoundException
+	{
+		fromProperties ((Map) in.readObject ());		
+	}
+
+
+	/**
+	 *	Implementation of the {@link Externalizable} interface to write
+	 *	the properties returned by {@link #toProperties}.
+	 */
+	public void writeExternal (ObjectOutput out)
+		throws IOException
+	{
+		if (_props != null)
+			out.writeObject (_props);
+		else
+			out.writeObject (toProperties (false));
+	}
+
+
+	/**
+	 *	Uses {@link #toProperties} and {@link #fromProperties} to clone
+	 *	configuration.
+	 */
+	public Object clone ()
+	{
+		try
+		{
+			Constructor cons = getClass ().getConstructor 
+				(new Class[] { boolean.class });
+			Configuration clone = (Configuration) cons.newInstance
+				(new Object[] { Boolean.FALSE });
+			clone.fromProperties (toProperties (true));
+			return clone;
+		}
+		catch (RuntimeException re)
+		{
+			throw re;
+		}
+		catch (Exception e)
+		{
+			throw new ParseException (e);
+		}
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected Value addValue (Value val)
+	{
+		_vals.add (val);
+		val.setListener (this);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected StringValue addString (String property)
+	{
+		StringValue val = new StringValue (property);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected FileValue addFile (String property)
+	{
+		FileValue val = new FileValue (property);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected IntValue addInt (String property)
+	{
+		IntValue val = new IntValue (property);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected DoubleValue addDouble (String property)
+	{
+		DoubleValue val = new DoubleValue (property);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected BooleanValue addBoolean (String property)
+	{
+		BooleanValue val = new BooleanValue (property);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected StringListValue addStringList (String property)
+	{
+		StringListValue val = new StringListValue (property);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected ObjectValue addObject (String property)
+	{
+		ObjectValue val = new ObjectValue (property);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected PluginValue addPlugin (String property, boolean singleton)
+	{
+		PluginValue val = new PluginValue (property, singleton);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Add the given value to the set of configuration properties.
+	 */
+	protected PluginListValue addPluginList (String property)
+	{
+		PluginListValue val = new PluginListValue (property);
+		addValue (val);
+		return val;
+	}
+
+
+	/**
+	 *	Exposes our values list as a list of property names.
+	 */ 
+	private class PropertyList
+		extends AbstractList
+	{
+		public Object get (int i)
+		{
+			return ((Value) _vals.get (i)).getProperty ();
+		}
+
+
+		public int size ()
+		{
+			return _vals.size ();
+		}
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java Sat May 13 20:25:56 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+import java.io.*;
+import java.util.*;
+
+
+/**
+ *	Implementations of this interface can populate {@link Configuration}s in
+ *	some environment-specific way.  Implementations must implement the 
+ *	<code>equals</code> and <code>hashCode</code> methods so that equivalent
+ *	configurations compare equal.
+ *
+ * 	@since 4.0.0
+ *	@nojavadoc
+ */
+public interface ConfigurationProvider
+{
+	/**
+	 *	Load defaults, or return false if no defaults for this provider found.
+	 */
+	public boolean loadDefaults (ClassLoader loader)
+		throws Exception;
+
+
+	/**
+	 *	Load the given given resource, or return false if it is not a resource 
+	 *	this provider understands.  The given class loader may be null.
+	 */
+	public boolean load (String resource, ClassLoader loader)
+		throws Exception;
+
+
+	/**
+	 *	Load given file, or return false if it is not a file this provider 
+	 *	understands.
+	 */
+	public boolean load (File file)
+		throws Exception;
+
+
+	/**
+	 *	Return properties loaded thus far, or empty map if none.
+	 */
+	public Map getProperties ();
+
+
+	/**
+	 *	Add the given properties to those in this provider, overwriting
+	 *	any exisitng properties under the same keys.
+	 */
+	public void addProperties (Map props);
+
+
+	/**
+	 *	Set loaded information into the given configuration.
+	 */
+	public void setInto (Configuration conf);
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurations.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurations.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurations.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurations.java Sat May 13 20:25:56 2006
@@ -0,0 +1,672 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+import java.io.*;
+import java.util.*;
+import javax.naming.*;
+
+import org.apache.commons.lang.exception.*;
+
+import org.apache.openjpa.lib.log.*;
+import org.apache.openjpa.lib.util.*;
+
+import serp.util.*;
+
+
+/**
+ *	<p>Utility methods dealing with configuration.</p>
+ *
+ *	@author	Abe White
+ *	@nojavadoc
+ */
+public class Configurations
+{
+	private static final Localizer _loc = Localizer.forPackage 
+		(Configurations.class);
+
+
+	/**
+	 *	Return the class name from the given plugin string, or null if none.
+ 	 */
+	public static String getClassName (String plugin)
+	{
+		return getPluginComponent (plugin, true);
+	}
+
+
+	/**
+	 *	Return the properties part of the given plugin string, or null if none.
+	 */
+	public static String getProperties (String plugin)
+	{
+		return getPluginComponent (plugin, false);
+	}
+
+
+	/**
+	 *	Return either the class name or properties string from a plugin string.
+	 */
+	private static String getPluginComponent (String plugin, boolean clsName)
+	{
+		if (plugin != null)
+			plugin = plugin.trim ();
+		if (plugin == null || plugin.length () == 0)
+			return null;
+
+		int openParen = -1;
+		if (plugin.charAt (plugin.length () - 1) == ')')
+			openParen = plugin.indexOf ('(');
+		if (openParen == -1)
+		{
+			int eq = plugin.indexOf ('=');
+			if (eq == -1)
+				return (clsName) ? plugin : null;	
+			return (clsName) ? null : plugin;
+		}
+
+		// clsName(props) form
+		if (clsName)
+			return plugin.substring (0, openParen).trim ();
+		String prop = plugin.substring (openParen + 1, 
+			plugin.length () - 1).trim ();
+		return (prop.length () == 0) ? null : prop;
+	}
+
+
+	/**
+	 *	Combine the given class name and properties into a plugin string.
+	 */
+	public static String getPlugin (String clsName, String props)
+	{
+		if (clsName == null || clsName.length () == 0)
+			return props;
+		if (props == null || props.length () == 0)
+			return clsName;
+		return clsName + "(" + props + ")";
+	}
+
+
+	/**
+	 *	Create the instance with the given class name, using the given
+	 *	class loader.  No configuration of the instance is performed by 
+	 *	this method.
+	 */
+	public static Object newInstance (String clsName, ClassLoader loader)
+	{	
+		return newInstance (clsName, null, null, loader, true);
+	}
+
+
+	/**
+	 *	Create and configure an instance with the given class name and
+	 *	properties.
+	 */
+	public static Object newInstance (String clsName, Configuration conf,
+		String props, ClassLoader loader)
+	{
+		Object obj = newInstance (clsName, null, conf, loader, true);
+		configureInstance (obj, conf, props);
+		return obj;
+	}
+
+
+	/**
+	 *	Helper method used by members of this package to instantiate plugin
+	 *	values.
+	 */
+	static Object newInstance (String clsName, Value val, Configuration conf,
+		ClassLoader loader, boolean fatal)
+	{
+		if (clsName == null || clsName.length () == 0)
+			return null;
+		if (loader == null && conf != null)
+			loader = conf.getClass ().getClassLoader ();
+
+		Class cls = null;
+		try
+		{
+			cls = Strings.toClass (clsName, loader);
+		}
+		catch (RuntimeException re)
+		{
+			if (val != null)
+				re = getCreateException (clsName, val, re);
+			if (fatal)
+				throw re;
+			Log log = (conf == null) ? null : conf.getConfigurationLog ();
+			if (log != null && log.isErrorEnabled ())
+				log.error (re);
+			return null;
+		}
+
+		try
+		{
+			return cls.newInstance ();
+		}
+		catch (Exception e)
+		{
+			RuntimeException re = new NestableRuntimeException (_loc.get 
+				("obj-create", cls), e);
+			if (fatal)
+				throw re;
+			Log log = (conf == null) ? null : conf.getConfigurationLog ();
+			if (log != null && log.isErrorEnabled ())
+				log.error (re);
+			return null;
+		}
+	}
+
+
+	/**
+	 *	Helper method to throw an informative description on instantiation 
+	 *	error.
+	 */
+	private static RuntimeException getCreateException (String clsName, 
+		Value val, Exception e)
+	{
+		// re-throw the exception with some better information
+		final String msg;
+		final Object[] params;
+
+		String alias = val.alias (clsName);
+		String[] aliases = val.getAliases ();
+		String[] keys;
+		if (aliases.length == 0)
+			keys = aliases;
+		else
+		{
+			keys = new String[aliases.length / 2];
+			for (int i = 0; i < aliases.length; i += 2)
+				keys[i / 2] = aliases[i];
+		}
+
+		String closest;
+		if (keys.length == 0)
+		{
+			msg = "invalid-plugin";
+			params = new Object[] { val.getProperty (), alias, e.toString (), };
+		}
+		else if ((closest = StringDistance.getClosestLevenshteinDistance
+			(alias, keys, 0.5f)) == null)
+		{
+			msg = "invalid-plugin-aliases";
+			params = new Object[] { 
+				val.getProperty (), alias, e.toString (), 
+				new TreeSet (Arrays.asList (keys)),
+			};
+		}
+		else
+		{
+			msg = "invalid-plugin-aliases-hint";
+			params = new Object[] { 
+				val.getProperty (), alias, e.toString (), 
+				new TreeSet (Arrays.asList (keys)), closest,
+			};
+		}
+		return new ParseException (_loc.get (msg, params), e);
+	}
+
+
+	/**
+	 *	Configures the given object with the given properties by
+	 *	matching the properties string to the object's setter
+	 *	methods. The properties string should be in the form
+	 *	"prop1=val1, prop2=val2 ...". Does not validate that setter
+	 *	methods exist for the properties.
+	 *
+	 *	@throws		RuntimeException on configuration error
+	 */
+	public static void configureInstance (Object obj, Configuration conf, 
+		String properties)
+	{
+		configureInstance (obj, conf, properties, null);
+	}
+
+
+	/**
+	 *	Configures the given object with the given properties by
+	 *	matching the properties string to the object's setter
+	 *	methods. The properties string should be in the form
+	 *	"prop1=val1, prop2=val2 ...". Validates that setter methods
+	 *	exist for the properties.
+	 *
+	 *	@throws		RuntimeException on configuration error
+	 */
+	public static void configureInstance (Object obj, Configuration conf, 
+		String properties, String configurationName)
+	{
+		if (obj == null)
+			return;
+
+		Properties props = null;
+		if (properties != null && properties.length () > 0)
+			props = parseProperties (properties);
+		configureInstance (obj, conf, props, configurationName);
+	}
+
+
+	/**
+	 *	Configures the given object with the given properties by
+	 *	matching the properties string to the object's setter
+	 *	methods. Does not validate that setter methods exist for the
+	 *	properties.
+	 *
+	 *	@throws		RuntimeException on configuration error
+	 */
+	public static void configureInstance (Object obj, Configuration conf, 
+		Properties properties)
+	{
+		configureInstance (obj, conf, properties, null);
+	}
+
+
+	/**
+	 *	Configures the given object with the given properties by
+	 *	matching the properties string to the object's setter
+	 *	methods. If <code>configurationName</code> is
+	 *	non-<code>null</code>, validates that setter methods exist for
+	 *	the properties.
+	 *
+	 *	@throws		RuntimeException on configuration error
+	 */
+	public static void configureInstance (Object obj, Configuration conf, 
+		Properties properties, String configurationName)
+	{
+		if (obj == null)
+			return;
+
+		Options opts = null;
+		if (properties instanceof Options)
+			opts = (Options) properties;
+		else if (properties != null)
+		{
+			opts = new Options ();
+			opts.putAll (properties);	
+		}
+
+		Configurable configurable = null;
+		if (conf != null && obj instanceof Configurable)
+			configurable = (Configurable) obj;
+
+		if (configurable != null)
+		{
+			configurable.setConfiguration (conf);	
+			configurable.startConfiguration ();
+		}
+		if (opts != null)
+		{
+			Map invalidEntries = opts.setInto (obj);
+			if (obj instanceof GenericConfigurable)
+				((GenericConfigurable) obj).setInto (invalidEntries);
+
+			if (!invalidEntries.isEmpty () && configurationName != null)
+			{
+				String msg = null;
+				String first = (String) invalidEntries.keySet ().iterator ()
+					.next ();
+				if (invalidEntries.keySet ().size () == 1 &&
+					first.indexOf ('.') == -1)
+				{
+					// if there's just one misspelling and this is not a
+					// path traversal, check for near misses.
+					Collection options =
+						Options.findOptionsFor (obj.getClass ());
+					String close = StringDistance.getClosestLevenshteinDistance
+						(first, options, 0.75f);
+					if (close != null)
+						msg = _loc.get ("invalid-config-param-hint",
+							new Object[] {
+								configurationName,
+								obj.getClass (),
+								first,
+								close,
+								options,
+							});
+				}
+
+				if (msg == null)
+				{
+					msg = _loc.get ("invalid-config-params", new String[] {
+						configurationName,
+						obj.getClass ().getName (),
+						invalidEntries.keySet ().toString (),
+						Options.findOptionsFor (obj.getClass ()).toString (),
+					});
+				}
+				throw new ParseException (msg);
+			}
+		}
+		if (configurable != null)
+			configurable.endConfiguration ();
+	}
+
+
+	/**
+	 *	Turn a set of properties into a comma-separated string.
+	 */
+	public static String serializeProperties (Map map)
+	{
+		if (map == null || map.isEmpty ())
+			return null;
+	
+		StringBuffer buf = new StringBuffer ();
+		Map.Entry entry;
+		String val;
+		for (Iterator itr = map.entrySet ().iterator (); itr.hasNext ();)
+		{
+			entry = (Map.Entry) itr.next ();
+			if (buf.length () > 0)
+				buf.append (", ");
+			buf.append (entry.getKey ()).append ('=');
+			val = String.valueOf (entry.getValue ());
+			if (val.indexOf (',') != -1)
+				buf.append ('"').append (val).append ('"');
+			else
+				buf.append (val);
+		}
+		return buf.toString ();
+	}
+
+
+	/**
+	 *	Parse a set of properties from a comma-separated string.
+	 */
+	public static Options parseProperties (String properties)
+	{
+		Options opts = new Options ();
+		if (properties == null)
+			return opts;
+		properties = properties.trim ();
+		if (properties.length () == 0)
+			return opts;
+
+		try
+		{
+			String[] props = Strings.split (properties, ",", 0);
+			int idx;
+			char quote;
+			String prop;
+			String val;
+			for (int i = 0; i < props.length; i++)
+			{
+				idx = props[i].indexOf ('=');
+				if (idx == -1)
+				{
+					// if the key is not assigned to any value, set the
+					// value to the same thing as the key, and continue.
+					// This permits GenericConfigurable instances to
+					// behave meaningfully. We might consider setting the
+					// value to some well-known "value was not set, but
+					// key is present" string so that instances getting
+					// values injected can differentiate between a mentioned
+					// property and one set to a particular value.
+					prop = props[i];
+					val = prop;
+				}
+				else
+				{
+					prop = props[i].substring (0, idx).trim ();
+					val = props[i].substring (idx + 1).trim ();
+				}
+
+				// if the value is quoted, read until the end quote
+				if (((val.startsWith ("\"") && val.endsWith ("\""))
+					|| (val.startsWith ("'") && val.endsWith ("'")))
+					&& val.length () > 1)
+					val = val.substring (1, val.length () - 1);
+				else if (val.startsWith ("\"") || val.startsWith ("'"))
+				{
+					quote = val.charAt (0);
+					StringBuffer buf = new StringBuffer (val.substring (1));
+					int quotIdx;
+					while (++i < props.length)
+					{
+						buf.append (",");
+
+						quotIdx = props[i].indexOf (quote);
+						if (quotIdx != -1)
+						{
+							buf.append (props[i].substring (0, quotIdx));
+							if (quotIdx + 1 < props[i].length ())
+								buf.append (props[i].substring (quotIdx + 1));
+							break;
+						}
+						else
+							buf.append (props[i]);
+					}
+		
+					val = buf.toString ();
+				}
+
+				opts.put (prop, val);
+			}
+			return opts;
+		}
+		catch (RuntimeException re)
+		{
+			throw new ParseException (_loc.get ("prop-parse", properties), re);
+		}
+	}
+
+
+	/**
+	 *	Set the given {@link Configuration} instance from the command line
+	 *	options provided.  All property names of the given configuration are
+	 *	recognized; additionally, if a <code>properties</code> or 
+	 *	<code>p</code> argument exists, the resource it
+	 *	points to will be loaded and set into the given configuration instance.
+	 *	It can point to either a file or a resource name. 
+	 */
+	public static void populateConfiguration (Configuration conf, Options opts)
+	{
+		String props = opts.removeProperty ("properties", "p", null);
+		if (props != null && props.length () > 0)
+		{
+			File file = new File (props);
+			ConfigurationProvider provider;
+			if (file.isFile ())
+				provider = load (file, null);	
+			else
+			{
+				file = new File ("META-INF" + File.separatorChar + props);
+				if (file.isFile ())
+					provider = load (file, null);
+				else
+					provider = load (props, null);
+			}
+			provider.setInto (conf);
+		}
+		opts.setInto (conf);
+	}
+
+
+	/**
+	 *	Return a {@link ConfigurationProvider} that has parsed system defaults,
+	 *	or null if no provider or defaults found.
+	 */
+	public static ConfigurationProvider loadDefaults (ClassLoader loader)
+	{
+		if (loader == null)
+			loader = Thread.currentThread ().getContextClassLoader ();
+		Class[] impls = Services.getImplementorClasses
+			(ConfigurationProvider.class, loader);
+		ConfigurationProvider provider = null;
+		StringBuffer errs = null;
+		for (int i = 0; i < impls.length; i++)
+		{
+			provider = newProvider (impls[i]);
+			try
+			{
+				if (provider != null && provider.loadDefaults (loader))
+					return provider;
+			}
+			catch (MissingResourceException mre)
+			{
+				throw mre;
+			}
+			catch (Exception e)
+			{
+				if (errs == null)
+					errs = new StringBuffer ();
+				else
+					errs.append (", ");
+				errs.append (e.toString ());
+			}
+		}
+		if (errs != null)
+			throw new MissingResourceException (errs.toString (),
+				Configurations.class.getName (), "defaults");
+		return null;
+	}
+
+
+	/**
+	 *	Return a new new configuration provider instance of the given class,
+	 *	or null if the class cannot be instantiated.
+	 */
+	private static ConfigurationProvider newProvider (Class cls)
+	{
+		try
+		{
+			return (ConfigurationProvider) cls.newInstance ();
+		}
+		catch (InstantiationException e)
+		{
+			return null;
+		}
+		catch (IllegalAccessException e)
+		{
+			return null;
+		}
+	}
+
+
+	/**
+	 *	Return a {@link ConfigurationProvider} that has parsed the given 
+	 *	resource.  Throws {@link MissingResourceException} if resource does
+	 *	not exist.
+	 */
+	public static ConfigurationProvider load (String resource, 
+		ClassLoader loader)
+	{
+		if (resource == null || resource.length () == 0)
+			return null;
+
+		if (loader == null)
+			loader = Thread.currentThread ().getContextClassLoader ();
+		Class[] impls = Services.getImplementorClasses
+			(ConfigurationProvider.class, loader);
+		ConfigurationProvider provider = null;
+		StringBuffer errs = null;
+		for (int i = 0; i < impls.length; i++)
+		{
+			provider = newProvider (impls[i]);
+			try
+			{
+				if (provider != null && provider.load (resource, loader))
+					return provider;
+			}
+			catch (MissingResourceException mre)
+			{
+				throw mre;
+			}
+			catch (Exception e)
+			{
+				if (errs == null)
+					errs = new StringBuffer ();
+				else
+					errs.append (", ");
+				errs.append (e.toString ());
+			}
+		}
+		String msg = (errs == null) ? resource : errs.toString ();
+		throw new MissingResourceException (msg,
+			Configurations.class.getName (), resource);
+	}
+
+
+	/**
+	 *	Return a {@link ConfigurationProvider} that has parsed the given 
+	 *	file.  Throws {@link MissingResourceException} if file does
+	 *	not exist.
+	 */
+	public static ConfigurationProvider load (File file, ClassLoader loader)
+	{
+		if (file == null)
+			return null;
+
+		if (loader == null)
+			loader = Thread.currentThread ().getContextClassLoader ();
+		Class[] impls = Services.getImplementorClasses
+			(ConfigurationProvider.class, loader);
+		ConfigurationProvider provider = null;
+		StringBuffer errs = null;
+		for (int i = 0; i < impls.length; i++)
+		{
+			provider = newProvider (impls[i]);
+			try
+			{
+				if (provider != null && provider.load (file))
+					return provider;
+			}
+			catch (MissingResourceException mre)
+			{
+				throw mre;
+			}
+			catch (Exception e)
+			{
+				if (errs == null)
+					errs = new StringBuffer ();
+				else
+					errs.append (", ");
+				errs.append (e.toString ());
+			}
+		}
+		String msg = (errs == null) ? file.toString () : errs.toString ();
+		throw new MissingResourceException (msg,
+			Configurations.class.getName (), file.toString ());
+	}
+
+
+	/**
+	 *	Looks up the given name in JNDI.  If the name is null, null is 
+	 *	returned.
+	 */
+	public static Object lookup (String name)
+	{
+		if (name == null || name.length () == 0)
+			return null;
+
+		Context ctx = null;
+		try
+		{
+			ctx = new InitialContext ();
+			return ctx.lookup (name);	
+		}
+		catch (NamingException ne)
+		{
+			throw new NestableRuntimeException (_loc.get ("naming-err", name), 
+				ne);
+		}
+		finally
+		{
+			if (ctx != null)
+				try { ctx.close (); } catch (Exception e) {}
+		}
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/Configurations.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/DoubleValue.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/DoubleValue.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/DoubleValue.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/DoubleValue.java Sat May 13 20:25:56 2006
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+/**
+ *	A double {@link Value}.
+ *
+ *	@author	Marc Prud'hommeaux
+ */
+public class DoubleValue
+	extends Value
+{
+ 	private double value;
+
+
+	public DoubleValue (String prop)
+	{
+		super (prop);
+	}
+
+
+	public Class getValueType ()
+	{
+		return double.class;
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public void set (double value)
+	{
+		double oldValue = this.value;
+		this.value = value;
+		if (oldValue != value)
+			valueChanged ();
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public double get ()
+	{
+		return value;
+	}
+
+
+	protected String getInternalString ()
+	{
+		return String.valueOf (value);
+	}
+
+
+	protected void setInternalString (String val)
+	{
+		if (val == null || val.length () == 0)
+			set (0D);
+		else
+			set (Double.parseDouble (val));
+	}
+
+
+	protected void setInternalObject (Object obj)
+	{
+		if (obj == null)
+			set (0D);
+		else
+			set (((Number) obj).doubleValue ());
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/DoubleValue.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/FileValue.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/FileValue.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/FileValue.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/FileValue.java Sat May 13 20:25:56 2006
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+import java.io.*;
+
+import org.apache.commons.lang.*;
+
+
+/**
+ *	A {@link File} {@link Value}.
+ *
+ *	@author	Marc Prud'hommeaux
+ */
+public class FileValue
+	extends Value
+{
+ 	private File value;
+
+
+	public FileValue (String prop)
+	{
+		super (prop);
+	}
+
+
+	public Class getValueType ()
+	{
+		return File.class;
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public void set (File value)
+	{
+		File oldValue = this.value;
+		this.value = value;
+		if (!ObjectUtils.equals (oldValue, value))
+			valueChanged ();
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public File get ()
+	{
+		return value;
+	}
+
+
+	protected String getInternalString ()
+	{
+		return (value == null) ? null : value.getAbsolutePath ();
+	}
+
+
+	protected void setInternalString (String val)
+	{
+		set (new File (val));
+	}
+
+
+	protected void setInternalObject (Object obj)
+	{
+		set ((File) obj);
+	}
+}
+
+

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/FileValue.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/GenericConfigurable.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/GenericConfigurable.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/GenericConfigurable.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/GenericConfigurable.java Sat May 13 20:25:56 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+import java.util.*;
+
+
+/**
+ *	<p>Implementations of this interface may perform additional
+ *	generic configuration with any key-value pairs that cannot be set
+ *	into the object via the normal {@link org.apache.openjpa.lib.util.Options#setInto}
+ *	means.</p>
+ *
+ *	@author	Patrick Linskey
+ */
+public interface GenericConfigurable
+{
+	/**
+	 *	Perform any generic configuration based on the data in
+	 *	<code>m</code>. This method should remove any values in
+	 *	<code>m</code> that have been successfully processed; if any
+	 *	values remain in <code>m</code> after this method is executed,
+	 *	an exception will be thrown identifying those key-value pairs
+	 *	as invalid.
+	 */
+	public void setInto (Map m);
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/GenericConfigurable.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/IntValue.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/IntValue.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/IntValue.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/IntValue.java Sat May 13 20:25:56 2006
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+/**
+ *	An int {@link Value}.
+ *
+ *	@author	Marc Prud'hommeaux
+ */
+public class IntValue
+	extends Value
+{
+ 	private int value;
+
+
+	public IntValue (String prop)
+	{
+		super (prop);
+	}
+
+
+	public Class getValueType ()
+	{
+		return int.class;
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public void set (int value)
+	{
+		int oldValue = this.value;
+		this.value = value;
+		if (value != oldValue)
+			valueChanged ();
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public int get ()
+	{
+		return this.value;
+	}
+
+
+	protected String getInternalString ()
+	{
+		return String.valueOf (this.value);
+	}
+
+
+	protected void setInternalString (String val)
+	{
+		if (val == null || val.length () == 0)
+			set (0);
+		else
+			set (Integer.parseInt (val));
+	}
+
+
+	protected void setInternalObject (Object obj)
+	{
+		if (obj == null)
+			set (0);
+		else
+			set (((Number) obj).intValue ());
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/IntValue.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java Sat May 13 20:25:56 2006
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.openjpa.lib.log.*;
+import org.apache.openjpa.lib.util.*;
+
+
+/**
+ *	<p>Simple configuration provider that sets configuration based on a 
+ *	provided map.</p>
+ *
+ *	@author		Abe White 
+ *	@nojavadoc
+ */
+public class MapConfigurationProvider
+	implements ConfigurationProvider
+{
+	private static final Localizer _loc = Localizer.forPackage
+		(MapConfigurationProvider.class);
+
+	private Map _props = null;
+
+
+	/**
+	 *	Construct with null properties.
+	 */
+	public MapConfigurationProvider ()
+	{
+	}
+
+
+	/**
+	 *	Constructor; supply properties map.
+	 */
+	public MapConfigurationProvider (Map props)
+	{
+		addProperties (props);
+	}
+
+
+	public boolean loadDefaults (ClassLoader loader)
+		throws Exception
+	{
+		return false;
+	}
+
+
+	public boolean load (String resource, ClassLoader loader)
+		throws Exception
+	{
+		return false;
+	}
+
+
+	public boolean load (File file)
+		throws Exception
+	{
+		return false;
+	}
+
+
+	public Map getProperties ()
+	{
+		return _props;
+	}
+
+
+	public void addProperties (Map props)
+	{
+		if (props == null || props.isEmpty ())
+			return;
+		if (_props == null)
+			_props = props;
+		else
+			_props.putAll (props);
+	}
+
+
+	public void setInto (Configuration conf)
+	{
+		setInto (conf, conf.getConfigurationLog ());
+	}
+
+
+	/**
+	 *	Set properties into configuration.  If the log is non-null, will log
+	 *	a TRACE message about the set.
+	 */
+	protected void setInto (Configuration conf, Log log)
+	{
+		if (log != null && log.isTraceEnabled ())
+			log.trace (_loc.get ("conf-load", _props));
+		conf.fromProperties (_props);
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/NoneConfigurationProvider.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/NoneConfigurationProvider.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/NoneConfigurationProvider.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/NoneConfigurationProvider.java Sat May 13 20:25:56 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.commons.collections.*;
+
+
+/**
+ *	<p>No-op configuration provider.</p>
+ *
+ *	@author		Abe White 
+ *	@nojavadoc
+ */
+public class NoneConfigurationProvider
+	implements ConfigurationProvider
+{
+	private static final NoneConfigurationProvider _instance = 
+		new NoneConfigurationProvider ();
+
+
+	/**
+	 *	Singleton.
+	 */
+	public static NoneConfigurationProvider getInstance ()
+	{
+		return _instance;
+	}
+
+
+	public boolean loadDefaults (ClassLoader loader)
+	{
+		return false;
+	}
+
+
+	public boolean load (String resource, ClassLoader loader)
+	{
+		return false;
+	}
+
+
+	public boolean load (File file)
+	{
+		return false;
+	}
+
+
+	public Map getProperties ()
+	{
+		return MapUtils.EMPTY_MAP;
+	}
+
+
+	public void addProperties (Map props)
+	{
+		if (props != null && !props.isEmpty ())
+			throw new UnsupportedOperationException ();
+	}
+
+
+	public void setInto (Configuration conf)
+	{
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/NoneConfigurationProvider.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ObjectValue.java
URL: http://svn.apache.org/viewcvs/incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ObjectValue.java?rev=406215&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ObjectValue.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ObjectValue.java Sat May 13 20:25:56 2006
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+
+import org.apache.commons.lang.*;
+
+import org.apache.openjpa.lib.util.*;
+
+
+/**
+ *	<p>An object {@link Value}.</p>
+ *
+ *	@author		Abe White
+ */
+public class ObjectValue
+	extends Value
+{
+	private static final Localizer _loc = Localizer.forPackage 
+		(ObjectValue.class);
+
+	private Object _value = null;
+
+
+	public ObjectValue (String prop)
+	{
+		super (prop);
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public Object get ()
+	{
+		return _value;
+	}
+
+
+	/**
+	 *	The internal value.
+	 */
+	public void set (Object obj)
+	{
+		set (obj, false);
+	}
+
+
+	/**
+	 *	The internal value.
+	 *
+	 *	@param	derived	if true, this value was derived from other properties
+	 */
+	public void set (Object obj, boolean derived)
+	{
+		Object oldValue = _value;
+		_value = obj;
+		if (!derived && !ObjectUtils.equals (obj, oldValue))
+		{
+			objectChanged ();
+			valueChanged ();
+		}
+	}
+
+
+	public Class getValueType ()
+	{
+		return Object.class;
+	}
+
+
+	/**
+	 *	Implement this method to synchronize internal data with the new
+	 *	object value.
+	 */
+	protected void objectChanged ()
+	{
+	}
+
+
+	protected String getInternalString ()
+	{
+		return null;
+	}
+
+
+	protected void setInternalString (String str)
+	{
+		if (str == null)
+			set (null);
+		else
+			throw new IllegalArgumentException (_loc.get ("cant-set-string", 
+				getProperty ()));
+	}
+
+
+	protected void setInternalObject (Object obj)
+	{
+		set (obj);
+	}
+} 

Propchange: incubator/openjpa/trunk/openjpa-lib/java/org/apache/openjpa/lib/conf/ObjectValue.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message