/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2011, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.as.ee.component;

import org.jboss.as.naming.JndiInjectable;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
import org.jboss.invocation.Interceptors;
import org.jboss.invocation.proxy.ProxyFactory;

/**
 * A single view of a component.  This will return a proxy to of a single instance of the component.  The proxy will
 * be based on the provided view interface.
 *
 * @author John Bailey
 */
public class ComponentView implements JndiInjectable {

    private final Class<?> viewClass;
    private final ProxyFactory<?> proxyFactory;
    private final ProxyInvocationHandler proxyInvocationHandler;

    /**
     * Construct a new instance.
     *
     * @param component the component for this view
     * @param viewClass the view class
     * @param proxyFactory the proxy factory
     */
    public ComponentView(final AbstractComponent component, final Class<?> viewClass, final ProxyFactory<?> proxyFactory) {
        this.viewClass = viewClass;
        this.proxyFactory = proxyFactory;
        proxyInvocationHandler = new ProxyInvocationHandler(new InterceptorFactory() {
            public Interceptor create(final InterceptorFactoryContext context) {
                return Interceptors.getChainedInterceptor(component.createClientInterceptor(viewClass), component.getComponentInterceptor());
            }
        });
    }

    /** {@inheritDoc} */
    public Object getInjectedValue() {
        try {
            return viewClass.cast(proxyFactory.newInstance(proxyInvocationHandler));
        } catch (InstantiationException e) {
            throw new InstantiationError(e.getMessage());
        } catch (IllegalAccessException e) {
            throw new IllegalAccessError(e.getMessage());
        }
    }

    /** {@inheritDoc} */
    public void returnInjectedValue(final Object injectedValue) {
//        component.returnValue(injectedValue);
    }
}

@@ -1690,53 +1690,35 @@
 nal 
-ProxyInvocationHandler proxyInvocationHandler
+AbstractComponent component
 ;%0A%0A 
@@ -2122,33 +2122,180 @@
     
-proxyInvocationHandler = 
+this.component = component;%0A    %7D%0A%0A    /** %7B@inheritDoc%7D */%0A    public Object getInjectedValue() %7B%0A        try %7B%0A            return viewClass.cast(proxyFactory.newInstance(
 new 
@@ -2352,24 +2352,28 @@
             
+ 
+   
 public Inter
@@ -2425,24 +2425,28 @@
  context) %7B%0A
+    
             
@@ -2591,188 +2591,28 @@
     
-%7D%0A        %7D);
+    %7D
 %0A    
-%7D%0A%0A
     
-/** %7B@inheritDoc%7D */%0A    public Object getInjectedValue() %7B%0A        try %7B%0A            return viewClass.cast(proxyFactory.newInstance(proxyInvocationHandler
+    %7D)
 ));%0A

Create a new invocation handler per proxy