Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 86954 invoked from network); 30 Jun 2009 20:04:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Jun 2009 20:04:09 -0000 Received: (qmail 50777 invoked by uid 500); 30 Jun 2009 20:04:19 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 50708 invoked by uid 500); 30 Jun 2009 20:04:19 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 50699 invoked by uid 99); 30 Jun 2009 20:04:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Jun 2009 20:04:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Jun 2009 20:04:13 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B87FF2388876; Tue, 30 Jun 2009 20:03:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r789914 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/ main/java/org/apache/geronimo/blueprint/container/ main/java/org/apache/geronimo/blueprint/di/ main/java/org/apache/geronimo/blueprint/nam... Date: Tue, 30 Jun 2009 20:03:51 -0000 To: scm@geronimo.apache.org From: gnodet@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090630200351.B87FF2388876@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gnodet Date: Tue Jun 30 20:03:50 2009 New Revision: 789914 URL: http://svn.apache.org/viewvc?rev=789914&view=rev Log: Fix a few tck problems Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java - copied, changed from r788924, geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefListRecipe.java Removed: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefListRecipe.java Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintConstants.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/MapRecipe.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintConstants.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintConstants.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintConstants.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintConstants.java Tue Jun 30 20:03:50 2009 @@ -24,7 +24,7 @@ public static final String TIMEOUT_DIRECTIVE = "blueprint.timeout"; - public static final String WAIT_FOR_DEPENDENCIES_DIRECTIVE = "blueprint.wait-for-dependencies"; + public static final String GRACE_PERIOD = "blueprint.graceperiod"; public static final String BUNDLE_VERSION = "bundle.version"; Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java Tue Jun 30 20:03:50 2009 @@ -61,6 +61,8 @@ * TODO: if we have a single interface (which is the standard behavior), then we should be able to get rid of * the proxyClassloader and just use this interface classloader to define the proxy * + * TODO: it is allowed to have no interface defined at all, which should result in an empty proxy + * * @author Apache Geronimo Project * @version $Rev: 760378 $, $Date: 2009-03-31 11:31:38 +0200 (Tue, 31 Mar 2009) $ */ @@ -78,6 +80,7 @@ protected final String filter; /** The list of listeners for this reference. This list will be lazy created */ protected List listeners; + protected boolean listenersCreated = true; private final List references = new ArrayList(); private final AtomicBoolean started = new AtomicBoolean(); @@ -411,8 +414,10 @@ for (Method method : objectPropMethods) { if (props == null) { props = new HashMap(); - for (String name : reference.getPropertyKeys()) { - props.put(name, reference.getProperty(name)); + if (reference == null) { + for (String name : reference.getPropertyKeys()) { + props.put(name, reference.getProperty(name)); + } } } try { Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AggregateConverter.java Tue Jun 30 20:03:50 2009 @@ -22,20 +22,25 @@ import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; +import java.util.Hashtable; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import java.util.regex.Pattern; +import java.math.BigInteger; +import java.math.BigDecimal; import org.apache.geronimo.blueprint.ExtendedBlueprintContainer; import org.apache.geronimo.blueprint.di.CollectionRecipe; import org.apache.geronimo.blueprint.di.MapRecipe; import static org.apache.geronimo.blueprint.utils.ReflectionUtils.getRealCause; -import org.osgi.service.blueprint.container.BlueprintContainer; import org.osgi.service.blueprint.container.ReifiedType; import org.osgi.service.blueprint.container.Converter; @@ -112,14 +117,18 @@ } Object value = convertWithConverters(fromValue, type); if (value == null) { - if (fromValue instanceof String) { + if (fromValue instanceof Number && Number.class.isAssignableFrom(unwrap(toClass(type)))) { + return convertToNumber((Number) fromValue, toClass(type)); + } else if (fromValue instanceof String) { return convertFromString((String) fromValue, toClass(type), blueprintContainer); - } else if (toClass(type).isArray()) { - return convertArray(fromValue, type); - } else if (Map.class.isAssignableFrom(toClass(type))) { - return convertMap(fromValue, type); - } else if (Collection.class.isAssignableFrom(toClass(type))) { - return convertCollection(fromValue, type); + } else if (toClass(type).isArray() && (fromValue instanceof Collection || fromValue.getClass().isArray())) { + return convertToArray(fromValue, type); + } else if (Map.class.isAssignableFrom(toClass(type)) && (fromValue instanceof Map || fromValue instanceof Dictionary)) { + return convertToMap(fromValue, type); + } else if (Dictionary.class.isAssignableFrom(toClass(type)) && (fromValue instanceof Map || fromValue instanceof Dictionary)) { + return convertToDictionary(fromValue, type); + } else if (Collection.class.isAssignableFrom(toClass(type)) && (fromValue instanceof Collection || fromValue.getClass().isArray())) { + return convertToCollection(fromValue, type); } else { throw new Exception("Unable to convert value " + fromValue + " to type " + type); } @@ -140,7 +149,35 @@ return value; } + public Object convertToNumber(Number value, Class toType) throws Exception { + toType = unwrap(toType); + if (AtomicInteger.class == toType) { + return new AtomicInteger((Integer) convertToNumber(value, Integer.class)); + } else if (AtomicLong.class == toType) { + return new AtomicLong((Long) convertToNumber(value, Long.class)); + } else if (Integer.class == toType) { + return value.intValue(); + } else if (Short.class == toType) { + return value.shortValue(); + } else if (Long.class == toType) { + return value.longValue(); + } else if (Float.class == toType) { + return value.floatValue(); + } else if (Double.class == toType) { + return value.doubleValue(); + } else if (Byte.class == toType) { + return value.byteValue(); + } else if (BigInteger.class == toType) { + return new BigInteger(value.toString()); + } else if (BigDecimal.class == toType) { + return new BigDecimal(value.toString()); + } else { + throw new Exception("Unable to convert number " + value + " to " + toType); + } + } + public Object convertFromString(String value, Class toType, Object loader) throws Exception { + toType = unwrap(toType); if (ReifiedType.class == toType) { try { return GenericType.parse(value, loader); @@ -171,7 +208,7 @@ ByteArrayInputStream in = new ByteArrayInputStream(value.getBytes("UTF8")); props.load(in); return props; - } else if (Boolean.class == toType || boolean.class == toType) { + } else if (Boolean.class == toType) { if ("yes".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value) || "on".equalsIgnoreCase(value)) { return Boolean.TRUE; } else if ("no".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value) || "off".equalsIgnoreCase(value)) { @@ -179,17 +216,17 @@ } else { throw new RuntimeException("Invalid boolean value: " + value); } - } else if (Integer.class == toType || int.class == toType) { + } else if (Integer.class == toType) { return Integer.valueOf(value); - } else if (Short.class == toType || short.class == toType) { + } else if (Short.class == toType) { return Short.valueOf(value); - } else if (Long.class == toType || long.class == toType) { + } else if (Long.class == toType) { return Long.valueOf(value); - } else if (Float.class == toType || float.class == toType) { + } else if (Float.class == toType) { return Float.valueOf(value); - } else if (Double.class == toType || double.class == toType) { + } else if (Double.class == toType) { return Double.valueOf(value); - } else if (Character.class == toType || char.class == toType) { + } else if (Character.class == toType) { if (value.length() == 6 && value.startsWith("\\u")) { int code = Integer.parseInt(value.substring(2), 16); return (char)code; @@ -198,7 +235,7 @@ } else { throw new Exception("Invalid value for character type: " + value); } - } else if (Byte.class == toType || byte.class == toType) { + } else if (Byte.class == toType) { return Byte.valueOf(value); } else if (Enum.class.isAssignableFrom(toType)) { return Enum.valueOf((Class) toType, value); @@ -224,7 +261,7 @@ } } - private Object convertCollection(Object obj, ReifiedType type) throws Exception { + private Object convertToCollection(Object obj, ReifiedType type) throws Exception { ReifiedType valueType = type.getActualTypeArgument(0); Collection newCol = (Collection) CollectionRecipe.getCollection(toClass(type)).newInstance(); if (obj.getClass().isArray()) { @@ -247,28 +284,71 @@ return newCol; } - private Object convertMap(Object obj, ReifiedType type) throws Exception { + private Object convertToDictionary(Object obj, ReifiedType type) throws Exception { + ReifiedType keyType = type.getActualTypeArgument(0); + ReifiedType valueType = type.getActualTypeArgument(1); + Dictionary newDic = new Hashtable(); + if (obj instanceof Dictionary) { + Dictionary dic = (Dictionary) obj; + for (Enumeration keyEnum = dic.keys(); keyEnum.hasMoreElements();) { + Object key = keyEnum.nextElement(); + try { + newDic.put(convert(key, keyType), convert(dic.get(key), valueType)); + } catch (Exception t) { + throw new Exception("Unable to convert from " + obj + " to " + type + "(error converting map entry)", t); + } + } + } else { + for (Map.Entry e : ((Map) obj).entrySet()) { + try { + newDic.put(convert(e.getKey(), keyType), convert(e.getValue(), valueType)); + } catch (Exception t) { + throw new Exception("Unable to convert from " + obj + " to " + type + "(error converting map entry)", t); + } + } + } + return newDic; + } + + private Object convertToMap(Object obj, ReifiedType type) throws Exception { ReifiedType keyType = type.getActualTypeArgument(0); ReifiedType valueType = type.getActualTypeArgument(1); Map newMap = (Map) MapRecipe.getMap(toClass(type)).newInstance(); - for (Map.Entry e : ((Map) obj).entrySet()) { - try { - newMap.put(convert(e.getKey(), keyType), convert(e.getValue(), valueType)); - } catch (Exception t) { - throw new Exception("Unable to convert from " + obj + " to " + type + "(error converting map entry)", t); + if (obj instanceof Dictionary) { + Dictionary dic = (Dictionary) obj; + for (Enumeration keyEnum = dic.keys(); keyEnum.hasMoreElements();) { + Object key = keyEnum.nextElement(); + try { + newMap.put(convert(key, keyType), convert(dic.get(key), valueType)); + } catch (Exception t) { + throw new Exception("Unable to convert from " + obj + " to " + type + "(error converting map entry)", t); + } + } + } else { + for (Map.Entry e : ((Map) obj).entrySet()) { + try { + newMap.put(convert(e.getKey(), keyType), convert(e.getValue(), valueType)); + } catch (Exception t) { + throw new Exception("Unable to convert from " + obj + " to " + type + "(error converting map entry)", t); + } } } return newMap; } - private Object convertArray(Object obj, ReifiedType type) throws Exception { + private Object convertToArray(Object obj, ReifiedType type) throws Exception { if (obj instanceof Collection) { obj = ((Collection) obj).toArray(); } if (!obj.getClass().isArray()) { throw new Exception("Unable to convert from " + obj + " to " + type); } - ReifiedType componentType = type.getActualTypeArgument(0); + ReifiedType componentType; + if (type.size() > 0) { + componentType = type.getActualTypeArgument(0); + } else { + componentType = new GenericType(type.getRawClass().getComponentType()); + } Object array = Array.newInstance(toClass(componentType), Array.getLength(obj)); for (int i = 0; i < Array.getLength(obj); i++) { try { @@ -280,9 +360,10 @@ return array; } - private boolean isAssignable(Object source, ReifiedType target) { - return target.size() == 0 - && unwrap(target.getRawClass()).isAssignableFrom(unwrap(source.getClass())); + public static boolean isAssignable(Object source, ReifiedType target) { + return source == null + || (target.size() == 0 + && unwrap(target.getRawClass()).isAssignableFrom(unwrap(source.getClass()))); } private static Class unwrap(Class c) { Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BeanRecipe.java Tue Jun 30 20:03:50 2009 @@ -36,7 +36,6 @@ import org.apache.geronimo.blueprint.di.Recipe; import org.apache.geronimo.blueprint.utils.ReflectionUtils; import static org.apache.geronimo.blueprint.utils.ReflectionUtils.getRealCause; -import static org.apache.geronimo.blueprint.utils.TypeUtils.isInstance; import org.osgi.service.blueprint.container.ReifiedType; import org.osgi.service.blueprint.container.ComponentDefinitionException; import org.slf4j.Logger; @@ -175,7 +174,7 @@ // Instanciate arguments List args = new ArrayList(); - List argTypes = new ArrayList(); + List argTypes = new ArrayList(); if (arguments != null) { for (int i = 0; i < arguments.size(); i++) { Object arg = arguments.get(i); @@ -185,7 +184,7 @@ args.add(arg); } if (this.argTypes != null) { - argTypes.add(this.argTypes.get(i) != null ? loadClass(this.argTypes.get(i)) : null); + argTypes.add(this.argTypes.get(i) != null ? loadType(this.argTypes.get(i)) : null); } } } @@ -245,7 +244,7 @@ return instance; } - private Map> findMatchingMethods(Class type, String name, boolean instance, List args, List types) { + private Map> findMatchingMethods(Class type, String name, boolean instance, List args, List types) { Map> matches = new HashMap>(); // Get constructors List methods = new ArrayList(Arrays.asList(type.getMethods())); @@ -267,11 +266,12 @@ boolean found = true; List match = new ArrayList(); for (int i = 0; i < args.size(); i++) { - if (types.get(i) != null && !mth.getParameterTypes()[i].equals(types.get(i))) { + ReifiedType argType = new GenericType(mth.getGenericParameterTypes()[i]); + if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) { found = false; break; } - if (!isInstance(mth.getParameterTypes()[i], args.get(i))) { + if (!AggregateConverter.isAssignable(args.get(i), argType)) { found = false; break; } @@ -297,12 +297,13 @@ boolean found = true; List match = new ArrayList(); for (int i = 0; i < args.size(); i++) { - if (types.get(i) != null && !mth.getParameterTypes()[i].equals(types.get(i))) { + ReifiedType argType = new GenericType(mth.getGenericParameterTypes()[i]); + if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) { found = false; break; } try { - Object val = convert(args.get(i), mth.getGenericParameterTypes()[i]); + Object val = convert(args.get(i), argType); match.add(val); } catch (Throwable t) { found = false; @@ -348,7 +349,7 @@ return matches; } - private Map> findMatchingConstructors(Class type, List args, List types) { + private Map> findMatchingConstructors(Class type, List args, List types) { Map> matches = new HashMap>(); // Get constructors List constructors = new ArrayList(Arrays.asList(type.getConstructors())); @@ -365,11 +366,12 @@ boolean found = true; List match = new ArrayList(); for (int i = 0; i < args.size(); i++) { - if (types.get(i) != null && !cns.getParameterTypes()[i].equals(types.get(i))) { + ReifiedType argType = new GenericType(cns.getGenericParameterTypes()[i]); + if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) { found = false; break; } - if (!isInstance(cns.getParameterTypes()[i], args.get(i))) { + if (!AggregateConverter.isAssignable(args.get(i), argType)) { found = false; break; } @@ -395,12 +397,13 @@ boolean found = true; List match = new ArrayList(); for (int i = 0; i < args.size(); i++) { - if (types.get(i) != null && !cns.getParameterTypes()[i].equals(types.get(i))) { + ReifiedType argType = new GenericType(cns.getGenericParameterTypes()[i]); + if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) { found = false; break; } try { - Object val = convert(args.get(i), cns.getGenericParameterTypes()[i]); + Object val = convert(args.get(i), argType); match.add(val); } catch (Throwable t) { found = false; @@ -633,12 +636,12 @@ public ArgumentMatcher(Type[] types, boolean convert) { entries = new ArrayList(); for (Type type : types) { - entries.add(new TypeEntry(type)); + entries.add(new TypeEntry(new GenericType(type))); } this.convert = convert; } - public List match(List arguments, List forcedTypes) { + public List match(List arguments, List forcedTypes) { if (find(arguments, forcedTypes)) { return getArguments(); } @@ -657,7 +660,7 @@ return list; } - private boolean find(List arguments, List forcedTypes) { + private boolean find(List arguments, List forcedTypes) { if (entries.size() == arguments.size()) { boolean matched = true; for (int i = 0; i < arguments.size() && matched; i++) { @@ -668,7 +671,7 @@ return false; } - private boolean find(Object arg, Class forcedType) { + private boolean find(Object arg, ReifiedType forcedType) { for (TypeEntry entry : entries) { Object val = arg; if (entry.argument != UNMATCHED) { @@ -687,7 +690,7 @@ continue; } } else { - if (!isInstance(entry.type, arg)) { + if (!AggregateConverter.isAssignable(arg, entry.type)) { continue; } } @@ -702,10 +705,10 @@ private static class TypeEntry { - private final Type type; + private final ReifiedType type; private Object argument; - public TypeEntry(Type type) { + public TypeEntry(ReifiedType type) { this.type = type; this.argument = UNMATCHED; } Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java Tue Jun 30 20:03:50 2009 @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.LinkedHashSet; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -169,10 +170,10 @@ timeout = Integer.parseInt(timeoutDirective); } - String waitForDependenciesDirective = paths.get(0).getDirective(BlueprintConstants.WAIT_FOR_DEPENDENCIES_DIRECTIVE); - if (waitForDependenciesDirective != null) { - LOGGER.debug("Wait-for-dependencies directive: " + waitForDependenciesDirective); - waitForDependencies = Boolean.parseBoolean(waitForDependenciesDirective); + String graceperiod = paths.get(0).getDirective(BlueprintConstants.GRACE_PERIOD); + if (graceperiod != null) { + LOGGER.debug("Grace-period directive: " + graceperiod); + waitForDependencies = Boolean.parseBoolean(graceperiod); } String xmlValidationDirective = paths.get(0).getDirective(BlueprintConstants.XML_VALIDATION); @@ -559,7 +560,13 @@ } public Set getComponentIds() { - return componentDefinitionRegistry.getComponentDefinitionNames(); + Set set = new LinkedHashSet(); + set.addAll(componentDefinitionRegistry.getComponentDefinitionNames()); + set.add("blueprintContainer"); + set.add("blueprintBundle"); + set.add("blueprintBundleContext"); + set.add("blueprintConverter"); + return set; } public Object getComponentInstance(String id) throws NoSuchComponentException { @@ -569,6 +576,8 @@ try { LOGGER.debug("Instantiating component {}", id); return repository.create(id); + } catch (NoSuchComponentException e) { + throw e; } catch (ComponentDefinitionException e) { throw e; } catch (Throwable t) { Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java Tue Jun 30 20:03:50 2009 @@ -150,7 +150,7 @@ filePattern = name.substring(pos + 1); } if (hasWildcards(filePattern)) { - addEntries(bundle, baseName, filePattern, true, urls); + addEntries(bundle, baseName, filePattern, false, urls); } else { addEntry(bundle, name, urls); } Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/GenericType.java Tue Jun 30 20:03:50 2009 @@ -120,7 +120,11 @@ public String toString() { Class cl = getRawClass(); if (cl.isArray()) { - return parameters[0].toString() + "[]"; + if (parameters.length > 0) { + return parameters[0].toString() + "[]"; + } else { + return cl.getComponentType().getName() + "[]"; + } } if (parameters.length > 0) { StringBuilder sb = new StringBuilder(); @@ -142,7 +146,12 @@ if ( type instanceof Class ) { Class clazz = (Class) type; if (clazz.isArray()) { - return new GenericType[] { new GenericType(clazz.getComponentType()) }; + GenericType t = new GenericType(clazz.getComponentType()); + if (t.size() > 0) { + return new GenericType[] { t }; + } else { + return EMPTY; + } } else { return EMPTY; } Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java Tue Jun 30 20:03:50 2009 @@ -82,7 +82,6 @@ repository.putDefault("blueprintBundle", blueprintContainer.getBundleContext().getBundle()); repository.putDefault("blueprintBundleContext", blueprintContainer.getBundleContext()); repository.putDefault("blueprintConverter", blueprintContainer.getConverter()); - repository.putDefault("blueprintExtenderBundle", blueprintContainer.getExtenderBundle()); } } @@ -125,7 +124,7 @@ for (String name : metadata.getDependsOn()) { deps.add(new RefRecipe(getName(null), name)); } - RefListRecipe recipe = new RefListRecipe(getName(metadata.getId()), + ReferenceListRecipe recipe = new ReferenceListRecipe(getName(metadata.getId()), blueprintContainer, metadata, listenersRecipe, Copied: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java (from r788924, geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefListRecipe.java) URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java?p2=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java&p1=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefListRecipe.java&r1=788924&r2=789914&rev=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefListRecipe.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java Tue Jun 30 20:03:50 2009 @@ -50,16 +50,16 @@ * @author Apache Geronimo Project * @version $Rev: 760378 $, $Date: 2009-03-31 11:31:38 +0200 (Tue, 31 Mar 2009) $ */ -public class RefListRecipe extends AbstractServiceReferenceRecipe { +public class ReferenceListRecipe extends AbstractServiceReferenceRecipe { - private static final Logger LOGGER = LoggerFactory.getLogger(RefListRecipe.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ReferenceListRecipe.class); private final ReferenceListMetadata metadata; private final List collections = new ArrayList(); private final DynamicCollection storage = new DynamicCollection(); private final List unboundDispatchers = new ArrayList(); - public RefListRecipe(String name, + public ReferenceListRecipe(String name, ExtendedBlueprintContainer blueprintContainer, ReferenceListMetadata metadata, Recipe listenersRecipe, @@ -258,6 +258,10 @@ /** * Base class for managed collections. + * + * TODO: list iterators should not be supported + * TODO: rework the iteration so that if hasNext() has returned false, it will always return false + * TODO: implement subList() */ public static class ManagedCollection extends AbstractCollection implements List, RandomAccess { Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java Tue Jun 30 20:03:50 2009 @@ -143,6 +143,7 @@ for (Listener listener : listeners) { listener.bind(trackedServiceReference, proxy); } + listenersCreated = false; } } } @@ -154,11 +155,19 @@ for (Listener listener : listeners) { listener.unbind(trackedServiceReference, proxy); } + listenersCreated = false; } blueprintContainer.getBundleContext().ungetService(trackedServiceReference); trackedServiceReference = null; trackedService = null; monitor.notifyAll(); + } else if (listenersCreated) { + if (listeners != null) { + for (Listener listener : listeners) { + listener.unbind(null, null); + } + listenersCreated = false; + } } } } Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java Tue Jun 30 20:03:50 2009 @@ -73,7 +73,6 @@ private Map registrationProperties; private List listeners; private Object service; - private final Object serviceLock = new Object(); private boolean prototypeService; public ServiceRecipe(String name, @@ -229,10 +228,18 @@ listeners = Collections.emptyList(); } LOGGER.debug("Listeners created: {}", listeners); - LOGGER.debug("Calling listeners for service registration"); - for (ServiceListener listener : listeners) { - listener.register(prototypeService || service instanceof ServiceFactory ? null : service, - registrationProperties); + if (registered) { // Do not call isRegistered() because of the synchronization + LOGGER.debug("Calling listeners for initial service registration"); + for (ServiceListener listener : listeners) { + listener.register(prototypeService || service instanceof ServiceFactory ? null : service, + registrationProperties); + } + } else { + LOGGER.debug("Calling listeners for initial service unregistration"); + for (ServiceListener listener : listeners) { + listener.unregister(prototypeService || service instanceof ServiceFactory ? null : service, + registrationProperties); + } } } } catch (RuntimeException e) { Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/MapRecipe.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/MapRecipe.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/MapRecipe.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/MapRecipe.java Tue Jun 30 20:03:50 2009 @@ -25,6 +25,7 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import java.util.Hashtable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java Tue Jun 30 20:03:50 2009 @@ -29,6 +29,7 @@ import org.apache.geronimo.blueprint.ComponentNameAlreadyInUseException; import org.osgi.service.blueprint.reflect.ComponentMetadata; import org.osgi.service.blueprint.reflect.Target; +import org.osgi.service.blueprint.container.ComponentDefinitionException; /** * ComponentDefinitionRegistry implementation. @@ -68,6 +69,12 @@ // TODO: should we generate a unique name? throw new IllegalArgumentException("Component must have a valid id"); } + if (id.equals("blueprintContainer") || id.equals("blueprintBundle") + || id.equals("blueprintBundleContext") || id.equals("blueprintConverter")) { + throw new ComponentDefinitionException("Can not override an environment manager (" + id + ")"); + } else if (id.startsWith("blueprint")) { + // TODO: log a warning + } // TODO: perform other validation: scope, class/runtimeClass/factoryMethod, etc... if (components.containsKey(id)) { throw new ComponentNameAlreadyInUseException(id); Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/TypeUtils.java Tue Jun 30 20:03:50 2009 @@ -16,19 +16,8 @@ */ package org.apache.geronimo.blueprint.utils; -import java.lang.reflect.Array; import java.lang.reflect.Constructor; -import java.lang.reflect.GenericArrayType; import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.util.HashMap; -import java.util.Map; - -import org.apache.geronimo.blueprint.ExtendedBlueprintContainer; -import org.apache.geronimo.blueprint.di.ExecutionContext; -import org.osgi.framework.Bundle; /** * @version $Rev: 6687 $ $Date: 2005-12-28T21:08:56.733437Z $ @@ -54,54 +43,4 @@ return false; } - public static boolean isInstance(Type t, Object instance) { - Class type = toClass(t); - if (type.isPrimitive()) { - // for primitives the insance can't be null - if (instance == null) { - return false; - } - - // verify instance is the correct wrapper type - if (type.equals(boolean.class)) { - return instance instanceof Boolean; - } else if (type.equals(char.class)) { - return instance instanceof Character; - } else if (type.equals(byte.class)) { - return instance instanceof Byte; - } else if (type.equals(short.class)) { - return instance instanceof Short; - } else if (type.equals(int.class)) { - return instance instanceof Integer; - } else if (type.equals(long.class)) { - return instance instanceof Long; - } else if (type.equals(float.class)) { - return instance instanceof Float; - } else if (type.equals(double.class)) { - return instance instanceof Double; - } else { - throw new AssertionError("Invalid primitve type: " + type); - } - } - - return instance == null || type.isInstance(instance); - } - - public static Class toClass(Type type) { - // GenericArrayType, ParameterizedType, TypeVariable, WildcardType - if (type instanceof Class) { - Class clazz = (Class) type; - return clazz; - } else if (type instanceof GenericArrayType) { - GenericArrayType arrayType = (GenericArrayType) type; - Class componentType = toClass(arrayType.getGenericComponentType()); - return Array.newInstance(componentType, 0).getClass(); - } else if (type instanceof ParameterizedType) { - ParameterizedType parameterizedType = (ParameterizedType) type; - return toClass(parameterizedType.getRawType()); - } else { - return Object.class; - } - } - } Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java Tue Jun 30 20:03:50 2009 @@ -37,6 +37,8 @@ import org.apache.geronimo.blueprint.pojos.PojoB; import org.apache.geronimo.blueprint.pojos.PojoGenerics; import org.apache.geronimo.blueprint.pojos.PojoListener; +import org.apache.geronimo.blueprint.container.AggregateConverter; +import org.apache.geronimo.blueprint.container.GenericType; import org.osgi.framework.ServiceRegistration; public class WiringTest extends AbstractBlueprintTest { Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java Tue Jun 30 20:03:50 2009 @@ -40,6 +40,11 @@ service = new AggregateConverter(new TestBlueprintContainer(null)); } + public void testConvertNumbers() throws Exception { + assertEquals(1, service.convert(1.46f, int.class)); + assertEquals(1.0d, service.convert(1, double.class)); + } + public void testConvertSimpleTypes() throws Exception { assertEquals(123, service.convert("123", int.class)); assertEquals(123, service.convert("123", Integer.class)); Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java Tue Jun 30 20:03:50 2009 @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.net.URI; import junit.framework.TestCase; @@ -32,6 +33,14 @@ return type; } + public void testArrays() { + assertTrue(AggregateConverter.isAssignable(new Object[0], new GenericType(Object[].class))); + assertFalse(AggregateConverter.isAssignable(new Object[0], new GenericType(String[].class))); + assertTrue(AggregateConverter.isAssignable(new String[0], new GenericType(String[].class))); + assertFalse(AggregateConverter.isAssignable(new String[0], new GenericType(URI[].class))); + assertTrue(AggregateConverter.isAssignable(new String[0], new GenericType(Object[].class))); + } + public void testParseTypes() throws Exception { GenericType type = parse("java.util.List"); Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml?rev=789914&r1=789913&r2=789914&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-generics.xml Tue Jun 30 20:03:50 2009 @@ -32,7 +32,7 @@ - + 10 20 @@ -42,7 +42,7 @@ - + 1000 2000