コード例 #1
0
ファイル: JavaPropertyReader.cs プロジェクト: minam365/JavApi
        /// <summary>
        /// <para>Load key value pairs (properties) from an input Stream expected to have ISO-8859-1 encoding (code page 28592).
        /// The input stream (usually reading from a ".properties" file) consists of a series of lines (terminated
        /// by \r, \n or \r\n) each a key value pair, a comment or a blank line.</para>
        ///
        /// <para>Leading whitespace (spaces, tabs, formfeeds) are ignored at the start of any line - and a line that is empty or
        /// contains only whitespace is blank and ignored.</para>
        ///
        /// <para>A line with the first non-whitespace character is a '#' or '!' is a comment line and the rest of the line is
        /// ignored.</para>
        ///
        /// <para>If the first non-whitespace character is not '#' or '!' then it is the start of a key.  A key is all the
        /// characters up to the first whitespace or a key/value separator - '=' or ':'.</para>
        ///
        /// <para>The separator is optional.  Any whitespace after the key or after the separator (if present) is ignored.</para>
        ///
        /// <para>The first non-whitespace character after the separator (or after the key if no separator) begins the value.
        /// The value may include whitespace, separators, or comment characters.</para>
        ///
        /// <para>Any unicode character may be included in either key or value by using escapes preceded by the escape
        /// character '\'.</para>
        ///
        /// <para>The following special cases are defined:</para>
        /// <code>
        ///     '\t' - horizontal tab.
        ///     '\f' - form feed.
        ///     '\r' - return
        ///     '\n' - new line
        ///     '\\' - add escape character.
        ///
        ///     '\ ' - add space in a key or at the start of a value.
        ///     '\!', '\#' - add comment markers at the start of a key.
        ///     '\=', '\:' - add a separator in a key.
        /// </code>
        ///
        /// <para>Any unicode character using the following escape:</para>
        /// <code>
        ///     '\uXXXX' - where XXXX represents the unicode character code as 4 hexadecimal digits.
        /// </code>
        ///
        /// <para>Finally, longer lines can be broken by putting an escape at the very end of the line.  Any leading space
        /// (unless escaped) is skipped at the beginning of the following line.</para>
        ///
        /// Examples
        /// <code>
        ///     a-key = a-value
        ///     a-key : a-value
        ///     a-key=a-value
        ///     a-key a-value
        /// </code>
        ///
        /// <para>All the above will result in the same key/value pair - key "a-key" and value "a-value".</para>
        /// <code>
        ///     ! comment...
        ///     # another comment...
        /// </code>
        ///
        /// <para>The above are two examples of comments.</para>
        /// <code>
        ///     Honk\ Kong = Near China
        /// </code>
        ///
        /// <para>The above shows how to embed a space in a key - key is "Hong Kong", value is "Near China".</para>
        /// <code>
        ///     a-longer-key-example = a really long value that is \
        ///             split over two lines.
        /// </code>
        ///
        /// <para>An example of a long line split into two.</para>
        /// </summary>
        /// <param name="stream">The input stream that the properties are read from.</param>
        public void Parse(java.io.Reader stream)
        {
            reader = new java.io.BufferedReader(stream, bufferSize);

            int state = STATE_start;

            do
            {
                int ch = nextChar();

                bool matched = false;

                for (int s = 0; s < states[state].Length; s += 3)
                {
                    if (matches(states[state][s], ch))
                    {
                        matched = true;
                        doAction(states[state][s + 2], ch);

                        state = states[state][s + 1];
                        break;
                    }
                }

                if (!matched)
                {
                    throw new java.lang.IllegalArgumentException("Unexpected character at " + 1 + ": <<<" + ch + ">>>");
                }
            } while (state != STATE_finish);
        }
コード例 #2
0
        private static String readProviderFromFile()
        {//throws InternalError {
            java.lang.ClassLoader systemLoader = java.lang.ClassLoader.getSystemClassLoader();

            if (systemLoader != null)
            {
                java.io.InputStream inJ = systemLoader.getResourceAsStream("META-INF/services/java.util.prefs.PreferencesFactory"); //$NON-NLS-1$
                if (inJ != null)
                {
                    java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(inJ));
                    String line = null;
                    try
                    {
                        while ((line = reader.readLine()) != null)
                        {
                            int index = line.indexOf("#"); //$NON-NLS-1$
                            // Trim comments
                            if (index != -1)
                            {
                                line = line.substring(0, index);
                            }
                            String trimedName = line.trim();
                            if (!"".equals(trimedName))
                            { //$NON-NLS-1$
                                return(trimedName);
                            }
                        }
                    }
                    catch (java.io.IOException e)
                    {
                        // prefs.11=Load provider configuration file faild: {0}
                        throw new java.lang.InternalError("Load provider configuration file faild: " + e);   //$NON-NLS-1$
                    }
                    finally
                    {
                        try
                        {
                            reader.close();
                        }
                        catch (java.io.IOException e)
                        {
                            // ignore
                        }
                    }
                }
            }
            return(null);
        }
コード例 #3
0
ファイル: StreamWrapper.cs プロジェクト: bastie/NetVampire
        public static Stream convert(java.io.Reader reader)
        {
            java.io.BufferedReader br = new java.io.BufferedReader(reader);

            String input = "";
            String line  = br.readLine();

            while (line != null)
            {
                input += java.lang.SystemJ.getProperty("line.separator")
                         + line;
                line = br.readLine();
            }
            MemoryStream memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(input));

            return(memoryStream);
        }
コード例 #4
0
 public void readFile()
 {
     // Step 1 - file greater than FileBuffer
     java.io.File           file = new java.io.File("/Develop/Projekte/Kobol/ITIL RPC/src/biz/ritter/dbms/views/AufgabenUebersichtView.java");
     java.io.BufferedReader br   = new java.io.BufferedReader(new java.io.FileReader(file));
     while (br.ready())
     {
         char c = (char)br.read();
         java.lang.SystemJ.outJ.print(c);
     }
     // Step 2 - file smaller than FileBuffer
     file = new java.io.File("/Develop/Projekte/Kobol/ITIL RPC/src/biz/ritter/dbms/ItilActivator.java");
     br   = new java.io.BufferedReader(new java.io.FileReader(file));
     while (br.ready())
     {
         char c = (char)br.read();
         java.lang.SystemJ.outJ.print(c);
     }
 }
コード例 #5
0
ファイル: TinySQLGlobals.cs プロジェクト: bastie/NetVampire
        public static void readLongNames(String inputDataDir)
        {
            String fullPath, longNameRecord;

            String[]       fields;
            FieldTokenizer ft;

            java.io.File longColumnNameFile;
            dataDir = inputDataDir;
            java.io.BufferedReader longNameReader = (java.io.BufferedReader)null;
            fullPath           = dataDir + fileSep + "TINYSQL_LONG_COLUMN_NAMES.dat";
            longColumnNames    = new java.util.Vector <Object>();
            longColumnNameFile = new java.io.File(fullPath);
            if (longColumnNameFile.exists())
            {
                try
                {
                    longNameReader = new java.io.BufferedReader(new java.io.FileReader(fullPath));
                    while ((longNameRecord = longNameReader.readLine()) != null)
                    {
                        ft     = new FieldTokenizer(longNameRecord, '|', false);
                        fields = ft.getFields();
                        longColumnNames.addElement(fields[0]);
                        longColumnNames.addElement(fields[1]);
                    }
                    longNameReader.close();
                    longNamesInFileCount = longColumnNames.size() / 2;
                    if (debug)
                    {
                        java.lang.SystemJ.outJ.println("Long Names read: " + longNamesInFileCount);
                    }
                }
                catch (Exception readEx)
                {
                    java.lang.SystemJ.outJ.println("Reader exception " + readEx.getMessage());
                    longNamesInFileCount = 0;
                }
            }
        }
コード例 #6
0
        /**
         * This method attempts to return the first line of the resource
         * META_INF/services/org.w3c.dom.DOMImplementationSourceList
         * from the provided ClassLoader.
         *
         * @param classLoader classLoader, may not be <code>null</code>.
         * @return first line of resource, or <code>null</code>
         */
        private static String getServiceValue(java.lang.ClassLoader classLoader)
        {
            String serviceId = "META-INF/services/" + PROPERTY;

            // try to find services in CLASSPATH
            try
            {
                java.io.InputStream input = getResourceAsStream(classLoader, serviceId);

                if (input != null)
                {
                    java.io.BufferedReader rd;
                    try
                    {
                        rd =
                            new java.io.BufferedReader(new java.io.InputStreamReader(input, "UTF-8"),
                                                       DEFAULT_LINE_LENGTH);
                    }
                    catch (java.io.UnsupportedEncodingException)
                    {
                        rd =
                            new java.io.BufferedReader(new java.io.InputStreamReader(input),
                                                       DEFAULT_LINE_LENGTH);
                    }
                    String serviceValue = rd.readLine();
                    rd.close();
                    if (serviceValue != null && serviceValue.length() > 0)
                    {
                        return(serviceValue);
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(null);
        }
コード例 #7
0
        public TinySQLParser(java.io.InputStream sqlInput, TinySQL inputEngine)
        //throws TinySQLException
        {
            java.io.StreamTokenizer st;
            FieldTokenizer          ft;

            java.io.Reader r;
            String         nextToken, upperField, nextField, keyWord = (String)null;

            java.lang.StringBuffer cmdBuffer, inputSQLBuffer;
            int lastIndex, keyIndex;

            r               = new java.io.BufferedReader(new java.io.InputStreamReader(sqlInput));
            dbEngine        = inputEngine;
            actionList      = new java.util.Vector <Object>();
            columnList      = new java.util.Vector <Object>();
            columns         = new java.util.Vector <Object>();
            columnAliasList = new java.util.Vector <Object>();
            contextList     = new java.util.Vector <Object>();
            valueList       = new java.util.Vector <Object>();
            tableName       = (String)null;
            whereClause     = (TinySQLWhere)null;

/*
 *    The tableList is a list of table names, in the optimal order
 *    in which they should be scanned for the SELECT phrase.
 *    The java.util.Hashtable<Object,Object> tables contains table objects keyed by table
 *    alias and name.
 */
            tableList = new java.util.Vector <Object>();
            tables    = new java.util.Hashtable <Object, Object>();
            tables.put("TABLE_SELECT_ORDER", tableList);
            try
            {
                st = new java.io.StreamTokenizer(r);
                st.eolIsSignificant(false);
                st.wordChars('\'', '}');
                st.wordChars('?', '?');
                st.wordChars('"', '.');
                st.ordinaryChars('0', '9');
                st.wordChars('0', '9');
                cmdBuffer      = new java.lang.StringBuffer();
                inputSQLBuffer = new java.lang.StringBuffer();
                while (st.nextToken() != java.io.StreamTokenizer.TT_EOF)
                {
                    if (st.ttype == java.io.StreamTokenizer.TT_WORD)
                    {
                        nextToken = st.sval.trim();
                    }
                    else
                    {
                        continue;
                    }
                    if (inputSQLBuffer.length() > 0)
                    {
                        inputSQLBuffer.append(" ");
                    }
                    inputSQLBuffer.append(nextToken);
                }
                ft = new FieldTokenizer(inputSQLBuffer.toString(), ' ', false);
                while (ft.hasMoreFields())
                {
                    nextField  = ft.nextField();
                    upperField = nextField.toUpperCase();
                    if (statementType == (String)null)
                    {
                        statementType = upperField;
                        lastIndex     = getKeywordIndex(statementType, statementType);
                        if (lastIndex != 0)
                        {
                            throwException(9);
                        }
                        keyWord = statementType;
                    }
                    else
                    {
                        keyIndex = getKeywordIndex(statementType, upperField);
                        if (keyIndex < 0)
                        {
                            if (cmdBuffer.length() > 0)
                            {
                                cmdBuffer.append(" ");
                            }
                            cmdBuffer.append(nextField);
                        }
                        else
                        {
                            setPhrase(keyWord, cmdBuffer.toString());
                            cmdBuffer = new java.lang.StringBuffer();
                            keyWord   = upperField;
                            if (TinySQLGlobals.PARSER_DEBUG)
                            {
                                java.lang.SystemJ.outJ.println("Found keyword " + keyWord);
                            }
                        }
                    }
                }
                if (keyWord != (String)null)
                {
                    setPhrase(keyWord, cmdBuffer.toString());
                }
                addAction();
                if (TinySQLGlobals.PARSER_DEBUG)
                {
                    java.lang.SystemJ.outJ.println("SQL:" + inputSQLBuffer.toString());
                }
            } catch (Exception ex) {
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println(ex.StackTrace);                 //ex.printStackTrace(java.lang.SystemJ.outJ);
                }
                throw new TinySQLException(ex.getMessage());
            }
        }
コード例 #8
0
ファイル: FactoryFinder.cs プロジェクト: sailesh341/JavApi
        //throws ConfigurationError
        /*
         * Try to find provider using Jar Service Provider Mechanism
         *
         * @return instance of provider class if found or null
         */
        private static Object findJarServiceProvider(String factoryId)
        {
            String serviceId = "META-INF/services/" + factoryId;
            java.io.InputStream isJ = null;

            // First try the Context ClassLoader
            java.lang.ClassLoader cl = SecuritySupport.getContextClassLoader ();
            if (cl != null) {
                isJ = SecuritySupport.getResourceAsStream (cl, serviceId);

                // If no provider found then try the current ClassLoader
                if (isJ == null) {
                    cl = typeof(FactoryFinder).getClass ().getClassLoader ();
                    isJ = SecuritySupport.getResourceAsStream (cl, serviceId);
                }
            } else {
                // No Context ClassLoader, try the current
                // ClassLoader
                cl = typeof(FactoryFinder).getClass ().getClassLoader ();
                isJ = SecuritySupport.getResourceAsStream (cl, serviceId);
            }

            if (isJ == null) {
                // No provider found
                return null;
            }

            if (debug)
                dPrint ("found jar resource=" + serviceId +
                " using ClassLoader: " + cl);

            // Read the service provider name in UTF-8 as specified in
            // the jar spec.  Unfortunately this fails in Microsoft
            // VJ++, which does not implement the UTF-8
            // encoding. Theoretically, we should simply let it fail in
            // that case, since the JVM is obviously broken if it
            // doesn't support such a basic standard.  But since there
            // are still some users attempting to use VJ++ for
            // development, we have dropped in a fallback which makes a
            // second attempt using the platform's default encoding. In
            // VJ++ this is apparently ASCII, which is a subset of
            // UTF-8... and since the strings we'll be reading here are
            // also primarily limited to the 7-bit ASCII range (at
            // least, in English versions), this should work well
            // enough to keep us on the air until we're ready to
            // officially decommit from VJ++. [Edited comment from
            // jkesselm]
            java.io.BufferedReader rd;
            try {
                rd = new java.io.BufferedReader (new java.io.InputStreamReader (isJ, "UTF-8"), DEFAULT_LINE_LENGTH);
            } catch (java.io.UnsupportedEncodingException e) {
                rd = new java.io.BufferedReader (new java.io.InputStreamReader (isJ), DEFAULT_LINE_LENGTH);
            }

            String factoryClassName = null;
            try {
                // XXX Does not handle all possible input as specified by the
                // Jar Service Provider specification
                factoryClassName = rd.readLine ();
            } catch (java.io.IOException x) {
                // No provider found
                return null;
            } finally {
                try {
                    // try to close the reader.
                    rd.close ();
                }
            // Ignore the exception.
            catch (java.io.IOException exc) {
                }
            }

            if (factoryClassName != null &&
                     ! "".equals (factoryClassName)) {
                if (debug)
                    dPrint ("found in resource, value="
                    + factoryClassName);

                // Note: here we do not want to fall back to the current
                // ClassLoader because we want to avoid the case where the
                // resource file was found using one ClassLoader and the
                // provider class was instantiated using a different one.
                return newInstance (factoryClassName, cl, false);
            }

            // No provider found
            return null;
        }
コード例 #9
0
            /*
             * Parse the provider-configuration file as specified
             * @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Provider Configuration File">JAR File Specification</a>
             */
            private java.util.Set <String> parse(java.net.URL u)
            {
                java.io.InputStream    input  = null;
                java.io.BufferedReader reader = null;
                java.util.Set <String> names  = new java.util.HashSet <String>();
                try
                {
                    input  = u.openStream();
                    reader = new java.io.BufferedReader(new java.io.InputStreamReader(input, "utf-8")); //$NON-NLS-1$

                    String line;
                    while ((line = reader.readLine()) != null)
                    {
                        // The comment character is '#' (0x23)
                        // on each line all characters following the first comment character are ignored
                        int sharpIndex = line.indexOf('#');
                        if (sharpIndex >= 0)
                        {
                            line = line.substring(0, sharpIndex);
                        }

                        // Whitespaces are ignored
                        line = line.trim();

                        if (line.length() > 0)
                        {
                            // a java class name, check if identifier correct
                            char[] namechars = line.toCharArray();
                            for (int i = 0; i < namechars.Length; i++)
                            {
                                if (!(java.lang.Character.isJavaIdentifierPart(namechars[i]) || namechars[i] == '.'))
                                {
                                    throw new ServiceConfigurationError(Messages.getString("imageio.99", line));
                                }
                            }
                            names.add(line);
                        }
                    }
                }
                catch (java.io.IOException e)
                {
                    throw new ServiceConfigurationError(e.toString());
                }
                finally
                {
                    try
                    {
                        if (reader != null)
                        {
                            reader.close();
                        }
                        if (input != null)
                        {
                            input.close();
                        }
                    }
                    catch (java.io.IOException e)
                    {
                        throw new ServiceConfigurationError(e.toString());
                    }
                }

                return(names);
            }
コード例 #10
0
        // end methods implemented from tinySQLTable.java
        // the rest of this stuff is internal methods
        // for textFileTable
        //

        /*
         *
         * Reads in a table definition and populates the column_info
         * Hashtable
         *
         */
        void readColumnInfo()
        {//throws tinySQLException {
            try
            {
                column_info = new java.util.Hashtable <Object, Object>();

                // Open an FileInputStream to the .def (table
                // definition) file
                //
                java.io.FileInputStream fdef =
                    new java.io.FileInputStream(dataDir + "/" + table + ".def");

                // use a StreamTokenizer to break up the stream.
                //
                java.io.Reader r = new java.io.BufferedReader(
                    new java.io.InputStreamReader(fdef));
                java.io.StreamTokenizer def = new java.io.StreamTokenizer(r);

                // set the | as a delimiter, and set everything between
                // 0 and z as word characters. Let it know that eol is
                // *not* significant, and that it should parse numbers.
                //
                def.whitespaceChars('|', '|');
                def.wordChars('0', 'z');
                def.eolIsSignificant(false);
                def.parseNumbers();

                // read each token from the tokenizer
                //
                while (def.nextToken() != java.io.StreamTokenizer.TT_EOF)
                {
                    // first token is the datatype
                    //
                    // Q&D: Default is char value, numeric is special
                    String datatype = java.lang.StringJ.valueOf(java.sql.Types.CHAR);
                    if (def.sval.equals("NUMERIC"))
                    {
                        datatype = java.lang.StringJ.valueOf(java.sql.Types.NUMERIC);
                    }

                    // get the next token; it's the column name
                    //
                    def.nextToken();
                    String column = def.sval;

                    // get the third token; it's the size of the column
                    //
                    def.nextToken();
                    long size = (new java.lang.Double(def.nval)).longValue();

                    // create an info array
                    //
                    String[] info = new String[3];

                    // store the datatype, the size, and the position
                    // within the record (the record length *before*
                    // we increment it with the size of this column
                    //
                    info[COLUMN_TYPE] = datatype;
                    info[COLUMN_SIZE] = java.lang.Long.toString(size);
                    info[COLUMN_POS]  = java.lang.Long.toString(record_length);

                    // this is the start position of the next column
                    //
                    record_length += size;

                    // store this info in the column_info hash,
                    // keyed by column name.
                    //
                    column_info.put(column, info);
                }

                fdef.close(); // close the file
            }
            catch (Exception e)
            {
                throw new TinySQLException(e.getMessage());
            }
        }
コード例 #11
0
        /*
         * Try to find provider using Jar Service Provider Mechanism
         *
         * @return instance of provider class if found or null
         */
        private static Object findJarServiceProvider(String factoryId)
        //throws ConfigurationError
        {
            String serviceId = "META-INF/services/" + factoryId;

            java.io.InputStream isJ = null;

            // First try the Context ClassLoader
            java.lang.ClassLoader cl = SecuritySupport.getContextClassLoader();
            if (cl != null)
            {
                isJ = SecuritySupport.getResourceAsStream(cl, serviceId);

                // If no provider found then try the current ClassLoader
                if (isJ == null)
                {
                    cl  = typeof(FactoryFinder).getClass().getClassLoader();
                    isJ = SecuritySupport.getResourceAsStream(cl, serviceId);
                }
            }
            else
            {
                // No Context ClassLoader, try the current
                // ClassLoader
                cl  = typeof(FactoryFinder).getClass().getClassLoader();
                isJ = SecuritySupport.getResourceAsStream(cl, serviceId);
            }

            if (isJ == null)
            {
                // No provider found
                return(null);
            }

            if (debug)
            {
                dPrint("found jar resource=" + serviceId +
                       " using ClassLoader: " + cl);
            }

            // Read the service provider name in UTF-8 as specified in
            // the jar spec.  Unfortunately this fails in Microsoft
            // VJ++, which does not implement the UTF-8
            // encoding. Theoretically, we should simply let it fail in
            // that case, since the JVM is obviously broken if it
            // doesn't support such a basic standard.  But since there
            // are still some users attempting to use VJ++ for
            // development, we have dropped in a fallback which makes a
            // second attempt using the platform's default encoding. In
            // VJ++ this is apparently ASCII, which is a subset of
            // UTF-8... and since the strings we'll be reading here are
            // also primarily limited to the 7-bit ASCII range (at
            // least, in English versions), this should work well
            // enough to keep us on the air until we're ready to
            // officially decommit from VJ++. [Edited comment from
            // jkesselm]
            java.io.BufferedReader rd;
            try {
                rd = new java.io.BufferedReader(new java.io.InputStreamReader(isJ, "UTF-8"), DEFAULT_LINE_LENGTH);
            } catch (java.io.UnsupportedEncodingException e) {
                rd = new java.io.BufferedReader(new java.io.InputStreamReader(isJ), DEFAULT_LINE_LENGTH);
            }

            String factoryClassName = null;

            try {
                // XXX Does not handle all possible input as specified by the
                // Jar Service Provider specification
                factoryClassName = rd.readLine();
            } catch (java.io.IOException x) {
                // No provider found
                return(null);
            } finally {
                try {
                    // try to close the reader.
                    rd.close();
                }
                // Ignore the exception.
                catch (java.io.IOException exc) {
                }
            }

            if (factoryClassName != null &&
                !"".equals(factoryClassName))
            {
                if (debug)
                {
                    dPrint("found in resource, value="
                           + factoryClassName);
                }

                // Note: here we do not want to fall back to the current
                // ClassLoader because we want to avoid the case where the
                // resource file was found using one ClassLoader and the
                // provider class was instantiated using a different one.
                return(newInstance(factoryClassName, cl, false));
            }

            // No provider found
            return(null);
        }
コード例 #12
0
ファイル: TinySQLCmd.cs プロジェクト: bastie/NetVampire
        public static void main(String[] args) //throws IOException,SQLException
        {
            java.sql.DatabaseMetaData  dbMeta;
            java.sql.ResultSetMetaData meta;
            java.sql.ResultSet         display_rs, typesRS;
            java.io.BufferedReader     stdin, loadFileReader;
            java.io.BufferedReader     startReader = (java.io.BufferedReader)null;
            String[]            fields;
            java.sql.Connection con;
            java.sql.Statement  stmt;
            FieldTokenizer      ft;

            java.sql.PreparedStatement pstmt = (java.sql.PreparedStatement)null;
            int i, rsColCount, endAt, colWidth, colScale, colPrecision, typeCount,
                colType, parameterIndex, b1, b2, parameterInt, startAt, columnIndex, valueIndex;
            String fName, tableName = null, inputString, cmdString, colTypeName, dbType,
                   parameterString, loadString, fieldString, readString;

            java.lang.StringBuffer lineOut, prepareBuffer, valuesBuffer, inputBuffer;
            bool echo = false;

            stdin = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.SystemJ.inJ));
            try
            {
                /*
                 *       Register the JDBC driver for dBase
                 */
                java.lang.Class.forName("com.sqlmagic.tinysql.dbfFileDriver");
            }
            catch (java.lang.ClassNotFoundException e)
            {
                java.lang.SystemJ.err.println(
                    "JDBC Driver could not be registered!!\n");
                if (TinySQLGlobals.DEBUG)
                {
                    e.printStackTrace();
                }
            }
            fName = ".";
            if (args.Length > 0)
            {
                fName = args[0];
            }

            /*
             *    Establish a connection to dBase
             */
            con = dbConnect(fName);
            if (con == (java.sql.Connection)null)
            {
                fName = ".";
                con   = dbConnect(fName);
            }
            dbMeta    = con.getMetaData();
            dbType    = dbMeta.getDatabaseProductName();
            dbVersion = dbMeta.getDatabaseProductVersion();
            java.lang.SystemJ.outJ.println("===================================================");
            java.lang.SystemJ.outJ.println(dbType + " Command line interface version "
                                           + dbVersion + " Java version released March 15, 2007");
            java.lang.SystemJ.outJ.println("Type HELP to get information on available commands.");
            cmdString   = "NULL";
            stmt        = con.createStatement();
            inputString = (String)null;
            if (args.Length > 1)
            {
                inputString = args[1].trim();
            }
            while (!cmdString.toUpperCase().equals("EXIT"))
            {
                try
                {
                    if (startReader != (java.io.BufferedReader)null)
                    {
                        /*
                         *             Command START files can contain comments and can have
                         *             commands broken over several lines.  However, they
                         *             cannot have partial commands on a line.
                         */
                        inputBuffer = new java.lang.StringBuffer();
                        inputString = (String)null;
                        while ((readString = startReader.readLine()) != null)
                        {
                            if (readString.startsWith("--") |
                                readString.startsWith("#"))
                            {
                                continue;
                            }
                            inputBuffer.append(readString + " ");

                            /*
                             *                A field tokenizer must be used to avoid problems with
                             *                semi-colons inside quoted strings.
                             */
                            ft = new FieldTokenizer(inputBuffer.toString(), ';', true);
                            if (ft.countFields() > 1)
                            {
                                inputString = inputBuffer.toString();
                                break;
                            }
                        }
                        if (inputString == (String)null)
                        {
                            startReader = (java.io.BufferedReader)null;
                            continue;
                        }
                    }
                    else if (args.Length == 0)
                    {
                        java.lang.SystemJ.outJ.print("tinySQL>");
                        inputString = stdin.readLine().trim();
                    }
                    if (inputString == (String)null)
                    {
                        break;
                    }
                    if (inputString.toUpperCase().startsWith("EXIT") |
                        inputString.toUpperCase().startsWith("QUIT"))
                    {
                        break;
                    }
                    startAt = 0;
                    while (startAt < inputString.length() - 1)
                    {
                        endAt = inputString.indexOf(";", startAt);
                        if (endAt == -1)
                        {
                            endAt = inputString.length();
                        }
                        cmdString = inputString.substring(startAt, endAt);
                        if (echo)
                        {
                            java.lang.SystemJ.outJ.println(cmdString);
                        }
                        startAt = endAt + 1;
                        if (cmdString.toUpperCase().startsWith("SELECT"))
                        {
                            display_rs = stmt.executeQuery(cmdString);
                            if (display_rs == (java.sql.ResultSet)null)
                            {
                                java.lang.SystemJ.outJ.println("Null ResultSet returned from query");
                                continue;
                            }
                            meta = display_rs.getMetaData();

                            /*
                             *                The actual number of columns retrieved has to be checked
                             */
                            rsColCount = meta.getColumnCount();
                            lineOut    = new java.lang.StringBuffer(100);
                            int[]    columnWidths     = new int[rsColCount];
                            int[]    columnScales     = new int[rsColCount];
                            int[]    columnPrecisions = new int[rsColCount];
                            int[]    columnTypes      = new int[rsColCount];
                            String[] columnNames      = new String[rsColCount];
                            for (i = 0; i < rsColCount; i++)
                            {
                                columnNames[i]      = meta.getColumnName(i + 1);
                                columnWidths[i]     = meta.getColumnDisplaySize(i + 1);
                                columnTypes[i]      = meta.getColumnType(i + 1);
                                columnScales[i]     = meta.getScale(i + 1);
                                columnPrecisions[i] = meta.getPrecision(i + 1);
                                if (columnNames[i].length() > columnWidths[i])
                                {
                                    columnWidths[i] = columnNames[i].length();
                                }
                                lineOut.append(padString(columnNames[i], columnWidths[i]) + " ");
                            }
                            if (TinySQLGlobals.DEBUG)
                            {
                                java.lang.SystemJ.outJ.println(lineOut.toString());
                            }
                            displayResults(display_rs);
                        }
                        else if (cmdString.toUpperCase().startsWith("CONNECT"))
                        {
                            con = dbConnect(cmdString.substring(8, cmdString.length()));
                        }
                        else if (cmdString.toUpperCase().startsWith("HELP"))
                        {
                            helpMsg(cmdString);
                        }
                        else if (cmdString.toUpperCase().startsWith("DESCRIBE"))
                        {
                            dbMeta     = con.getMetaData();
                            tableName  = cmdString.toUpperCase().substring(9);
                            display_rs = dbMeta.getColumns(null, null, tableName, null);
                            java.lang.SystemJ.outJ.println("\nColumns for table " + tableName + "\n"
                                                           + "Name                            Type");
                            while (display_rs.next())
                            {
                                lineOut = new java.lang.StringBuffer(100);
                                lineOut.append(padString(display_rs.getString(4), 32));
                                colTypeName  = display_rs.getString(6);
                                colType      = display_rs.getInt(5);
                                colWidth     = display_rs.getInt(7);
                                colScale     = display_rs.getInt(9);
                                colPrecision = display_rs.getInt(10);
                                if (colTypeName.equals("CHAR"))
                                {
                                    colTypeName = colTypeName + "("
                                                  + java.lang.Integer.toString(colWidth) + ")";
                                }
                                else if (colTypeName.equals("FLOAT"))
                                {
                                    colTypeName += "(" + java.lang.Integer.toString(colPrecision)
                                                   + "," + java.lang.Integer.toString(colScale) + ")";
                                }
                                lineOut.append(padString(colTypeName, 20) + padString(colType, 12));
                                java.lang.SystemJ.outJ.println(lineOut.toString());
                            }
                        }
                        else if (cmdString.toUpperCase().equals("SHOW TABLES"))
                        {
                            for (i = 0; i < tableList.size(); i++)
                            {
                                java.lang.SystemJ.outJ.println((String)tableList.elementAt(i));
                            }
                        }
                        else if (cmdString.toUpperCase().equals("SHOW TYPES"))
                        {
                            typesRS   = dbMeta.getTypeInfo();
                            typeCount = displayResults(typesRS);
                        }
                        else if (cmdString.toUpperCase().startsWith("SET "))
                        {
                            /*
                             *                Support for SET DEBUG ON/OFF and SET ECHO ON/OFF
                             */
                            ft     = new FieldTokenizer(cmdString.toUpperCase(), ' ', false);
                            fields = ft.getFields();
                            if (fields[1].equals("ECHO"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    echo = true;
                                }
                                else
                                {
                                    echo = false;
                                }
                            }
                            else if (fields[1].equals("DEBUG"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    TinySQLGlobals.DEBUG = true;
                                }
                                else
                                {
                                    TinySQLGlobals.DEBUG = false;
                                }
                            }
                            else if (fields[1].equals("PARSER_DEBUG"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    TinySQLGlobals.PARSER_DEBUG = true;
                                }
                                else
                                {
                                    TinySQLGlobals.PARSER_DEBUG = false;
                                }
                            }
                            else if (fields[1].equals("WHERE_DEBUG"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    TinySQLGlobals.WHERE_DEBUG = true;
                                }
                                else
                                {
                                    TinySQLGlobals.WHERE_DEBUG = false;
                                }
                            }
                            else if (fields[1].equals("EX_DEBUG"))
                            {
                                if (fields[2].equals("ON"))
                                {
                                    TinySQLGlobals.EX_DEBUG = true;
                                }
                                else
                                {
                                    TinySQLGlobals.EX_DEBUG = false;
                                }
                            }
                        }
                        else if (cmdString.toUpperCase().startsWith("SPOOL "))
                        {
                            /*
                             *                Spool output to a file.
                             */
                            ft    = new FieldTokenizer(cmdString, ' ', false);
                            fName = ft.getField(1);
                            if (fName.equals("OFF"))
                            {
                                try
                                {
                                    spoolFileWriter.close();
                                }
                                catch (Exception spoolEx)
                                {
                                    java.lang.SystemJ.outJ.println("Unable to close spool file "
                                                                   + spoolEx.getMessage() + newLine);
                                }
                            }
                            else
                            {
                                try
                                {
                                    spoolFileWriter = new java.io.FileWriter(fName);
                                    if (spoolFileWriter != (java.io.FileWriter)null)
                                    {
                                        java.lang.SystemJ.outJ.println("Output spooled to " + fName);
                                    }
                                }
                                catch (Exception spoolEx)
                                {
                                    java.lang.SystemJ.outJ.println("Unable to spool to file "
                                                                   + spoolEx.getMessage() + newLine);
                                }
                            }
                        }
                        else if (cmdString.toUpperCase().startsWith("START "))
                        {
                            ft    = new FieldTokenizer(cmdString, ' ', false);
                            fName = ft.getField(1);
                            if (!fName.toUpperCase().endsWith(".SQL"))
                            {
                                fName += ".SQL";
                            }
                            try
                            {
                                startReader = new java.io.BufferedReader(new java.io.FileReader(fName));
                            }
                            catch (Exception)
                            {
                                startReader = (java.io.BufferedReader)null;
                                throw new TinySQLException("No such file: " + fName);
                            }
                        }
                        else if (cmdString.toUpperCase().startsWith("LOAD"))
                        {
                            ft         = new FieldTokenizer(cmdString, ' ', false);
                            fName      = ft.getField(1);
                            tableName  = ft.getField(3);
                            display_rs = stmt.executeQuery("SELECT * FROM " + tableName);
                            meta       = display_rs.getMetaData();
                            rsColCount = meta.getColumnCount();

                            /*
                             *                Set up the PreparedStatement for the inserts
                             */
                            prepareBuffer = new java.lang.StringBuffer("INSERT INTO " + tableName);
                            valuesBuffer  = new java.lang.StringBuffer(" VALUES");
                            for (i = 0; i < rsColCount; i++)
                            {
                                if (i == 0)
                                {
                                    prepareBuffer.append(" (");
                                    valuesBuffer.append(" (");
                                }
                                else
                                {
                                    prepareBuffer.append(",");
                                    valuesBuffer.append(",");
                                }
                                prepareBuffer.append(meta.getColumnName(i + 1));
                                valuesBuffer.append("?");
                            }
                            prepareBuffer.append(")" + valuesBuffer.toString() + ")");
                            try
                            {
                                pstmt          = con.prepareStatement(prepareBuffer.toString());
                                loadFileReader = new java.io.BufferedReader(new java.io.FileReader(fName));
                                while ((loadString = loadFileReader.readLine()) != null)
                                {
                                    if (loadString.toUpperCase().equals("ENDOFDATA"))
                                    {
                                        break;
                                    }
                                    columnIndex = 0;
                                    valueIndex  = 0;
                                    ft          = new FieldTokenizer(loadString, '|', true);
                                    while (ft.hasMoreFields())
                                    {
                                        fieldString = ft.nextField();
                                        if (fieldString.equals("|"))
                                        {
                                            columnIndex++;
                                            if (columnIndex > valueIndex)
                                            {
                                                pstmt.setString(valueIndex + 1, (String)null);
                                                valueIndex++;
                                            }
                                        }
                                        else if (columnIndex < rsColCount)
                                        {
                                            pstmt.setString(valueIndex + 1, fieldString);
                                            valueIndex++;
                                        }
                                    }
                                    pstmt.executeUpdate();
                                }
                                pstmt.close();
                            }
                            catch (Exception loadEx)
                            {
                                java.lang.SystemJ.outJ.println(loadEx.getMessage());
                            }
                        }
                        else if (cmdString.toUpperCase().startsWith("SETSTRING") |
                                 cmdString.toUpperCase().startsWith("SETINT"))
                        {
                            b1 = cmdString.indexOf(" ");
                            b2 = cmdString.lastIndexOf(" ");
                            if (b2 > b1 & b1 > 0)
                            {
                                parameterIndex  = java.lang.Integer.parseInt(cmdString.substring(b1 + 1, b2));
                                parameterString = cmdString.substring(b2 + 1);
                                if (TinySQLGlobals.DEBUG)
                                {
                                    java.lang.SystemJ.outJ.println("Set parameter["
                                                                   + parameterIndex + "]=" + parameterString);
                                }
                                if (cmdString.toUpperCase().startsWith("SETINT"))
                                {
                                    parameterInt = java.lang.Integer.parseInt(parameterString);
                                    pstmt.setInt(parameterIndex, parameterInt);
                                }
                                else
                                {
                                    pstmt.setString(parameterIndex, parameterString);
                                }
                                if (parameterIndex == 2)
                                {
                                    pstmt.executeUpdate();
                                }
                            }
                        }
                        else
                        {
                            if (cmdString.indexOf("?") > -1)
                            {
                                pstmt = con.prepareStatement(cmdString);
                            }
                            else
                            {
                                try
                                {
                                    stmt.executeUpdate(cmdString);
                                    java.lang.SystemJ.outJ.println("DONE\n");
                                }
                                catch (java.lang.Exception upex)
                                {
                                    java.lang.SystemJ.outJ.println(upex.getMessage());
                                    if (TinySQLGlobals.DEBUG)
                                    {
                                        upex.printStackTrace();
                                    }
                                }
                            }
                        }
                    }
                    if (args.Length > 1)
                    {
                        cmdString = "EXIT";
                    }
                }
                catch (java.sql.SQLException te)
                {
                    java.lang.SystemJ.outJ.println(te.getMessage());
                    if (TinySQLGlobals.DEBUG)
                    {
                        te.printStackTrace(java.lang.SystemJ.outJ);
                    }
                    inputString = (String)null;
                }
                catch (Exception e)
                {
                    java.lang.SystemJ.outJ.println(e.getMessage());
                    cmdString = "EXIT";
                    break;
                }
            }
            try
            {
                if (spoolFileWriter != (java.io.FileWriter)null)
                {
                    spoolFileWriter.close();
                }
            }
            catch (Exception spoolEx)
            {
                java.lang.SystemJ.outJ.println("Unable to close spool file "
                                               + spoolEx.getMessage() + newLine);
            }
        }
コード例 #13
0
ファイル: XMLReaderFactory.cs プロジェクト: sailesh341/JavApi
        //throws SAXException
        /**
         * Attempt to create an XMLReader from system defaults.
         * In environments which can support it, the name of the XMLReader
         * class is determined by trying each these options in order, and
         * using the first one which succeeds:<p/> <ul>
         *
         * <li>If the system property <code>org.xml.sax.driver</code>
         * has a value, that is used as an XMLReader class name. </li>
         *
         * <li>The JAR "Services API" is used to look for a class name
         * in the <em>META-INF/services/org.xml.sax.driver</em> file in
         * jarfiles available to the runtime.</li>
         *
         * <li> SAX parser distributions are strongly encouraged to provide
         * a default XMLReader class name that will take effect only when
         * previous options (on this list) are not successful.</li>
         *
         * <li>Finally, if {@link ParserFactory#makeParser()} can
         * return a system default SAX1 parser, that parser is wrapped in
         * a {@link ParserAdapter}.  (This is a migration aid for SAX1
         * environments, where the <code>org.xml.sax.parser</code> system
         * property will often be usable.) </li>
         *
         * </ul>
         *
         * <p> In environments such as small embedded systems, which can not
         * support that flexibility, other mechanisms to determine the default
         * may be used. </p>
         *
         * <p>Note that many Java environments allow system properties to be
         * initialized on a command line.  This means that <em>in most cases</em>
         * setting a good value for that property ensures that calls to this
         * method will succeed, except when security policies intervene.
         * This will also maximize application portability to older SAX
         * environments, with less robust implementations of this method.
         * </p>
         *
         * @return A new XMLReader.
         * @exception org.xml.sax.SAXException If no default XMLReader class
         *            can be identified and instantiated.
         * @see #createXMLReader(java.lang.String)
         */
        public static XMLReader createXMLReader()
        {
            String		className = null;
            java.lang.ClassLoader	loader = NewInstance.getClassLoader ();

            // 1. try the JVM-instance-wide system property
            try { className = java.lang.SystemJ.getProperty (property); }
            catch (java.lang.RuntimeException e) { /* normally fails for applets */ }

            // 2. if that fails, try META-INF/services/
            if (className == null) {
            try {
            String		service = "META-INF/services/" + property;
            java.io.InputStream	input;
            java.io.BufferedReader	reader;

            if (loader == null)
            input = java.lang.ClassLoader.getSystemResourceAsStream (service);
            else
            input = loader.getResourceAsStream (service);

            if (input != null) {
            reader = new java.io.BufferedReader (
                new java.io.InputStreamReader (input, "UTF8"));
            className = reader.readLine ();
            input.close ();
            }
            } catch (Exception e) {
            }
            }

            // 3. Distro-specific fallback
            if (className == null) {
            // BEGIN DISTRIBUTION-SPECIFIC

            // EXAMPLE:
            // className = "com.example.sax.XmlReader";
            // or a $JAVA_HOME/jre/lib/*properties setting...

            //Take a look in Java 7 shows: className = "com.sun.org.apache.xerces.internal.parsers.SAXParser";

            // END DISTRIBUTION-SPECIFIC
            }

            // do we know the XMLReader implementation class yet?
            if (className != null)
            return loadClass (loader, className);

            // 4. panic -- adapt any SAX1 parser
            try {
            return new ParserAdapter (ParserFactory.makeParser ());
            } catch (java.lang.Exception e) {
            throw new SAXException ("Can't create default XMLReader; "
            + "is system property org.xml.sax.driver set?");
            }
        }
コード例 #14
0
        private void paxHeaders() //throws IOException
        {
            java.io.BufferedReader         br      = new java.io.BufferedReader(new java.io.InputStreamReader(this, "UTF-8"));
            java.util.Map <String, String> headers = new java.util.HashMap <String, String>();
            // Format is "length keyword=value\n";
            while (true) // get length
            {
                int ch;
                int len  = 0;
                int read = 0;
                while ((ch = br.read()) != -1)
                {
                    read++;
                    if (ch == ' ')  // End of length string
                    // Get keyword
                    {
                        StringBuilder sb = new StringBuilder();
                        while ((ch = br.read()) != -1)
                        {
                            read++;
                            if (ch == '=')  // end of keyword
                            {
                                String keyword = sb.toString();
                                // Get rest of entry
                                char[] cbuf = new char[len - read];
                                int    got  = br.read(cbuf);
                                if (got != len - read)
                                {
                                    throw new java.io.IOException("Failed to read Paxheader. Expected " + (len - read) + " chars, read " + got);
                                }
                                String value = new String(cbuf, 0, len - read - 1); // Drop trailing NL
                                headers.put(keyword, value);
                                break;
                            }
                            sb.Append((char)ch);
                        }
                        break; // Processed single header
                    }
                    len *= 10;
                    len += ch - '0';
                }
                if (ch == -1)  // EOF
                {
                    break;
                }
            }
            getNextEntry(); // Get the actual file entry

            /*
             * The following headers are defined for Pax.
             * atime, ctime, mtime, charset: cannot use these without changing TarArchiveEntry fields
             * comment
             * gid, gname
             * linkpath
             * size
             * uid,uname
             */
            java.util.Iterator <java.util.MapNS.Entry <String, String> > hdrs = headers.entrySet().iterator();
            while (hdrs.hasNext())
            {
                java.util.MapNS.Entry <String, String> ent = hdrs.next();
                String key = ent.getKey();
                String val = ent.getValue();
                if ("path".equals(key))
                {
                    currEntry.setName(val);
                }
                else if ("linkpath".equals(key))
                {
                    currEntry.setLinkName(val);
                }
                else if ("gid".equals(key))
                {
                    currEntry.setGroupId(java.lang.Integer.parseInt(val));
                }
                else if ("gname".equals(key))
                {
                    currEntry.setGroupName(val);
                }
                else if ("uid".equals(key))
                {
                    currEntry.setUserId(java.lang.Integer.parseInt(val));
                }
                else if ("uname".equals(key))
                {
                    currEntry.setUserName(val);
                }
                else if ("size".equals(key))
                {
                    currEntry.setSize(java.lang.Long.parseLong(val));
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// <para>Load key value pairs (properties) from an input Stream expected to have ISO-8859-1 encoding (code page 28592).  
        /// The input stream (usually reading from a ".properties" file) consists of a series of lines (terminated 
        /// by \r, \n or \r\n) each a key value pair, a comment or a blank line.</para>
        /// 
        /// <para>Leading whitespace (spaces, tabs, formfeeds) are ignored at the start of any line - and a line that is empty or 
        /// contains only whitespace is blank and ignored.</para>
        /// 
        /// <para>A line with the first non-whitespace character is a '#' or '!' is a comment line and the rest of the line is 
        /// ignored.</para>
        /// 
        /// <para>If the first non-whitespace character is not '#' or '!' then it is the start of a key.  A key is all the
        /// characters up to the first whitespace or a key/value separator - '=' or ':'.</para>
        /// 
        /// <para>The separator is optional.  Any whitespace after the key or after the separator (if present) is ignored.</para>
        /// 
        /// <para>The first non-whitespace character after the separator (or after the key if no separator) begins the value.  
        /// The value may include whitespace, separators, or comment characters.</para>
        /// 
        /// <para>Any unicode character may be included in either key or value by using escapes preceded by the escape 
        /// character '\'.</para>
        /// 
        /// <para>The following special cases are defined:</para>
        /// <code>
        /// 	'\t' - horizontal tab.
        /// 	'\f' - form feed.
        /// 	'\r' - return
        /// 	'\n' - new line
        /// 	'\\' - add escape character.
        /// 
        /// 	'\ ' - add space in a key or at the start of a value.
        /// 	'\!', '\#' - add comment markers at the start of a key.
        /// 	'\=', '\:' - add a separator in a key.
        /// </code>
        /// 
        /// <para>Any unicode character using the following escape:</para>
        /// <code>
        /// 	'\uXXXX' - where XXXX represents the unicode character code as 4 hexadecimal digits.
        /// </code>
        /// 
        /// <para>Finally, longer lines can be broken by putting an escape at the very end of the line.  Any leading space
        /// (unless escaped) is skipped at the beginning of the following line.</para>
        /// 
        /// Examples
        /// <code>
        /// 	a-key = a-value
        /// 	a-key : a-value
        /// 	a-key=a-value
        /// 	a-key a-value
        /// </code>
        /// 
        /// <para>All the above will result in the same key/value pair - key "a-key" and value "a-value".</para>
        /// <code>
        /// 	! comment...
        /// 	# another comment...
        /// </code>
        /// 
        /// <para>The above are two examples of comments.</para>
        /// <code>
        /// 	Honk\ Kong = Near China
        /// </code>
        /// 
        /// <para>The above shows how to embed a space in a key - key is "Hong Kong", value is "Near China".</para>
        /// <code>
        /// 	a-longer-key-example = a really long value that is \
        /// 			split over two lines.
        /// </code>
        /// 
        /// <para>An example of a long line split into two.</para>
        /// </summary>
        /// <param name="stream">The input stream that the properties are read from.</param>
        public void Parse( java.io.Reader stream )
        {
            reader = new java.io.BufferedReader( stream, bufferSize );

            int state = STATE_start;
            do
            {
                int ch = nextChar();

                bool matched = false;

                for( int s = 0; s < states[ state ].Length; s += 3 )
                {
                    if( matches( states[ state ][ s ], ch ) )
                    {
                        matched = true;
                        doAction( states[ state ][ s + 2 ], ch );

                        state = states[ state ][ s + 1 ];
                        break;
                    }
                }

                if( !matched )
                {
                    throw new java.lang.IllegalArgumentException( "Unexpected character at " + 1 + ": <<<" + ch + ">>>" );
                }
            } while( state != STATE_finish );
        }
コード例 #16
0
ファイル: XMLReaderFactory.cs プロジェクト: minam365/JavApi
        /*
         * Attempt to create an XMLReader from system defaults.
         * In environments which can support it, the name of the XMLReader
         * class is determined by trying each these options in order, and
         * using the first one which succeeds:<p/> <ul>
         *
         * <li>If the system property <code>org.xml.sax.driver</code>
         * has a value, that is used as an XMLReader class name. </li>
         *
         * <li>The JAR "Services API" is used to look for a class name
         * in the <em>META-INF/services/org.xml.sax.driver</em> file in
         * jarfiles available to the runtime.</li>
         *
         * <li> SAX parser distributions are strongly encouraged to provide
         * a default XMLReader class name that will take effect only when
         * previous options (on this list) are not successful.</li>
         *
         * <li>Finally, if {@link ParserFactory#makeParser()} can
         * return a system default SAX1 parser, that parser is wrapped in
         * a {@link ParserAdapter}.  (This is a migration aid for SAX1
         * environments, where the <code>org.xml.sax.parser</code> system
         * property will often be usable.) </li>
         *
         * </ul>
         *
         * <p> In environments such as small embedded systems, which can not
         * support that flexibility, other mechanisms to determine the default
         * may be used. </p>
         *
         * <p>Note that many Java environments allow system properties to be
         * initialized on a command line.  This means that <em>in most cases</em>
         * setting a good value for that property ensures that calls to this
         * method will succeed, except when security policies intervene.
         * This will also maximize application portability to older SAX
         * environments, with less robust implementations of this method.
         * </p>
         *
         * @return A new XMLReader.
         * @exception org.xml.sax.SAXException If no default XMLReader class
         *            can be identified and instantiated.
         * @see #createXMLReader(java.lang.String)
         */
        public static XMLReader createXMLReader()
        //throws SAXException
        {
            String className = null;

            java.lang.ClassLoader loader = NewInstance.getClassLoader();

            // 1. try the JVM-instance-wide system property
            try { className = java.lang.SystemJ.getProperty(property); }
            catch (java.lang.RuntimeException e) { /* normally fails for applets */ }

            // 2. if that fails, try META-INF/services/
            if (className == null)
            {
                try {
                    String service = "META-INF/services/" + property;
                    java.io.InputStream    input;
                    java.io.BufferedReader reader;

                    if (loader == null)
                    {
                        input = java.lang.ClassLoader.getSystemResourceAsStream(service);
                    }
                    else
                    {
                        input = loader.getResourceAsStream(service);
                    }

                    if (input != null)
                    {
                        reader = new java.io.BufferedReader(
                            new java.io.InputStreamReader(input, "UTF8"));
                        className = reader.readLine();
                        input.close();
                    }
                } catch (Exception e) {
                }
            }

            // 3. Distro-specific fallback
            if (className == null)
            {
// BEGIN DISTRIBUTION-SPECIFIC

                // EXAMPLE:
                // className = "com.example.sax.XmlReader";
                // or a $JAVA_HOME/jre/lib/*properties setting...

                //Take a look in Java 7 shows: className = "com.sun.org.apache.xerces.internal.parsers.SAXParser";

// END DISTRIBUTION-SPECIFIC
            }

            // do we know the XMLReader implementation class yet?
            if (className != null)
            {
                return(loadClass(loader, className));
            }

            // 4. panic -- adapt any SAX1 parser
            try {
                return(new ParserAdapter(ParserFactory.makeParser()));
            } catch (java.lang.Exception e) {
                throw new SAXException("Can't create default XMLReader; "
                                       + "is system property org.xml.sax.driver set?");
            }
        }