openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r726292 - in /incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component: ComponentImpl.java ProducerComponentImpl.java xml/XMLComponentImpl.java xml/XMLProducerComponentImpl.java
Date Sat, 13 Dec 2008 23:21:25 GMT
Author: gerdogdu
Date: Sat Dec 13 15:21:25 2008
New Revision: 726292

URL: http://svn.apache.org/viewvc?rev=726292&view=rev
Log:
XML specific actions has done.

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLProducerComponentImpl.java
  (with props)
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java?rev=726292&r1=726291&r2=726292&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ComponentImpl.java
Sat Dec 13 15:21:25 2008
@@ -92,7 +92,7 @@
 	/*
 	 * Call before object constructor
 	 */
-	private void beforeConstructor()
+	protected void beforeConstructor()
 	{
 
 	}
@@ -100,7 +100,7 @@
 	/*
 	 * Call after object construction
 	 */
-	private void afterConstructor(T instance)
+	protected void afterConstructor(T instance)
 	{
 		injectFields(instance);
 		injectMethods(instance);
@@ -133,7 +133,7 @@
 	/*
 	 * Injectable fields
 	 */
-	private void injectFields(T instance)
+	protected void injectFields(T instance)
 	{
 		Set<Field> fields = getInjectedFields();
 		Iterator<Field> it = fields.iterator();
@@ -155,7 +155,7 @@
 	 * Injectable methods
 	 */
 	@SuppressWarnings("unchecked")
-	private void injectMethods(T instance)
+	protected void injectMethods(T instance)
 	{
 		Set<Method> methods = getInjectedMethods();
 		Iterator<Method> it = methods.iterator();

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java?rev=726292&r1=726291&r2=726292&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java
Sat Dec 13 15:21:25 2008
@@ -42,13 +42,13 @@
 public class ProducerComponentImpl<T> extends AbstractComponent<T>
 {	
 	/**Parent component that this producer method belongs*/
-	private AbstractComponent<?> parent;
+	protected AbstractComponent<?> parent;
 	
 	/**Creator method of the parent component*/
-	private Method creatorMethod;
+	protected Method creatorMethod;
 	
 	/**Disposal method*/
-	private Method disposalMethod;
+	protected Method disposalMethod;
 	
 	/*
 	 * Constructor
@@ -161,7 +161,7 @@
 	
 	
 	@SuppressWarnings("unchecked")
-	private <K> void destroyBean(Bean<?> bean, Object instance)
+	protected <K> void destroyBean(Bean<?> bean, Object instance)
 	{
 		Bean<K> destroy = (Bean<K>)bean;
 		K inst = (K) instance;
@@ -191,14 +191,14 @@
 	}
 	
 	
-	private Object getParentInstance()
+	protected Object getParentInstance()
 	{
 		Object parentInstance = ManagerImpl.getManager().getInstance(this.parent);
 		
 		return parentInstance;
 	}
 	
-	private void checkNullInstance(Object instance)
+	protected void checkNullInstance(Object instance)
 	{
 		if(instance == null)
 		{
@@ -209,7 +209,7 @@
 		}		
 	}
 	
-	private void checkScopeType()
+	protected void checkScopeType()
 	{
 		//Scope type check
 		ScopeType scope = this.getScopeType().getAnnotation(ScopeType.class);

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java?rev=726292&r1=726291&r2=726292&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java
Sat Dec 13 15:21:25 2008
@@ -16,85 +16,164 @@
  */
 package org.apache.webbeans.component.xml;
 
-import java.lang.reflect.Type;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.webbeans.component.ComponentImpl;
+import org.apache.webbeans.inject.xml.XMLInjectableConstructor;
+import org.apache.webbeans.inject.xml.XMLInjectableField;
+import org.apache.webbeans.inject.xml.XMLInjectableMethods;
+import org.apache.webbeans.inject.xml.XMLInjectionPointModel;
+import org.apache.webbeans.util.Asserts;
 
 public class XMLComponentImpl<T> extends ComponentImpl<T>
-{
-	private List<Type> constructorApiTypes = new ArrayList<Type>();
+{	
+	/**Constructor injection point decleration*/
+	private XMLInjectableConstructor<T> injectableConstructor = null;
 	
-	private Map<String, Type> fieldApiType = new HashMap<String, Type>();
+	/**Injection points for fields*/
+	private Map<Field,XMLInjectionPointModel> injectableFields = new HashMap<Field,
XMLInjectionPointModel>();
 	
-	private Map<String, Type> methodApiType = new HashMap<String, Type>();
+	/**Injection points for initializer methods*/
+	private Map<Method,List<XMLInjectionPointModel>> injectableMethods = new HashMap<Method,
List<XMLInjectionPointModel>>();
 	
+	/**Initial field values of the webbean defined in the XML*/
 	private Map<String, Object> fieldValues = new HashMap<String, Object>();
-	
-	
+		
+	/**
+	 * Creates new XML defined webbeans component.
+	 * 
+	 * @param returnType type of the webbeans component
+	 */
 	public XMLComponentImpl(Class<T> returnType)
 	{
 		super(returnType);
 	}
 	
-	public void addConstructorApiType(Type apiType)
-	{
-		constructorApiTypes.add(apiType);
-	}
 	
-	public void addFieldApiType(Type apiType, String name)
-	{
-		fieldApiType.put(name, apiType);
-	}
 	
-	public void addMethodApiType(Type apiType, String name)
+	/* (non-Javadoc)
+	 * @see org.apache.webbeans.component.ComponentImpl#createInstance()
+	 */
+	@Override
+	protected T createInstance()
 	{
-		methodApiType.put(name, apiType);
+		T instance = null;
+		instance = this.injectableConstructor.doInjection();
+		
+		return instance;
 	}
+
 	
 	
-	public void addFieldValue(String name, Object value)
+	/* (non-Javadoc)
+	 * @see org.apache.webbeans.component.ComponentImpl#injectFields(java.lang.Object)
+	 */
+	@Override
+	protected void injectFields(T instance)
 	{
-		fieldValues.put(name, value);
+		Set<Field> fieldSet = this.injectableFields.keySet();
+		Iterator<Field> itField = fieldSet.iterator();
+		
+		while(itField.hasNext())
+		{	
+			Field field = itField.next();
+			XMLInjectionPointModel model = this.injectableFields.get(field);
+			XMLInjectableField injectableField = new XMLInjectableField(field, instance, this, model);
+			
+			injectableField.doInjection();
+		}
 	}
 
-	/**
-	 * @return the constructorApiTypes
+
+	/* (non-Javadoc)
+	 * @see org.apache.webbeans.component.ComponentImpl#injectMethods(java.lang.Object)
 	 */
-	public List<Type> getConstructorApiTypes()
+	@Override
+	protected void injectMethods(T instance)
 	{
-		return constructorApiTypes;
+		Set<Method> methodSet = this.injectableMethods.keySet();
+		Iterator<Method> itMethods = methodSet.iterator();
+		while(itMethods.hasNext())
+		{
+			Method method = itMethods.next();
+			List<XMLInjectionPointModel> listInjectionPointModel = this.injectableMethods.get(method);
+			XMLInjectableMethods<T> injectableMethod = new XMLInjectableMethods<T>(method,
instance, this, listInjectionPointModel);
+			
+			injectableMethod.doInjection();
+		}
+		
 	}
 
+
 	/**
-	 * @return the fieldApiTypes
+	 * Sets injection point for constructor.
+	 * 
+	 * @param constructor constructor injection point
 	 */
-	public Map<String, Type> getFieldApiType()
+	public void setInjectableConstructor(XMLInjectableConstructor<T> constructor)
 	{
-		return fieldApiType;
+		Asserts.assertNotNull(constructor, "constructor parameter can not be null");
+		this.injectableConstructor = constructor;
 	}
-
+	
 	/**
-	 * @return the fieldValues
+	 * Adds new field injection point
+	 * 
+	 * @param field field injection point
+	 * @param model injection point model
 	 */
-	public Map<String, Object> getFieldValues()
+	public void addFieldInjectionPoint(Field field, XMLInjectionPointModel model)
 	{
-		return fieldValues;
+		Asserts.assertNotNull(field,"field parameter can not be null");
+		Asserts.assertNotNull(model,"model parameter can not be null");
+		
+		this.injectableFields.put(field, model);
 	}
-
+	
 	/**
-	 * @return the methodApiType
+	 * Adds new method injection point
+	 * 
+	 * @param method method injection point
+	 * @param model injection point model
 	 */
-	public Map<String, Type> getMethodApiType()
+	public void addMethodInjectionPoint(Method method, XMLInjectionPointModel model)
 	{
-		return methodApiType;
-	}
-	
-	
-	
+		Asserts.assertNotNull(method,"method parameter can not be null");
+		Asserts.assertNotNull(model,"model parameter can not be null");
+		
+		List<XMLInjectionPointModel> listModel = this.injectableMethods.get(method);
+		if(listModel == null)
+		{
+			listModel = new ArrayList<XMLInjectionPointModel>();
+			this.injectableMethods.put(method, listModel);
+		}
+		
+		listModel.add(model);
+	}	
 	
+	/**
+	 * Add new field value.
+	 * 
+	 * @param name name of the field
+	 * @param value value of the field
+	 */
+	public void addFieldValue(String name, Object value)
+	{
+		fieldValues.put(name, value);
+	}
 
-}
+	/**
+	 * @return the fieldValues
+	 */
+	public Map<String, Object> getFieldValues()
+	{
+		return fieldValues;
+	}
+}
\ No newline at end of file

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLProducerComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLProducerComponentImpl.java?rev=726292&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLProducerComponentImpl.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLProducerComponentImpl.java
Sat Dec 13 15:21:25 2008
@@ -0,0 +1,95 @@
+/*
+ *  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.component.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.webbeans.Dependent;
+
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.component.ProducerComponentImpl;
+import org.apache.webbeans.inject.xml.XMLInjectableMethods;
+import org.apache.webbeans.inject.xml.XMLInjectionPointModel;
+import org.apache.webbeans.util.Asserts;
+
+public class XMLProducerComponentImpl<T> extends ProducerComponentImpl<T>
+{
+	private List<XMLInjectionPointModel> producerMethodParameters = new ArrayList<XMLInjectionPointModel>();
+	
+	private List<XMLInjectionPointModel> disposalMethodParameters = new ArrayList<XMLInjectionPointModel>();
+	
+	public XMLProducerComponentImpl(AbstractComponent<?> parent, Class<T> returnType)
+	{
+		super(parent, returnType);
+		this.parent = parent;
+	}
+	
+	public void addProducerMethodInjectionPointModel(XMLInjectionPointModel model)
+	{
+		Asserts.assertNotNull(model,"model parameter can not be null");
+		this.producerMethodParameters.add(model);
+	}
+	
+	public void addDisposalMethodInjectionPointModel(XMLInjectionPointModel model)
+	{
+		Asserts.assertNotNull(model,"model parameter can not be null");
+		this.disposalMethodParameters.add(model);
+	}
+	
+	protected void destroyInstance(T instance)
+	{
+		if(disposalMethod != null)
+		{
+			
+			Object object = getParentInstance();
+			
+			XMLInjectableMethods<T> methods = new XMLInjectableMethods<T>(creatorMethod,object,this,this.disposalMethodParameters);
+			methods.doInjection();
+			
+		}
+		
+		instance = null;
+	}
+	
+	
+	protected T createInstance()
+	{	
+		T instance = null;
+		Object  parentInstance = getParentInstance();
+
+		try
+		{
+			XMLInjectableMethods<T> methods = new XMLInjectableMethods<T>(creatorMethod,parentInstance,this,this.producerMethodParameters);
+			methods.doInjection();
+		}
+		finally
+		{
+			if(getParent().getScopeType().equals(Dependent.class))
+			{
+				destroyBean(getParent(), parentInstance);
+			}
+		}
+		
+		checkNullInstance(instance);
+		checkScopeType();
+		
+		return instance;
+	}
+	
+
+}

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



Mime
View raw message