openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r640685 [13/14] - in /openjpa/trunk: ./ openjpa-all/ openjpa-jdbc-5/ openjpa-jdbc/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/ope...
Date Tue, 25 Mar 2008 03:38:02 GMT
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java?rev=640685&r1=640684&r2=640685&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/JDBCEventConnectionDecorator.java Mon Mar 24 20:37:56 2008
@@ -1,295 +1,295 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.jdbc;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
-
-/**
- * Manages the firing of {@link JDBCEvent}s.
- *
- * @author Abe White
- * @nojavadoc
- */
-public class JDBCEventConnectionDecorator extends AbstractConcurrentEventManager
-    implements ConnectionDecorator {
-
-    public Connection decorate(Connection conn) {
-        if (!hasListeners())
-            return conn;
-        return new EventConnection(conn);
-    }
-
-    /**
-     * Fire the given event to all listeners. Prevents creation of an
-     * event object when there are no listeners.
-     */
-    private JDBCEvent fireEvent(Connection source, short type,
-        JDBCEvent associatedEvent, Statement stmnt, String sql) {
-        if (!hasListeners())
-            return null;
-
-        JDBCEvent event = new JDBCEvent(source, type, associatedEvent,
-            stmnt, sql);
-        fireEvent(event);
-        return event;
-    }
-
-    /**
-     * Fire the given event to all listeners.
-     */
-    protected void fireEvent(Object event, Object listener) {
-        JDBCListener listen = (JDBCListener) listener;
-        JDBCEvent ev = (JDBCEvent) event;
-        switch (ev.getType()) {
-            case JDBCEvent.BEFORE_PREPARE_STATEMENT:
-                listen.beforePrepareStatement(ev);
-                break;
-            case JDBCEvent.AFTER_PREPARE_STATEMENT:
-                listen.afterPrepareStatement(ev);
-                break;
-            case JDBCEvent.BEFORE_CREATE_STATEMENT:
-                listen.beforeCreateStatement(ev);
-                break;
-            case JDBCEvent.AFTER_CREATE_STATEMENT:
-                listen.afterCreateStatement(ev);
-                break;
-            case JDBCEvent.BEFORE_EXECUTE_STATEMENT:
-                listen.beforeExecuteStatement(ev);
-                break;
-            case JDBCEvent.AFTER_EXECUTE_STATEMENT:
-                listen.afterExecuteStatement(ev);
-                break;
-            case JDBCEvent.BEFORE_COMMIT:
-                listen.beforeCommit(ev);
-                break;
-            case JDBCEvent.AFTER_COMMIT:
-                listen.afterCommit(ev);
-                break;
-            case JDBCEvent.BEFORE_ROLLBACK:
-                listen.beforeRollback(ev);
-                break;
-            case JDBCEvent.AFTER_ROLLBACK:
-                listen.afterRollback(ev);
-                break;
-            case JDBCEvent.AFTER_CONNECT:
-                listen.afterConnect(ev);
-                break;
-            case JDBCEvent.BEFORE_CLOSE:
-                listen.beforeClose(ev);
-                break;
-        }
-    }
-
-    /**
-     * Fires events as appropriate.
-     */
-    private class EventConnection extends DelegatingConnection {
-
-        public EventConnection(Connection conn) {
-            super(conn);
-            fireEvent(getDelegate(), JDBCEvent.AFTER_CONNECT, null, null, null);
-        }
-
-        public void commit() throws SQLException {
-            JDBCEvent before = fireEvent(getDelegate(),
-                JDBCEvent.BEFORE_COMMIT, null, null, null);
-            try {
-                super.commit();
-            } finally {
-                fireEvent(getDelegate(), JDBCEvent.AFTER_COMMIT, before,
-                    null, null);
-            }
-        }
-
-        public void rollback() throws SQLException {
-            JDBCEvent before = fireEvent(getDelegate(),
-                JDBCEvent.BEFORE_ROLLBACK, null, null, null);
-            try {
-                super.rollback();
-            } finally {
-                fireEvent(getDelegate(), JDBCEvent.AFTER_ROLLBACK, before,
-                    null, null);
-            }
-        }
-
-        protected Statement createStatement(boolean wrap) throws SQLException {
-            JDBCEvent before = fireEvent(getDelegate(),
-                JDBCEvent.BEFORE_CREATE_STATEMENT, null, null, null);
-            Statement stmnt = null;
-            try {
-                stmnt = new EventStatement(super.createStatement(false),
-                    EventConnection.this);
-            } finally {
-                fireEvent(getDelegate(), JDBCEvent.AFTER_CREATE_STATEMENT,
-                    before, stmnt, null);
-            }
-            return stmnt;
-        }
-
-        protected Statement createStatement(int rsType, int rsConcur,
-            boolean wrap) throws SQLException {
-            JDBCEvent before = fireEvent(getDelegate(),
-                JDBCEvent.BEFORE_CREATE_STATEMENT, null, null, null);
-            Statement stmnt = null;
-            try {
-                stmnt = new EventStatement(super.createStatement
-                    (rsType, rsConcur, false), EventConnection.this);
-            } finally {
-                fireEvent(getDelegate(), JDBCEvent.AFTER_CREATE_STATEMENT,
-                    before, stmnt, null);
-            }
-            return stmnt;
-        }
-
-        protected PreparedStatement prepareStatement(String sql, boolean wrap)
-            throws SQLException {
-            JDBCEvent before = fireEvent(getDelegate(),
-                JDBCEvent.BEFORE_PREPARE_STATEMENT, null, null, sql);
-            PreparedStatement stmnt = null;
-            try {
-                stmnt = new EventPreparedStatement(super.prepareStatement
-                    (sql, false), EventConnection.this, sql);
-            } finally {
-                fireEvent(getDelegate(), JDBCEvent.AFTER_PREPARE_STATEMENT,
-                    before, stmnt, sql);
-            }
-            return stmnt;
-        }
-
-        protected PreparedStatement prepareStatement(String sql, int rsType,
-            int rsConcur, boolean wrap) throws SQLException {
-            JDBCEvent before = fireEvent(getDelegate(),
-                JDBCEvent.BEFORE_PREPARE_STATEMENT, null, null, sql);
-            PreparedStatement stmnt = null;
-            try {
-                stmnt = new EventPreparedStatement(super.prepareStatement
-                    (sql, rsType, rsConcur, false), EventConnection.this, sql);
-            } finally {
-                fireEvent(getDelegate(), JDBCEvent.AFTER_PREPARE_STATEMENT,
-                    before, stmnt, sql);
-            }
-            return stmnt;
-        }
-
-        public void close() throws SQLException {
-            try {
-                fireEvent(getDelegate(), JDBCEvent.BEFORE_CLOSE,
-                    null, null, null);
-            } finally {
-                super.close();
-            }
-        }
-    }
-
-    /**
-     * Fires events as appropriate.
-     */
-    private class EventPreparedStatement extends DelegatingPreparedStatement {
-
-        private final EventConnection _conn;
-        private final String _sql;
-
-        public EventPreparedStatement(PreparedStatement ps,
-            EventConnection conn, String sql) {
-            super(ps, conn);
-            _conn = conn;
-            _sql = sql;
-        }
-
-        public int executeUpdate() throws SQLException {
-            JDBCEvent before = fireEvent(_conn.getDelegate(),
-                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), _sql);
-            try {
-                return super.executeUpdate();
-            } finally {
-                fireEvent(_conn.getDelegate(),
-                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
-                    getDelegate(), _sql);
-            }
-        }
-
-        protected ResultSet executeQuery(boolean wrap) throws SQLException {
-            JDBCEvent before = fireEvent(_conn.getDelegate(),
-                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), _sql);
-            try {
-                return super.executeQuery(wrap);
-            } finally {
-                fireEvent(_conn.getDelegate(),
-                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
-                    getDelegate(), _sql);
-            }
-        }
-
-        public int[] executeBatch() throws SQLException {
-            JDBCEvent before = fireEvent(_conn.getDelegate(),
-                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), _sql);
-            try {
-                return super.executeBatch();
-            } finally {
-                fireEvent(_conn.getDelegate(),
-                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
-                    getDelegate(), _sql);
-            }
-        }
-    }
-
-    /**
-     * Fires events as appropriate.
-     */
-    private class EventStatement extends DelegatingStatement {
-
-        private final EventConnection _conn;
-
-        public EventStatement(Statement stmnt, EventConnection conn) {
-            super(stmnt, conn);
-            _conn = conn;
-        }
-
-        public int executeUpdate(String sql) throws SQLException {
-            JDBCEvent before = fireEvent(_conn.getDelegate(),
-                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), sql);
-            try {
-                return super.executeUpdate(sql);
-            } finally {
-                fireEvent(_conn.getDelegate(),
-                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
-                    getDelegate(), sql);
-            }
-        }
-
-        protected ResultSet executeQuery(String sql, boolean wrap)
-            throws SQLException {
-            JDBCEvent before = fireEvent(_conn.getDelegate(),
-                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), sql);
-            try {
-                return super.executeQuery(sql, wrap);
-            } finally {
-                fireEvent(_conn.getDelegate(),
-                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
-                    getDelegate(), sql);
-            }
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
+
+/**
+ * Manages the firing of {@link JDBCEvent}s.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
+public class JDBCEventConnectionDecorator extends AbstractConcurrentEventManager
+    implements ConnectionDecorator {
+
+    public Connection decorate(Connection conn) {
+        if (!hasListeners())
+            return conn;
+        return new EventConnection(conn);
+    }
+
+    /**
+     * Fire the given event to all listeners. Prevents creation of an
+     * event object when there are no listeners.
+     */
+    private JDBCEvent fireEvent(Connection source, short type,
+        JDBCEvent associatedEvent, Statement stmnt, String sql) {
+        if (!hasListeners())
+            return null;
+
+        JDBCEvent event = new JDBCEvent(source, type, associatedEvent,
+            stmnt, sql);
+        fireEvent(event);
+        return event;
+    }
+
+    /**
+     * Fire the given event to all listeners.
+     */
+    protected void fireEvent(Object event, Object listener) {
+        JDBCListener listen = (JDBCListener) listener;
+        JDBCEvent ev = (JDBCEvent) event;
+        switch (ev.getType()) {
+            case JDBCEvent.BEFORE_PREPARE_STATEMENT:
+                listen.beforePrepareStatement(ev);
+                break;
+            case JDBCEvent.AFTER_PREPARE_STATEMENT:
+                listen.afterPrepareStatement(ev);
+                break;
+            case JDBCEvent.BEFORE_CREATE_STATEMENT:
+                listen.beforeCreateStatement(ev);
+                break;
+            case JDBCEvent.AFTER_CREATE_STATEMENT:
+                listen.afterCreateStatement(ev);
+                break;
+            case JDBCEvent.BEFORE_EXECUTE_STATEMENT:
+                listen.beforeExecuteStatement(ev);
+                break;
+            case JDBCEvent.AFTER_EXECUTE_STATEMENT:
+                listen.afterExecuteStatement(ev);
+                break;
+            case JDBCEvent.BEFORE_COMMIT:
+                listen.beforeCommit(ev);
+                break;
+            case JDBCEvent.AFTER_COMMIT:
+                listen.afterCommit(ev);
+                break;
+            case JDBCEvent.BEFORE_ROLLBACK:
+                listen.beforeRollback(ev);
+                break;
+            case JDBCEvent.AFTER_ROLLBACK:
+                listen.afterRollback(ev);
+                break;
+            case JDBCEvent.AFTER_CONNECT:
+                listen.afterConnect(ev);
+                break;
+            case JDBCEvent.BEFORE_CLOSE:
+                listen.beforeClose(ev);
+                break;
+        }
+    }
+
+    /**
+     * Fires events as appropriate.
+     */
+    private class EventConnection extends DelegatingConnection {
+
+        public EventConnection(Connection conn) {
+            super(conn);
+            fireEvent(getDelegate(), JDBCEvent.AFTER_CONNECT, null, null, null);
+        }
+
+        public void commit() throws SQLException {
+            JDBCEvent before = fireEvent(getDelegate(),
+                JDBCEvent.BEFORE_COMMIT, null, null, null);
+            try {
+                super.commit();
+            } finally {
+                fireEvent(getDelegate(), JDBCEvent.AFTER_COMMIT, before,
+                    null, null);
+            }
+        }
+
+        public void rollback() throws SQLException {
+            JDBCEvent before = fireEvent(getDelegate(),
+                JDBCEvent.BEFORE_ROLLBACK, null, null, null);
+            try {
+                super.rollback();
+            } finally {
+                fireEvent(getDelegate(), JDBCEvent.AFTER_ROLLBACK, before,
+                    null, null);
+            }
+        }
+
+        protected Statement createStatement(boolean wrap) throws SQLException {
+            JDBCEvent before = fireEvent(getDelegate(),
+                JDBCEvent.BEFORE_CREATE_STATEMENT, null, null, null);
+            Statement stmnt = null;
+            try {
+                stmnt = new EventStatement(super.createStatement(false),
+                    EventConnection.this);
+            } finally {
+                fireEvent(getDelegate(), JDBCEvent.AFTER_CREATE_STATEMENT,
+                    before, stmnt, null);
+            }
+            return stmnt;
+        }
+
+        protected Statement createStatement(int rsType, int rsConcur,
+            boolean wrap) throws SQLException {
+            JDBCEvent before = fireEvent(getDelegate(),
+                JDBCEvent.BEFORE_CREATE_STATEMENT, null, null, null);
+            Statement stmnt = null;
+            try {
+                stmnt = new EventStatement(super.createStatement
+                    (rsType, rsConcur, false), EventConnection.this);
+            } finally {
+                fireEvent(getDelegate(), JDBCEvent.AFTER_CREATE_STATEMENT,
+                    before, stmnt, null);
+            }
+            return stmnt;
+        }
+
+        protected PreparedStatement prepareStatement(String sql, boolean wrap)
+            throws SQLException {
+            JDBCEvent before = fireEvent(getDelegate(),
+                JDBCEvent.BEFORE_PREPARE_STATEMENT, null, null, sql);
+            PreparedStatement stmnt = null;
+            try {
+                stmnt = new EventPreparedStatement(super.prepareStatement
+                    (sql, false), EventConnection.this, sql);
+            } finally {
+                fireEvent(getDelegate(), JDBCEvent.AFTER_PREPARE_STATEMENT,
+                    before, stmnt, sql);
+            }
+            return stmnt;
+        }
+
+        protected PreparedStatement prepareStatement(String sql, int rsType,
+            int rsConcur, boolean wrap) throws SQLException {
+            JDBCEvent before = fireEvent(getDelegate(),
+                JDBCEvent.BEFORE_PREPARE_STATEMENT, null, null, sql);
+            PreparedStatement stmnt = null;
+            try {
+                stmnt = new EventPreparedStatement(super.prepareStatement
+                    (sql, rsType, rsConcur, false), EventConnection.this, sql);
+            } finally {
+                fireEvent(getDelegate(), JDBCEvent.AFTER_PREPARE_STATEMENT,
+                    before, stmnt, sql);
+            }
+            return stmnt;
+        }
+
+        public void close() throws SQLException {
+            try {
+                fireEvent(getDelegate(), JDBCEvent.BEFORE_CLOSE,
+                    null, null, null);
+            } finally {
+                super.close();
+            }
+        }
+    }
+
+    /**
+     * Fires events as appropriate.
+     */
+    private class EventPreparedStatement extends DelegatingPreparedStatement {
+
+        private final EventConnection _conn;
+        private final String _sql;
+
+        public EventPreparedStatement(PreparedStatement ps,
+            EventConnection conn, String sql) {
+            super(ps, conn);
+            _conn = conn;
+            _sql = sql;
+        }
+
+        public int executeUpdate() throws SQLException {
+            JDBCEvent before = fireEvent(_conn.getDelegate(),
+                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), _sql);
+            try {
+                return super.executeUpdate();
+            } finally {
+                fireEvent(_conn.getDelegate(),
+                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
+                    getDelegate(), _sql);
+            }
+        }
+
+        protected ResultSet executeQuery(boolean wrap) throws SQLException {
+            JDBCEvent before = fireEvent(_conn.getDelegate(),
+                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), _sql);
+            try {
+                return super.executeQuery(wrap);
+            } finally {
+                fireEvent(_conn.getDelegate(),
+                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
+                    getDelegate(), _sql);
+            }
+        }
+
+        public int[] executeBatch() throws SQLException {
+            JDBCEvent before = fireEvent(_conn.getDelegate(),
+                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), _sql);
+            try {
+                return super.executeBatch();
+            } finally {
+                fireEvent(_conn.getDelegate(),
+                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
+                    getDelegate(), _sql);
+            }
+        }
+    }
+
+    /**
+     * Fires events as appropriate.
+     */
+    private class EventStatement extends DelegatingStatement {
+
+        private final EventConnection _conn;
+
+        public EventStatement(Statement stmnt, EventConnection conn) {
+            super(stmnt, conn);
+            _conn = conn;
+        }
+
+        public int executeUpdate(String sql) throws SQLException {
+            JDBCEvent before = fireEvent(_conn.getDelegate(),
+                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), sql);
+            try {
+                return super.executeUpdate(sql);
+            } finally {
+                fireEvent(_conn.getDelegate(),
+                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
+                    getDelegate(), sql);
+            }
+        }
+
+        protected ResultSet executeQuery(String sql, boolean wrap)
+            throws SQLException {
+            JDBCEvent before = fireEvent(_conn.getDelegate(),
+                JDBCEvent.BEFORE_EXECUTE_STATEMENT, null, getDelegate(), sql);
+            try {
+                return super.executeQuery(sql, wrap);
+            } finally {
+                fireEvent(_conn.getDelegate(),
+                    JDBCEvent.AFTER_EXECUTE_STATEMENT, before,
+                    getDelegate(), sql);
+            }
+        }
+    }
+}

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java?rev=640685&r1=640684&r2=640685&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryAdapter.java Mon Mar 24 20:37:56 2008
@@ -1,51 +1,51 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.log;
-
-import java.util.Map;
-
-import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
-
-/**
- * Base type that aids in adapting an external log framework to the
- * {@link LogFactory}.
- *
- * @author Abe White
- */
-public abstract class LogFactoryAdapter implements LogFactory {
-
-    // cache category to log adapters
-    private Map _logs = new ConcurrentHashMap();
-
-    public Log getLog(String channel) {
-        // no locking; OK if same adapter created multiple times
-        Log log = (Log) _logs.get(channel);
-        if (log == null) {
-            log = newLogAdapter(channel);
-            _logs.put(channel, log);
-        }
-        return log;
-    }
-
-    /**
-     * Return a log adapter for the given channel. This method may be called
-     * multiple times for the same channel in concurrent situations.
-     */
-    protected abstract Log newLogAdapter(String channel);
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.log;
+
+import java.util.Map;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Base type that aids in adapting an external log framework to the
+ * {@link LogFactory}.
+ *
+ * @author Abe White
+ */
+public abstract class LogFactoryAdapter implements LogFactory {
+
+    // cache category to log adapters
+    private Map _logs = new ConcurrentHashMap();
+
+    public Log getLog(String channel) {
+        // no locking; OK if same adapter created multiple times
+        Log log = (Log) _logs.get(channel);
+        if (log == null) {
+            log = newLogAdapter(channel);
+            _logs.put(channel, log);
+        }
+        return log;
+    }
+
+    /**
+     * Return a log adapter for the given channel. This method may be called
+     * multiple times for the same channel in concurrent situations.
+     */
+    protected abstract Log newLogAdapter(String channel);
+}

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java?rev=640685&r1=640684&r2=640685&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java Mon Mar 24 20:37:56 2008
@@ -1,365 +1,365 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.log;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.openjpa.lib.conf.Configurable;
-import org.apache.openjpa.lib.conf.Configuration;
-import org.apache.openjpa.lib.conf.GenericConfigurable;
-import org.apache.openjpa.lib.util.Files;
-import org.apache.openjpa.lib.util.J2DoPrivHelper;
-import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.lib.util.Options;
-import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
-
-/**
- * Default {@link LogFactory} implementation. For ease of automatic
- * configuration, this implementation keys on only the last dot-separated
- * token of the log channel name.
- *
- * @author Patrick Linskey
- */
-public class LogFactoryImpl 
-    implements LogFactory, GenericConfigurable, Configurable {
-
-    private static Localizer _loc = Localizer.forPackage(LogFactoryImpl.class);
-
-    public static final String TRACE_STR = _loc.get("log-trace").getMessage();
-    public static final String INFO_STR = _loc.get("log-info").getMessage();
-    public static final String WARN_STR = _loc.get("log-warn").getMessage();
-    public static final String ERROR_STR = _loc.get("log-error").getMessage();
-    public static final String FATAL_STR = _loc.get("log-fatal").getMessage();
-
-    public static final String STDOUT = "stdout";
-    public static final String STDERR = "stderr";
-
-    private static final String NEWLINE = J2DoPrivHelper.getLineSeparator();
-
-    /**
-     * The time at which this factory was initialized.
-     */
-    protected final long initializationMillis;
-
-    /**
-     * The {@link Log}s that this factory manages, keyed by log channel name.
-     */
-    private Map _logs = new ConcurrentHashMap(); // <String,Log>
-
-    /**
-     * The default logging level.
-     */
-    private short _defaultLogLevel = Log.INFO;
-
-    /**
-     * Storage for logging level configuration specified at configuration time.
-     */
-    private Map _configuredLevels = new HashMap(); // <String,Integer>
-
-    /**
-     * The stream to write to. Defaults to System.err.
-     */
-    private PrintStream _out = System.err;
-
-    /**
-     * A token to add to all log messages. If <code>null</code>, the 
-     * configuration's id will be used.
-     */
-    private String _diagContext = null;
-    private boolean _diagContextComputed = false;
-    
-    private Configuration _conf;
-
-
-    public LogFactoryImpl() {
-        initializationMillis = System.currentTimeMillis();
-    }
-
-    public Log getLog(String channel) {
-        // no locking; ok if same log created multiple times
-        LogImpl l = (LogImpl) _logs.get(channel);
-        if (l == null) {
-            l = newLogImpl();
-            l.setChannel(channel);
-            Short lvl = (Short) _configuredLevels.get(shorten(channel));
-            l.setLevel(lvl == null ? _defaultLogLevel : lvl.shortValue());
-            _logs.put(channel, l);
-        }
-        return l;
-    }
-
-    /**
-     * Create a new log. The log will be cached.
-     */
-    protected LogImpl newLogImpl() {
-        return new LogImpl();
-    }
-
-    /**
-     * The string name of the default level for unconfigured log channels;
-     * used for automatic configuration.
-     */
-    public void setDefaultLevel(String level) {
-        _defaultLogLevel = getLevel(level);
-    }
-
-    /**
-     * The default level for unconfigured log channels.
-     */
-    public short getDefaultLevel() {
-        return _defaultLogLevel;
-    }
-
-    /**
-     * The default level for unconfigured log channels.
-     */
-    public void setDefaultLevel(short level) {
-        _defaultLogLevel = level;
-    }
-
-    /**
-     * A string to prefix all log messages with. Set to
-     * <code>null</code> to use the configuration's Id property setting.
-     */
-    public void setDiagnosticContext(String val) {
-        _diagContext = val;
-    }
-
-    /**
-     * A string to prefix all log messages with. Set to
-     * <code>null</code> to use the configuration's Id property setting.
-     */
-    public String getDiagnosticContext() {
-        if (!_diagContextComputed) {
-            // this initialization has to happen lazily because there is no
-            // guarantee that conf.getId() will be populated by the time that
-            // endConfiguration() is called.
-            if (_diagContext == null && _conf != null) {
-                _diagContext = _conf.getId();
-            }
-            if ("".equals(_diagContext))
-                _diagContext = null;
-            _diagContextComputed = true;
-        }
-        return _diagContext;
-    }
-
-    /**
-     * The stream to write to. Recognized values are: <code>stdout</code>
-     * and <code>stderr</code>. Any other value will be considered a file name.
-     */
-    public void setFile(String file) {
-        if (STDOUT.equals(file))
-            _out = System.out;
-        else if (STDERR.equals(file))
-            _out = System.err;
-        else {
-            File f = Files.getFile(file, null);
-            try {
-                _out = new PrintStream((FileOutputStream)
-                    AccessController.doPrivileged(
-                        J2DoPrivHelper.newFileOutputStreamAction(
-                            (String) AccessController.doPrivileged(
-                                J2DoPrivHelper.getCanonicalPathAction(f)),
-                            true)));
-            } catch (PrivilegedActionException pae) {
-                throw new IllegalArgumentException(_loc.get("log-bad-file",
-                        file) + " " + pae.getException());
-            } catch (IOException ioe) {
-                throw new IllegalArgumentException(_loc.get("log-bad-file",
-                    file) + " " + ioe.toString());
-            }
-        }
-    }
-
-    /**
-     * The stream to write to.
-     */
-    public PrintStream getStream() {
-        return _out;
-    }
-
-    /**
-     * The stream to write to.
-     */
-    public void setStream(PrintStream stream) {
-        if (stream == null)
-            throw new NullPointerException("stream == null");
-        _out = stream;
-    }
-
-    /**
-     * Returns a string representation of the specified log level constant.
-     */
-    public static String getLevelName(short level) {
-        switch (level) {
-            case Log.TRACE:
-                return TRACE_STR;
-            case Log.INFO:
-                return INFO_STR;
-            case Log.WARN:
-                return WARN_STR;
-            case Log.ERROR:
-                return ERROR_STR;
-            case Log.FATAL:
-                return FATAL_STR;
-            default:
-                return _loc.get("log-unknown").getMessage();
-        }
-    }
-
-    /**
-     * Returns a symbolic constant for the specified string level.
-     */
-    public static short getLevel(String str) {
-        str = str.toUpperCase().trim();
-        short val = TRACE_STR.equals(str) ? Log.TRACE :
-            INFO_STR.equals(str) ? Log.INFO :
-                WARN_STR.equals(str) ? Log.WARN :
-                    ERROR_STR.equals(str) ? Log.ERROR :
-                        FATAL_STR.equals(str) ? Log.FATAL : -1;
-
-        if (val == -1)
-            throw new IllegalArgumentException
-                (_loc.get("log-bad-constant", str).getMessage());
-
-        return val;
-    }
-
-    // ---------- Configurable implementation ----------
-    
-    public void setConfiguration(Configuration conf) {
-        _conf = conf;
-    }
-    
-    public void startConfiguration() {
-    }
-
-    public void endConfiguration() {
-    }
-
-    // ---------- GenericConfigurable implementation ----------
-
-    public void setInto(Options opts) {
-        if (!opts.isEmpty()) {
-            Map.Entry e;
-            for (Iterator iter = opts.entrySet().iterator(); iter.hasNext();) {
-                e = (Map.Entry) iter.next();
-                _configuredLevels.put(shorten((String) e.getKey()),
-                    new Short(getLevel((String) e.getValue())));
-            }
-            opts.clear();
-        }
-    }
-
-    private static String shorten(String channel) {
-        return channel.substring(channel.lastIndexOf('.') + 1);
-    }
-
-    /**
-     * A simple implementation of the {@link Log} interface. Writes
-     * output to stderr.
-     */
-    public class LogImpl extends AbstractLog {
-
-        private short _level = INFO;
-        private String _channel;
-
-        protected boolean isEnabled(short level) {
-            return level >= _level;
-        }
-
-        protected void log(short level, String message, Throwable t) {
-            String msg = formatMessage(level, message, t);
-            synchronized (_out) {
-                _out.print(msg);
-            }
-        }
-
-        /**
-         * Convert <code>message</code> into a string ready to be written to
-         * the log. The string should include the terminating newline.
-         *
-         * @param t may be null
-         */
-        protected String formatMessage(short level, String message,
-            Throwable t) {
-            // we write to a StringBuffer and then flush it all at
-            // once as a single line, since some environments(e.g., JBoss)
-            // override the System output stream to flush any calls
-            // to write without regard to line breaks, making the
-            // output incomprehensibe.
-            StringBuffer buf = new StringBuffer();
-
-            buf.append(getOffset());
-            buf.append("  ");
-            if (getDiagnosticContext() != null)
-                buf.append(getDiagnosticContext()).append("  ");
-            buf.append(getLevelName(level));
-            if (level == INFO || level == WARN)
-                buf.append(" ");
-            buf.append("  [");
-            buf.append(Thread.currentThread().getName());
-            buf.append("] ");
-            buf.append(_channel);
-            buf.append(" - ");
-            buf.append(message);
-            buf.append(NEWLINE);
-
-            if (t != null) {
-                StringWriter swriter = new StringWriter();
-                PrintWriter pwriter = new PrintWriter(swriter);
-                t.printStackTrace(pwriter);
-                pwriter.flush();
-                buf.append(swriter.toString());
-            }
-            return buf.toString();
-        }
-
-        private long getOffset() {
-            return System.currentTimeMillis() - initializationMillis;
-        }
-
-        public void setChannel(String val) {
-            _channel = val;
-        }
-
-        public String getChannel() {
-            return _channel;
-        }
-
-        public void setLevel(short val) {
-            _level = val;
-        }
-
-        public short getLevel() {
-            return _level;
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.log;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.openjpa.lib.conf.Configurable;
+import org.apache.openjpa.lib.conf.Configuration;
+import org.apache.openjpa.lib.conf.GenericConfigurable;
+import org.apache.openjpa.lib.util.Files;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.Options;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Default {@link LogFactory} implementation. For ease of automatic
+ * configuration, this implementation keys on only the last dot-separated
+ * token of the log channel name.
+ *
+ * @author Patrick Linskey
+ */
+public class LogFactoryImpl 
+    implements LogFactory, GenericConfigurable, Configurable {
+
+    private static Localizer _loc = Localizer.forPackage(LogFactoryImpl.class);
+
+    public static final String TRACE_STR = _loc.get("log-trace").getMessage();
+    public static final String INFO_STR = _loc.get("log-info").getMessage();
+    public static final String WARN_STR = _loc.get("log-warn").getMessage();
+    public static final String ERROR_STR = _loc.get("log-error").getMessage();
+    public static final String FATAL_STR = _loc.get("log-fatal").getMessage();
+
+    public static final String STDOUT = "stdout";
+    public static final String STDERR = "stderr";
+
+    private static final String NEWLINE = J2DoPrivHelper.getLineSeparator();
+
+    /**
+     * The time at which this factory was initialized.
+     */
+    protected final long initializationMillis;
+
+    /**
+     * The {@link Log}s that this factory manages, keyed by log channel name.
+     */
+    private Map _logs = new ConcurrentHashMap(); // <String,Log>
+
+    /**
+     * The default logging level.
+     */
+    private short _defaultLogLevel = Log.INFO;
+
+    /**
+     * Storage for logging level configuration specified at configuration time.
+     */
+    private Map _configuredLevels = new HashMap(); // <String,Integer>
+
+    /**
+     * The stream to write to. Defaults to System.err.
+     */
+    private PrintStream _out = System.err;
+
+    /**
+     * A token to add to all log messages. If <code>null</code>, the 
+     * configuration's id will be used.
+     */
+    private String _diagContext = null;
+    private boolean _diagContextComputed = false;
+    
+    private Configuration _conf;
+
+
+    public LogFactoryImpl() {
+        initializationMillis = System.currentTimeMillis();
+    }
+
+    public Log getLog(String channel) {
+        // no locking; ok if same log created multiple times
+        LogImpl l = (LogImpl) _logs.get(channel);
+        if (l == null) {
+            l = newLogImpl();
+            l.setChannel(channel);
+            Short lvl = (Short) _configuredLevels.get(shorten(channel));
+            l.setLevel(lvl == null ? _defaultLogLevel : lvl.shortValue());
+            _logs.put(channel, l);
+        }
+        return l;
+    }
+
+    /**
+     * Create a new log. The log will be cached.
+     */
+    protected LogImpl newLogImpl() {
+        return new LogImpl();
+    }
+
+    /**
+     * The string name of the default level for unconfigured log channels;
+     * used for automatic configuration.
+     */
+    public void setDefaultLevel(String level) {
+        _defaultLogLevel = getLevel(level);
+    }
+
+    /**
+     * The default level for unconfigured log channels.
+     */
+    public short getDefaultLevel() {
+        return _defaultLogLevel;
+    }
+
+    /**
+     * The default level for unconfigured log channels.
+     */
+    public void setDefaultLevel(short level) {
+        _defaultLogLevel = level;
+    }
+
+    /**
+     * A string to prefix all log messages with. Set to
+     * <code>null</code> to use the configuration's Id property setting.
+     */
+    public void setDiagnosticContext(String val) {
+        _diagContext = val;
+    }
+
+    /**
+     * A string to prefix all log messages with. Set to
+     * <code>null</code> to use the configuration's Id property setting.
+     */
+    public String getDiagnosticContext() {
+        if (!_diagContextComputed) {
+            // this initialization has to happen lazily because there is no
+            // guarantee that conf.getId() will be populated by the time that
+            // endConfiguration() is called.
+            if (_diagContext == null && _conf != null) {
+                _diagContext = _conf.getId();
+            }
+            if ("".equals(_diagContext))
+                _diagContext = null;
+            _diagContextComputed = true;
+        }
+        return _diagContext;
+    }
+
+    /**
+     * The stream to write to. Recognized values are: <code>stdout</code>
+     * and <code>stderr</code>. Any other value will be considered a file name.
+     */
+    public void setFile(String file) {
+        if (STDOUT.equals(file))
+            _out = System.out;
+        else if (STDERR.equals(file))
+            _out = System.err;
+        else {
+            File f = Files.getFile(file, null);
+            try {
+                _out = new PrintStream((FileOutputStream)
+                    AccessController.doPrivileged(
+                        J2DoPrivHelper.newFileOutputStreamAction(
+                            (String) AccessController.doPrivileged(
+                                J2DoPrivHelper.getCanonicalPathAction(f)),
+                            true)));
+            } catch (PrivilegedActionException pae) {
+                throw new IllegalArgumentException(_loc.get("log-bad-file",
+                        file) + " " + pae.getException());
+            } catch (IOException ioe) {
+                throw new IllegalArgumentException(_loc.get("log-bad-file",
+                    file) + " " + ioe.toString());
+            }
+        }
+    }
+
+    /**
+     * The stream to write to.
+     */
+    public PrintStream getStream() {
+        return _out;
+    }
+
+    /**
+     * The stream to write to.
+     */
+    public void setStream(PrintStream stream) {
+        if (stream == null)
+            throw new NullPointerException("stream == null");
+        _out = stream;
+    }
+
+    /**
+     * Returns a string representation of the specified log level constant.
+     */
+    public static String getLevelName(short level) {
+        switch (level) {
+            case Log.TRACE:
+                return TRACE_STR;
+            case Log.INFO:
+                return INFO_STR;
+            case Log.WARN:
+                return WARN_STR;
+            case Log.ERROR:
+                return ERROR_STR;
+            case Log.FATAL:
+                return FATAL_STR;
+            default:
+                return _loc.get("log-unknown").getMessage();
+        }
+    }
+
+    /**
+     * Returns a symbolic constant for the specified string level.
+     */
+    public static short getLevel(String str) {
+        str = str.toUpperCase().trim();
+        short val = TRACE_STR.equals(str) ? Log.TRACE :
+            INFO_STR.equals(str) ? Log.INFO :
+                WARN_STR.equals(str) ? Log.WARN :
+                    ERROR_STR.equals(str) ? Log.ERROR :
+                        FATAL_STR.equals(str) ? Log.FATAL : -1;
+
+        if (val == -1)
+            throw new IllegalArgumentException
+                (_loc.get("log-bad-constant", str).getMessage());
+
+        return val;
+    }
+
+    // ---------- Configurable implementation ----------
+    
+    public void setConfiguration(Configuration conf) {
+        _conf = conf;
+    }
+    
+    public void startConfiguration() {
+    }
+
+    public void endConfiguration() {
+    }
+
+    // ---------- GenericConfigurable implementation ----------
+
+    public void setInto(Options opts) {
+        if (!opts.isEmpty()) {
+            Map.Entry e;
+            for (Iterator iter = opts.entrySet().iterator(); iter.hasNext();) {
+                e = (Map.Entry) iter.next();
+                _configuredLevels.put(shorten((String) e.getKey()),
+                    new Short(getLevel((String) e.getValue())));
+            }
+            opts.clear();
+        }
+    }
+
+    private static String shorten(String channel) {
+        return channel.substring(channel.lastIndexOf('.') + 1);
+    }
+
+    /**
+     * A simple implementation of the {@link Log} interface. Writes
+     * output to stderr.
+     */
+    public class LogImpl extends AbstractLog {
+
+        private short _level = INFO;
+        private String _channel;
+
+        protected boolean isEnabled(short level) {
+            return level >= _level;
+        }
+
+        protected void log(short level, String message, Throwable t) {
+            String msg = formatMessage(level, message, t);
+            synchronized (_out) {
+                _out.print(msg);
+            }
+        }
+
+        /**
+         * Convert <code>message</code> into a string ready to be written to
+         * the log. The string should include the terminating newline.
+         *
+         * @param t may be null
+         */
+        protected String formatMessage(short level, String message,
+            Throwable t) {
+            // we write to a StringBuffer and then flush it all at
+            // once as a single line, since some environments(e.g., JBoss)
+            // override the System output stream to flush any calls
+            // to write without regard to line breaks, making the
+            // output incomprehensibe.
+            StringBuffer buf = new StringBuffer();
+
+            buf.append(getOffset());
+            buf.append("  ");
+            if (getDiagnosticContext() != null)
+                buf.append(getDiagnosticContext()).append("  ");
+            buf.append(getLevelName(level));
+            if (level == INFO || level == WARN)
+                buf.append(" ");
+            buf.append("  [");
+            buf.append(Thread.currentThread().getName());
+            buf.append("] ");
+            buf.append(_channel);
+            buf.append(" - ");
+            buf.append(message);
+            buf.append(NEWLINE);
+
+            if (t != null) {
+                StringWriter swriter = new StringWriter();
+                PrintWriter pwriter = new PrintWriter(swriter);
+                t.printStackTrace(pwriter);
+                pwriter.flush();
+                buf.append(swriter.toString());
+            }
+            return buf.toString();
+        }
+
+        private long getOffset() {
+            return System.currentTimeMillis() - initializationMillis;
+        }
+
+        public void setChannel(String val) {
+            _channel = val;
+        }
+
+        public String getChannel() {
+            return _channel;
+        }
+
+        public void setLevel(short val) {
+            _level = val;
+        }
+
+        public short getLevel() {
+            return _level;
+        }
+    }
+}

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java?rev=640685&r1=640684&r2=640685&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java Mon Mar 24 20:37:56 2008
@@ -1,193 +1,193 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.log;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.openjpa.lib.util.concurrent.CopyOnWriteArrayList;
-
-/**
- * A LogFactory implementation to pass events through multiple
- * LogFactory implementations(such as log4j and LogPanelFactory).
- *
- * @author Steve Kim
- */
-public class MultiLogFactory implements LogFactory {
-
-    private List _delegates;
-
-    /**
-     * Create an instance with the given delegates.
-     */
-    public MultiLogFactory(LogFactory d1, LogFactory d2) {
-        this(new LogFactory[]{ d1, d2 });
-    }
-
-    /**
-     * Create an instance with the given delegates.
-     */
-    public MultiLogFactory(LogFactory d1, LogFactory d2, LogFactory d3) {
-        this(new LogFactory[]{ d1, d2, d3 });
-    }
-
-    /**
-     * Create an instance with the given delegates.
-     */
-    public MultiLogFactory(LogFactory[] delegates) {
-        _delegates = new CopyOnWriteArrayList(Arrays.asList(delegates));
-    }
-
-    public void addLogFactory(LogFactory factory) {
-        _delegates.add(factory);
-    }
-
-    public void removeLogFactory(LogFactory factory) {
-        _delegates.remove(factory);
-    }
-
-    /**
-     * Returns the delegates that this MultiLogFactory delegates messages to.
-     */
-    public LogFactory[] getDelegates() {
-        return (LogFactory[]) _delegates.toArray(new LogFactory[0]);
-    }
-
-    /**
-     * Returns a Log impl that combines all logs.
-     */
-    public synchronized Log getLog(String channel) {
-        List logs = new ArrayList(_delegates.size());
-        for (Iterator i = _delegates.iterator(); i.hasNext();) {
-            LogFactory f = (LogFactory) i.next();
-            if (f != null) {
-                Log l = f.getLog(channel);
-                if (l != null)
-                    logs.add(l);
-            }
-        }
-        return new MultiLog((Log[]) logs.toArray(new Log[logs.size()]));
-    }
-
-    /**
-     * Combinatory Log impl.
-     */
-    private static class MultiLog implements Log {
-
-        private Log[] _logs;
-
-        public MultiLog(Log[] logs) {
-            _logs = logs;
-        }
-
-        /**
-         * Return the logs that this log delegates to.
-         */
-        public Log[] getDelegates() {
-            return _logs;
-        }
-
-        public void trace(Object msg) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].trace(msg);
-        }
-
-        public void trace(Object msg, Throwable t) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].trace(msg, t);
-        }
-
-        public void info(Object msg) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].info(msg);
-        }
-
-        public void info(Object msg, Throwable t) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].info(msg, t);
-        }
-
-        public void warn(Object msg) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].warn(msg);
-        }
-
-        public void warn(Object msg, Throwable t) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].warn(msg, t);
-        }
-
-        public void error(Object msg) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].error(msg);
-        }
-
-        public void error(Object msg, Throwable t) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].error(msg, t);
-        }
-
-        public void fatal(Object msg) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].fatal(msg);
-        }
-
-        public void fatal(Object msg, Throwable t) {
-            for (int i = 0; i < _logs.length; i++)
-                _logs[i].fatal(msg, t);
-        }
-
-        public boolean isTraceEnabled() {
-            for (int i = 0; i < _logs.length; i++)
-                if (_logs[i].isTraceEnabled())
-                    return true;
-            return false;
-        }
-
-        public boolean isInfoEnabled() {
-            for (int i = 0; i < _logs.length; i++)
-                if (_logs[i].isInfoEnabled())
-                    return true;
-            return false;
-        }
-
-        public boolean isWarnEnabled() {
-            for (int i = 0; i < _logs.length; i++)
-                if (_logs[i].isWarnEnabled())
-                    return true;
-            return false;
-        }
-
-        public boolean isErrorEnabled() {
-            for (int i = 0; i < _logs.length; i++)
-                if (_logs[i].isErrorEnabled())
-                    return true;
-            return false;
-        }
-
-        public boolean isFatalEnabled() {
-            for (int i = 0; i < _logs.length; i++)
-                if (_logs[i].isFatalEnabled())
-                    return true;
-            return false;
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.log;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * A LogFactory implementation to pass events through multiple
+ * LogFactory implementations(such as log4j and LogPanelFactory).
+ *
+ * @author Steve Kim
+ */
+public class MultiLogFactory implements LogFactory {
+
+    private List _delegates;
+
+    /**
+     * Create an instance with the given delegates.
+     */
+    public MultiLogFactory(LogFactory d1, LogFactory d2) {
+        this(new LogFactory[]{ d1, d2 });
+    }
+
+    /**
+     * Create an instance with the given delegates.
+     */
+    public MultiLogFactory(LogFactory d1, LogFactory d2, LogFactory d3) {
+        this(new LogFactory[]{ d1, d2, d3 });
+    }
+
+    /**
+     * Create an instance with the given delegates.
+     */
+    public MultiLogFactory(LogFactory[] delegates) {
+        _delegates = new CopyOnWriteArrayList(Arrays.asList(delegates));
+    }
+
+    public void addLogFactory(LogFactory factory) {
+        _delegates.add(factory);
+    }
+
+    public void removeLogFactory(LogFactory factory) {
+        _delegates.remove(factory);
+    }
+
+    /**
+     * Returns the delegates that this MultiLogFactory delegates messages to.
+     */
+    public LogFactory[] getDelegates() {
+        return (LogFactory[]) _delegates.toArray(new LogFactory[0]);
+    }
+
+    /**
+     * Returns a Log impl that combines all logs.
+     */
+    public synchronized Log getLog(String channel) {
+        List logs = new ArrayList(_delegates.size());
+        for (Iterator i = _delegates.iterator(); i.hasNext();) {
+            LogFactory f = (LogFactory) i.next();
+            if (f != null) {
+                Log l = f.getLog(channel);
+                if (l != null)
+                    logs.add(l);
+            }
+        }
+        return new MultiLog((Log[]) logs.toArray(new Log[logs.size()]));
+    }
+
+    /**
+     * Combinatory Log impl.
+     */
+    private static class MultiLog implements Log {
+
+        private Log[] _logs;
+
+        public MultiLog(Log[] logs) {
+            _logs = logs;
+        }
+
+        /**
+         * Return the logs that this log delegates to.
+         */
+        public Log[] getDelegates() {
+            return _logs;
+        }
+
+        public void trace(Object msg) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].trace(msg);
+        }
+
+        public void trace(Object msg, Throwable t) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].trace(msg, t);
+        }
+
+        public void info(Object msg) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].info(msg);
+        }
+
+        public void info(Object msg, Throwable t) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].info(msg, t);
+        }
+
+        public void warn(Object msg) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].warn(msg);
+        }
+
+        public void warn(Object msg, Throwable t) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].warn(msg, t);
+        }
+
+        public void error(Object msg) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].error(msg);
+        }
+
+        public void error(Object msg, Throwable t) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].error(msg, t);
+        }
+
+        public void fatal(Object msg) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].fatal(msg);
+        }
+
+        public void fatal(Object msg, Throwable t) {
+            for (int i = 0; i < _logs.length; i++)
+                _logs[i].fatal(msg, t);
+        }
+
+        public boolean isTraceEnabled() {
+            for (int i = 0; i < _logs.length; i++)
+                if (_logs[i].isTraceEnabled())
+                    return true;
+            return false;
+        }
+
+        public boolean isInfoEnabled() {
+            for (int i = 0; i < _logs.length; i++)
+                if (_logs[i].isInfoEnabled())
+                    return true;
+            return false;
+        }
+
+        public boolean isWarnEnabled() {
+            for (int i = 0; i < _logs.length; i++)
+                if (_logs[i].isWarnEnabled())
+                    return true;
+            return false;
+        }
+
+        public boolean isErrorEnabled() {
+            for (int i = 0; i < _logs.length; i++)
+                if (_logs[i].isErrorEnabled())
+                    return true;
+            return false;
+        }
+
+        public boolean isFatalEnabled() {
+            for (int i = 0; i < _logs.length; i++)
+                if (_logs[i].isFatalEnabled())
+                    return true;
+            return false;
+        }
+    }
+}

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/LRUMap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/LRUMap.java?rev=640685&r1=640684&r2=640685&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/LRUMap.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/LRUMap.java Mon Mar 24 20:37:56 2008
@@ -38,12 +38,12 @@
     public LRUMap() {
     }
 
-    public LRUMap(int maxSize) {
-        super(maxSize);
+    public LRUMap(int initCapacity) {
+        super(initCapacity);
     }
 
-    public LRUMap(int maxSize, float loadFactor) {
-        super(maxSize, loadFactor);
+    public LRUMap(int initCapacity, float loadFactor) {
+        super(initCapacity, loadFactor);
     }
 
     public LRUMap(Map map) {

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java?rev=640685&r1=640684&r2=640685&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java Mon Mar 24 20:37:56 2008
@@ -1,302 +1,302 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.util;
-
-import java.security.AccessController;
-import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.Properties;
-import java.util.ResourceBundle;
-
-import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
-import org.apache.openjpa.lib.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * The Localizer provides convenient access to localized
- * strings. It includes built-in support for parameter substitution through
- * the use of the {@link MessageFormat} utility.
- * Strings are stored in per-package {@link Properties} files.
- * The property file for the default locale must be named
- * <code>localizer.properties</code>. Additional locales can be supported
- * through additional property files using the naming conventions specified
- * in the {@link ResourceBundle} class. For example, the German locale
- * could be supported through a <code>localizer_de_DE.properties</code> file.
- *
- * @author Abe White
- */
-public class Localizer {
-
-    // static cache of package+loc name to localizer mappings
-    private static final Map _localizers = new ConcurrentHashMap();
-
-    // list of resource providers to delegate to when locating resources
-    private static final Collection _providers = new CopyOnWriteArraySet
-        (Arrays.asList(new Object[]{
-            new SimpleResourceBundleProvider(),
-            new StreamResourceBundleProvider(),
-            new ZipResourceBundleProvider(), }));
-
-    /**
-     * Return a Localizer instance that will access the properties file
-     * in the package of the given class using the system default locale.
-     *
-     * @see #forPackage(Class,Locale)
-     */
-    public static Localizer forPackage(Class cls) {
-        return forPackage(cls, null);
-    }
-
-    /**
-     * Return a Localizer instance that will access the properties file
-     * in the package of the given class using the given locale.
-     *
-     * @param cls the class whose package to check for the localized
-     * properties file; if null, the system will check for
-     * a top-level properties file
-     * @param locale the locale to which strings should be localized; if
-     * null, the system default will be assumed
-     */
-    public static Localizer forPackage(Class cls, Locale locale) {
-        if (locale == null)
-            locale = Locale.getDefault();
-
-        int dot = (cls == null) ? -1 : cls.getName().lastIndexOf('.');
-        String pkg;
-        String file;
-        if (dot == -1) {
-            pkg = "";
-            file = "localizer";
-        } else {
-            pkg = cls.getName().substring(0, dot);
-            file = pkg + ".localizer";
-        }
-        String key = file + locale.toString();
-
-        // no locking; ok if bundle created multiple times
-        // check for cached version
-        Localizer loc = (Localizer) _localizers.get(key);
-        if (loc != null)
-            return loc;
-        else {
-            loc = new Localizer(pkg, file, locale, 
-                cls == null ? null:(ClassLoader) AccessController.doPrivileged(
-                    J2DoPrivHelper.getClassLoaderAction(cls))); 
-            _localizers.put(key, loc);
-            return loc;
-        }
-    }
-
-    /**
-     * Register a resource provider.
-     */
-    public static void addProvider(ResourceBundleProvider provider) {
-        _providers.add(provider);
-    }
-
-    /**
-     * Remove a resource provider.
-     */
-    public static boolean removeProvider(ResourceBundleProvider provider) {
-        return _providers.remove(provider);
-    }
-
-    private String _file;
-    private String _pkg;
-    private ResourceBundle _bundle = null;
-    private Locale _locale;
-    private ClassLoader _loader;
-
-    private Localizer(String pkg, String f, Locale locale, ClassLoader loader) {
-        _pkg = pkg;
-        _file = f;
-        _locale = locale;
-        _loader = loader;
-    }
-    
-    private ResourceBundle getBundle() {
-        // no locking; it's ok to create multiple bundles
-        if (_bundle == null) {
-            // find resource bundle
-            for (Iterator itr = _providers.iterator();
-                itr.hasNext() && _bundle == null; ) {
-                _bundle = ((ResourceBundleProvider) itr.next())
-                    .findResource(_file, _locale, _loader);
-            }
-        }
-        return _bundle;
-    }
-
-    /**
-     * Return the localized string matching the given key.
-     */
-    public Message get(String key) {
-        return get(key, null);
-    }
-
-    /**
-     * Return the localized string matching the given key.
-     */
-    public Message getFatal(String key) {
-        return getFatal(key, null);
-    }
-
-    /**
-     * Return the localized string matching the given key. The given
-     * <code>sub</code> object will be packed into an array and substituted
-     * into the found string according to the rules of the
-     * {@link MessageFormat} class.
-     *
-     * @see #get(String)
-     */
-    public Message get(String key, Object sub) {
-        return get(key, new Object[]{ sub });
-    }
-
-    /**
-     * Return the localized string matching the given key. The given
-     * <code>sub</code> object will be packed into an array and substituted
-     * into the found string according to the rules of the
-     * {@link MessageFormat} class.
-     *
-     * @see #getFatal(String)
-     */
-    public Message getFatal(String key, Object sub) {
-        return getFatal(key, new Object[]{ sub });
-    }
-
-    /**
-     * Return the localized string for the given key.
-     *
-     * @see #get(String,Object)
-     */
-    public Message get(String key, Object sub1, Object sub2) {
-        return get(key, new Object[]{ sub1, sub2 });
-    }
-
-    /**
-     * Return the localized string for the given key.
-     *
-     * @see #getFatal(String,Object)
-     */
-    public Message getFatal(String key, Object sub1, Object sub2) {
-        return getFatal(key, new Object[]{ sub1, sub2 });
-    }
-
-    /**
-     * Return the localized string for the given key.
-     *
-     * @see #get(String,Object)
-     */
-    public Message get(String key, Object sub1, Object sub2, Object sub3) {
-        return get(key, new Object[]{ sub1, sub2, sub3 });
-    }
-
-    /**
-     * Return the localized string matching the given key. The given
-     * <code>subs</code> objects will be substituted
-     * into the found string according to the rules of the
-     * {@link MessageFormat} class.
-     *
-     * @see #get(String)
-     */
-    public Message get(String key, Object[] subs) {
-        return new Message(_pkg, getBundle(), key, subs, false);
-    }
-
-    /**
-     * Return the localized string matching the given key. The given
-     * <code>subs</code> objects will be substituted
-     * into the found string according to the rules of the
-     * {@link MessageFormat} class.
-     *
-     * @see #getFatal(String)
-     */
-    public Message getFatal(String key, Object[] subs) {
-        return new Message(_pkg, getBundle(), key, subs, true);
-    }
-
-    /**
-     * A <code>Message</code> can provide a localized message via the 
-     * {@link #getMessage} method call, and can also provide the original key,
-     * package, and substitution array that were used to assemble the message.
-     */
-    public static class Message {
-
-        private final String _pkg;
-        private final String _key;
-        private final Object[] _subs;
-        private final String _localizedMessage;
-
-        private Message(String packageName, ResourceBundle bundle, String key, 
-            Object[] subs, boolean fatal) {
-            if (bundle == null && fatal)
-                throw new MissingResourceException(key, key, key);
-
-            _pkg = packageName;
-            _key = key;
-            _subs = subs;
-            if (bundle == null) {
-                _localizedMessage = key;
-            } else {
-                String localized = null;
-                try {
-                    localized = bundle.getString(key);
-                } catch (MissingResourceException mre) {
-                    if (fatal)
-                        throw mre;
-                }
-                _localizedMessage = (localized == null) ? key : localized;
-            }
-        }
-
-        /**
-         * The localized message.
-         */
-        public String getMessage() {
-            return MessageFormat.format(_localizedMessage, _subs);
-        }
-
-        /**
-         * The unique key for the localized message.
-         */
-        public String getKey() {
-            return _key;
-        }
-
-        /**
-         * Substitutions inserted into the message.
-         */
-        public Object[] getSubstitutions() {
-            return _subs;
-        }
-
-        public String getPackageName() {
-            return _pkg;
-        }
-
-        public String toString() {
-            return getMessage();
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.util;
+
+import java.security.AccessController;
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.Properties;
+import java.util.ResourceBundle;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+/**
+ * The Localizer provides convenient access to localized
+ * strings. It inlcudes built-in support for parameter substitution through
+ * the use of the {@link MessageFormat} utility.
+ * Strings are stored in per-package {@link Properties} files.
+ * The property file for the default locale must be named
+ * <code>localizer.properties</code>. Additional locales can be supported
+ * through additional property files using the naming conventions specified
+ * in the {@link ResourceBundle} class. For example, the german locale
+ * could be supported through a <code>localizer_de_DE.properties</code> file.
+ *
+ * @author Abe White
+ */
+public class Localizer {
+
+    // static cache of package+loc name to localizer mappings
+    private static final Map _localizers = new ConcurrentHashMap();
+
+    // list of resource providers to delegate to when locating resources
+    private static final Collection _providers = new CopyOnWriteArraySet
+        (Arrays.asList(new Object[]{
+            new SimpleResourceBundleProvider(),
+            new StreamResourceBundleProvider(),
+            new ZipResourceBundleProvider(), }));
+
+    /**
+     * Return a Localizer instance that will access the properties file
+     * in the package of the given class using the system default locale.
+     *
+     * @see #forPackage(Class,Locale)
+     */
+    public static Localizer forPackage(Class cls) {
+        return forPackage(cls, null);
+    }
+
+    /**
+     * Return a Localizer instance that will access the properties file
+     * in the package of the given class using the given locale.
+     *
+     * @param cls the class whose package to check for the localized
+     * properties file; if null, the system will check for
+     * a top-level properties file
+     * @param locale the locale to which strings should be localized; if
+     * null, the system default will be assumed
+     */
+    public static Localizer forPackage(Class cls, Locale locale) {
+        if (locale == null)
+            locale = Locale.getDefault();
+
+        int dot = (cls == null) ? -1 : cls.getName().lastIndexOf('.');
+        String pkg;
+        String file;
+        if (dot == -1) {
+            pkg = "";
+            file = "localizer";
+        } else {
+            pkg = cls.getName().substring(0, dot);
+            file = pkg + ".localizer";
+        }
+        String key = file + locale.toString();
+
+        // no locking; ok if bundle created multiple times
+        // check for cached version
+        Localizer loc = (Localizer) _localizers.get(key);
+        if (loc != null)
+            return loc;
+        else {
+            loc = new Localizer(pkg, file, locale,
+                cls == null ? null:(ClassLoader) AccessController.doPrivileged(
+                    J2DoPrivHelper.getClassLoaderAction(cls)));
+            _localizers.put(key, loc);
+            return loc;
+        }
+    }
+
+    /**
+     * Register a resource provider.
+     */
+    public static void addProvider(ResourceBundleProvider provider) {
+        _providers.add(provider);
+    }
+
+    /**
+     * Remove a resource provider.
+     */
+    public static boolean removeProvider(ResourceBundleProvider provider) {
+        return _providers.remove(provider);
+    }
+
+    private String _file;
+    private String _pkg;
+    private ResourceBundle _bundle = null;
+    private Locale _locale;
+    private ClassLoader _loader;
+
+    private Localizer(String pkg, String f, Locale locale, ClassLoader loader) {
+        _pkg = pkg;
+        _file = f;
+        _locale = locale;
+        _loader = loader;
+    }
+
+    private ResourceBundle getBundle() {
+        // no locking; it's ok to create multiple bundles
+        if (_bundle == null) {
+            // find resource bundle
+            for (Iterator itr = _providers.iterator();
+                itr.hasNext() && _bundle == null; ) {
+                _bundle = ((ResourceBundleProvider) itr.next())
+                    .findResource(_file, _locale, _loader);
+            }
+        }
+        return _bundle;
+    }
+
+    /**
+     * Return the localized string matching the given key.
+     */
+    public Message get(String key) {
+        return get(key, null);
+    }
+
+    /**
+     * Return the localized string matching the given key.
+     */
+    public Message getFatal(String key) {
+        return getFatal(key, null);
+    }
+
+    /**
+     * Return the localized string matching the given key. The given
+     * <code>sub</code> object will be packed into an array and substituted
+     * into the found string according to the rules of the
+     * {@link MessageFormat} class.
+     *
+     * @see #get(String)
+     */
+    public Message get(String key, Object sub) {
+        return get(key, new Object[]{ sub });
+    }
+
+    /**
+     * Return the localized string matching the given key. The given
+     * <code>sub</code> object will be packed into an array and substituted
+     * into the found string according to the rules of the
+     * {@link MessageFormat} class.
+     *
+     * @see #getFatal(String)
+     */
+    public Message getFatal(String key, Object sub) {
+        return getFatal(key, new Object[]{ sub });
+    }
+
+    /**
+     * Return the localized string for the given key.
+     *
+     * @see #get(String,Object)
+     */
+    public Message get(String key, Object sub1, Object sub2) {
+        return get(key, new Object[]{ sub1, sub2 });
+    }
+
+    /**
+     * Return the localized string for the given key.
+     *
+     * @see #getFatal(String,Object)
+     */
+    public Message getFatal(String key, Object sub1, Object sub2) {
+        return getFatal(key, new Object[]{ sub1, sub2 });
+    }
+
+    /**
+     * Return the localized string for the given key.
+     *
+     * @see #get(String,Object)
+     */
+    public Message get(String key, Object sub1, Object sub2, Object sub3) {
+        return get(key, new Object[]{ sub1, sub2, sub3 });
+    }
+
+    /**
+     * Return the localized string matching the given key. The given
+     * <code>subs</code> objects will be substituted
+     * into the found string according to the rules of the
+     * {@link MessageFormat} class.
+     *
+     * @see #get(String)
+     */
+    public Message get(String key, Object[] subs) {
+        return new Message(_pkg, getBundle(), key, subs, false);
+    }
+
+    /**
+     * Return the localized string matching the given key. The given
+     * <code>subs</code> objects will be substituted
+     * into the found string according to the rules of the
+     * {@link MessageFormat} class.
+     *
+     * @see #getFatal(String)
+     */
+    public Message getFatal(String key, Object[] subs) {
+        return new Message(_pkg, getBundle(), key, subs, true);
+    }
+
+    /**
+     * A <code>Message</code> can provide a localized message via the
+     * {@link #getMessage} method call, and can also provide the original key,
+     * package, and substitution array that were used to assemble the message.
+     */
+    public static class Message {
+
+        private final String _pkg;
+        private final String _key;
+        private final Object[] _subs;
+        private final String _localizedMessage;
+
+        private Message(String packageName, ResourceBundle bundle, String key,
+            Object[] subs, boolean fatal) {
+            if (bundle == null && fatal)
+                throw new MissingResourceException(key, key, key);
+
+            _pkg = packageName;
+            _key = key;
+            _subs = subs;
+            if (bundle == null) {
+                _localizedMessage = key;
+            } else {
+                String localized = null;
+                try {
+                    localized = bundle.getString(key);
+                } catch (MissingResourceException mre) {
+                    if (fatal)
+                        throw mre;
+                }
+                _localizedMessage = (localized == null) ? key : localized;
+            }
+        }
+
+        /**
+         * The localized message.
+         */
+        public String getMessage() {
+            return MessageFormat.format(_localizedMessage, _subs);
+        }
+
+        /**
+         * The unique key for the localized message.
+         */
+        public String getKey() {
+            return _key;
+        }
+
+        /**
+         * Substitutions inserted into the message.
+         */
+        public Object[] getSubstitutions() {
+            return _subs;
+        }
+
+        public String getPackageName() {
+            return _pkg;
+        }
+
+        public String toString() {
+            return getMessage();
+        }
+    }
+}

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TimestampHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TimestampHelper.java?rev=640685&r1=640684&r2=640685&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TimestampHelper.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TimestampHelper.java Mon Mar 24 20:37:56 2008
@@ -22,8 +22,7 @@
 
 /**
  * Helper base class attempts to return java.sql.Timestamp object with
- * nanosecond precision. This base class is created to allow JDK 1.4 maven build
- * and only implements millisecond precision.
+ * nanosecond precision. 
  * 
  * @author Albert Lee
  */
@@ -34,34 +33,29 @@
     protected static final long MicroMuliplier = MilliMuliplier * 1000L;
     protected static final long NanoMuliplier = MicroMuliplier * 1000L;
 
-    private static TimestampHelper instance = null;
-    
+    // number of seconds passed 1970/1/1 00:00:00 GMT.
+    private static long sec0;
+    // fraction of seconds passed 1970/1/1 00:00:00 GMT, offset by
+    // the base System.nanoTime (nano0), in nanosecond unit.
+    private static long nano0;
+
     static {
-        if (JavaVersions.VERSION >= 5) {
-            try {
-                Class timestamp5HelperClass = Class
-                    .forName("org.apache.openjpa.lib.util.Timestamp5Helper");
-                instance = (TimestampHelper) timestamp5HelperClass
-                    .newInstance();
-            } catch (Throwable e) {
-                instance = new TimestampHelper();
-            }
-        } else {
-            instance = new TimestampHelper();
-        }
+        // initialize base time in second and fraction of second (ns).
+        long curTime = System.currentTimeMillis();
+        sec0 = curTime / MilliMuliplier;
+        nano0 = (curTime % MilliMuliplier) * MicroMuliplier - System.nanoTime();
     }
 
     /*
      * Return a java.sql.Timestamp object of current time.
      */
     public static Timestamp getNanoPrecisionTimestamp() {
-        return instance.getTimestamp();
-    }
-    
-    /*
-     * This class implements a millisecond precision Timestamp.
-     */
-    protected Timestamp getTimestamp() { 
-        return new Timestamp(System.currentTimeMillis());
+        long nano_delta = nano0 + System.nanoTime();
+        long sec1 = sec0 + (nano_delta / NanoMuliplier);
+        long nano1 = nano_delta % NanoMuliplier;
+
+        Timestamp rtnTs = new Timestamp(sec1 * MilliMuliplier);
+        rtnTs.setNanos((int) nano1);
+        return rtnTs;
     }
 }



Mime
View raw message