geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: svn commit: r124822 - Includes capability to save enhanced classes in DeploymentContext
Date Mon, 10 Jan 2005 19:33:36 GMT
I accidentally committed these changes to allow you to save an enhanced  
class in the deployment context with the GERONIMO-450 changes.  You can  
see how to set up an Enhancer and save the class in the  
DeploymentContextTest.

thanks
david jencks

On Jan 10, 2005, at 11:01 AM, djencks@apache.org wrote:

> Author: djencks
> Date: Mon Jan 10 11:01:13 2005
> New Revision: 124822
>
> URL: http://svn.apache.org/viewcvs?view=rev&rev=124822
> Log:
> Partial implementation of GERONIMO-450. GBean names are (mostly)  
> constructed like jsr-77 names and xml config usually only needs to  
> specify namePart and optionally type
> Added:
<snip>
>     
> geronimo/trunk/modules/deployment/src/test/org/apache/geronimo/ 
> deployment/DeploymentContextTest.java
> Modified:
<snip>
>    geronimo/trunk/modules/deployment/project.xml
>     
> geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/ 
> deployment/DeploymentContext.java

>
> Modified: geronimo/trunk/modules/deployment/project.xml
> Url:  
> http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/ 
> project.xml?view=diff&rev=124822&p1=geronimo/trunk/modules/deployment/ 
> project.xml&r1=124821&p2=geronimo/trunk/modules/deployment/ 
> project.xml&r2=124822
> ======================================================================= 
> =======
> --- geronimo/trunk/modules/deployment/project.xml	(original)
> +++ geronimo/trunk/modules/deployment/project.xml	Mon Jan 10 11:01:13  
> 2005
> @@ -72,6 +72,13 @@
>          </dependency>
>
>          <dependency>
> +            <groupId>cglib</groupId>
> +            <artifactId>cglib-full</artifactId>
> +            <version>${cglib_version}</version>
> +            <url>http://cglib.sf.net/</url>
> +        </dependency>
> +
> +        <dependency>
>              <groupId>commons-logging</groupId>
>              <artifactId>commons-logging</artifactId>
>              <version>${commons_logging_version}</version>
>
> Modified:  
> geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/ 
> deployment/DeploymentContext.java
> Url:  
> http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/ 
> java/org/apache/geronimo/deployment/DeploymentContext.java? 
> view=diff&rev=124822&p1=geronimo/trunk/modules/deployment/src/java/ 
> org/apache/geronimo/deployment/ 
> DeploymentContext.java&r1=124821&p2=geronimo/trunk/modules/deployment/ 
> src/java/org/apache/geronimo/deployment/ 
> DeploymentContext.java&r2=124822
> ======================================================================= 
> =======
> ---  
> geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/ 
> deployment/DeploymentContext.java	(original)
> +++  
> geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/ 
> deployment/DeploymentContext.java	Mon Jan 10 11:01:13 2005
> @@ -189,6 +189,10 @@
>          gbeans.put(gbean.getName(), gbean);
>      }
>
> +    public Set getGBeanNames() {
> +        return Collections.unmodifiableSet(gbeans.keySet());
> +    }
> +
>      public void addDependency(URI uri) {
>          dependencies.add(uri);
>      }
> @@ -337,6 +341,12 @@
>          addFile(getTargetFile(targetPath), new  
> ByteArrayInputStream(source.getBytes()));
>      }
>
> +    public void addClass(URI location, String fqcn, byte[] bytes)  
> throws IOException, URISyntaxException {
> +        classPath.add(location);
> +        String classFileName = fqcn.replace('.', '/') + ".class";
> +        addFile(getTargetFile(new URI(location.toString() + "/" +  
> classFileName)), new ByteArrayInputStream(bytes));
> +    }
> +
>      private void addFile(File targetFile, ZipFile zipFile, ZipEntry  
> zipEntry) throws IOException {
>          if (zipEntry.isDirectory()) {
>              targetFile.mkdirs();
> @@ -462,7 +472,7 @@
>                  }
>              }
>              config.setAttribute("gBeanState",  
> Configuration.storeGBeans(gbeanArray));
> -            config.setReferencePatterns("Repositories",  
> Collections.singleton(new ObjectName("*:role=Repository,*")));
> +            config.setReferencePatterns("Repositories",  
> Collections.singleton(new ObjectName("*:name=Repository,*")));
>              config.setAttribute("dependencies", new  
> ArrayList(dependencies));
>              config.setAttribute("classPath", new  
> ArrayList(classPath));
>          } catch (Exception e) {
>
> Added:  
> geronimo/trunk/modules/deployment/src/test/org/apache/geronimo/ 
> deployment/DeploymentContextTest.java
> Url:  
> http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/ 
> test/org/apache/geronimo/deployment/DeploymentContextTest.java? 
> view=auto&rev=124822
> ======================================================================= 
> =======
> --- (empty file)
> +++  
> geronimo/trunk/modules/deployment/src/test/org/apache/geronimo/ 
> deployment/DeploymentContextTest.java	Mon Jan 10 11:01:13 2005
> @@ -0,0 +1,77 @@
> +/**
> + *
> + * Copyright 2003-2004 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
> + *
> + *  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.geronimo.deployment;
> +
> +import java.io.File;
> +import java.net.URI;
> +import java.net.URLClassLoader;
> +import java.net.URL;
> +
> +import javax.sql.DataSource;
> +
> +import org.apache.geronimo.kernel.config.ConfigurationModuleType;
> +import net.sf.cglib.proxy.Enhancer;
> +import net.sf.cglib.proxy.MethodInterceptor;
> +import net.sf.cglib.core.DefaultGeneratorStrategy;
> +import junit.framework.TestCase;
> +
> +/**
> + * @version $Rev$ $Date$
> + */
> +public class DeploymentContextTest extends TestCase {
> +    private byte[] classBytes;
> +
> +    public void testAddClass() throws Exception {
> +        File basedir = File.createTempFile("car", "tmp");
> +        basedir.delete();
> +        basedir.mkdirs();
> +        try {
> +            basedir.deleteOnExit();
> +            URI configID = new URI("test");
> +            DeploymentContext context = new  
> DeploymentContext(basedir, configID, ConfigurationModuleType.CAR,  
> null, null);
> +            Enhancer enhancer = new Enhancer();
> +            enhancer.setInterfaces(new Class[]{DataSource.class});
> +            enhancer.setCallbackType(MethodInterceptor.class);
> +            enhancer.setStrategy(new DefaultGeneratorStrategy() {
> +                public byte[] transform(byte[] b) {
> +                    classBytes = b;
> +                    return b;
> +                }
> +            });
> +            enhancer.setClassLoader(new URLClassLoader(new URL[0],  
> this.getClass().getClassLoader()));
> +            Class type = enhancer.createClass();
> +            URI location = new URI("cglib");
> +            context.addClass(location, type.getName(), classBytes);
> +            ClassLoader cl = context.getClassLoader(null);
> +            Class loadedType = cl.loadClass(type.getName());
> +            assertTrue(DataSource.class.isAssignableFrom(loadedType));
> +            assertTrue(type != loadedType);
> +        } finally {
> +            recursiveDelete(basedir);
> +        }
> +    }
> +
> +    private void recursiveDelete(File file) {
> +        if (file.isDirectory()) {
> +            File[] files = file.listFiles();
> +            for (int i = 0; i < files.length; i++) {
> +                recursiveDelete(files[i]);
> +            }
> +        }
> +        file.delete();
> +    }
> +}


Mime
View raw message