You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/10/26 18:21:21 UTC
svn commit: r1027627 - in /openwebbeans/trunk:
webbeans-impl/src/main/java/org/apache/webbeans/component/
webbeans-impl/src/main/java/org/apache/webbeans/container/
webbeans-impl/src/main/java/org/apache/webbeans/event/
webbeans-impl/src/main/java/org/...
Author: gerdogdu
Date: Tue Oct 26 16:21:20 2010
New Revision: 1027627
URL: http://svn.apache.org/viewvc?rev=1027627&view=rev
Log:
[OWB-484] Running TCK 1.0.1 Final and Respective Corrections
Added:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OwbCustomObjectInputStream.java (with props)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSessionBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java
openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/api/ResourceReference.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java?rev=1027627&r1=1027626&r2=1027627&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java Tue Oct 26 16:21:20 2010
@@ -19,6 +19,7 @@
package org.apache.webbeans.component;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Modifier;
import javassist.util.proxy.ProxyFactory;
@@ -65,6 +66,13 @@ public class ResourceBean<X, T extends A
}
catch (Exception e)
{
+ //check type is final
+ //return actual resource
+ if(Modifier.isFinal(this.actualResourceReference.getClass().getModifiers()))
+ {
+ return this.actualResourceReference;
+ }
+
throw new WebBeansException(e);
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1027627&r1=1027626&r2=1027627&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java Tue Oct 26 16:21:20 2010
@@ -504,7 +504,12 @@ public class BeanManagerImpl implements
getManager().webBeansDecorators.add(decorator);
if (decorator instanceof OwbBean)
{
- this.addPassivationInfo((OwbBean)decorator);
+ OwbBean<?> owbBean = (OwbBean<?>)decorator;
+
+ if(owbBean.isPassivationCapable())
+ {
+ this.addPassivationInfo((OwbBean)decorator);
+ }
}
return this;
}
@@ -515,7 +520,12 @@ public class BeanManagerImpl implements
getManager().webBeansInterceptors.add(interceptor);
if (interceptor instanceof OwbBean)
{
- this.addPassivationInfo((OwbBean)interceptor);
+ OwbBean<?> owbBean = (OwbBean<?>)interceptor;
+ if(owbBean.isPassivationCapable())
+ {
+ this.addPassivationInfo((OwbBean)interceptor);
+ }
+
}
return this;
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java?rev=1027627&r1=1027626&r2=1027627&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectableBeanManager.java Tue Oct 26 16:21:20 2010
@@ -227,4 +227,47 @@ public class InjectableBeanManager imple
this.bm = BeanManagerImpl.getManager();
}
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((bm == null) ? 0 : System.identityHashCode(bm));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+
+ InjectableBeanManager other = (InjectableBeanManager) obj;
+ if (bm == null)
+ {
+ if (other.bm != null)
+ {
+ return false;
+ }
+ }
+ else if (System.identityHashCode(bm) != (System.identityHashCode(other.bm)))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+
+
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java?rev=1027627&r1=1027626&r2=1027627&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java Tue Oct 26 16:21:20 2010
@@ -20,12 +20,10 @@ package org.apache.webbeans.event;
import java.io.IOException;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.util.HashSet;
import java.util.Set;
@@ -33,9 +31,10 @@ import javax.enterprise.event.Event;
import javax.enterprise.util.TypeLiteral;
import org.apache.webbeans.container.BeanManagerImpl;
-import org.apache.webbeans.logger.WebBeansLogger;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.OwbCustomObjectInputStream;
+import org.apache.webbeans.util.WebBeansUtil;
/**
* Event implementation.
@@ -47,8 +46,6 @@ public class EventImpl<T> implements Eve
{
private static final long serialVersionUID = -9035218380365451350L;
- private final WebBeansLogger logger = WebBeansLogger.getLogger(EventImpl.class);
-
/**Event binding types*/
private Annotation[] injectedBindings;
@@ -153,49 +150,20 @@ public class EventImpl<T> implements Eve
return select(subtype.getRawType(), bindings);
}
- @SuppressWarnings("unchecked")
+ private void writeObject(java.io.ObjectOutputStream op) throws IOException
+ {
+ ObjectOutputStream oos = new ObjectOutputStream(op);
+ oos.writeObject(this.eventType);
+ oos.writeObject(this.injectedBindings);
+
+ oos.flush();
+ }
+
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
{
- try
- {
- final ObjectInputStream inputStream = in;
-
- AccessController.doPrivileged(
- new PrivilegedExceptionAction()
- {
- public Object run() throws Exception
- {
- inputStream.defaultReadObject();
- return null;
- }
- }
- );
- }
- catch (PrivilegedActionException pae)
- {
- Throwable cause = ((PrivilegedActionException)pae).getCause();
-
- if (cause instanceof IOException)
- {
- throw (IOException)cause;
- }
- else if (cause instanceof ClassNotFoundException)
- {
- throw (ClassNotFoundException)cause;
- }
- else if (cause instanceof RuntimeException)
- {
- throw (RuntimeException)cause;
- }
- else
- {
- if (logger.wblWillLogDebug())
- {
- logger.trace("Unexpected exception via PAE [{0}]", cause);
- }
-
- }
- }
+ final ObjectInputStream inputStream = new OwbCustomObjectInputStream(in, WebBeansUtil.getCurrentClassLoader());
+ this.eventType = (Type)inputStream.readObject();
+ this.injectedBindings = (Annotation[])inputStream.readObject();
this.manager = BeanManagerImpl.getManager();
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java?rev=1027627&r1=1027626&r2=1027627&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java Tue Oct 26 16:21:20 2010
@@ -19,6 +19,8 @@
package org.apache.webbeans.inject.instance;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
@@ -35,6 +37,8 @@ import org.apache.webbeans.container.Inj
import org.apache.webbeans.container.ResolutionUtil;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.OwbCustomObjectInputStream;
+import org.apache.webbeans.util.WebBeansUtil;
/**
* Implements the {@link Instance} interface.
@@ -220,6 +224,23 @@ class InstanceImpl<T> implements Instanc
return instances.iterator();
}
+
+ private void writeObject(java.io.ObjectOutputStream op) throws IOException
+ {
+ ObjectOutputStream oos = new ObjectOutputStream(op);
+ oos.writeObject(this.injectionClazz);
+ oos.writeObject(this.qualifierAnnotations);
+
+ oos.flush();
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ final ObjectInputStream inputStream = new OwbCustomObjectInputStream(in, WebBeansUtil.getCurrentClassLoader());
+ this.injectionClazz = (Type)inputStream.readObject();
+ this.qualifierAnnotations = (Set<Annotation>)inputStream.readObject();
+ }
+
public String toString()
{
@@ -245,27 +266,4 @@ class InstanceImpl<T> implements Instanc
return builder.toString();
}
- private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- this.injectionClazz = (Type)in.readObject();
- int q = in.readByte();
- if(q != 0)
- {
- this.qualifierAnnotations = new HashSet<Annotation>();
- for(int i =0; i< q; i++)
- {
- this.qualifierAnnotations.add((Annotation)in.readObject());
- }
- }
- }
-
- private void writeObject(java.io.ObjectOutputStream out) throws IOException
- {
- out.writeObject(this.injectionClazz);
- out.writeByte(this.qualifierAnnotations.size());
- for(Annotation ann : this.qualifierAnnotations)
- {
- out.writeObject(ann);
- }
- }
}
\ No newline at end of file
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSessionBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSessionBean.java?rev=1027627&r1=1027626&r2=1027627&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSessionBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSessionBean.java Tue Oct 26 16:21:20 2010
@@ -25,11 +25,16 @@ import javax.enterprise.inject.spi.Sessi
import org.apache.webbeans.portable.events.ProcessSessionBeanImpl;
@SuppressWarnings("unchecked")
-public class GProcessSessionBean extends ProcessSessionBeanImpl
+public class GProcessSessionBean extends ProcessSessionBeanImpl implements GenericBeanEvent
{
public GProcessSessionBean(Bean<Object> bean, AnnotatedType<?> annotatedType, String name, SessionBeanType type)
{
super(bean, annotatedType, name, type);
}
+ @Override
+ public Class<?> getBeanClass()
+ {
+ return getBean().getBeanClass();
+ }
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java?rev=1027627&r1=1027626&r2=1027627&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java Tue Oct 26 16:21:20 2010
@@ -33,34 +33,13 @@ import org.apache.webbeans.logger.WebBea
*/
public final class JNDIUtil
{
- private static InitialContext initialContext = null;
-
private static final WebBeansLogger LOGGER = WebBeansLogger.getLogger(JNDIUtil.class);
- static
- {
- try
- {
- initialContext = new InitialContext();
-
- }
- catch (Exception e)
- {
- LOGGER.error(OWBLogConst.ERROR_0004, e);
- throw new ExceptionInInitializerError(e);
- }
- }
-
private JNDIUtil()
{
}
- public static InitialContext getInitialContext()
- {
- return initialContext;
- }
-
public static void bind(String name, Object object)
{
Asserts.assertNotNull(name, "name parameter can not be null");
@@ -68,6 +47,7 @@ public final class JNDIUtil
try
{
+ InitialContext initialContext = new InitialContext();
Context context = initialContext;
String[] parts = name.split("/");
@@ -100,7 +80,7 @@ public final class JNDIUtil
try
{
- initialContext.unbind(name);
+ new InitialContext().unbind(name);
}
catch (NamingException e)
@@ -117,7 +97,7 @@ public final class JNDIUtil
try
{
- return (T) initialContext.lookup(name);
+ return (T) new InitialContext().lookup(name);
}
catch (NamingException e)
{
Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OwbCustomObjectInputStream.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OwbCustomObjectInputStream.java?rev=1027627&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OwbCustomObjectInputStream.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OwbCustomObjectInputStream.java Tue Oct 26 16:21:20 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.webbeans.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+
+public class OwbCustomObjectInputStream extends ObjectInputStream
+{
+ private ClassLoader classLoader;
+
+ public OwbCustomObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException
+ {
+ super(in);
+ this.classLoader = classLoader;
+ }
+
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException
+ {
+ return Class.forName(desc.getName(), false, this.classLoader);
+ }
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/OwbCustomObjectInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/api/ResourceReference.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/api/ResourceReference.java?rev=1027627&r1=1027626&r2=1027627&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/api/ResourceReference.java (original)
+++ openwebbeans/trunk/webbeans-spi/src/main/java/org/apache/webbeans/spi/api/ResourceReference.java Tue Oct 26 16:21:20 2010
@@ -19,16 +19,20 @@
package org.apache.webbeans.spi.api;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
public class ResourceReference<X,T extends Annotation>
{
- private T annotation;
+ private final T annotation;
+
+ private final Class<X> resourceType;
- private Class<X> resourceType;
+ private final Class<?> ownerClass;
- private Class<?> ownerClass;
+ private final String name;
- private String name;
+ private String jndiName;
public ResourceReference(Class<?> ownerClass, String name, Class<X> resourceType, T annotation)
{
@@ -76,4 +80,61 @@ public class ResourceReference<X,T exten
return this.name;
}
+ public String getJndiName()
+ {
+ if(this.jndiName == null)
+ {
+ this.jndiName = getResourceName();
+ }
+
+ return normalize(this.jndiName);
+ }
+
+ private Method getNameMethod(Class cls)
+ {
+ try
+ {
+ return cls.getMethod("name", null);
+ }
+ catch (NoSuchMethodException e)
+ {
+ return null;
+ }
+ }
+
+ private String getResourceName()
+ {
+ String value = null;
+ Method nameMethod = getNameMethod(this.annotation.getClass());
+ if (nameMethod != null)
+ {
+ try
+ {
+ value = (String) nameMethod.invoke(this.annotation, null);
+ }
+ catch (Exception e)
+ {
+ // ignore
+ }
+ }
+
+ if(value == null || value.equals(""))
+ {
+ value = this.ownerClass.getName() + "/" + this.name;
+ }
+
+ return value;
+ }
+
+ private String normalize(String refName)
+ {
+ if (refName.startsWith("java:"))
+ {
+ return refName;
+ }
+
+ return "java:comp/env/" + refName;
+ }
+
+
}