Package org.osgi.service.blueprint.container

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


    protected Object convert(Object obj, Type type) throws Exception {
        return ExecutionContext.Holder.getContext().convert(obj, new GenericType(type));
    }

    protected Class loadClass(String className) {
        ReifiedType t = loadType(className, null);
        return t != null ? t.getRawClass() : null;
    }
View Full Code Here


            Map<Constructor, List<Object>> nmatches = new HashMap<Constructor, List<Object>>();
            for (Constructor cns : constructors) {
                boolean found = true;
                List<Object> match = new ArrayList<Object>();
                for (int i = 0; i < args.size(); i++) {
                    ReifiedType argType = new GenericType(cns.getGenericParameterTypes()[i]);
                    if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) {
                        found = false;
                        break;
                    }
                    if (!isAssignable(args.get(i), argType)) {
                        found = false;
                        break;
                    }
                    try {
                        match.add(convert(args.get(i), cns.getGenericParameterTypes()[i]));
                    } catch (Throwable t) {
                        found = false;
                        break;
                    }
                }
                if (found) {
                    nmatches.put(cns, match);
                }
            }
            if (nmatches.size() > 0) {
                matches = nmatches;
            }
        }
        // Find a direct match with conversion
        if (matches.size() != 1) {
            Map<Constructor, List<Object>> nmatches = new HashMap<Constructor, List<Object>>();
            for (Constructor cns : constructors) {
                boolean found = true;
                List<Object> match = new ArrayList<Object>();
                for (int i = 0; i < args.size(); 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), argType);
View Full Code Here

    /*
     * Test the canConvert method
     */
    public void testCanConvert() {
        assertTrue(converter.canConvert("a string", new ReifiedType(Properties.class)));
        assertFalse(converter.canConvert(new Object(), new ReifiedType(Properties.class)));
        assertFalse(converter.canConvert("a string", new ReifiedType(List.class)));
    }
View Full Code Here

     * Test the convert method when dealing with unix paths (no \)
     */
    public void testConvertWithUnixPathNames() throws Exception {
        Properties properties =
                (Properties) converter.convert("users = /opt/karaf/etc/users.properties",
                        new ReifiedType(Properties.class));
        assertNotNull(properties);
        assertEquals("/opt/karaf/etc/users.properties", properties.get("users"));
    }
View Full Code Here

     * Test the convert method when dealing with windows paths (avoid escaping \)
     */
    public void testConvertWithWindowsPathNames() throws Exception {
        Properties properties =
                (Properties) converter.convert("users = c:\\opt\\karaf/etc/users.properties",
                        new ReifiedType(Properties.class));
        assertNotNull(properties);
        assertEquals("c:/opt/karaf/etc/users.properties", properties.get("users"));
    }
View Full Code Here

            Map<Constructor, List<Object>> nmatches = new HashMap<Constructor, List<Object>>();
            for (Constructor cns : constructors) {
                boolean found = true;
                List<Object> match = new ArrayList<Object>();
                for (int i = 0; i < args.size(); i++) {
                    ReifiedType argType = new GenericType(cns.getGenericParameterTypes()[i]);
                    if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) {
                        found = false;
                        break;
                    }
                    if (!isAssignable(args.get(i), argType)) {
                        found = false;
                        break;
                    }
                    try {
                        match.add(convert(args.get(i), cns.getGenericParameterTypes()[i]));
                    } catch (Throwable t) {
                        found = false;
                        break;
                    }
                }
                if (found) {
                    nmatches.put(cns, match);
                }
            }
            if (nmatches.size() > 0) {
                matches = nmatches;
            }
        }
        // Find a direct match with conversion
        if (matches.size() != 1) {
            Map<Constructor, List<Object>> nmatches = new HashMap<Constructor, List<Object>>();
            for (Constructor cns : constructors) {
                boolean found = true;
                List<Object> match = new ArrayList<Object>();
                for (int i = 0; i < args.size(); 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), argType);
View Full Code Here

    /*
     * Test the canConvert method
     */
    public void testCanConvert() {
        assertTrue(converter.canConvert("a string", new ReifiedType(Properties.class)));
        assertFalse(converter.canConvert(new Object(), new ReifiedType(Properties.class)));
        assertFalse(converter.canConvert("a string", new ReifiedType(List.class)));
    }
View Full Code Here

     * Test the convert method when dealing with unix paths (no \)
     */
    public void testConvertWithUnixPathNames() throws Exception {
        Properties properties =
                (Properties) converter.convert("users = /opt/karaf/etc/users.properties",
                        new ReifiedType(Properties.class));
        assertNotNull(properties);
        assertEquals("/opt/karaf/etc/users.properties", properties.get("users"));
    }
View Full Code Here

     * Test the convert method when dealing with windows paths (avoid escaping \)
     */
    public void testConvertWithWindowsPathNames() throws Exception {
        Properties properties =
                (Properties) converter.convert("users = c:\\opt\\karaf/etc/users.properties",
                        new ReifiedType(Properties.class));
        assertNotNull(properties);
        assertEquals("c:/opt/karaf/etc/users.properties", properties.get("users"));
    }
View Full Code Here

        }
        return nestedRecipes;
    }
   
    private ReifiedType getType(Object o) {
      ReifiedType type;
        if (o instanceof Class) {
            type = new ReifiedType((Class) o);
        } else if (o instanceof String) {
            type = loadType((String) o);
        } else {
            type = new ReifiedType(Object.class);
        }
        return type;
    }
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.