FELIX-4631 : [DS][R6/RFC212] Implement field injection. Use boolen to test strategy
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1637851 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java b/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java
index 0bc3712..0592088 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java
@@ -324,7 +324,7 @@
}
// if the field is dynamic with the replace strategy it has to be volatile
- if ( !metadata.isStatic() && metadata.getFieldStrategy().equals(ReferenceMetadata.FIELD_STRATEGY_REPLACE) )
+ if ( !metadata.isStatic() && metadata.isReplace() )
{
if ( !Modifier.isVolatile(f.getModifiers()) )
{
@@ -336,7 +336,7 @@
// replace strategy: field must not be final
// only collection and list allowed
- if ( metadata.getFieldStrategy().equals(ReferenceMetadata.FIELD_STRATEGY_REPLACE) )
+ if ( metadata.isReplace() )
{
if ( Modifier.isFinal(f.getModifiers()) )
{
@@ -410,7 +410,7 @@
if ( metadata.isMultiple()
&& !metadata.isStatic() )
{
- if ( ReferenceMetadata.FIELD_STRATEGY_REPLACE.equals(metadata.getFieldStrategy()) )
+ if ( metadata.isReplace() )
{
this.setFieldValue(componentInstance, Collections.emptyList());
}
@@ -517,7 +517,7 @@
{
final Object obj = getValue(key, refPair);
this.boundValues.put(refPair, obj);
- if ( ReferenceMetadata.FIELD_STRATEGY_REPLACE.equals(metadata.getFieldStrategy()) )
+ if ( metadata.isReplace() )
{
this.setFieldValue(componentInstance, getReplaceCollection());
}
@@ -534,7 +534,7 @@
if ( !metadata.isStatic() )
{
final Object obj = this.boundValues.remove(refPair);
- if ( ReferenceMetadata.FIELD_STRATEGY_REPLACE.equals(metadata.getFieldStrategy()) )
+ if ( metadata.isReplace() )
{
this.setFieldValue(componentInstance, getReplaceCollection());
}
@@ -556,7 +556,7 @@
final Object obj = getValue(key, refPair);
final Object oldObj = this.boundValues.put(refPair, obj);
- if ( ReferenceMetadata.FIELD_STRATEGY_REPLACE.equals(metadata.getFieldStrategy()) )
+ if ( metadata.isReplace() )
{
this.setFieldValue(componentInstance, getReplaceCollection());
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java b/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
index 8284164..8842972 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
@@ -65,10 +65,10 @@
private static final Set<String> POLICY_OPTION_VALID;
// constant for update field strategy
- public static final String FIELD_STRATEGY_UPDATE = "update";
+ private static final String FIELD_STRATEGY_UPDATE = "update";
// constant for replace field strategy
- public static final String FIELD_STRATEGY_REPLACE = "replace";
+ private static final String FIELD_STRATEGY_REPLACE = "replace";
// set of valid field strategy settings
private static final Set<String> FIELD_STRATEGY_VALID;
@@ -135,6 +135,7 @@
private boolean m_isOptional = false;
private boolean m_isMultiple = false;
private boolean m_isReluctant = true;
+ private boolean m_isReplace = true;
// Flag that is set once the component is verified (its properties cannot be changed)
private boolean m_validated = false;
@@ -363,6 +364,8 @@
}
m_field_strategy = strategy;
+
+ m_isReplace = FIELD_STRATEGY_REPLACE.equals(strategy);
}
/**
@@ -539,7 +542,6 @@
return m_isStatic;
}
-
/**
* Test if dependency is optional (0..1 or 0..n)
*
@@ -572,6 +574,15 @@
return m_isReluctant;
}
+ /**
+ * Test if field strategy is replace.
+ *
+ * @return true if field strategy is replace
+ */
+ public boolean isReplace()
+ {
+ return m_isReplace;
+ }
/**
* Returns the name of the component property referring to the {@link #getTarget() target}
@@ -746,6 +757,7 @@
return getField() +
"interface=" + this.getInterface() +
", filter=" + this.getTarget() +
+ ", strategy=" + this.getFieldStrategy() +
", policy=" + this.getPolicy() +
", cardinality=" + this.getCardinality();
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
index d2f31ef..42331da 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
@@ -317,14 +317,7 @@
dto.scope = r.getScope().name();
if ( r.getField() != null )
{
- if ( ReferenceMetadata.FIELD_STRATEGY_REPLACE.equals(r.getFieldStrategy()) )
- {
- dto.strategy = ReferenceDTO.STRATEGY_FIELD_REPLACE;
- }
- else
- {
- dto.strategy = ReferenceDTO.STRATEGY_FIELD_UPDATE;
- }
+ dto.strategy = r.isReplace() ? ReferenceDTO.STRATEGY_FIELD_REPLACE : ReferenceDTO.STRATEGY_FIELD_UPDATE;
}
else
{