[jboss-cvs] JBossAS SVN: r94795 - in projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist: classpool and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 13 17:12:01 EDT 2009
Author: flavia.rainone at jboss.com
Date: 2009-10-13 17:12:01 -0400 (Tue, 13 Oct 2009)
New Revision: 94795
Added:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/ClassPoolFactory.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/DefaultClassPoolFactory.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/RepositoryClassPoolFactory.java
Removed:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/ClassPoolFactory.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/DefaultClassPoolFactory.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/DummyClassPoolFactory.java
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
Log:
[JBREFLECT-58] It was not necessary to add a dependency to the jboss-classpool project. I created a RepositoryClassPoolFactory, that uses ScopedClassPoolRepository in order to create classes. All factories have been moved to org.jboss.reflect.plugins.javassist.classpools.
Plus, JavassistTypeInfoFactoryImpl now has a configurable classpool factory.
Deleted: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/ClassPoolFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/ClassPoolFactory.java 2009-10-13 21:07:19 UTC (rev 94794)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/ClassPoolFactory.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.reflect.plugins.javassist;
-
-import javassist.ClassPool;
-import javassist.scopedpool.ScopedClassPoolRepository;
-
-/**
- * A ClassPoolFactory.
- *
- * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
- * @version $Revision: 1.1 $
- */
-public interface ClassPoolFactory
-{
- /**
- * Get class pool for class loader.
- *
- * @param cl the classloader
- * @return class pool instance
- */
- public ClassPool getPoolForLoader(ClassLoader cl);
-}
Deleted: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/DefaultClassPoolFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/DefaultClassPoolFactory.java 2009-10-13 21:07:19 UTC (rev 94794)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/DefaultClassPoolFactory.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -1,46 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.reflect.plugins.javassist;
-
-import javassist.ClassPool;
-
-/**
- * A default class pool factory. Creates instances of {@code javassist.ClassPool}.
- *
- * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
- * @version $Revision: 1.1 $
- */
-public class DefaultClassPoolFactory implements ClassPoolFactory
-{
-
- public ClassPool create(ClassLoader cl)
- {
- return ClassPool.getDefault();
- }
-
- public ClassPool create(ClassLoader cl, ClassPool parentPool)
- {
- return new ClassPool(parentPool);
- }
-
- public ClassPool getPoolForLoader(ClassLoader cl){return null;}
-}
\ No newline at end of file
Deleted: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/DummyClassPoolFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/DummyClassPoolFactory.java 2009-10-13 21:07:19 UTC (rev 94794)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/DummyClassPoolFactory.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.reflect.plugins.javassist;
-
-import javassist.ClassPool;
-
-import org.jboss.reflect.plugins.javassist.ClassPoolFactory;
-
-/**
- * A DummyClassPoolFactory.
- *
- * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
- * @version $Revision: 1.1 $
- */
-public class DummyClassPoolFactory implements ClassPoolFactory
-{
-
- public ClassPool getPoolForLoader(ClassLoader cl)
- {
- return ClassPool.getDefault();
- }
-
-}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java 2009-10-13 21:07:19 UTC (rev 94794)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -79,8 +79,8 @@
*/
public JavassistMethod createMethod(CtMethod ctMethod) throws Throwable
{
- //TODO JBREFLECT-58: Fix this to use a more reasonable factory
- ClassPool pool = JavassistTypeInfoFactoryImpl.poolFactory.getPoolForLoader(null);
+ //TODO shouldn't we provide a not null class loader?
+ ClassPool pool = JavassistTypeInfoFactoryImpl.getPoolFactory().getPoolForLoader(null);
final CtClass result = pool.makeClass(JavassistMethod.class.getName() + counter.incrementAndGet());
/* TODO JBREFLECT-2 figure out how to do this on all JDKs
try
@@ -261,8 +261,8 @@
*/
public JavassistConstructor createConstructor(CtConstructor ctConstructor) throws Throwable
{
- //TODO: FIx this to use a more reasonable factory
- ClassPool pool = JavassistTypeInfoFactoryImpl.poolFactory.getPoolForLoader(null);
+ //TODO: Should we provide a non-null class loader?
+ ClassPool pool = JavassistTypeInfoFactoryImpl.getPoolFactory().getPoolForLoader(null);
final CtClass result = pool.makeClass(JavassistConstructor.class.getName() + counter.incrementAndGet());
try
{
@@ -388,8 +388,8 @@
*/
public JavassistField createField(CtField ctField) throws Throwable
{
- // Fix this to use a better pool factory
- ClassPool pool = JavassistTypeInfoFactoryImpl.poolFactory.getPoolForLoader(null);
+ // TODO should we provide a non-null class loader?
+ ClassPool pool = JavassistTypeInfoFactoryImpl.getPoolFactory().getPoolForLoader(null);
final CtClass result = pool.makeClass(JavassistField.class.getName() + counter.incrementAndGet());
// TODO JBREFLECT-2
try
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2009-10-13 21:07:19 UTC (rev 94794)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -253,7 +253,7 @@
for(int i=0; i<parameters.length;i++)
{
typeParams[i] = factory.getTypeInfo(parameters[i],
- JavassistTypeInfoFactoryImpl.poolFactory.getPoolForLoader(null).getClassLoader());
+ JavassistTypeInfoFactoryImpl.getPoolFactory().getPoolForLoader(null).getClassLoader());
}
return getDeclaredConstructor(typeParams);
}
@@ -331,7 +331,7 @@
for(int i=0; i<parameters.length;i++)
{
typeParams[i] = factory.getTypeInfo(parameters[i],
- JavassistTypeInfoFactoryImpl.poolFactory.getPoolForLoader(null).getClassLoader());
+ JavassistTypeInfoFactoryImpl.getPoolFactory().getPoolForLoader(null).getClassLoader());
}
return getDeclaredMethod(methodName, typeParams);
}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java 2009-10-13 21:07:19 UTC (rev 94794)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -32,15 +32,17 @@
import javassist.CtMethod;
import javassist.CtPrimitiveType;
import javassist.NotFoundException;
+
import org.jboss.reflect.plugins.AnnotationAttributeImpl;
import org.jboss.reflect.plugins.AnnotationHelper;
import org.jboss.reflect.plugins.AnnotationValueFactory;
import org.jboss.reflect.plugins.AnnotationValueImpl;
import org.jboss.reflect.plugins.EnumConstantInfoImpl;
+import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
+import org.jboss.reflect.plugins.javassist.classpool.DefaultClassPoolFactory;
import org.jboss.reflect.spi.AnnotationInfo;
import org.jboss.reflect.spi.AnnotationValue;
import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.plugins.javassist.ClassPoolFactory;
import org.jboss.reflect.spi.MutableClassInfo;
import org.jboss.reflect.spi.MutableTypeInfoFactory;
import org.jboss.reflect.spi.NumberInfo;
@@ -57,9 +59,18 @@
*/
public class JavassistTypeInfoFactoryImpl extends WeakClassCache implements MutableTypeInfoFactory, AnnotationHelper
{
- //TODO JBREFLECT-58: Need to change this to a usable CPF.
- static final ClassPoolFactory poolFactory = new DummyClassPoolFactory();
+ private static ClassPoolFactory poolFactory = DefaultClassPoolFactory.getInstance();
+ public static ClassPoolFactory getPoolFactory()
+ {
+ return poolFactory;
+ }
+
+ public static void setPoolFactory(ClassPoolFactory classPoolFactory)
+ {
+ poolFactory = classPoolFactory;
+ }
+
static final AnnotationValue[] NO_ANNOTATIONS = new AnnotationValue[0];
/**
* Raise NoClassDefFoundError for javassist not found
Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/ClassPoolFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/ClassPoolFactory.java (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/ClassPoolFactory.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.reflect.plugins.javassist.classpool;
+
+import javassist.ClassPool;
+
+/**
+ * A ClassPoolFactory.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ *
+ * @version $Revision$
+ */
+public interface ClassPoolFactory
+{
+ /**
+ * Get class pool for class loader.
+ *
+ * @param cl the classloader
+ * @return class pool instance
+ */
+ public ClassPool getPoolForLoader(ClassLoader classLoader);
+}
Property changes on: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/ClassPoolFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/DefaultClassPoolFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/DefaultClassPoolFactory.java (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/DefaultClassPoolFactory.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.reflect.plugins.javassist.classpool;
+
+
+import javassist.ClassPool;
+
+/**
+ * A default class pool factory. Obtains the default instance of {@code javassist.ClassPool}.
+ *
+ * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision$
+ * @see ClassPool#getDefault()
+ */
+public class DefaultClassPoolFactory implements ClassPoolFactory
+{
+ public static final DefaultClassPoolFactory INSTANCE = new DefaultClassPoolFactory();
+
+ public static final DefaultClassPoolFactory getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private DefaultClassPoolFactory() {}
+
+ public ClassPool getPoolForLoader(ClassLoader cl)
+ {
+ return ClassPool.getDefault();
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/DefaultClassPoolFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/RepositoryClassPoolFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/RepositoryClassPoolFactory.java (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/RepositoryClassPoolFactory.java 2009-10-13 21:12:01 UTC (rev 94795)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.reflect.plugins.javassist.classpool;
+
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+/**
+ * This ClassPoolFactory is tailored for use with scoped class pools.
+ * In order to retrieve a ClassPool, this factory registers the
+ * corresponding ClassLoader with
+ * {@link ScopedClassPoolRepository#registerClassLoader(ClassLoader)}.
+ * For that reason, it is important to register a ScopedClassPoolFactory
+ * ({@link ScopedClassPoolRepository#setClassPoolFactory(javassist.scopedpool.ScopedClassPoolFactory))
+ * prior to using this factory.
+ *
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ *
+ * @version $Revision$
+ * @see ScopedClassPoolRepository#registerClassLoader(ClassLoader)
+ */
+public class RepositoryClassPoolFactory implements ClassPoolFactory
+{
+ private ScopedClassPoolRepository classPoolRepository;
+
+ public RepositoryClassPoolFactory(ScopedClassPoolRepository classPoolRepository)
+ {
+ this.classPoolRepository = classPoolRepository;
+ }
+
+ public ClassPool getPoolForLoader(ClassLoader cl)
+ {
+ return classPoolRepository.registerClassLoader(cl);
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/classpool/RepositoryClassPoolFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list