openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r726295 - in /incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject: ./ xml/
Date Sat, 13 Dec 2008 23:23:17 GMT
Author: gerdogdu
Date: Sat Dec 13 15:23:16 2008
New Revision: 726295

URL: http://svn.apache.org/viewvc?rev=726295&view=rev
Log:
XML configuration injections are added.

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableField.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableMethods.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java
  (with props)
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java?rev=726295&r1=726294&r2=726295&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
Sat Dec 13 15:23:16 2008
@@ -45,7 +45,7 @@
 public class InjectableConstructor<T> extends AbstractInjectable
 {
 	/** Injectable constructor instance */
-	private Constructor<T> con;
+	protected Constructor<T> con;
 
 	/**
 	 * Sets the constructor.
@@ -121,9 +121,8 @@
 				}				
 			}
 
-		} catch (Throwable e)
+		} catch (Exception e)
 		{
-			e.printStackTrace();
 			throw new WebBeansException(e);
 		}
 

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java?rev=726295&r1=726294&r2=726295&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
Sat Dec 13 15:23:16 2008
@@ -23,6 +23,7 @@
 
 import org.apache.webbeans.annotation.CurrentLiteral;
 import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ClassUtil;
 
@@ -34,8 +35,8 @@
  */
 public class InjectableField extends AbstractInjectable
 {
-	private Field field;
-	private Object instance;
+	protected Field field;
+	protected Object instance;
 
 	public InjectableField(Field field, Object instance, AbstractComponent<?> owner)
 	{
@@ -86,16 +87,18 @@
 				clazz = (Class<?>) type;
 			}
 
+			if(!field.isAccessible())
+			{
+				field.setAccessible(true);
+			}
+			
 			field.set(instance, inject(clazz, args, annots));
 
-		} catch (Throwable e)
+		} catch (Exception e)
 		{
-			// no-op
-			e.printStackTrace();
-
+			throw new WebBeansException(e);
 		}
 
 		return null;
 	}
-
 }
\ No newline at end of file

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java?rev=726295&r1=726294&r2=726295&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java
Sat Dec 13 15:23:16 2008
@@ -25,6 +25,7 @@
 
 import org.apache.webbeans.annotation.CurrentLiteral;
 import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ClassUtil;
 
@@ -32,10 +33,10 @@
 public class InjectableMethods<T> extends AbstractInjectable
 {
 	/** Injectable method */
-	private Method m;
+	protected Method m;
 
 	/** Component instance that owns the method */
-	private Object instance;
+	protected Object instance;
 
 	/**
 	 * Constructs new instance.
@@ -107,12 +108,10 @@
 
 			return (T) m.invoke(instance, list.toArray());
 
-		} catch (Throwable e)
+		} catch (Exception e)
 		{
-			// no-op
-			e.printStackTrace();
+			throw new WebBeansException(e);
 		}
-		return null;
 	}
 
 }
\ No newline at end of file

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java?rev=726295&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java
Sat Dec 13 15:23:16 2008
@@ -0,0 +1,103 @@
+/*
+ *  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.inject.xml;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.webbeans.Dependent;
+
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.ejb.EJBUtil;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.inject.InjectableConstructor;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
+import org.apache.webbeans.util.Asserts;
+
+public class XMLInjectableConstructor<T> extends InjectableConstructor<T>
+{
+	private Constructor<T> constructor;
+	
+	private List<XMLInjectionPointModel> injectionPointModelList = new ArrayList<XMLInjectionPointModel>();
+	
+
+	public XMLInjectableConstructor(Constructor<T> constructor, AbstractComponent<?>
owner)
+	{
+		super(constructor,owner);
+	}
+	
+
+	/* (non-Javadoc)
+	 * @see org.apache.webbeans.inject.InjectableConstructor#doInjection()
+	 */
+	@Override
+	@SuppressWarnings("unchecked")
+	public T doInjection()
+	{
+		T instance = null;
+		List<Object> list = new ArrayList<Object>();
+		
+		Iterator<XMLInjectionPointModel> it = this.injectionPointModelList.iterator();
+		while(it.hasNext())
+		{
+			XMLInjectionPointModel model = it.next();
+			Annotation[] anns = new Annotation[model.getBindingTypes().size()];
+			anns = model.getBindingTypes().toArray(anns);
+			
+			list.add(inject(model.getInjectionClassType(), model.getActualTypeArguments(),anns));
+		}		
+		
+		try
+		{
+			if (!EJBUtil.isEJBSessionClass(con.getDeclaringClass()))
+			{
+				if(getInjectionOwnerComponent().getScopeType().equals(Dependent.class))
+				{
+					instance = con.newInstance(list.toArray());
+				}
+				else
+				{
+					instance = (T) JavassistProxyFactory.createNewProxyInstance(con.getDeclaringClass(),
con.getParameterTypes(), list.toArray(), getInjectionOwnerComponent());					
+				}				
+			}
+
+		} catch (Throwable e)
+		{
+			e.printStackTrace();
+			throw new WebBeansException(e);
+		}
+
+		return instance;
+	}
+
+	/**
+	 * @return the constructor
+	 */
+	public Constructor<T> getConstructor()
+	{
+		return constructor;
+	}
+
+	public void addInjectionPointModel(XMLInjectionPointModel model)
+	{
+		Asserts.assertNotNull(model, "model parameter can not be null");
+		this.injectionPointModelList.add(model);
+	}
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableField.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableField.java?rev=726295&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableField.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableField.java
Sat Dec 13 15:23:16 2008
@@ -0,0 +1,62 @@
+/*
+ *  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.inject.xml;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.inject.InjectableField;
+
+public class XMLInjectableField extends InjectableField
+{
+	private XMLInjectionPointModel injectionPointModel = null;
+
+	public XMLInjectableField(Field field, Object instance, AbstractComponent<?> owner,
XMLInjectionPointModel model)
+	{
+		super(field, instance, owner);
+		this.injectionPointModel = model;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.webbeans.inject.InjectableField#doInjection()
+	 */
+	@Override
+	public Object doInjection()
+	{
+		Annotation[] anns = new Annotation[this.injectionPointModel.getBindingTypes().size()];
+		anns = this.injectionPointModel.getBindingTypes().toArray(anns);
+
+		try
+		{
+			if(!field.isAccessible())
+			{
+				field.setAccessible(true);
+			}
+			
+			field.set(instance, inject(this.injectionPointModel.getInjectionClassType(), this.injectionPointModel.getActualTypeArguments(),
anns));
+			
+		}catch(Exception e)
+		{
+			throw new WebBeansException(e);
+		}
+			
+		
+		return null;
+	}	
+}
\ No newline at end of file

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableMethods.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableMethods.java?rev=726295&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableMethods.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableMethods.java
Sat Dec 13 15:23:16 2008
@@ -0,0 +1,74 @@
+/*
+ *  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.inject.xml;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.inject.InjectableMethods;
+import org.apache.webbeans.util.ClassUtil;
+
+public class XMLInjectableMethods<T> extends InjectableMethods<T>
+{
+	private List<XMLInjectionPointModel> injectionPointModelList = new ArrayList<XMLInjectionPointModel>();
+	
+	public XMLInjectableMethods(Method m, Object instance, AbstractComponent<?> owner,
List<XMLInjectionPointModel> injectionPointModelList)
+	{
+		super(m, instance, owner);
+		this.injectionPointModelList = injectionPointModelList;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.webbeans.inject.InjectableMethods#doInjection()
+	 */
+	@Override
+	@SuppressWarnings("unchecked")
+	public T doInjection()
+	{
+		List<Object> list = new ArrayList<Object>();
+		
+		Iterator<XMLInjectionPointModel> it = this.injectionPointModelList.iterator();
+		while(it.hasNext())
+		{
+			XMLInjectionPointModel model = it.next();
+			Annotation[] anns = new Annotation[model.getBindingTypes().size()];
+			anns = model.getBindingTypes().toArray(anns);
+			
+			list.add(inject(model.getInjectionClassType(), model.getActualTypeArguments(),anns));
+		}
+		
+		try
+		{
+			if (!ClassUtil.isPublic(m.getModifiers()))
+			{
+				m.setAccessible(true);
+			}
+
+			return (T) m.invoke(instance, list.toArray());
+
+		} catch (Throwable e)
+		{
+			// no-op
+			e.printStackTrace();
+		}
+		return null;
+	}
+}
\ No newline at end of file

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableMethods.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java?rev=726295&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java
Sat Dec 13 15:23:16 2008
@@ -0,0 +1,172 @@
+/*
+ *  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.inject.xml;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.webbeans.util.ClassUtil;
+
+/**
+ * Defines the model that is related with injection point decleration.
+ * Each injection point decleration defined in the XML file defines
+ * the injection point API type and Binding type annotations.
+ * 
+ * <p>
+ * If injection point is a parametrized type, actual type arguments
+ * are defined in the XML file. See specification for further details.
+ * </p>
+ * 
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class XMLInjectionPointModel
+{	
+	/**Injection point raw/actual class type*/
+	private Class<?> injectionClassType;
+	
+	/**This injection point is parametrized*/
+	private boolean parametrized;
+	
+	/**Actual type arguments defined in the XML*/
+	private Type[] actualTypeArguments = new Type[0];
+	
+	/**Injection point binding types*/
+	private Set<Annotation> bindingTypes = new HashSet<Annotation>();
+	
+	/**
+	 * Creates new injection point model.
+	 * 
+	 * @param injectionClassType injection point class type
+	 * @param actualTypeArguments injection point actual type arguments
+	 */
+	public XMLInjectionPointModel(Class<?> injectionClassType, Type[] actualTypeArguments)
+	{
+		this.injectionClassType = injectionClassType;
+		
+		if(actualTypeArguments != null && actualTypeArguments.length > 0)
+		{
+			this.actualTypeArguments = actualTypeArguments;	
+		}
+		
+		if(ClassUtil.isParametrized(this.injectionClassType))
+		{
+			this.parametrized = true;
+		}	
+	}
+	
+	/**
+	 * Add new binding type annotation to the injection point.
+	 * 
+	 * @param bindingType new binding type annotation
+	 */
+	public void addBindingType(Annotation bindingType)
+	{
+		this.bindingTypes.add(bindingType);
+	}
+
+	/**
+	 * Gets injection point class type.
+	 * 
+	 * @return the injectionClassType
+	 */
+	public Class<?> getInjectionClassType()
+	{
+		return injectionClassType;
+	}
+
+	/**
+	 * Returns the injection point is parametrized type.
+	 * 
+	 * @return the parametrized
+	 */
+	public boolean isParametrized()
+	{
+		return parametrized;
+	}
+
+	/**
+	 * Gets actual type arguments.
+	 * 
+	 * @return the actualTypeArguments
+	 */
+	public Type[] getActualTypeArguments()
+	{
+		return actualTypeArguments;
+	}
+
+	/**
+	 * Gets unmodifiable binding types of the injection point.
+	 * 
+	 * @return the bindingTypes
+	 */
+	public Set<Annotation> getBindingTypes()
+	{
+		return Collections.unmodifiableSet(this.bindingTypes);
+	}
+
+	/* (non-Javadoc)
+	 * @see java.lang.Object#hashCode()
+	 */
+	@Override
+	public int hashCode()
+	{
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + Arrays.hashCode(actualTypeArguments);
+		result = prime * result + ((bindingTypes == null) ? 0 : bindingTypes.hashCode());
+		result = prime * result + ((injectionClassType == null) ? 0 : injectionClassType.hashCode());
+		result = prime * result + (parametrized ? 1231 : 1237);
+		return result;
+	}
+
+	/* (non-Javadoc)
+	 * @see java.lang.Object#equals(java.lang.Object)
+	 */
+	@Override
+	public boolean equals(Object obj)
+	{
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		final XMLInjectionPointModel other = (XMLInjectionPointModel) obj;
+		if (!Arrays.equals(actualTypeArguments, other.actualTypeArguments))
+			return false;
+		if (bindingTypes == null)
+		{
+			if (other.bindingTypes != null)
+				return false;
+		} else if (!bindingTypes.equals(other.bindingTypes))
+			return false;
+		if (injectionClassType == null)
+		{
+			if (other.injectionClassType != null)
+				return false;
+		} else if (!injectionClassType.equals(other.injectionClassType))
+			return false;
+		if (parametrized != other.parametrized)
+			return false;
+		return true;
+	}
+}
\ No newline at end of file

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message