@ BeanStoreFilter see http://s.apache.org/Gx0

2012/8/5 <[email protected]>

> Updated Branches:
>   refs/heads/master b3f9509cd -> 0006638cc
>
>
> Revert "DELTASPIKE-258 ProxyUtils, use proxy to filter calls"
>
> This reverts commit b3f9509cd9947026f85403ce4190a8759719556d.
>
> We don't need that! A user can just startApplication again.
> I also HATE utility classes which just wraps 1 liners.
> We shall NOT overcomplicate such things!
>
>
> Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/0006638c
> Tree:
> http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/0006638c
> Diff:
> http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/0006638c
>
> Branch: refs/heads/master
> Commit: 0006638cc39413b50c8e9dea11ffbb2218774a71
> Parents: a9211aa
> Author: Mark Struberg <[email protected]>
> Authored: Sun Aug 5 13:30:30 2012 +0200
> Committer: Mark Struberg <[email protected]>
> Committed: Sun Aug 5 13:30:30 2012 +0200
>
> ----------------------------------------------------------------------
>  .../deltaspike/cdise/weld/BeanStoreFilter.java     |   48 ---------
>  .../deltaspike/cdise/weld/ContextController.java   |   33 ++++++-
>  .../apache/deltaspike/cdise/weld/ProxyUtils.java   |   77 ---------------
>  .../impl/message/TypedMessageBundleProducer.java   |   16 +++-
>  .../deltaspike/core/impl/util/ProxyUtils.java      |   43 --------
>  5 files changed, 44 insertions(+), 173 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/0006638c/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/BeanStoreFilter.java
> ----------------------------------------------------------------------
> diff --git
> a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/BeanStoreFilter.java
> b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/BeanStoreFilter.java
> deleted file mode 100644
> index 7d793f5..0000000
> ---
> a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/BeanStoreFilter.java
> +++ /dev/null
> @@ -1,48 +0,0 @@
> -/*
> - * 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.deltaspike.cdise.weld;
> -
> -import org.jboss.weld.context.beanstore.BeanStore;
> -
> -import java.lang.reflect.InvocationHandler;
> -import java.lang.reflect.Method;
> -
> -/**
> - * Method filter - needed to fix WELD-1072
> - */
> -public class BeanStoreFilter implements InvocationHandler
> -{
> -    private final BeanStore wrapped;
> -
> -    public BeanStoreFilter(BeanStore wrapped)
> -    {
> -        this.wrapped = wrapped;
> -    }
> -
> -    @Override
> -    public Object invoke(Object proxy, Method method, Object[] args)
> throws Throwable
> -    {
> -        if ("clear".equals(method.getName()) &&
> method.getParameterTypes().length == 0)
> -        {
> -            return null;
> -        }
> -
> -        return method.invoke(this.wrapped, args);
> -    }
> -}
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/0006638c/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
> ----------------------------------------------------------------------
> diff --git
> a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
> b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
> index b7c0486..dec1d0c 100644
> ---
> a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
> +++
> b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ContextController.java
> @@ -100,7 +100,38 @@ public class ContextController
>                  final BeanStore beanStore = beanStoreHolder.get();
>                  originalBeanStore = beanStore;
>
> -
>  beanStoreHolder.set(ProxyUtils.createProxy(BeanStore.class, new
> BeanStoreFilter(beanStore)));
> +                beanStoreHolder.set(new BeanStore()
> +                {
> +                    @Override
> +                    public <T> ContextualInstance<T> get(String id)
> +                    {
> +                        return beanStore.get(id);
> +                    }
> +
> +                    @Override
> +                    public boolean contains(String id)
> +                    {
> +                        return beanStore.contains(id);
> +                    }
> +
> +                    @Override
> +                    public void clear()
> +                    {
> +                        //do nothing
> +                    }
> +
> +                    @Override
> +                    public Iterator<String> iterator()
> +                    {
> +                        return beanStore.iterator();
> +                    }
> +
> +                    @Override
> +                    public <T> void put(String id, ContextualInstance<T>
> contextualInstance)
> +                    {
> +                        beanStore.put(id, contextualInstance);
> +                    }
> +                });
>              }
>              catch (Exception e)
>              {
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/0006638c/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ProxyUtils.java
> ----------------------------------------------------------------------
> diff --git
> a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ProxyUtils.java
> b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ProxyUtils.java
> deleted file mode 100644
> index 6b1d009..0000000
> ---
> a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/ProxyUtils.java
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -/*
> - * 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.deltaspike.cdise.weld;
> -
> -import javax.enterprise.inject.Typed;
> -import java.lang.reflect.InvocationHandler;
> -import java.lang.reflect.Proxy;
> -
> -/**
> - * This is the internal helper class for JDK proxies
> - * TODO remove it and use org.apache.deltaspike.core.impl.util.ProxyUtils
> instead (discussion needed)
> - */
> -
> -@Typed()
> -abstract class ProxyUtils
> -{
> -    private ProxyUtils()
> -    {
> -        // prevent instantiation
> -    }
> -
> -    static <T> T createProxy(Class<T> type, InvocationHandler
> invocationHandler)
> -    {
> -        return type.cast(Proxy.newProxyInstance(getClassLoader(null),
> -                new Class<?>[]{type}, invocationHandler));
> -    }
> -
> -    private static ClassLoader getClassLoader(Object o)
> -    {
> -        return getClassLoaderInternal(o);
> -
> -        //TODO if we don't introduce the dependency to core, we have to
> copy GetClassLoaderAction as well
> -        /*
> -        if (System.getSecurityManager() != null)
> -        {
> -            return AccessController.doPrivileged(new
> GetClassLoaderAction(o));
> -        }
> -        else
> -        {
> -            return getClassLoaderInternal(o);
> -        }
> -        */
> -    }
> -
> -    private static ClassLoader getClassLoaderInternal(Object o)
> -    {
> -        ClassLoader loader =
> Thread.currentThread().getContextClassLoader();
> -
> -        if (loader == null && o != null)
> -        {
> -            loader = o.getClass().getClassLoader();
> -        }
> -
> -        if (loader == null)
> -        {
> -            loader = ProxyUtils.class.getClassLoader();
> -        }
> -
> -        return loader;
> -    }
> -}
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/0006638c/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
> ----------------------------------------------------------------------
> diff --git
> a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
> b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
> index 6ff976e..466d404 100644
> ---
> a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
> +++
> b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
> @@ -18,13 +18,15 @@
>   */
>  package org.apache.deltaspike.core.impl.message;
>
> -import org.apache.deltaspike.core.impl.util.ProxyUtils;
> +import static org.apache.deltaspike.core.util.ReflectionUtils.getRawType;
> +
> +import java.io.Serializable;
> +import java.lang.reflect.Proxy;
>
>  import javax.enterprise.inject.Produces;
>  import javax.enterprise.inject.spi.InjectionPoint;
> -import java.io.Serializable;
>
> -import static org.apache.deltaspike.core.util.ReflectionUtils.getRawType;
> +import org.apache.deltaspike.core.util.ClassUtils;
>
>  /**
>   * The <code>TypedMessageBundleProducer</code> provides a producer method
> for
> @@ -39,6 +41,12 @@ public class TypedMessageBundleProducer implements
> Serializable
>      @SuppressWarnings("UnusedDeclaration")
>      Object produceTypedMessageBundle(InjectionPoint injectionPoint)
>      {
> -        return
> ProxyUtils.createProxy(getRawType(injectionPoint.getType()), new
> MessageBundleInvocationHandler());
> +        return
> createMessageBundleProxy(getRawType(injectionPoint.getType()));
> +    }
> +
> +    private <T> T createMessageBundleProxy(Class<T> type)
> +    {
> +        return
> type.cast(Proxy.newProxyInstance(ClassUtils.getClassLoader(null),
> +                new Class<?>[]{type}, new
> MessageBundleInvocationHandler()));
>      }
>  }
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/0006638c/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/util/ProxyUtils.java
> ----------------------------------------------------------------------
> diff --git
> a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/util/ProxyUtils.java
> b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/util/ProxyUtils.java
> deleted file mode 100644
> index ae0ab74..0000000
> ---
> a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/util/ProxyUtils.java
> +++ /dev/null
> @@ -1,43 +0,0 @@
> -/*
> - * 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.deltaspike.core.impl.util;
> -
> -import org.apache.deltaspike.core.util.ClassUtils;
> -
> -import javax.enterprise.inject.Typed;
> -import java.lang.reflect.InvocationHandler;
> -import java.lang.reflect.Proxy;
> -
> -/**
> - * This is the internal helper class for JDK proxies
> - */
> -@Typed()
> -public abstract class ProxyUtils
> -{
> -    private ProxyUtils()
> -    {
> -        // prevent instantiation
> -    }
> -
> -    public static <T> T createProxy(Class<T> type, InvocationHandler
> invocationHandler)
> -    {
> -        return
> type.cast(Proxy.newProxyInstance(ClassUtils.getClassLoader(null),
> -                new Class<?>[]{type}, invocationHandler));
> -    }
> -}
>
>

Reply via email to