You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2009/04/13 21:11:39 UTC
svn commit: r764567 -
/geronimo/sandbox/gnodet/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
Author: gnodet
Date: Mon Apr 13 19:11:39 2009
New Revision: 764567
URL: http://svn.apache.org/viewvc?rev=764567&view=rev
Log:
Clean a bit the recipe creation
Modified:
geronimo/sandbox/gnodet/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
Modified: geronimo/sandbox/gnodet/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java?rev=764567&r1=764566&r2=764567&view=diff
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java (original)
+++ geronimo/sandbox/gnodet/blueprint/org.apache.felix.blueprint/src/main/java/org/apache/felix/blueprint/context/Instanciator.java Mon Apr 13 19:11:39 2009
@@ -33,6 +33,7 @@
import org.apache.xbean.recipe.MapRecipe;
import org.apache.xbean.recipe.ConstructionException;
import org.apache.xbean.recipe.ReferenceRecipe;
+import org.apache.xbean.recipe.Recipe;
import org.osgi.service.blueprint.namespace.ComponentDefinitionRegistry;
import org.osgi.service.blueprint.reflect.ComponentMetadata;
import org.osgi.service.blueprint.reflect.LocalComponentMetadata;
@@ -44,6 +45,10 @@
import org.osgi.service.blueprint.reflect.ListValue;
import org.osgi.service.blueprint.reflect.SetValue;
import org.osgi.service.blueprint.reflect.MapValue;
+import org.osgi.service.blueprint.reflect.ComponentValue;
+import org.osgi.service.blueprint.reflect.ArrayValue;
+import org.osgi.service.blueprint.reflect.ReferenceNameValue;
+import org.osgi.service.blueprint.reflect.PropertiesValue;
/**
* TODO: javadoc
@@ -58,31 +63,36 @@
// Create recipes
for (String name : (Set<String>) registry.getComponentDefinitionNames()) {
ComponentMetadata component = registry.getComponentDefinition(name);
- if (component instanceof LocalComponentMetadata) {
- LocalComponentMetadata local = (LocalComponentMetadata) component;
- ObjectRecipe recipe = new ObjectRecipe(local.getClassName());
- recipe.setName(name);
- for (PropertyInjectionMetadata property : (Collection<PropertyInjectionMetadata>) local.getPropertyInjectionMetadata()) {
- Object value = getValue(repository, property.getValue());
- recipe.setProperty(property.getName(), value);
- }
- // TODO: constructor args
- // TODO: init-method
- // TODO: destroy-method
- // TODO: lazy
- // TODO: scope
- // TODO: factory-method
- // TODO: factory-component
- repository.add(name, recipe);
- } else {
- // TODO
- throw new IllegalStateException("Unsupported component " + component.getClass());
- }
+ Recipe recipe = createRecipe(component);
+ repository.add(name, recipe);
}
return repository;
}
- private static Object getValue(Repository repository, Value v) {
+ private static Recipe createRecipe(ComponentMetadata component) {
+ if (component instanceof LocalComponentMetadata) {
+ LocalComponentMetadata local = (LocalComponentMetadata) component;
+ ObjectRecipe recipe = new ObjectRecipe(local.getClassName());
+ recipe.setName(component.getName());
+ for (PropertyInjectionMetadata property : (Collection<PropertyInjectionMetadata>) local.getPropertyInjectionMetadata()) {
+ Object value = getValue(property.getValue());
+ recipe.setProperty(property.getName(), value);
+ }
+ // TODO: constructor args
+ // TODO: init-method
+ // TODO: destroy-method
+ // TODO: lazy
+ // TODO: scope
+ // TODO: factory-method
+ // TODO: factory-component
+ return recipe;
+ } else {
+ // TODO
+ throw new IllegalStateException("Unsupported component " + component.getClass());
+ }
+ }
+
+ private static Object getValue(Value v) {
if (v instanceof NullValue) {
return null;
} else if (v instanceof TypedStringValue) {
@@ -94,27 +104,37 @@
} else if (v instanceof ListValue) {
CollectionRecipe cr = new CollectionRecipe(ArrayList.class);
for (Value lv : (List<Value>) ((ListValue) v).getList()) {
- cr.add(getValue(repository, lv));
+ cr.add(getValue(lv));
}
// TODO: ListValue#getValueType()
return cr;
} else if (v instanceof SetValue) {
CollectionRecipe cr = new CollectionRecipe(HashSet.class);
for (Value lv : (Set<Value>) ((SetValue) v).getSet()) {
- cr.add(getValue(repository, lv));
+ cr.add(getValue(lv));
}
// TODO: SetValue#getValueType()
return cr;
} else if (v instanceof MapValue) {
MapRecipe mr = new MapRecipe(HashMap.class);
for (Map.Entry<Value,Value> entry : ((Map<Value,Value>) ((MapValue) v).getMap()).entrySet()) {
- Object key = getValue(repository, entry.getKey());
- Object val = getValue(repository, entry.getValue());
+ Object key = getValue(entry.getKey());
+ Object val = getValue(entry.getValue());
mr.put(key, val);
}
// TODO: MapValue#getKeyType()
// TODO: MapValue#getValueType()
return mr;
+ } else if (v instanceof ArrayValue) {
+ // TODO
+ throw new IllegalStateException("Unsupported value: " + v.getClass().getName());
+ } else if (v instanceof ComponentValue) {
+ return createRecipe(((ComponentValue) v).getComponentMetadata());
+ } else if (v instanceof PropertiesValue) {
+ // TODO
+ throw new IllegalStateException("Unsupported value: " + v.getClass().getName());
+ } else if (v instanceof ReferenceNameValue) {
+ return ((ReferenceNameValue) v).getReferenceName();
} else {
throw new IllegalStateException("Unsupported value: " + v.getClass().getName());
}