[weld-commits] Weld SVN: r6301 - in core/trunk/impl/src/main/java/org/jboss/weld: bean/proxy/util and 1 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Mon May 24 13:39:48 EDT 2010
Author: dallen6
Date: 2010-05-24 13:39:47 -0400 (Mon, 24 May 2010)
New Revision: 6301
Added:
core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/SerializableProxy.java
Log:
Fixed serialization problem with proxies
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java 2010-05-24 16:45:51 UTC (rev 6300)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java 2010-05-24 17:39:47 UTC (rev 6301)
@@ -56,7 +56,7 @@
this.delegateInjectionPoint = delegateInjectionPoint;
try
{
- delegateClass = classPool.get(((Class<?>) delegateInjectionPoint.getBaseType()).getName());
+ delegateClass = getClassPool().get(((Class<?>) delegateInjectionPoint.getBaseType()).getName());
}
catch (NotFoundException e)
{
@@ -77,7 +77,7 @@
{
try
{
- CtClass baseType = classPool.get(beanType.getName());
+ CtClass baseType = getClassPool().get(getBeanType().getName());
for (CtConstructor constructor : baseType.getConstructors())
{
int delegateInjectionPosition = getDelegateInjectionPosition(constructor);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java 2010-05-24 16:45:51 UTC (rev 6300)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java 2010-05-24 17:39:47 UTC (rev 6301)
@@ -71,7 +71,7 @@
// Add methods for the EnterpriseBeanInstance interface
try
{
- CtClass enterpriseBeanInstanceInterface = classPool.get(EnterpriseBeanInstance.class.getName());
+ CtClass enterpriseBeanInstanceInterface = getClassPool().get(EnterpriseBeanInstance.class.getName());
proxyClassType.addInterface(enterpriseBeanInstanceInterface);
for (CtMethod method : enterpriseBeanInstanceInterface.getDeclaredMethods())
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java 2010-05-24 16:45:51 UTC (rev 6300)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java 2010-05-24 17:39:47 UTC (rev 6301)
@@ -65,11 +65,11 @@
// Default proxy class name suffix
public static final String PROXY_SUFFIX = "Proxy";
- protected final Class<?> beanType;
- protected final ArrayList<Class<?>> additionalInterfaces = new ArrayList<Class<?>>();
- protected final ClassLoader classLoader;
- protected final ProtectionDomain protectionDomain;
- protected final ClassPool classPool;
+ private final Class<?> beanType;
+ private final ArrayList<Class<?>> additionalInterfaces = new ArrayList<Class<?>>();
+ private final ClassLoader classLoader;
+ private final ProtectionDomain protectionDomain;
+ private final ClassPool classPool;
/**
* Creates a new proxy factory from any type of BeanInstance. This bean
@@ -318,7 +318,7 @@
}
/**
- * Adds special serialization code be providing a writeReplace() method on
+ * Adds special serialization code by providing a writeReplace() method on
* the proxy. This method when first called will substitute the proxy
* object with an instance of {@link org.jboss.weld.proxy.util.SerializableProxy}.
* The next call will receive the proxy object itself permitting the substitute
@@ -515,4 +515,14 @@
return bodyString.toString();
}
+ public ClassPool getClassPool()
+ {
+ return classPool;
+ }
+
+ public Class<?> getBeanType()
+ {
+ return beanType;
+ }
+
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/SerializableProxy.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/SerializableProxy.java 2010-05-24 16:45:51 UTC (rev 6300)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/SerializableProxy.java 2010-05-24 17:39:47 UTC (rev 6301)
@@ -52,6 +52,7 @@
// The wrapped proxy object not serialized by default actions
private transient Object proxyObject;
+ private transient boolean writeProxy;
public SerializableProxy(Object proxyObject)
{
@@ -75,9 +76,8 @@
private void writeObject(ObjectOutputStream out) throws IOException
{
out.defaultWriteObject();
- // Must use another OO stream since the proxy was replaced in the original
- ObjectOutputStream out2 = new ObjectOutputStream(out);
- out2.writeObject(proxyObject);
+ writeProxy = true;
+ out.writeUnshared(this);
}
/**
@@ -91,8 +91,6 @@
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
in.defaultReadObject();
- // Must use another OO stream per writeObject() above
- ObjectInputStream in2 = new ObjectInputStream(in);
Class<?> proxyBeanType = Container.instance().services().get(ProxyServices.class).loadProxySuperClass(proxySuperClassName);
Class<?> proxyClass = null;
if (proxyClassName.endsWith(ProxyFactory.PROXY_SUFFIX))
@@ -106,7 +104,7 @@
}
try
{
- proxyObject = proxyClass.getDeclaredMethod("deserializeProxy", ObjectInputStream.class).invoke(null, in2);
+ proxyObject = proxyClass.getDeclaredMethod("deserializeProxy", ObjectInputStream.class).invoke(null, in);
}
catch (Exception e)
{
@@ -125,6 +123,11 @@
return proxyObject;
}
+ Object writeReplace() throws ObjectStreamException
+ {
+ return writeProxy ? proxyObject : this;
+ }
+
private <T> Class<?> generateClientProxyClass(Class<T> beanType)
{
return new ProxyFactory<T>(beanType).getProxyClass();
Added: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java 2010-05-24 17:39:47 UTC (rev 6301)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.weld.util.collections;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * <p>
+ * A {@link Set} which is backed by a simple array of elements. This provides
+ * all the behaviors of a set backed by an array, thus insert and remove
+ * operations are always O(n) time to check for uniqueness. This should only be
+ * used for sets which are known to be mostly empty or to contain only a handful
+ * of elements.
+ * </p>
+ * <p>
+ * The primary use of this set is for those cases where small sets exists and
+ * will not be changed. The savings in memory is significant compared to hash
+ * sets which may contain many empty buckets.
+ * </p>
+ *
+ * @author David Allen
+ */
+public class ArraySet<E> implements Set<E>
+{
+ // Underlying array of set elements
+ private ArrayList<E> elements;
+
+ public ArraySet(Collection<E> initialElements)
+ {
+ this(initialElements.size());
+ addAll(initialElements);
+ }
+
+ public ArraySet(int size)
+ {
+ elements = new ArrayList<E>(size);
+ }
+
+ public ArraySet()
+ {
+ this(5);
+ }
+
+ public boolean add(E e)
+ {
+ if (contains(e))
+ {
+ return false;
+ }
+ else
+ {
+ elements.add(e);
+ return true;
+ }
+ }
+
+ public boolean addAll(Collection<? extends E> otherCollection)
+ {
+ boolean modified = false;
+ boolean realSet = otherCollection instanceof Set<?>;
+ Iterator<? extends E> setIterator = otherCollection.iterator();
+ while (setIterator.hasNext())
+ {
+ E element = setIterator.next();
+ if (realSet || !contains(element))
+ {
+ elements.add(element);
+ modified = true;
+ }
+ }
+ elements.trimToSize();
+ return modified;
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean contains(Object o)
+ {
+ return elements.contains(o);
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ return elements.containsAll(c);
+ }
+
+ public boolean isEmpty()
+ {
+ return elements.isEmpty();
+ }
+
+ public Iterator<E> iterator()
+ {
+ return elements.iterator();
+ }
+
+ public boolean remove(Object o)
+ {
+ return elements.remove(o);
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ return elements.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ return elements.retainAll(c);
+ }
+
+ public int size()
+ {
+ return elements.size();
+ }
+
+ public Object[] toArray()
+ {
+ return elements.toArray();
+ }
+
+ public <T> T[] toArray(T[] a)
+ {
+ return elements.toArray(a);
+ }
+
+ // Needed to provide set equals semantics
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj instanceof Set<?>)
+ {
+ int elementQuantity = size();
+ Object[] otherArray = ((Set<?>) obj).toArray();
+ if (elementQuantity != otherArray.length)
+ {
+ return false;
+ }
+ boolean arraysEqual = true;
+ for (int i = 0; i < elementQuantity; i++)
+ {
+ boolean objFound = false;
+ for (int j = 0; j < otherArray.length; j++)
+ {
+ if (elements.get(i).equals(otherArray[j]))
+ {
+ objFound = true;
+ break;
+ }
+ }
+ if (!objFound)
+ {
+ arraysEqual = false;
+ break;
+ }
+ }
+ return arraysEqual;
+ }
+ return false;
+ }
+
+ @Override
+ public String toString()
+ {
+ return elements.toString();
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list