Package org.apache.karaf.shell.support.converter

Examples of org.apache.karaf.shell.support.converter.GenericType


            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


        }
        return matches;
    }

    protected Object convert(Object obj, Type type) throws Exception {
        return converter.convert(obj, new GenericType(type));
    }
View Full Code Here

        private boolean convert;

        public ArgumentMatcher(Type[] types, boolean convert) {
            entries = new ArrayList<TypeEntry>();
            for (Type type : types) {
                entries.add(new TypeEntry(new GenericType(type)));
            }
            this.convert = convert;
        }
View Full Code Here

        T instance = clazz.newInstance();
        // Inject services
        for (Class<?> cl = clazz; cl != Object.class; cl = cl.getSuperclass()) {
            for (Field field : cl.getDeclaredFields()) {
                if (field.getAnnotation(Reference.class) != null) {
                    GenericType type = new GenericType(field.getGenericType());
                    Object value;
                    if (type.getRawClass() == List.class) {
                        Set<Object> set = new HashSet<Object>();
                        set.addAll(registry.getServices(type.getActualTypeArgument(0).getRawClass()));
                        if (registry != this.dependencies) {
                            set.addAll(this.dependencies.getServices(type.getActualTypeArgument(0).getRawClass()));
                        }
                        value = new ArrayList<Object>(set);
                    } else {
                        value = registry.getService(type.getRawClass());
                        if (value == null && registry != this.dependencies) {
                            value = this.dependencies.getService(type.getRawClass());
                        }
                    }
                    if (!allowCustomServices && value == null) {
                        throw new IllegalStateException("No service matching " + field.getType().getName());
                    }
View Full Code Here

    @SuppressWarnings("unchecked")
    private Completer getDefaultCompleter(Field field, boolean multi) {
        Completer completer = null;
        Class<?> type = field.getType();
        GenericType genericType = new GenericType(field.getGenericType());
        if (Collection.class.isAssignableFrom(genericType.getRawClass()) && multi) {
            type = genericType.getActualTypeArgument(0).getRawClass();
        }
        if (type.isAssignableFrom(URI.class)) {
            completer = new UriCompleter();
        } else if (type.isAssignableFrom(File.class)) {
            completer = new FileCompleter();
View Full Code Here

            try {
                value = convert(action, entry.getValue(), field.getGenericType());
            } catch (Exception e) {
                    throw new CommandException(commandErrorSt +
                            "unable to convert option " + INTENSITY_BOLD + entry.getKey().name() + INTENSITY_NORMAL + " with value '"
                            + entry.getValue() + "' to type " + new GenericType(field.getGenericType()).toString(),
                            "Unable to convert option " + entry.getKey().name() + " with value '"
                                    + entry.getValue() + "' to type " + new GenericType(field.getGenericType()).toString(),
                            e
                    );
            }
            field.setAccessible(true);
            field.set(action, value);
        }
        for (Map.Entry<Argument, Object> entry : argumentValues.entrySet()) {
            Field field = arguments.get(entry.getKey());
            Object value;
            try {
                value = convert(action, entry.getValue(), field.getGenericType());
            } catch (Exception e) {
                    throw new CommandException(commandErrorSt +
                            "unable to convert argument " + INTENSITY_BOLD + entry.getKey().name() + INTENSITY_NORMAL + " with value '"
                            + entry.getValue() + "' to type " + new GenericType(field.getGenericType()).toString(),
                            "Unable to convert argument " + entry.getKey().name() + " with value '"
                                    + entry.getValue() + "' to type " + new GenericType(field.getGenericType()).toString(),
                            e
                    );
            }
            field.setAccessible(true);
            field.set(action, value);
View Full Code Here

        }
        // Create trackers
        for (Class<?> cl = clazz; cl != Object.class; cl = cl.getSuperclass()) {
            for (Field field : cl.getDeclaredFields()) {
                if (field.getAnnotation(Reference.class) != null) {
                    GenericType type = new GenericType(field.getGenericType());
                    Class clazzRef = type.getRawClass() == List.class ? type.getActualTypeArgument(0).getRawClass() : type.getRawClass();
                    if (clazzRef != BundleContext.class
                            && clazzRef != Session.class
                            && clazzRef != Terminal.class
                            && clazzRef != History.class
                            && clazzRef != Registry.class
View Full Code Here

TOP

Related Classes of org.apache.karaf.shell.support.converter.GenericType

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.