http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQFactory.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQFactory.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQFactory.java index 19fc6df..52da2af 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQFactory.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQFactory.java @@ -1,154 +1,154 @@ -/* - * 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.openejb.resource.activemq; - -import org.apache.activemq.broker.BrokerService; -import org.apache.openejb.OpenEJBRuntimeException; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URI; -import java.util.Collection; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; - -public class ActiveMQFactory { - - private static final AtomicBoolean initialized = new AtomicBoolean(false); - private static Method setThreadProperties; - private static Method createBroker; - private static Method getBrokers; - private static Object instance; - private static String brokerPrefix; - - private static void init() { - - synchronized (initialized) { - - if (!initialized.getAndSet(true)) { - - Class tmp; - - try { - tmp = Class.forName("org.apache.openejb.resource.activemq.ActiveMQ5Factory"); - brokerPrefix = "amq5factory:"; - } catch (final Throwable t1) { - try { - tmp = Class.forName("org.apache.openejb.resource.activemq.ActiveMQ4Factory"); - brokerPrefix = "amq4factory:"; - } catch (final Throwable t2) { - throw new OpenEJBRuntimeException("Unable to load ActiveMQFactory: Check ActiveMQ jar files are on classpath", t1); - } - } - - final Class clazz = tmp; - - try { - instance = clazz.newInstance(); - } catch (final InstantiationException e) { - throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory instance", e); - } catch (final IllegalAccessException e) { - throw new OpenEJBRuntimeException("Unable to access ActiveMQFactory instance", e); - } - - try { - setThreadProperties = clazz.getDeclaredMethod("setThreadProperties", new Class[]{Properties.class}); - } catch (final NoSuchMethodException e) { - throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory setThreadProperties method", e); - } - - try { - createBroker = clazz.getDeclaredMethod("createBroker", new Class[]{URI.class}); - } catch (final NoSuchMethodException e) { - throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory createBroker method", e); - } - - try { - getBrokers = clazz.getDeclaredMethod("getBrokers", (Class[]) null); - } catch (final NoSuchMethodException e) { - throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory createBroker method", e); - } - } - } - } - - /** - * Returns the prefix metafile name of the poperties file that ActiveMQ should be - * provided with. This file is located at META-INF/services/org/apache/activemq/broker/ - * and defines the BrokerFactoryHandler to load. - * - * @return String name - will be either 'amq5factory:' or 'amq4factory:' - note the trailing ':' - */ - public static String getBrokerMetaFile() { - ActiveMQFactory.init(); - return brokerPrefix; - } - - public static void setThreadProperties(final Properties p) { - - ActiveMQFactory.init(); - - try { - setThreadProperties.invoke(instance, p); - } catch (final IllegalAccessException e) { - throw new OpenEJBRuntimeException("ActiveMQFactory.setThreadProperties.IllegalAccessException", e); - } catch (final IllegalArgumentException e) { - throw new OpenEJBRuntimeException("ActiveMQFactory.setThreadProperties.IllegalArgumentException", e); - } catch (final InvocationTargetException e) { - throw new OpenEJBRuntimeException("ActiveMQFactory.setThreadProperties.InvocationTargetException", e); - } - } - - public static BrokerService createBroker(final URI brokerURI) throws Exception { - - ActiveMQFactory.init(); - - try { - return (BrokerService) createBroker.invoke(instance, brokerURI); - } catch (final IllegalAccessException e) { - throw new Exception("ActiveMQFactory.createBroker.IllegalAccessException", e); - } catch (final IllegalArgumentException e) { - throw new Exception("ActiveMQFactory.createBroker.IllegalArgumentException", e); - } catch (final InvocationTargetException e) { - throw new Exception("ActiveMQFactory.createBroker.InvocationTargetException", e); - } - } - - /** - * Returns a map of configured brokers. - * This intended for access upon RA shutdown in order to wait for the brokers to finish. - * - * @return Map(URI, BrokerService) - * @throws Exception On error - */ - public static Collection<BrokerService> getBrokers() throws Exception { - - ActiveMQFactory.init(); - - try { - //noinspection unchecked - return (Collection<BrokerService>) getBrokers.invoke(instance, (Object[]) null); - } catch (final IllegalAccessException e) { - throw new Exception("ActiveMQFactory.createBroker.IllegalAccessException", e); - } catch (final IllegalArgumentException e) { - throw new Exception("ActiveMQFactory.createBroker.IllegalArgumentException", e); - } catch (final InvocationTargetException e) { - throw new Exception("ActiveMQFactory.createBroker.InvocationTargetException", e); - } - } -} +/* + * 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.openejb.resource.activemq; + +import org.apache.activemq.broker.BrokerService; +import org.apache.openejb.OpenEJBRuntimeException; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Collection; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicBoolean; + +public class ActiveMQFactory { + + private static final AtomicBoolean initialized = new AtomicBoolean(false); + private static Method setThreadProperties; + private static Method createBroker; + private static Method getBrokers; + private static Object instance; + private static String brokerPrefix; + + private static void init() { + + synchronized (initialized) { + + if (!initialized.getAndSet(true)) { + + Class tmp; + + try { + tmp = Class.forName("org.apache.openejb.resource.activemq.ActiveMQ5Factory"); + brokerPrefix = "amq5factory:"; + } catch (final Throwable t1) { + try { + tmp = Class.forName("org.apache.openejb.resource.activemq.ActiveMQ4Factory"); + brokerPrefix = "amq4factory:"; + } catch (final Throwable t2) { + throw new OpenEJBRuntimeException("Unable to load ActiveMQFactory: Check ActiveMQ jar files are on classpath", t1); + } + } + + final Class clazz = tmp; + + try { + instance = clazz.newInstance(); + } catch (final InstantiationException e) { + throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory instance", e); + } catch (final IllegalAccessException e) { + throw new OpenEJBRuntimeException("Unable to access ActiveMQFactory instance", e); + } + + try { + setThreadProperties = clazz.getDeclaredMethod("setThreadProperties", new Class[]{Properties.class}); + } catch (final NoSuchMethodException e) { + throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory setThreadProperties method", e); + } + + try { + createBroker = clazz.getDeclaredMethod("createBroker", new Class[]{URI.class}); + } catch (final NoSuchMethodException e) { + throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory createBroker method", e); + } + + try { + getBrokers = clazz.getDeclaredMethod("getBrokers", (Class[]) null); + } catch (final NoSuchMethodException e) { + throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory createBroker method", e); + } + } + } + } + + /** + * Returns the prefix metafile name of the poperties file that ActiveMQ should be + * provided with. This file is located at META-INF/services/org/apache/activemq/broker/ + * and defines the BrokerFactoryHandler to load. + * + * @return String name - will be either 'amq5factory:' or 'amq4factory:' - note the trailing ':' + */ + public static String getBrokerMetaFile() { + ActiveMQFactory.init(); + return brokerPrefix; + } + + public static void setThreadProperties(final Properties p) { + + ActiveMQFactory.init(); + + try { + setThreadProperties.invoke(instance, p); + } catch (final IllegalAccessException e) { + throw new OpenEJBRuntimeException("ActiveMQFactory.setThreadProperties.IllegalAccessException", e); + } catch (final IllegalArgumentException e) { + throw new OpenEJBRuntimeException("ActiveMQFactory.setThreadProperties.IllegalArgumentException", e); + } catch (final InvocationTargetException e) { + throw new OpenEJBRuntimeException("ActiveMQFactory.setThreadProperties.InvocationTargetException", e); + } + } + + public static BrokerService createBroker(final URI brokerURI) throws Exception { + + ActiveMQFactory.init(); + + try { + return (BrokerService) createBroker.invoke(instance, brokerURI); + } catch (final IllegalAccessException e) { + throw new Exception("ActiveMQFactory.createBroker.IllegalAccessException", e); + } catch (final IllegalArgumentException e) { + throw new Exception("ActiveMQFactory.createBroker.IllegalArgumentException", e); + } catch (final InvocationTargetException e) { + throw new Exception("ActiveMQFactory.createBroker.InvocationTargetException", e); + } + } + + /** + * Returns a map of configured brokers. + * This intended for access upon RA shutdown in order to wait for the brokers to finish. + * + * @return Map(URI, BrokerService) + * @throws Exception On error + */ + public static Collection<BrokerService> getBrokers() throws Exception { + + ActiveMQFactory.init(); + + try { + //noinspection unchecked + return (Collection<BrokerService>) getBrokers.invoke(instance, (Object[]) null); + } catch (final IllegalAccessException e) { + throw new Exception("ActiveMQFactory.createBroker.IllegalAccessException", e); + } catch (final IllegalArgumentException e) { + throw new Exception("ActiveMQFactory.createBroker.IllegalArgumentException", e); + } catch (final InvocationTargetException e) { + throw new Exception("ActiveMQFactory.createBroker.InvocationTargetException", e); + } + } +}
http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/RoutedDataSource.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/RoutedDataSource.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/RoutedDataSource.java index dd727c3..9e94cd2 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/RoutedDataSource.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/RoutedDataSource.java @@ -1,129 +1,129 @@ -/* - * 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.openejb.resource.jdbc; - -import org.apache.openejb.loader.SystemInstance; -import org.apache.openejb.resource.jdbc.router.Router; -import org.apache.openejb.spi.ContainerSystem; -import org.apache.openejb.util.reflection.Reflections; - -import javax.naming.NamingException; -import javax.sql.DataSource; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.logging.Logger; - -public class RoutedDataSource implements DataSource { - private static final String OPENEJB_RESOURCE_PREFIX = "openejb:Resource/"; - - private Router delegate; - - public RoutedDataSource() { - // no-op - } - - public RoutedDataSource(final String router) { - setRouter(router); - } - - public void setRouter(final String router) { - final Object o; - try { - o = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup(OPENEJB_RESOURCE_PREFIX + router); - } catch (final NamingException e) { - throw new IllegalArgumentException("Can't find router [" + router + "]", e); - } - - if (Router.class.isInstance(o)) { - delegate = Router.class.cast(o); - } else { - throw new IllegalArgumentException(o + " is not a router"); - } - } - - public PrintWriter getLogWriter() throws SQLException { - if (getTargetDataSource() == null) { - return null; - } - return getTargetDataSource().getLogWriter(); - } - - public void setLogWriter(final PrintWriter out) throws SQLException { - if (getTargetDataSource() != null) { - getTargetDataSource().setLogWriter(out); - } - } - - public void setLoginTimeout(final int seconds) throws SQLException { - if (getTargetDataSource() != null) { - getTargetDataSource().setLoginTimeout(seconds); - } - } - - public int getLoginTimeout() throws SQLException { - if (getTargetDataSource() == null) { - return -1; - } - return getTargetDataSource().getLoginTimeout(); - } - - public <T> T unwrap(final Class<T> iface) throws SQLException { - if (getTargetDataSource() == null) { - return null; - } - return (T) Reflections.invokeByReflection(getTargetDataSource(), "unwrap", - new Class<?>[]{Class.class}, new Object[]{iface}); - } - - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - if (getTargetDataSource() == null) { - return null; - } - return (Logger) Reflections.invokeByReflection(getTargetDataSource(), "getParentLogger", new Class<?>[0], null); - } - - public boolean isWrapperFor(final Class<?> iface) throws SQLException { - if (getTargetDataSource() == null) { - return false; - } - return (Boolean) Reflections.invokeByReflection(getTargetDataSource(), "isWrapperFor", - new Class<?>[]{Class.class}, new Object[]{iface}); - } - - public Connection getConnection() throws SQLException { - return getTargetDataSource().getConnection(); - } - - public Connection getConnection(final String username, final String password) - throws SQLException { - return getTargetDataSource().getConnection(username, password); - } - - public Router getDelegate() { - if (delegate == null) { - throw new IllegalStateException("a router has to be defined"); - } - return delegate; - } - - private DataSource getTargetDataSource() { - return getDelegate().getDataSource(); - } -} +/* + * 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.openejb.resource.jdbc; + +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.resource.jdbc.router.Router; +import org.apache.openejb.spi.ContainerSystem; +import org.apache.openejb.util.reflection.Reflections; + +import javax.naming.NamingException; +import javax.sql.DataSource; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.logging.Logger; + +public class RoutedDataSource implements DataSource { + private static final String OPENEJB_RESOURCE_PREFIX = "openejb:Resource/"; + + private Router delegate; + + public RoutedDataSource() { + // no-op + } + + public RoutedDataSource(final String router) { + setRouter(router); + } + + public void setRouter(final String router) { + final Object o; + try { + o = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup(OPENEJB_RESOURCE_PREFIX + router); + } catch (final NamingException e) { + throw new IllegalArgumentException("Can't find router [" + router + "]", e); + } + + if (Router.class.isInstance(o)) { + delegate = Router.class.cast(o); + } else { + throw new IllegalArgumentException(o + " is not a router"); + } + } + + public PrintWriter getLogWriter() throws SQLException { + if (getTargetDataSource() == null) { + return null; + } + return getTargetDataSource().getLogWriter(); + } + + public void setLogWriter(final PrintWriter out) throws SQLException { + if (getTargetDataSource() != null) { + getTargetDataSource().setLogWriter(out); + } + } + + public void setLoginTimeout(final int seconds) throws SQLException { + if (getTargetDataSource() != null) { + getTargetDataSource().setLoginTimeout(seconds); + } + } + + public int getLoginTimeout() throws SQLException { + if (getTargetDataSource() == null) { + return -1; + } + return getTargetDataSource().getLoginTimeout(); + } + + public <T> T unwrap(final Class<T> iface) throws SQLException { + if (getTargetDataSource() == null) { + return null; + } + return (T) Reflections.invokeByReflection(getTargetDataSource(), "unwrap", + new Class<?>[]{Class.class}, new Object[]{iface}); + } + + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + if (getTargetDataSource() == null) { + return null; + } + return (Logger) Reflections.invokeByReflection(getTargetDataSource(), "getParentLogger", new Class<?>[0], null); + } + + public boolean isWrapperFor(final Class<?> iface) throws SQLException { + if (getTargetDataSource() == null) { + return false; + } + return (Boolean) Reflections.invokeByReflection(getTargetDataSource(), "isWrapperFor", + new Class<?>[]{Class.class}, new Object[]{iface}); + } + + public Connection getConnection() throws SQLException { + return getTargetDataSource().getConnection(); + } + + public Connection getConnection(final String username, final String password) + throws SQLException { + return getTargetDataSource().getConnection(username, password); + } + + public Router getDelegate() { + if (delegate == null) { + throw new IllegalStateException("a router has to be defined"); + } + return delegate; + } + + private DataSource getTargetDataSource() { + return getDelegate().getDataSource(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PasswordCipher.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PasswordCipher.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PasswordCipher.java index 2c67f7a..d9665ca 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PasswordCipher.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PasswordCipher.java @@ -1,29 +1,29 @@ -/* - * 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.openejb.resource.jdbc.cipher; - -/** - * In order to reuse that same interface for every passwords in TomEE, it has been moved - * to another package. Just keeping that interface for compatibility reasons. - * - * @See org.apache.openejb.cipher.PasswordCipher - */ -@Deprecated -public interface PasswordCipher extends org.apache.openejb.cipher.PasswordCipher { - -} +/* + * 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.openejb.resource.jdbc.cipher; + +/** + * In order to reuse that same interface for every passwords in TomEE, it has been moved + * to another package. Just keeping that interface for compatibility reasons. + * + * @See org.apache.openejb.cipher.PasswordCipher + */ +@Deprecated +public interface PasswordCipher extends org.apache.openejb.cipher.PasswordCipher { + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PlainTextPasswordCipher.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PlainTextPasswordCipher.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PlainTextPasswordCipher.java index df1fcea..6297a37 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PlainTextPasswordCipher.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/PlainTextPasswordCipher.java @@ -1,22 +1,22 @@ -/* - * 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.openejb.resource.jdbc.cipher; - -@Deprecated -public class PlainTextPasswordCipher extends org.apache.openejb.cipher.PlainTextPasswordCipher implements PasswordCipher { -} +/* + * 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.openejb.resource.jdbc.cipher; + +@Deprecated +public class PlainTextPasswordCipher extends org.apache.openejb.cipher.PlainTextPasswordCipher implements PasswordCipher { +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/StaticDESPasswordCipher.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/StaticDESPasswordCipher.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/StaticDESPasswordCipher.java index e62d00d..1a820c0 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/StaticDESPasswordCipher.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/cipher/StaticDESPasswordCipher.java @@ -1,23 +1,23 @@ -/* - * 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.openejb.resource.jdbc.cipher; - -@Deprecated -@SuppressWarnings("deprecation") -public class StaticDESPasswordCipher extends org.apache.openejb.cipher.StaticDESPasswordCipher implements PasswordCipher { -} +/* + * 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.openejb.resource.jdbc.cipher; + +@Deprecated +@SuppressWarnings("deprecation") +public class StaticDESPasswordCipher extends org.apache.openejb.cipher.StaticDESPasswordCipher implements PasswordCipher { +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/AbstractRouter.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/AbstractRouter.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/AbstractRouter.java index 425a10d..c904670 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/AbstractRouter.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/AbstractRouter.java @@ -1,42 +1,42 @@ -/* - * 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.openejb.resource.jdbc.router; - -import org.apache.openejb.loader.SystemInstance; -import org.apache.openejb.spi.ContainerSystem; - -import javax.naming.Context; -import javax.naming.NamingException; - -public abstract class AbstractRouter implements Router { - private static final String OPENEJB_RESOURCE = "openejb:Resource/"; - - private final Context ctx; - - public AbstractRouter() { - ctx = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext(); - } - - protected Object getJndiResource(final String name) throws NamingException { - return ctx.lookup(name); - } - - protected Object getOpenEJBResource(final String name) throws NamingException { - return getJndiResource(OPENEJB_RESOURCE + name); - } -} +/* + * 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.openejb.resource.jdbc.router; + +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.spi.ContainerSystem; + +import javax.naming.Context; +import javax.naming.NamingException; + +public abstract class AbstractRouter implements Router { + private static final String OPENEJB_RESOURCE = "openejb:Resource/"; + + private final Context ctx; + + public AbstractRouter() { + ctx = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext(); + } + + protected Object getJndiResource(final String name) throws NamingException { + return ctx.lookup(name); + } + + protected Object getOpenEJBResource(final String name) throws NamingException { + return getJndiResource(OPENEJB_RESOURCE + name); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/Router.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/Router.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/Router.java index ea00735..05e2683 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/Router.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/router/Router.java @@ -1,37 +1,37 @@ -/* - * 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.openejb.resource.jdbc.router; - -import org.apache.openejb.resource.jdbc.RoutedDataSource; - -import javax.sql.DataSource; - -/** - * The Router interface is responsible for providing the target data source to the ${@link RoutedDataSource}}. - * <p/> - * $Rev:$ - */ -public interface Router { - - /** - * Used by ${@link RoutedDataSource} to get the active data source. - * - * @return the data source to delegate to - */ - DataSource getDataSource(); -} +/* + * 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.openejb.resource.jdbc.router; + +import org.apache.openejb.resource.jdbc.RoutedDataSource; + +import javax.sql.DataSource; + +/** + * The Router interface is responsible for providing the target data source to the ${@link RoutedDataSource}}. + * <p/> + * $Rev:$ + */ +public interface Router { + + /** + * Used by ${@link RoutedDataSource} to get the active data source. + * + * @return the data source to delegate to + */ + DataSource getDataSource(); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java index 5e41a0b..52b4265 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java @@ -1,96 +1,96 @@ -/* - * 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.openejb.rest; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.Application; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.SecurityContext; -import javax.ws.rs.core.UriInfo; -import javax.ws.rs.ext.ContextResolver; -import javax.ws.rs.ext.Providers; -import java.util.Map; - -public class ThreadLocalContextManager { - public static final ThreadLocalRequest REQUEST = new ThreadLocalRequest(); - public static final ThreadLocalServletConfig SERVLET_CONFIG = new ThreadLocalServletConfig(); - public static final ThreadLocalServletContext SERVLET_CONTEXT = new ThreadLocalServletContext(); - public static final ThreadLocalServletRequest SERVLET_REQUEST = new ThreadLocalServletRequest(); - public static final ThreadLocalHttpServletRequest HTTP_SERVLET_REQUEST = new ThreadLocalHttpServletRequest(); - public static final ThreadLocalHttpServletResponse HTTP_SERVLET_RESPONSE = new ThreadLocalHttpServletResponse(); - public static final ThreadLocalUriInfo URI_INFO = new ThreadLocalUriInfo(); - public static final ThreadLocalHttpHeaders HTTP_HEADERS = new ThreadLocalHttpHeaders(); - public static final ThreadLocalSecurityContext SECURITY_CONTEXT = new ThreadLocalSecurityContext(); - public static final ThreadLocalContextResolver CONTEXT_RESOLVER = new ThreadLocalContextResolver(); - public static final ThreadLocalProviders PROVIDERS = new ThreadLocalProviders(); - public static final ThreadLocal<Application> APPLICATION = new ThreadLocal<Application>(); - public static final ThreadLocal<Map<String, Object>> OTHERS = new ThreadLocal<Map<String, Object>>(); - - public static void reset() { - REQUEST.remove(); - SERVLET_REQUEST.remove(); - SERVLET_CONFIG.remove(); - SERVLET_CONTEXT.remove(); - HTTP_SERVLET_REQUEST.remove(); - HTTP_SERVLET_RESPONSE.remove(); - URI_INFO.remove(); - HTTP_HEADERS.remove(); - SECURITY_CONTEXT.remove(); - CONTEXT_RESOLVER.remove(); - PROVIDERS.remove(); - APPLICATION.remove(); - - final Map<String, Object> map = OTHERS.get(); - if (map != null) { - map.clear(); - } - OTHERS.remove(); - } - - public static Object findThreadLocal(final Class<?> type) { - if (Request.class.equals(type)) { - return ThreadLocalContextManager.REQUEST; - } else if (UriInfo.class.equals(type)) { - return ThreadLocalContextManager.URI_INFO; - } else if (HttpHeaders.class.equals(type)) { - return ThreadLocalContextManager.HTTP_HEADERS; - } else if (SecurityContext.class.equals(type)) { - return ThreadLocalContextManager.SECURITY_CONTEXT; - } else if (ContextResolver.class.equals(type)) { - return ThreadLocalContextManager.CONTEXT_RESOLVER; - } else if (Providers.class.equals(type)) { - return ThreadLocalContextManager.PROVIDERS; - } else if (ServletRequest.class.equals(type)) { - return ThreadLocalContextManager.SERVLET_REQUEST; - } else if (HttpServletRequest.class.equals(type)) { - return ThreadLocalContextManager.HTTP_SERVLET_REQUEST; - } else if (HttpServletResponse.class.equals(type)) { - return ThreadLocalContextManager.HTTP_SERVLET_RESPONSE; - } else if (ServletConfig.class.equals(type)) { - return ThreadLocalContextManager.SERVLET_CONFIG; - } else if (ServletContext.class.equals(type)) { - return ThreadLocalContextManager.SERVLET_CONTEXT; - } - return null; - } -} +/* + * 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.openejb.rest; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Providers; +import java.util.Map; + +public class ThreadLocalContextManager { + public static final ThreadLocalRequest REQUEST = new ThreadLocalRequest(); + public static final ThreadLocalServletConfig SERVLET_CONFIG = new ThreadLocalServletConfig(); + public static final ThreadLocalServletContext SERVLET_CONTEXT = new ThreadLocalServletContext(); + public static final ThreadLocalServletRequest SERVLET_REQUEST = new ThreadLocalServletRequest(); + public static final ThreadLocalHttpServletRequest HTTP_SERVLET_REQUEST = new ThreadLocalHttpServletRequest(); + public static final ThreadLocalHttpServletResponse HTTP_SERVLET_RESPONSE = new ThreadLocalHttpServletResponse(); + public static final ThreadLocalUriInfo URI_INFO = new ThreadLocalUriInfo(); + public static final ThreadLocalHttpHeaders HTTP_HEADERS = new ThreadLocalHttpHeaders(); + public static final ThreadLocalSecurityContext SECURITY_CONTEXT = new ThreadLocalSecurityContext(); + public static final ThreadLocalContextResolver CONTEXT_RESOLVER = new ThreadLocalContextResolver(); + public static final ThreadLocalProviders PROVIDERS = new ThreadLocalProviders(); + public static final ThreadLocal<Application> APPLICATION = new ThreadLocal<Application>(); + public static final ThreadLocal<Map<String, Object>> OTHERS = new ThreadLocal<Map<String, Object>>(); + + public static void reset() { + REQUEST.remove(); + SERVLET_REQUEST.remove(); + SERVLET_CONFIG.remove(); + SERVLET_CONTEXT.remove(); + HTTP_SERVLET_REQUEST.remove(); + HTTP_SERVLET_RESPONSE.remove(); + URI_INFO.remove(); + HTTP_HEADERS.remove(); + SECURITY_CONTEXT.remove(); + CONTEXT_RESOLVER.remove(); + PROVIDERS.remove(); + APPLICATION.remove(); + + final Map<String, Object> map = OTHERS.get(); + if (map != null) { + map.clear(); + } + OTHERS.remove(); + } + + public static Object findThreadLocal(final Class<?> type) { + if (Request.class.equals(type)) { + return ThreadLocalContextManager.REQUEST; + } else if (UriInfo.class.equals(type)) { + return ThreadLocalContextManager.URI_INFO; + } else if (HttpHeaders.class.equals(type)) { + return ThreadLocalContextManager.HTTP_HEADERS; + } else if (SecurityContext.class.equals(type)) { + return ThreadLocalContextManager.SECURITY_CONTEXT; + } else if (ContextResolver.class.equals(type)) { + return ThreadLocalContextManager.CONTEXT_RESOLVER; + } else if (Providers.class.equals(type)) { + return ThreadLocalContextManager.PROVIDERS; + } else if (ServletRequest.class.equals(type)) { + return ThreadLocalContextManager.SERVLET_REQUEST; + } else if (HttpServletRequest.class.equals(type)) { + return ThreadLocalContextManager.HTTP_SERVLET_REQUEST; + } else if (HttpServletResponse.class.equals(type)) { + return ThreadLocalContextManager.HTTP_SERVLET_RESPONSE; + } else if (ServletConfig.class.equals(type)) { + return ThreadLocalContextManager.SERVLET_CONFIG; + } else if (ServletContext.class.equals(type)) { + return ThreadLocalContextManager.SERVLET_CONTEXT; + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java index c1db6b1..572e20d 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java @@ -1,47 +1,47 @@ -/* - * 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.openejb.testng; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -public class PropertiesBuilder { - private final Properties properties = new Properties(); - - public PropertiesBuilder p(final String key, final String value) { - return property(key, value); - } - - public PropertiesBuilder property(final String key, final String value) { - properties.setProperty(key, value); - return this; - } - - public Properties build() { - return properties; - } - - public Map<String, String> asMap() { - final Map<String, String> map = new HashMap<String, String>(); - for (final Map.Entry<Object, Object> entry : properties.entrySet()) { - map.put(String.class.cast(entry.getKey()), String.class.cast(entry.getValue())); - } - return map; - } -} +/* + * 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.openejb.testng; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +public class PropertiesBuilder { + private final Properties properties = new Properties(); + + public PropertiesBuilder p(final String key, final String value) { + return property(key, value); + } + + public PropertiesBuilder property(final String key, final String value) { + properties.setProperty(key, value); + return this; + } + + public Properties build() { + return properties; + } + + public Map<String, String> asMap() { + final Map<String, String> map = new HashMap<String, String>(); + for (final Map.Entry<Object, Object> entry : properties.entrySet()) { + map.put(String.class.cast(entry.getKey()), String.class.cast(entry.getValue())); + } + return map; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/util/CollectionsUtil.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/CollectionsUtil.java b/container/openejb-core/src/main/java/org/apache/openejb/util/CollectionsUtil.java index 8ceff40..2daa42f 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/util/CollectionsUtil.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/util/CollectionsUtil.java @@ -1,30 +1,30 @@ -/* - * 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.openejb.util; - -import java.util.Collections; -import java.util.List; - -public class CollectionsUtil { - public static <T> List<T> safe(final List<T> list) { - if (list == null) { - return Collections.emptyList(); - } - return list; - } -} +/* + * 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.openejb.util; + +import java.util.Collections; +import java.util.List; + +public class CollectionsUtil { + public static <T> List<T> safe(final List<T> list) { + if (list == null) { + return Collections.emptyList(); + } + return list; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/main/java/org/apache/openejb/util/LogStreamAsync.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/LogStreamAsync.java b/container/openejb-core/src/main/java/org/apache/openejb/util/LogStreamAsync.java index f514df8..eabd0c1 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/util/LogStreamAsync.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/util/LogStreamAsync.java @@ -1,224 +1,224 @@ -/* - * 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.openejb.util; - -import java.io.Closeable; -import java.io.IOException; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.atomic.AtomicBoolean; - -public class LogStreamAsync implements LogStream, Closeable { - - private static final LinkedBlockingQueue<Message> log = new LinkedBlockingQueue<Message>(); - private static final Thread t = new Thread(new Consumer(LogStreamAsync.log), "LogStreamAsync.Thread"); - private static final AtomicBoolean started = new AtomicBoolean(false); - private final LogStream ls; - - private enum level { - fatal, - error, - warn, - info, - debug, - quit, - } - - public LogStreamAsync(final LogStream ls) { - this.ls = ls; - - if (!started.getAndSet(true)) { - t.setDaemon(true); - t.start(); - } - } - - @Override - public void close() throws IOException { - LogStreamAsync.log.clear(); - try { - LogStreamAsync.log.put(new Message(this.ls, level.quit, "")); - } catch (final InterruptedException e) { - //Ignore - } - } - - @Override - public boolean isFatalEnabled() { - return ls.isFatalEnabled(); - } - - @Override - public void fatal(final String message) { - this.log(level.fatal, message); - } - - @Override - public void fatal(final String message, final Throwable t) { - this.log(level.fatal, message, t); - } - - @Override - public boolean isErrorEnabled() { - return ls.isErrorEnabled(); - } - - @Override - public void error(final String message) { - this.log(level.error, message); - } - - @Override - public void error(final String message, final Throwable t) { - this.log(level.error, message, t); - } - - @Override - public boolean isWarnEnabled() { - return ls.isWarnEnabled(); - } - - @Override - public void warn(final String message) { - this.log(level.warn, message); - } - - @Override - public void warn(final String message, final Throwable t) { - this.log(level.warn, message, t); - } - - @Override - public boolean isInfoEnabled() { - return ls.isInfoEnabled(); - } - - @Override - public void info(final String message) { - this.log(level.info, message, null); - } - - @Override - public void info(final String message, final Throwable t) { - this.log(level.info, message, null); - } - - @Override - public boolean isDebugEnabled() { - return ls.isDebugEnabled(); - } - - @Override - public void debug(final String message) { - this.log(level.debug, message); - } - - @Override - public void debug(final String message, final Throwable t) { - this.log(level.debug, message, t); - } - - public void log(final level l, final String s) { - this.log(l, s, null); - } - - public void log(final level l, final String s, final Throwable t) { - try { - LogStreamAsync.log.put(new Message(this.ls, l, s, t)); - } catch (final InterruptedException e) { - //Ignore - } - } - - private static final class Message { - - private final LogStream ls; - private final level l; - private final String s; - private final Throwable t; - - private Message(final LogStream ls, final level l, final String s) { - this(ls, l, s, null); - } - - private Message(final LogStream ls, final level l, final String s, final Throwable t) { - this.ls = ls; - this.l = l; - this.s = s; - this.t = t; - } - } - - private static final class Consumer implements Runnable { - - private final BlockingQueue<Message> queue; - - private Consumer(final BlockingQueue<Message> queue) { - this.queue = queue; - } - - public void run() { - - try { - Message msg; - while (!level.quit.equals((msg = queue.take()).l)) { - final Throwable t = msg.t; - - if (null != t) { - switch (msg.l) { - case fatal: - msg.ls.fatal(msg.s, t); - break; - case error: - msg.ls.error(msg.s, t); - break; - case warn: - msg.ls.warn(msg.s, t); - break; - case info: - msg.ls.info(msg.s, t); - break; - case debug: - msg.ls.debug(msg.s, t); - break; - } - } else { - switch (msg.l) { - case fatal: - msg.ls.fatal(msg.s); - break; - case error: - msg.ls.error(msg.s); - break; - case warn: - msg.ls.warn(msg.s); - break; - case info: - msg.ls.info(msg.s); - break; - case debug: - msg.ls.debug(msg.s); - break; - } - } - } - } catch (final InterruptedException e) { - //Exit - } - } - } -} +/* + * 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.openejb.util; + +import java.io.Closeable; +import java.io.IOException; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.atomic.AtomicBoolean; + +public class LogStreamAsync implements LogStream, Closeable { + + private static final LinkedBlockingQueue<Message> log = new LinkedBlockingQueue<Message>(); + private static final Thread t = new Thread(new Consumer(LogStreamAsync.log), "LogStreamAsync.Thread"); + private static final AtomicBoolean started = new AtomicBoolean(false); + private final LogStream ls; + + private enum level { + fatal, + error, + warn, + info, + debug, + quit, + } + + public LogStreamAsync(final LogStream ls) { + this.ls = ls; + + if (!started.getAndSet(true)) { + t.setDaemon(true); + t.start(); + } + } + + @Override + public void close() throws IOException { + LogStreamAsync.log.clear(); + try { + LogStreamAsync.log.put(new Message(this.ls, level.quit, "")); + } catch (final InterruptedException e) { + //Ignore + } + } + + @Override + public boolean isFatalEnabled() { + return ls.isFatalEnabled(); + } + + @Override + public void fatal(final String message) { + this.log(level.fatal, message); + } + + @Override + public void fatal(final String message, final Throwable t) { + this.log(level.fatal, message, t); + } + + @Override + public boolean isErrorEnabled() { + return ls.isErrorEnabled(); + } + + @Override + public void error(final String message) { + this.log(level.error, message); + } + + @Override + public void error(final String message, final Throwable t) { + this.log(level.error, message, t); + } + + @Override + public boolean isWarnEnabled() { + return ls.isWarnEnabled(); + } + + @Override + public void warn(final String message) { + this.log(level.warn, message); + } + + @Override + public void warn(final String message, final Throwable t) { + this.log(level.warn, message, t); + } + + @Override + public boolean isInfoEnabled() { + return ls.isInfoEnabled(); + } + + @Override + public void info(final String message) { + this.log(level.info, message, null); + } + + @Override + public void info(final String message, final Throwable t) { + this.log(level.info, message, null); + } + + @Override + public boolean isDebugEnabled() { + return ls.isDebugEnabled(); + } + + @Override + public void debug(final String message) { + this.log(level.debug, message); + } + + @Override + public void debug(final String message, final Throwable t) { + this.log(level.debug, message, t); + } + + public void log(final level l, final String s) { + this.log(l, s, null); + } + + public void log(final level l, final String s, final Throwable t) { + try { + LogStreamAsync.log.put(new Message(this.ls, l, s, t)); + } catch (final InterruptedException e) { + //Ignore + } + } + + private static final class Message { + + private final LogStream ls; + private final level l; + private final String s; + private final Throwable t; + + private Message(final LogStream ls, final level l, final String s) { + this(ls, l, s, null); + } + + private Message(final LogStream ls, final level l, final String s, final Throwable t) { + this.ls = ls; + this.l = l; + this.s = s; + this.t = t; + } + } + + private static final class Consumer implements Runnable { + + private final BlockingQueue<Message> queue; + + private Consumer(final BlockingQueue<Message> queue) { + this.queue = queue; + } + + public void run() { + + try { + Message msg; + while (!level.quit.equals((msg = queue.take()).l)) { + final Throwable t = msg.t; + + if (null != t) { + switch (msg.l) { + case fatal: + msg.ls.fatal(msg.s, t); + break; + case error: + msg.ls.error(msg.s, t); + break; + case warn: + msg.ls.warn(msg.s, t); + break; + case info: + msg.ls.info(msg.s, t); + break; + case debug: + msg.ls.debug(msg.s, t); + break; + } + } else { + switch (msg.l) { + case fatal: + msg.ls.fatal(msg.s); + break; + case error: + msg.ls.error(msg.s); + break; + case warn: + msg.ls.warn(msg.s); + break; + case info: + msg.ls.info(msg.s); + break; + case debug: + msg.ls.debug(msg.s); + break; + } + } + } + } catch (final InterruptedException e) { + //Exit + } + } + } +}
