Commit c80ea0bf authored by Lionel Seinturier's avatar Lionel Seinturier

New API for the property controller: store property types (suggested by Philippe and Christophe.)

parent 9d751e5f
......@@ -8,6 +8,7 @@ Tinfi 1.1.1
for references
* size of the generated code reduced by moving some common task to the
frascati-tinfi-runtime module (suggested by Philippe)
* new API for the property controller (requested by Philippe and Christophe)
Tinfi 1.1
......
......@@ -23,9 +23,7 @@ runtime-dyn/
Having a generic initializer should bypass this difficulty.
runtime-oo/
* about the management of properties (suggested by Philippe and Christophe)
* store property types
* store properties even if their values are not set
* about the management of properties (suggested by Philippe)
* detect settings on the property controller which do not correspond to
declared @Property annotated elements
* support polymorphic setter methods in POJOs (see p12 of "SCA Service Component
......
......@@ -178,7 +178,7 @@ implements ReconfigurableComponentContext {
throw new IllegalArgumentException(msg);
}
Object value = _this_weavablePC.get(propertyName);
Object value = _this_weavablePC.getValue(propertyName);
try {
@SuppressWarnings("unchecked")
......
......@@ -24,12 +24,12 @@
package org.ow2.frascati.tinfi.control.property;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.objectweb.fractal.api.control.ContentController;
import org.objectweb.fractal.api.control.NameController;
import org.ow2.frascati.tinfi.control.property.IllegalPromoterException;
import org.ow2.frascati.tinfi.control.property.SCAPropertyController;
/**
* Mixin layer for implementing the {@link ContentController} interface.
......@@ -49,46 +49,83 @@ implements SCAPropertyController {
// Implementation of the SCAPropertyController interface
// -------------------------------------------------------------------------
private Map<String,Object> properties = new HashMap<String,Object>();
private Map<String,Object> values = new HashMap<String,Object>();
private Map<String,Class<?>> types = new HashMap<String,Class<?>>();
private Map<String,SCAPropertyController> promoters =
new HashMap<String,SCAPropertyController>();
/**
* Set the value for the specified property name. If the property has
* already been set, the old value is lost, and the new value is recorded.
* Set the type of the specified property. If the property has already been
* set, the old value is lost, and the new value is recorded.
*
* @param type the property type
* @param value the property value
* @since 1.1.1
*/
public void setType( String name, Class<?> type ) {
SCAPropertyController promoter = promoters.get(name);
if( promoter == null ) {
types.put(name,type);
}
else {
promoter.setType(name,type);
}
}
/**
* Set the value of the specified property. If the property has already been
* set, the old value is lost, and the new value is recorded.
*
* @param name the property name
* @param value the property value
*/
public void set( String name, Object value ) {
public void setValue( String name, Object value ) {
SCAPropertyController promoter = promoters.get(name);
if( promoter == null ) {
values.put(name,value);
}
else {
promoter.setValue(name,value);
}
}
/**
* Return the type of the specified property. Return <code>null</code> if
* the property type has not been set.
*
* @param name the property name
* @return the property value
* @since 1.1.1
*/
public Class<?> getType( String name ) {
SCAPropertyController promoter = promoters.get(name);
if( promoter == null ) {
properties.put(name, value);
return types.get(name);
}
else {
promoter.set(name,value);
return promoter.getType(name);
}
}
/**
* Return the value for the specified property name. Return
* <code>null</code> if the property has not been set.
* Return the value of the specified property. Return <code>null</code> if
* the property value has not been set.
*
* @param name the property name
* @return the property value
*/
public Object get( String name ) {
public Object getValue( String name ) {
SCAPropertyController promoter = promoters.get(name);
if( promoter == null ) {
return properties.get(name);
return values.get(name);
}
else {
return promoter.get(name);
return promoter.getValue(name);
}
}
/**
* Return <code>true</code> if the specified property name has been set.
* Return <code>true</code> if the specified property has been set.
*
* @param name the property name
* @return <code>true</code> if the property has been set,
......@@ -97,7 +134,7 @@ implements SCAPropertyController {
public boolean containsKey( String name ) {
SCAPropertyController promoter = promoters.get(name);
if( promoter == null ) {
return properties.containsKey(name);
return values.containsKey(name);
}
else {
return promoter.containsKey(name);
......@@ -105,27 +142,19 @@ implements SCAPropertyController {
}
/**
* Return a map of all the properties which have been set so far.
* Return the property names.
*
* @return a map of all the properties which have been set so far
* @since 1.1.1
*/
public Map<String,Object> getAll() {
Map<String,Object> result = new HashMap<String,Object>();
for (Map.Entry<String,Object> entry : properties.entrySet()) {
String name = entry.getKey();
Object value = null;
SCAPropertyController promoter = promoters.get(name);
if( promoter == null ) {
value = entry.getValue();
}
else {
value = promoter.get(name);
}
result.put(name,value);
}
return result;
public Set<String> keySet() {
Set<String> set = new HashSet<String>();
Set<String> valueKeys = values.keySet();
Set<String> valueTypes = types.keySet();
set.addAll(valueKeys);
set.addAll(valueTypes);
return set;
}
/**
* Set the reference of the property controller which promotes the specified
* property to the current property controller.
......
......@@ -66,7 +66,7 @@ extends org.objectweb.fractal.juliac.desc.ComponentDesc {
pw.print (id);
pw.print (".getFcInterface(\"");
pw.print (SCAPropertyController.NAME);
pw.print ("\")).set(\"");
pw.print ("\")).setValue(\"");
pw.print (name);
pw.print ("\",\"");
pw.print (value);
......
......@@ -31,7 +31,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
......@@ -197,7 +196,7 @@ public abstract class AbstractScopeManager implements ScopeManager {
" is neither a reference name, nor a property name";
throw new InstantiationException(msg);
}
values[i] = scapc.get(name);
values[i] = scapc.getValue(name);
}
}
......@@ -310,10 +309,9 @@ public abstract class AbstractScopeManager implements ScopeManager {
* this set (it would be a bit difficult to decide whether they should
* be included in ccmd.refs or in ccmd.props.)
*/
Map<String,Object> props = scapc.getAll();
for (Map.Entry<String,Object> entry : props.entrySet()) {
String name = entry.getKey();
Object value = entry.getValue();
Set<String> propnames = scapc.keySet();
for (String name : propnames) {
Object value = scapc.getValue(name);
if( ccmd.props.containsReferenceName(name) ) {
// @Property annotation
ccmd.props.set(content,name,value);
......
......@@ -23,7 +23,7 @@
package org.ow2.frascati.tinfi.control.property;
import java.util.Map;
import java.util.Set;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
......@@ -46,25 +46,45 @@ public interface SCAPropertyController {
false, false, false );
/**
* Set the value for the specified property name. If the property has
* already been set, the old value is lost, and the new value is recorded.
* Set the type of the specified property. If the property has already been
* set, the old value is lost, and the new value is recorded.
*
* @param type the property type
* @param value the property value
* @since 1.1.1
*/
public void setType( String name, Class<?> type );
/**
* Set the value of the specified property. If the property has already been
* set, the old value is lost, and the new value is recorded.
*
* @param name the property name
* @param value the property value
*/
public void set( String name, Object value );
public void setValue( String name, Object value );
/**
* Return the type of the specified property. Return <code>null</code> if
* the property type has not been set.
*
* @param name the property name
* @return the property value
* @since 1.1.1
*/
public Class<?> getType( String name );
/**
* Return the value for the specified property name. Return null if the
* property has not been set.
* Return the value of the specified property. Return <code>null</code> if
* the property value has not been set.
*
* @param name the property name
* @return the property value
*/
public Object get( String name );
public Object getValue( String name );
/**
* Return <code>true</code> if the specified property name has been set.
* Return <code>true</code> if the specified property has been set.
*
* @param name the property name
* @return <code>true</code> if the property has been set,
......@@ -73,11 +93,11 @@ public interface SCAPropertyController {
public boolean containsKey( String name );
/**
* Return a map of all the properties which have been set so far.
* Return the property names.
*
* @return a map of all the properties which have been set so far
* @since 1.1.1
*/
public Map<String,Object> getAll();
public Set<String> keySet();
/**
* Set the reference of the property controller which promotes the specified
......
......@@ -100,7 +100,7 @@ public class ComponentContextTestCase extends TestCase {
Component client = Fractal.getContentController(c).getFcSubComponents()[0];
SCAPropertyController scapc = (SCAPropertyController)
client.getFcInterface(SCAPropertyController.NAME);
scapc.set("name", "Bob");
scapc.setValue("name", "Bob");
String value = itf.getProperty(String.class, "name");
assertEquals("Bob", value);
......
......@@ -53,7 +53,7 @@ public class ConstructorTestCase extends TestCase {
Component client = Fractal.getContentController(composite).getFcSubComponents()[0];
SCAPropertyController scapc = (SCAPropertyController)
client.getFcInterface(SCAPropertyController.NAME);
scapc.set("name", "Bob");
scapc.setValue("name", "Bob");
Runnable itf = TinfiDomain.getService(composite,Runnable.class,service);
......
......@@ -60,15 +60,15 @@ public class PropertyTestCase extends TestCase {
public void testNewValueForMandatoryProp() {
String expected = "bar";
scapc.set("mandatoryProp",expected);
scapc.setValue("mandatoryProp",expected);
String value = itf.mandatoryPropValue();
assertEquals(expected,value);
}
public void testNewValuePropWithDefault() {
String expected = "bar";
scapc.set("mandatoryProp",expected);
scapc.set("propWithDefault",expected);
scapc.setValue("mandatoryProp",expected);
scapc.setValue("propWithDefault",expected);
String value = itf.propWithDefaultValue();
assertEquals(expected,value);
}
......
......@@ -44,7 +44,7 @@ public class ConstructorPropertyInjectionTestCase extends TestCase {
Component client = Fractal.getContentController(composite).getFcSubComponents()[0];
SCAPropertyController scapc = (SCAPropertyController)
client.getFcInterface(SCAPropertyController.NAME);
scapc.set("bar", "fubar");
scapc.setValue("bar", "fubar");
Bar foo = (Bar) composite.getFcInterface("Foo1Component");
assertEquals("fubar", foo.getBar());
......@@ -55,7 +55,7 @@ public class ConstructorPropertyInjectionTestCase extends TestCase {
Component client = Fractal.getContentController(composite).getFcSubComponents()[1];
SCAPropertyController scapc = (SCAPropertyController)
client.getFcInterface(SCAPropertyController.NAME);
scapc.set("bar", "fubar");
scapc.setValue("bar", "fubar");
Bar foo = (Bar) composite.getFcInterface("Foo2Component");
assertEquals("fubar", foo.getBar());
......@@ -66,7 +66,7 @@ public class ConstructorPropertyInjectionTestCase extends TestCase {
Component client = Fractal.getContentController(composite).getFcSubComponents()[2];
SCAPropertyController scapc = (SCAPropertyController)
client.getFcInterface(SCAPropertyController.NAME);
scapc.set("bar", "fubar");
scapc.setValue("bar", "fubar");
Bar foo = (Bar) composite.getFcInterface("Foo3Component");
assertEquals("fubar", foo.getBar());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment