Package abbot.script.parsers

Examples of abbot.script.parsers.Parser


        assertEquals("Bad replacement", s2,
                     ArgumentParser.replace(s1, "st", "XX"));
    }

    public void testLoadParser() {
        Parser cvt = ArgumentParser.getParser(java.io.File.class);
        assertEquals("Wrong class loaded",
                     abbot.script.parsers.FileParser.class, cvt.getClass());
    }
View Full Code Here


        Log.debug("Trying " + name + " for " + targetClass);
        try {
            Class cvtClass = isExtension(name)
                ? Class.forName(name, true, targetClass.getClassLoader())
                : Class.forName(name);
            Parser parser = (Parser)cvtClass.newInstance();
            if (cvtClass.getName().indexOf(".extensions.") == -1)
                parsers.put(targetClass, parser);
            return parser;
        }
        catch(InstantiationException ie) {
View Full Code Here

        return null;
    }

    /** Set the parser for a given class.  Returns the old one, if any. */
    public static Parser setParser(Class cls, Parser parser) {
        Parser old = (Parser)parsers.get(cls);
        parsers.put(cls, parser);
        return old;
    }
View Full Code Here

    /** Find a string parser for the given class.  Returns null if none
     * found.
     */
    public static Parser getParser(Class cls) {
        Parser parser = (Parser)parsers.get(cls);
        // Load core testers with the current framework's class loader
        // context, and anything else in the context of the code under test
        if (parser == null) {
            String base = ComponentTester.simpleClassName(cls);
            String pkg = Parser.class.getPackage().getName();
View Full Code Here

               NoSuchReferenceException,
               ComponentSearchException {
        // Perform property substitution
        arg = substitute(resolver, arg);

        Parser parser;
        Object result = null;
        try {
            if (arg == null || arg.equals(NULL)) {
                result = null;
            }
            else if (cls.equals(Boolean.class)
                     || cls.equals(boolean.class)) {
                result = Boolean.valueOf(arg.trim());
            }
            else if (cls.equals(Short.class)
                     || cls.equals(short.class)) {
                result = Short.valueOf(arg.trim());
            }
            else if (cls.equals(Integer.class)
                     || cls.equals(int.class)) {
                result = Integer.valueOf(arg.trim());
            }
            else if (cls.equals(Long.class)
                     || cls.equals(long.class)) {
                result = Long.valueOf(arg.trim());
            }
            else if (cls.equals(Float.class)
                     || cls.equals(float.class)) {
                result = Float.valueOf(arg.trim());
            }
            else if (cls.equals(Double.class)
                     || cls.equals(double.class)) {
                result = Double.valueOf(arg.trim());
            }
            else if (cls.equals(ComponentReference.class)) {
                ComponentReference ref =
                    resolver.getComponentReference(arg.trim());
                if (ref == null)
                    throw new NoSuchReferenceException("The resolver "
                                                       + resolver
                                                       + " has no reference '"
                                                       + arg + "'");
                result = ref;
            }
            else if (Component.class.isAssignableFrom(cls)) {
                ComponentReference ref =
                    resolver.getComponentReference(arg.trim());
                if (ref == null)
                    throw new NoSuchReferenceException("The resolver "
                                                       + resolver
                                                       + " has no reference '"
                                                       + arg + "'");
                // Avoid requiring the user to wait for a component to become
                // available, in most cases.  In those cases where the
                // component creation is particularly slow, an explicit wait
                // can be added.
                // Note that this is not necessarily a wait for the component
                // to become visible, since menu items are not normally
                // visible even if they're available.
                result = waitForComponentAvailable(ref);
            }
            else if (cls.equals(String.class)) {
                result = arg;
            }
            else if (cls.isArray() && arg.trim().startsWith("[")) {
                arg = arg.trim();
                String[] args =
                    parseArgumentList(arg.substring(1, arg.length()-1));
                Class base = cls.getComponentType();
                Object arr = Array.newInstance(base, args.length);
                for (int i=0;i < args.length;i++) {
                    Object obj = eval(resolver, args[i], base);
                    Array.set(arr, i, obj);
                }
                result = arr;
            }
            else if ((parser = getParser(cls)) != null) {
                result = parser.parse(arg.trim());
            }
            else {
                String msg = Strings.get("parser.conversion_error",
                                         new Object[] {
                                             arg.trim(),
View Full Code Here

TOP

Related Classes of abbot.script.parsers.Parser

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.