Package org.osgi.service.blueprint.container

Examples of org.osgi.service.blueprint.container.ReifiedType


            instance = new DummyDictionaryAsMap((Dictionary) o);
        } else {
            throw new ComponentDefinitionException("Specified map type does not implement the Map interface: " + mapType.getName());
        }

        ReifiedType defaultConvertKeyType = getType(keyType);
        ReifiedType defaultConvertValueType = getType(valueType);
               
        // add map entries
        try {
            for (Recipe[] entry : entries) {
                ReifiedType convertKeyType = workOutConversionType(entry[0], defaultConvertKeyType);
                Object key = convert(entry[0].create(), convertKeyType);
                // Each entry may have its own types
                ReifiedType convertValueType = workOutConversionType(entry[1], defaultConvertValueType);
                Object value = entry[1] != null ? convert(entry[1].create(), convertValueType) : null;
                instance.put(key, value);
            }
        } catch (Exception e) {
          throw new ComponentDefinitionException(e);
View Full Code Here


        if (!(o instanceof Collection)) {
            throw new ComponentDefinitionException("Specified collection type does not implement the Collection interface: " + type.getName());
        }
        Collection instance = (Collection) o;

        ReifiedType defaultConversionType = loadType(defaultValueType);
        Type conversionType = null;
        for (Recipe recipe : list) {
            Object value;
            if (recipe != null) {
                try {
                  conversionType = defaultConversionType.getRawClass();
                    if (recipe instanceof ValueRecipe) {
                      conversionType = ((ValueRecipe)recipe).getValueType();
                    }
                    value = convert(recipe.create(), conversionType);
                } catch (Exception e) {
View Full Code Here

            throw new Exception("Unable to convert ", getRealCause(e));
        }
    }
   
    private Object convertToCollection(Object obj, ReifiedType type) throws Exception {
        ReifiedType valueType = type.getActualTypeArgument(0);
        Collection newCol = (Collection) ReflectionUtils.newInstance(blueprintContainer.getAccessControlContext(),
                                                                     CollectionRecipe.getCollection(toClass(type)));
        if (obj.getClass().isArray()) {
            for (int i = 0; i < Array.getLength(obj); i++) {
                try {
View Full Code Here

        }
        return newCol;
    }

    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();
View Full Code Here

        }
        return newDic;
    }

    private Object convertToMap(Object obj, ReifiedType type) throws Exception {
        ReifiedType keyType = type.getActualTypeArgument(0);
        ReifiedType valueType = type.getActualTypeArgument(1);
        Map newMap = (Map) ReflectionUtils.newInstance(blueprintContainer.getAccessControlContext(),
                                                       MapRecipe.getMap(toClass(type)));
        if (obj instanceof Dictionary) {
            Dictionary dic = (Dictionary) obj;
            for (Enumeration keyEnum = dic.keys(); keyEnum.hasMoreElements();) {
View Full Code Here

            obj = ((Collection) obj).toArray();
        }
        if (!obj.getClass().isArray()) {
            throw new Exception("Unable to convert from " + obj + " to " + type);
        }
        ReifiedType componentType;
        if (type.size() > 0) {
            componentType = type.getActualTypeArgument(0);
        } else {
            componentType = new GenericType(type.getRawClass().getComponentType());
        }
View Full Code Here

          
            try {
              Object o = serviceRecipe.create();
           
              if (o instanceof Convertible) {
                o = blueprintContainer.getRepository().convert(o, new ReifiedType(Object.class));
                    validateClasses(o);
              } else if (o instanceof UnwrapperedBeanHolder) {
                    UnwrapperedBeanHolder holder = (UnwrapperedBeanHolder) o;
                    validateClasses(holder.unwrapperedBean);
                    o = BeanRecipe.wrap(holder, getClassesForProxying(holder.unwrapperedBean));
View Full Code Here

    }

    @Override
    protected Class loadClass(String className) {
        ClassLoader loader = type instanceof Class ? ((Class) type).getClassLoader() : null;
        ReifiedType t = loadType(className, loader);
        return t != null ? t.getRawClass() : null;
    }
View Full Code Here

            Object factoryObj = factory.create();
           
            // If the factory is a service reference, we need to get hold of the actual proxy for the service
            if (factoryObj instanceof ReferenceRecipe.ServiceProxyWrapper) {
                try {
                    factoryObj = ((ReferenceRecipe.ServiceProxyWrapper) factoryObj).convert(new ReifiedType(Object.class));
                } catch (Exception e) {
                    throw new ComponentDefinitionException("Error when instantiating bean " + getName() + " of class " + getType(), getRealCause(e));
                }
            } else if (factoryObj instanceof UnwrapperedBeanHolder) {
              factoryObj = wrap((UnwrapperedBeanHolder) factoryObj, Object.class);
View Full Code Here

            Map<Method, List<Object>> nmatches = new HashMap<Method, List<Object>>();
            for (Method mth : methods) {
                boolean found = true;
                List<Object> match = new ArrayList<Object>();
                for (int i = 0; i < args.size(); i++) {
                    ReifiedType argType = new GenericType(mth.getGenericParameterTypes()[i]);
                    if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) {
                        found = false;
                        break;
                    }
                    //If the arg is an Unwrappered bean then we need to do the assignment check against the
                    //unwrappered bean itself.
                    Object arg = args.get(i);
                    Object argToTest = arg;
                    if(arg instanceof UnwrapperedBeanHolder)
                      argToTest = ((UnwrapperedBeanHolder)arg).unwrapperedBean;
                    if (!AggregateConverter.isAssignable(argToTest, argType)) {
                        found = false;
                        break;
                    }
                    try {
                        match.add(convert(arg, mth.getGenericParameterTypes()[i]));
                    } catch (Throwable t) {
                        found = false;
                        break;
                    }
                }
                if (found) {
                    nmatches.put(mth, match);
                }
            }
            if (nmatches.size() > 0) {
                matches = nmatches;
            }
        }
        // Find a direct match with conversion
        if (matches.size() != 1) {
            Map<Method, List<Object>> nmatches = new HashMap<Method, List<Object>>();
            for (Method mth : methods) {
                boolean found = true;
                List<Object> match = new ArrayList<Object>();
                for (int i = 0; i < args.size(); 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), argType);
View Full Code Here

TOP

Related Classes of org.osgi.service.blueprint.container.ReifiedType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.