Update of /cvsroot/monetdb/java/src/nl/cwi/monetdb/util
In directory 
sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10861/src/nl/cwi/monetdb/util

Added Files:
        Extract.java NamespaceContextImpl.java 
Log Message:
Moved the XRPC Wrapper to the new "java" module



--- NEW FILE: NamespaceContextImpl.java ---
/**
 * The contents of this file are subject to the MonetDB Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html

 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and
 * limitations under the License.

 * The Original Code is the MonetDB Database System.

 * The Initial Developer of the Original Code is CWI.
 * Portions created by CWI are Copyright (C) 1997-2007 CWI.
 * All Rights Reserved.
**/

package nl.cwi.monetdb.util;

import java.util.*;
import javax.xml.namespace.*;

/**
 * @author Ying Zhang <[EMAIL PROTECTED]>
 * @version 0.1
 */

public class NamespaceContextImpl implements NamespaceContext{
    private Map map;

    public NamespaceContextImpl(){
        map = new HashMap();
    }

    public NamespaceContextImpl(String prefix, String uri){
        map = new HashMap();
        map.put(prefix, uri);
    }

    public void add(String prefix, String uri){
        map.put(prefix, uri);
    }

    public String getNamespaceURI(String prefix){
        return (String) map.get(prefix);
    }

    public String getPrefix(String namespaceURI){
        String[] prefixes = (String[]) map.keySet().toArray(new String[0]);

        for (int i = 0; i < prefixes.length; i++) {
            if(((String)map.get(prefixes[i])).equals(namespaceURI))
                return prefixes[i];
        }
        return null;
    }

    public Iterator getPrefixes(String namespaceURI){
        List prefixes = new ArrayList();
        String[] keys = (String[]) map.keySet().toArray(new String[0]);

        for (int i = 0; i < keys.length; i++) {
            if(((String)map.get(keys[i])).equals(namespaceURI))
                prefixes.add(keys[i]);
        }
        return prefixes.iterator();
    }
}

--- NEW FILE: Extract.java ---
/**
 * The contents of this file are subject to the MonetDB Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html

 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and
 * limitations under the License.

 * The Original Code is the MonetDB Database System.

 * The Initial Developer of the Original Code is CWI.
 * Portions created by CWI are Copyright (C) 1997-2007 CWI.
 * All Rights Reserved.
**/

package nl.cwi.monetdb.util;

import java.io.*;
import java.net.*;


/**
 * @author Ying Zhang <[EMAIL PROTECTED]>
 * @version 0.1
 */

public class Extract {
        private static final int DEFAULT_BUFSIZE = 16386;

    public Extract() {}

    /* Extracts 'fromFile' from the jar package to 'toFile' */
        public static void extractFile(String fromFile, String toFile)
                throws FileNotFoundException, IOException
        {
                char[] cbuf = new char[DEFAULT_BUFSIZE];
                int ret = 0;

                InputStream is = new 
Extract().getClass().getResourceAsStream(fromFile);

                if(is == null) {
                        throw new FileNotFoundException("File " + fromFile +
                                        " does not exist in the JAR package.");
                }

                BufferedReader reader = new BufferedReader(new 
InputStreamReader(is));
                FileWriter writer = new FileWriter(toFile, false);

                ret = reader.read(cbuf, 0, DEFAULT_BUFSIZE);
                while(ret > 0){
                        writer.write(cbuf, 0, ret);
                        ret = reader.read(cbuf, 0, DEFAULT_BUFSIZE);
                }
                reader.close();
                writer.close();
        }
}


-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to