You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2011/04/14 00:22:37 UTC

svn commit: r1091935 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5: internal/services/ComponentInstantiatorSource.java internal/services/ComponentInstantiatorSourceImpl.java services/TapestryModule.java

Author: hlship
Date: Wed Apr 13 22:22:37 2011
New Revision: 1091935

URL: http://svn.apache.org/viewvc?rev=1091935&view=rev
Log:
TAP5-853: Introduce a @ComponentLayer PlasticProxyFactory service

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java?rev=1091935&r1=1091934&r2=1091935&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSource.java Wed Apr 13 22:22:37 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+// 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,
@@ -16,6 +16,7 @@ package org.apache.tapestry5.internal.se
 
 import org.apache.tapestry5.ioc.internal.services.CtClassSource;
 import org.apache.tapestry5.ioc.services.ClassFactory;
+import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
 import org.apache.tapestry5.services.InvalidationEventHub;
 
 /**
@@ -37,23 +38,26 @@ public interface ComponentInstantiatorSo
      * repeated calls to this method with the same class name will return the same instance; however, callers should
      * also be aware that the instantiators may lose validity after an invalidation (caused by changes to external Java
      * class files).
-     *
-     * @param classname FQCN to find (and perhaps transform and load)
+     * 
+     * @param classname
+     *            FQCN to find (and perhaps transform and load)
      * @return an object which can instantiate an instance of the component
      */
     Instantiator getInstantiator(String classname);
 
     /**
      * Adds a controlled package. Only classes within controlled packages are subject to transformation.
-     *
-     * @param packageName the package name to add (must not be blank)
+     * 
+     * @param packageName
+     *            the package name to add (must not be blank)
      */
     void addPackage(String packageName);
 
     /**
      * Checks to see if a fully qualfied class name exists. This method appears to exist only for testing.
-     *
-     * @param className name of class to check
+     * 
+     * @param className
+     *            name of class to check
      * @return true if the class exists (there's a ".class" file), false otherwise
      */
     boolean exists(String className);
@@ -65,13 +69,21 @@ public interface ComponentInstantiatorSo
     ClassFactory getClassFactory();
 
     /**
+     * Returns a proxy factory that can be used to generate additional classes around enhanced classes, or create
+     * subclasses of enhanced classes.
+     * 
+     * @since 5.3.0
+     */
+    PlasticProxyFactory getProxyFactory();
+
+    /**
      * Returns a class source used when creating new classes dynamically.
      */
     CtClassSource getClassSource();
 
     /**
      * Invalidation event hub used to notify listeners that component classes have changed.
-     *
+     * 
      * @see org.apache.tapestry5.services.ComponentClasses
      * @since 5.1.0.0
      */

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java?rev=1091935&r1=1091934&r2=1091935&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java Wed Apr 13 22:22:37 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -33,12 +33,14 @@ import org.apache.tapestry5.ioc.internal
 import org.apache.tapestry5.ioc.internal.services.ClassFactoryImpl;
 import org.apache.tapestry5.ioc.internal.services.CtClassSource;
 import org.apache.tapestry5.ioc.internal.services.CtClassSourceImpl;
+import org.apache.tapestry5.ioc.internal.services.PlasticProxyFactoryImpl;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.services.ClassFabUtils;
 import org.apache.tapestry5.ioc.services.ClassFactory;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
+import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
 import org.apache.tapestry5.services.InvalidationEventHub;
 import org.apache.tapestry5.services.UpdateListener;
 import org.slf4j.Logger;
@@ -71,6 +73,8 @@ public final class ComponentInstantiator
 
     private ClassFactory classFactory;
 
+    private PlasticProxyFactory proxyFactory;
+
     /**
      * Map from class name to Instantiator.
      */
@@ -171,6 +175,8 @@ public final class ComponentInstantiator
 
         classFactory = new ClassFactoryImpl(loader, classPool, classSource, logger);
 
+        proxyFactory = new PlasticProxyFactoryImpl(classFactory, loader);
+
         classToPriorTransformException.clear();
     }
 
@@ -359,6 +365,11 @@ public final class ComponentInstantiator
         return classFactory;
     }
 
+    public PlasticProxyFactory getProxyFactory()
+    {
+        return proxyFactory;
+    }
+
     public CtClassSource getClassSource()
     {
         return classSource;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=1091935&r1=1091934&r2=1091935&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Wed Apr 13 22:22:37 2011
@@ -201,6 +201,7 @@ import org.apache.tapestry5.ioc.services
 import org.apache.tapestry5.ioc.services.MasterObjectProvider;
 import org.apache.tapestry5.ioc.services.PerthreadManager;
 import org.apache.tapestry5.ioc.services.PipelineBuilder;
+import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
 import org.apache.tapestry5.ioc.services.PropertyAccess;
 import org.apache.tapestry5.ioc.services.PropertyShadowBuilder;
 import org.apache.tapestry5.ioc.services.StrategyBuilder;
@@ -1594,6 +1595,19 @@ public final class TapestryModule
     }
 
     /**
+     * Returns a {@link PlasticProxyFactory} that can be used to create extra classes around component classes. This
+     * factory will be cleared whenever an underlying component class is discovered to have changed. Use of this
+     * factory implies that your code will become aware of this (if necessary) to discard any cached object (alas,
+     * this currently involves dipping into the internals side to register for the correct notifications). Failure to
+     * properly clean up can result in really nasty PermGen space memory leaks.
+     */
+    @Marker(ComponentLayer.class)
+    public PlasticProxyFactory buildComponentProxyFactory(ComponentInstantiatorSource source)
+    {
+        return shadowBuilder.build(source, "proxyFactory", PlasticProxyFactory.class);
+    }
+
+    /**
      * Ordered contributions to the MasterDispatcher service allow different URL
      * matching strategies to occur.
      */