[Jboss-cvs] JBossAS SVN: r55839 - in projects/microcontainer/trunk/kernel/src/main/org/jboss: beans/metadata/plugins beans/metadata/spi/annotations kernel/plugins/dependency
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Aug 12 02:55:54 EDT 2006
Author: alesj
Date: 2006-08-12 02:55:48 -0400 (Sat, 12 Aug 2006)
New Revision: 55839
Added:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/InjectMode.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/InjectType.java
Modified:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/Inject.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java
Log:
Fixed property handling, enum in @Inject.
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java 2006-08-12 06:26:47 UTC (rev 55838)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java 2006-08-12 06:55:48 UTC (rev 55839)
@@ -104,6 +104,7 @@
}
return null;
}
+ return beans.iterator().next();
}
return super.getValue(info, cl);
}
@@ -113,6 +114,13 @@
// determine value
if (getUnderlyingValue() == null)
{
+ // check for property
+ if (property != null)
+ {
+ property = null;
+ log.warn("Ignoring property - contextual injection: " + this);
+ }
+
if (InjectionMode.BY_NAME.equals(injectionMode))
{
setValue(propertyMetaData.getName());
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/Inject.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/Inject.java 2006-08-12 06:26:47 UTC (rev 55838)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/Inject.java 2006-08-12 06:55:48 UTC (rev 55839)
@@ -4,20 +4,26 @@
package org.jboss.beans.metadata.spi.annotations;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* @author <a href="mailto:ales.justin at genera-lynx.com">Ales Justin</a>
*/
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.METHOD, ElementType.TYPE})
public @interface Inject
{
-
String bean() default "";
String property() default "";
String state() default "Installed";
- String mode() default "byType";
+ InjectMode mode() default InjectMode.BY_TYPE;
- String type() default "strict";
-
+ InjectType type() default InjectType.STRICT;
+
}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/InjectMode.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/InjectMode.java 2006-08-12 06:26:47 UTC (rev 55838)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/InjectMode.java 2006-08-12 06:55:48 UTC (rev 55839)
@@ -0,0 +1,23 @@
+package org.jboss.beans.metadata.spi.annotations;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public enum InjectMode
+{
+ BY_TYPE("ByType"),
+ BY_NAME("ByName");
+
+ private String modeString;
+
+ InjectMode(String modeString)
+ {
+ this.modeString = modeString;
+ }
+
+ public String toString()
+ {
+ return modeString;
+ }
+
+}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/InjectType.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/InjectType.java 2006-08-12 06:26:47 UTC (rev 55838)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/InjectType.java 2006-08-12 06:55:48 UTC (rev 55839)
@@ -0,0 +1,23 @@
+package org.jboss.beans.metadata.spi.annotations;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public enum InjectType
+{
+ STRICT("Strinct"),
+ LOOSE("Loose");
+
+ private String typeString;
+
+ InjectType(String modeString)
+ {
+ this.typeString = modeString;
+ }
+
+ public String toString()
+ {
+ return typeString;
+ }
+
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java 2006-08-12 06:26:47 UTC (rev 55838)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java 2006-08-12 06:55:48 UTC (rev 55839)
@@ -36,6 +36,7 @@
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.reflect.spi.*;
import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ControllerContext;
/**
* ConfigureAction.
@@ -139,8 +140,8 @@
StringValue beanValue = (StringValue) beanAttribute.getDefaultValue();
StringValue propertyValue = (StringValue) propertyAttribute.getDefaultValue();
StringValue stateValue = (StringValue) stateAttribute.getDefaultValue();
- StringValue modeValue = (StringValue) modeAttribute.getDefaultValue();
- StringValue typeValue = (StringValue) typeAttribute.getDefaultValue();
+ EnumValue modeValue = (EnumValue) modeAttribute.getDefaultValue();
+ EnumValue typeValue = (EnumValue) typeAttribute.getDefaultValue();
String value = beanValue.getValue();
String bean = (value != null && value.length() > 0 ? value : null);
@@ -149,31 +150,44 @@
ControllerState state = new ControllerState(stateValue.getValue());
InjectionMode injectionMode = new InjectionMode(modeValue.getValue());
InjectionType injectionType = new InjectionType(typeValue.getValue());
- Object result;
+ Object result = null;
if (bean != null)
{
- result = controller.getContext(bean, state);
+ ControllerContext context = controller.getContext(bean, state);
+ if (context != null && context.getTarget() != null)
+ {
+ result = getResult(controller, context.getTarget(), property);
+ }
}
else
{
+ // check for property
+ if (property != null)
+ {
+ log.warn("Ignoring property - contextual injection: " + pi);
+ }
+
if (InjectionMode.BY_TYPE.equals(injectionMode))
{
Set beans = controller.getInstantiatedBeans(pi.getType().getType());
int numberOfMatchingBeans = beans.size();
if (numberOfMatchingBeans > 1)
{
- throw new Error("Should not be here, too many matching beans - dependency failed! " + this);
+ throw new Error("Should not be here, too many matching beans - dependency failed! " + pi);
}
else if (numberOfMatchingBeans == 0 && InjectionType.STRICT.equals(injectionType))
{
- throw new Error("Should not be here, no bean matches class type - dependency failed! " + this);
+ throw new Error("Should not be here, no bean matches class type - dependency failed! " + pi);
}
- result = getResult(controller, beans.iterator().next(), property);
+ result = beans.iterator().next();
}
else if (InjectionMode.BY_NAME.equals(injectionMode))
{
- Object beanObject = controller.getContext(pi.getName(), state);
- result = getResult(controller, beanObject, property);
+ ControllerContext context = controller.getContext(pi.getName(), state);
+ if (context != null)
+ {
+ result = context.getTarget();
+ }
}
else
{
More information about the jboss-cvs-commits
mailing list