You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2012/02/13 01:54:18 UTC
svn commit: r1243383 - in /aries/trunk/sandbox/jmx-next/jmx-core/src:
main/java/org/apache/aries/jmx/codec/PropertyData.java
main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java
test/java/org/apache/aries/jmx/codec/PropertyDataTest.java
Author: davidb
Date: Mon Feb 13 00:54:17 2012
New Revision: 1243383
URL: http://svn.apache.org/viewvc?rev=1243383&view=rev
Log:
Fixes the calculation of the wiring closure.
Also includes a change that encodes a List as an Array.
Modified:
aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/PropertyData.java
aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java
aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/PropertyDataTest.java
Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/PropertyData.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/PropertyData.java?rev=1243383&r1=1243382&r2=1243383&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/PropertyData.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/PropertyData.java Mon Feb 13 00:54:17 2012
@@ -35,6 +35,7 @@ import static org.osgi.jmx.JmxConstants.
import java.lang.reflect.Array;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -50,7 +51,7 @@ import org.osgi.jmx.JmxConstants;
* <tt>PropertyData</tt> represents Property Type @see {@link JmxConstants#PROPERTY_TYPE}. It is a codec for the
* <code>CompositeData</code> representing a Property with an associated Type and Value.
* </p>
- *
+ *
* @version $Rev$ $Date$
*/
public class PropertyData<T> {
@@ -59,27 +60,27 @@ public class PropertyData<T> {
* @see JmxConstants#KEY_ITEM
*/
private String key;
-
+
/**
* @see JmxConstants#SCALAR
*/
private T value;
-
+
/**
* @see JmxConstants#VALUE_ITEM
*/
private String encodedValue;
-
+
/**
* @see JmxConstants#TYPE_ITEM
*/
private String encodedType;
-
+
private PropertyData() {
super();
}
-
-
+
+
@SuppressWarnings("unchecked")
private PropertyData(String key, T value, String preservedBaseType) throws IllegalArgumentException {
if (key == null) {
@@ -106,16 +107,16 @@ public class PropertyData<T> {
}
this.encodedValue = builder.toString();
} else if (type.equals(Vector.class)) {
- Vector vector = (Vector) value;
+ Vector<?> vector = (Vector<?>) value;
Class<? extends Object> componentType = Object.class;
if (vector.size() > 0) {
componentType = vector.firstElement().getClass();
}
this.encodedType = VECTOR_OF + componentType.getSimpleName();
StringBuilder builder = new StringBuilder();
- Vector valueVector = (Vector) value;
+ Vector<?> valueVector = (Vector<?>) value;
boolean useDelimiter = false;
- for (Object val: valueVector) {
+ for (Object val : valueVector) {
if (useDelimiter) {
builder.append(",");
} else {
@@ -124,12 +125,31 @@ public class PropertyData<T> {
builder.append(val);
}
this.encodedValue = builder.toString();
+ } else if (List.class.isAssignableFrom(type)) {
+ // Lists are encoded as Arrays...
+ List<?> list = (List<?>) value;
+ Class<?> componentType = Object.class;
+ if (list.size() > 0)
+ componentType = list.get(0).getClass();
+
+ this.encodedType = ARRAY_OF + componentType.getSimpleName();
+ StringBuilder builder = new StringBuilder();
+ boolean useDelimiter = false;
+ for (Object o : list) {
+ if (useDelimiter) {
+ builder.append(",");
+ } else {
+ useDelimiter = true;
+ }
+ builder.append(o);
+ }
+ this.encodedValue = builder.toString();
} else {
this.encodedType = (preservedBaseType == null) ? type.getSimpleName() : preservedBaseType;
this.encodedValue = value.toString();
}
}
-
+
/**
* Static factory method for <code>PropertyData</code> instance parameterized by value's type
* @param <T>
@@ -141,10 +161,10 @@ public class PropertyData<T> {
public static <T> PropertyData<T> newInstance(String key, T value) throws IllegalArgumentException {
return new PropertyData<T>(key, value, null);
}
-
+
/**
* Static factory method for <code>PropertyData</code> instance which preserves encoded type
- * information for primitive int type
+ * information for primitive int type
* @param key
* @param value
* @return
@@ -153,10 +173,10 @@ public class PropertyData<T> {
public static PropertyData<Integer> newInstance(String key, int value) throws IllegalArgumentException {
return new PropertyData<Integer>(key, value, P_INT);
}
-
+
/**
* Static factory method for <code>PropertyData</code> instance which preserves encoded type
- * information for primitive long type
+ * information for primitive long type
* @param key
* @param value
* @return
@@ -165,10 +185,10 @@ public class PropertyData<T> {
public static PropertyData<Long> newInstance(String key, long value) throws IllegalArgumentException {
return new PropertyData<Long>(key, value, P_LONG);
}
-
+
/**
* Static factory method for <code>PropertyData</code> instance which preserves encoded type
- * information for primitive float type
+ * information for primitive float type
* @param key
* @param value
* @return
@@ -177,10 +197,10 @@ public class PropertyData<T> {
public static PropertyData<Float> newInstance(String key, float value) throws IllegalArgumentException {
return new PropertyData<Float>(key, value, P_FLOAT);
}
-
+
/**
* Static factory method for <code>PropertyData</code> instance which preserves encoded type
- * information for primitive double type
+ * information for primitive double type
* @param key
* @param value
* @return
@@ -189,10 +209,10 @@ public class PropertyData<T> {
public static PropertyData<Double> newInstance(String key, double value) throws IllegalArgumentException {
return new PropertyData<Double>(key, value, P_DOUBLE);
}
-
+
/**
* Static factory method for <code>PropertyData</code> instance which preserves encoded type
- * information for primitive byte type
+ * information for primitive byte type
* @param key
* @param value
* @return
@@ -201,10 +221,10 @@ public class PropertyData<T> {
public static PropertyData<Byte> newInstance(String key, byte value) throws IllegalArgumentException {
return new PropertyData<Byte>(key, value, P_BYTE);
}
-
+
/**
* Static factory method for <code>PropertyData</code> instance which preserves encoded type
- * information for primitive char type
+ * information for primitive char type
* @param key
* @param value
* @return
@@ -213,10 +233,10 @@ public class PropertyData<T> {
public static PropertyData<Character> newInstance(String key, char value) throws IllegalArgumentException {
return new PropertyData<Character>(key, value, P_CHAR);
}
-
+
/**
* Static factory method for <code>PropertyData</code> instance which preserves encoded type
- * information for primitive boolean type
+ * information for primitive boolean type
* @param key
* @param value
* @return
@@ -225,7 +245,7 @@ public class PropertyData<T> {
public static PropertyData<Boolean> newInstance(String key, boolean value) throws IllegalArgumentException {
return new PropertyData<Boolean>(key, value, P_BOOLEAN);
}
-
+
/**
* Returns CompositeData representing a Property typed by {@link JmxConstants#PROPERTY_TYPE}.
@@ -244,7 +264,7 @@ public class PropertyData<T> {
}
return result;
}
-
+
/**
* Constructs a <code>PropertyData</code> object from the given <code>CompositeData</code>
* @param compositeData
@@ -307,8 +327,8 @@ public class PropertyData<T> {
}
return propertyData;
}
-
-
+
+
public String getKey() {
return key;
}
@@ -320,7 +340,7 @@ public class PropertyData<T> {
public String getEncodedType() {
return encodedType;
}
-
+
public String getEncodedValue() {
return encodedValue;
}
@@ -328,5 +348,5 @@ public class PropertyData<T> {
public boolean isEncodingPrimitive() {
return primitiveTypes.containsKey(encodedType);
}
-
+
}
Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java?rev=1243383&r1=1243382&r2=1243383&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java Mon Feb 13 00:54:17 2012
@@ -116,13 +116,21 @@ public class BundleWiringState implement
if (wiring == null)
return;
- List<BundleWire> wires = wiring.getRequiredWires(namespace);
- for (BundleWire wire : wires) {
+ List<BundleWire> requiredWires = wiring.getRequiredWires(namespace);
+ for (BundleWire wire : requiredWires) {
BundleRevision revision = wire.getCapability().getRevision();
if (!allRevisions.containsKey(revision)) {
populateTransitiveRevisions(namespace, revision, allRevisions);
}
}
+
+ List<BundleWire> providedWires = wiring.getProvidedWires(namespace);
+ for (BundleWire wire : providedWires) {
+ BundleRevision revision = wire.getRequirement().getRevision();
+ if (!allRevisions.containsKey(revision)) {
+ populateTransitiveRevisions(namespace, revision, allRevisions);
+ }
+ }
}
private CompositeData getRevisionWiring(BundleRevision revision, int revisionID, String namespace, Map<BundleRevision, Integer> revisionIDMap) {
Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/PropertyDataTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/PropertyDataTest.java?rev=1243383&r1=1243382&r2=1243383&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/PropertyDataTest.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/PropertyDataTest.java Mon Feb 13 00:54:17 2012
@@ -36,7 +36,9 @@ import static org.osgi.jmx.JmxConstants.
import static org.osgi.jmx.JmxConstants.VALUE;
import java.math.BigInteger;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Vector;
@@ -46,208 +48,208 @@ import javax.management.openmbean.Compos
import org.junit.Test;
/**
- *
+ *
*
* @version $Rev$ $Date$
*/
public class PropertyDataTest {
-
+
@Test
public void testToCompositeDataForPrimitiveTypes() throws Exception {
-
+
PropertyData<Integer> intData = PropertyData.newInstance("test", 1);
CompositeData intCData = intData.toCompositeData();
assertEquals("test", intCData.get(KEY));
assertEquals("1", intCData.get(VALUE));
assertEquals(P_INT, intCData.get(TYPE));
-
+
PropertyData<Double> doubleData = PropertyData.newInstance("test", 1.0);
CompositeData doubleCData = doubleData.toCompositeData();
assertEquals("test", doubleCData.get(KEY));
assertEquals("1.0", doubleCData.get(VALUE));
assertEquals(P_DOUBLE, doubleCData.get(TYPE));
-
+
PropertyData<Character> charData = PropertyData.newInstance("test", 'c');
CompositeData charCData = charData.toCompositeData();
assertEquals("test", charCData.get(KEY));
assertEquals("c", charCData.get(VALUE));
assertEquals(P_CHAR, charCData.get(TYPE));
-
+
PropertyData<Boolean> booleanData = PropertyData.newInstance("test", true);
CompositeData booleanCData = booleanData.toCompositeData();
assertEquals("test", booleanCData.get(KEY));
assertEquals("true", booleanCData.get(VALUE));
assertEquals(P_BOOLEAN, booleanCData.get(TYPE));
}
-
+
@Test
public void testFromCompositeDataForPrimitiveTypes() throws Exception {
-
+
Map<String, Object> items = new HashMap<String, Object>();
items.put(KEY, "key");
items.put(VALUE, "1");
items.put(TYPE, P_INT);
CompositeData compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
-
+
PropertyData<Integer> intData = PropertyData.from(compositeData);
assertEquals("key", intData.getKey());
assertEquals(new Integer(1), intData.getValue());
assertEquals(P_INT, intData.getEncodedType());
assertTrue(intData.isEncodingPrimitive());
-
+
items.clear();
items.put(KEY, "key");
items.put(VALUE, "1.0");
items.put(TYPE, P_DOUBLE);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
-
+
PropertyData<Double> doubleData = PropertyData.from(compositeData);
assertEquals("key", doubleData.getKey());
assertEquals(Double.valueOf(1.0), doubleData.getValue());
assertEquals(P_DOUBLE, doubleData.getEncodedType());
assertTrue(doubleData.isEncodingPrimitive());
-
+
items.clear();
items.put(KEY, "key");
items.put(VALUE, "a");
items.put(TYPE, P_CHAR);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
-
+
PropertyData<Character> charData = PropertyData.from(compositeData);
assertEquals("key", charData.getKey());
assertEquals(Character.valueOf('a'), charData.getValue());
assertEquals(P_CHAR, charData.getEncodedType());
assertTrue(charData.isEncodingPrimitive());
-
+
items.clear();
items.put(KEY, "key");
items.put(VALUE, "true");
items.put(TYPE, P_BOOLEAN);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
-
+
PropertyData<Boolean> booleanData = PropertyData.from(compositeData);
assertEquals("key", booleanData.getKey());
assertTrue(booleanData.getValue());
assertEquals(P_BOOLEAN, booleanData.getEncodedType());
assertTrue(booleanData.isEncodingPrimitive());
-
+
}
-
+
@Test
public void testToCompositeDataForWrapperTypes() {
-
+
PropertyData<Integer> intData = PropertyData.newInstance("test", new Integer(1));
CompositeData intCData = intData.toCompositeData();
assertEquals("test", intCData.get(KEY));
assertEquals("1", intCData.get(VALUE));
assertEquals(INTEGER, intCData.get(TYPE));
-
+
PropertyData<Double> doubleData = PropertyData.newInstance("test", new Double(1.0));
CompositeData doubleCData = doubleData.toCompositeData();
assertEquals("test", doubleCData.get(KEY));
assertEquals("1.0", doubleCData.get(VALUE));
assertEquals(DOUBLE, doubleCData.get(TYPE));
-
+
PropertyData<Character> charData = PropertyData.newInstance("test", Character.valueOf('c'));
CompositeData charCData = charData.toCompositeData();
assertEquals("test", charCData.get(KEY));
assertEquals("c", charCData.get(VALUE));
assertEquals(CHARACTER, charCData.get(TYPE));
-
+
PropertyData<Boolean> booleanData = PropertyData.newInstance("test", Boolean.TRUE);
CompositeData booleanCData = booleanData.toCompositeData();
assertEquals("test", booleanCData.get(KEY));
assertEquals("true", booleanCData.get(VALUE));
assertEquals(BOOLEAN, booleanCData.get(TYPE));
-
+
}
-
+
@Test
public void testFromCompositeDataForWrapperTypes() throws Exception {
-
+
Map<String, Object> items = new HashMap<String, Object>();
items.put(KEY, "key");
items.put(VALUE, "1");
items.put(TYPE, INTEGER);
CompositeData compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
-
+
PropertyData<Integer> intData = PropertyData.from(compositeData);
assertEquals("key", intData.getKey());
assertEquals(new Integer(1), intData.getValue());
assertEquals(INTEGER, intData.getEncodedType());
assertFalse(intData.isEncodingPrimitive());
-
+
items.clear();
items.put(KEY, "key");
items.put(VALUE, "1.0");
items.put(TYPE, DOUBLE);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
-
+
PropertyData<Double> doubleData = PropertyData.from(compositeData);
assertEquals("key", doubleData.getKey());
assertEquals(Double.valueOf(1.0), doubleData.getValue());
assertEquals(DOUBLE, doubleData.getEncodedType());
assertFalse(doubleData.isEncodingPrimitive());
-
+
items.clear();
items.put(KEY, "key");
items.put(VALUE, "a");
items.put(TYPE, CHARACTER);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
-
+
PropertyData<Character> charData = PropertyData.from(compositeData);
assertEquals("key", charData.getKey());
assertEquals(Character.valueOf('a'), charData.getValue());
assertEquals(CHARACTER, charData.getEncodedType());
assertFalse(charData.isEncodingPrimitive());
-
+
items.clear();
items.put(KEY, "key");
items.put(VALUE, "true");
items.put(TYPE, BOOLEAN);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
-
+
PropertyData<Boolean> booleanData = PropertyData.from(compositeData);
assertEquals("key", booleanData.getKey());
assertTrue(booleanData.getValue());
assertEquals(BOOLEAN, booleanData.getEncodedType());
assertFalse(booleanData.isEncodingPrimitive());
-
+
}
-
+
@Test
public void testToFromCompositeDataForAdditionalTypes() {
-
+
PropertyData<String> stringData = PropertyData.newInstance("test", "value");
-
+
CompositeData stringCData = stringData.toCompositeData();
assertEquals("test", stringCData.get(KEY));
assertEquals("value", stringCData.get(VALUE));
assertEquals(STRING, stringCData.get(TYPE));
-
+
stringData = PropertyData.from(stringCData);
assertEquals("test", stringData.getKey());
assertEquals("value", stringData.getValue());
assertEquals(STRING, stringData.getEncodedType());
-
+
PropertyData<BigInteger> bigIntData = PropertyData.newInstance("test", new BigInteger("1"));
-
+
CompositeData bigIntCData = bigIntData.toCompositeData();
assertEquals("test", bigIntCData.get(KEY));
assertEquals("1", bigIntCData.get(VALUE));
assertEquals(BIGINTEGER, bigIntCData.get(TYPE));
-
+
bigIntData = PropertyData.from(bigIntCData);
assertEquals("test", bigIntData.getKey());
assertEquals(new BigInteger("1"), bigIntData.getValue());
assertEquals(BIGINTEGER, bigIntData.getEncodedType());
-
+
}
@Test
public void testToFromCompositeDataForArrayTypes() {
-
+
//long[]
long[] primitiveLongValues = new long[] { 1, 2, 3 };
PropertyData<long[]> primitiveLongArrayData = PropertyData.newInstance("test", primitiveLongValues);
@@ -259,7 +261,7 @@ public class PropertyDataTest {
assertEquals("test", primitiveLongArrayData.getKey());
assertEquals("Array of long", primitiveLongArrayData.getEncodedType());
assertArrayEquals(primitiveLongValues, primitiveLongArrayData.getValue());
-
+
//Long[]
Long[] longValues = new Long[] { new Long(4), new Long(5), new Long(6) };
PropertyData<Long[]> longArrayData = PropertyData.newInstance("test", longValues);
@@ -271,7 +273,7 @@ public class PropertyDataTest {
assertEquals("test", longArrayData.getKey());
assertEquals("Array of Long", longArrayData.getEncodedType());
assertArrayEquals(longValues, longArrayData.getValue());
-
+
//char[]
char[] primitiveCharValues = new char[] { 'a', 'b', 'c' };
PropertyData<char[]> primitiveCharArrayData = PropertyData.newInstance("test", primitiveCharValues);
@@ -283,7 +285,7 @@ public class PropertyDataTest {
assertEquals("test", primitiveCharArrayData.getKey());
assertEquals("Array of char", primitiveCharArrayData.getEncodedType());
assertArrayEquals(primitiveCharValues, primitiveCharArrayData.getValue());
-
+
//Character[]
Character[] charValues = new Character[] { 'a', 'b', 'c' };
PropertyData<Character[]> charArrayData = PropertyData.newInstance("test", charValues);
@@ -295,30 +297,65 @@ public class PropertyDataTest {
assertEquals("test", charArrayData.getKey());
assertEquals("Array of Character", charArrayData.getEncodedType());
assertArrayEquals(charValues, charArrayData.getValue());
-
+
}
-
+
@Test
public void testToFromCompositeDataForVector() {
-
+
Vector<Long> vector = new Vector<Long>();
vector.add(new Long(40));
vector.add(new Long(50));
vector.add(new Long(60));
-
+
PropertyData<Vector<Long>> vectorPropertyData = PropertyData.newInstance("test", vector);
CompositeData vectorCompositeData = vectorPropertyData.toCompositeData();
-
+
assertEquals("test", vectorCompositeData.get(KEY));
assertEquals("40,50,60", vectorCompositeData.get(VALUE));
assertEquals("Vector of Long", vectorCompositeData.get(TYPE));
-
+
vectorPropertyData = PropertyData.from(vectorCompositeData);
assertEquals("test", vectorPropertyData.getKey());
assertEquals("Vector of Long", vectorPropertyData.getEncodedType());
assertArrayEquals(vector.toArray(new Long[vector.size()]), vectorPropertyData.getValue().toArray(new Long[vector.size()]));
-
+
}
-
+ @Test
+ public void testToFromCompositeDataForList() {
+ List<String> sl = new ArrayList<String>();
+ sl.add("A");
+ sl.add("B");
+
+ PropertyData<List<String>> pd = PropertyData.newInstance("test", sl);
+ CompositeData cd = pd.toCompositeData();
+
+ assertEquals("test", cd.get(KEY));
+ assertEquals("A,B", cd.get(VALUE));
+ assertEquals("Array of String", cd.get(TYPE));
+
+ PropertyData<String []> pd2 = PropertyData.from(cd);
+ assertEquals("test", pd2.getKey());
+ assertEquals("Array of String", pd2.getEncodedType());
+ assertArrayEquals(new String [] {"A", "B"}, pd2.getValue());
+ }
+
+ @Test
+ public void testToFromCompositeDataForList2() {
+ List<Long> sl = new ArrayList<Long>();
+ sl.add(Long.MAX_VALUE);
+
+ PropertyData<List<Long>> pd = PropertyData.newInstance("test", sl);
+ CompositeData cd = pd.toCompositeData();
+
+ assertEquals("test", cd.get(KEY));
+ assertEquals(new Long(Long.MAX_VALUE).toString(), cd.get(VALUE));
+ assertEquals("Array of Long", cd.get(TYPE));
+
+ PropertyData<Long []> pd2 = PropertyData.from(cd);
+ assertEquals("test", pd2.getKey());
+ assertEquals("Array of Long", pd2.getEncodedType());
+ assertArrayEquals(new Long [] {Long.MAX_VALUE}, pd2.getValue());
+ }
}