cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r515734 [6/11] - in /incubator/cxf/trunk/rt: ./ core/src/main/java/org/apache/cxf/endpoint/ databinding/aegis/ databinding/aegis/src/ databinding/aegis/src/main/ databinding/aegis/src/main/java/ databinding/aegis/src/main/java/org/ databind...
Date Wed, 07 Mar 2007 20:20:15 GMT
Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/Base64.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/Base64.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/Base64.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/Base64.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,292 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/**
+ * @author TAMURA Kent <kent@trl.ibm.co.jp>
+ */
+public class Base64 {
+    private static final char[] S_BASE64CHAR = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
+                                                'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+                                                'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
+                                                'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+                                                'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
+                                                '8', '9', '+', '/'};
+    private static final char S_BASE64PAD = '=';
+    private static final byte[] S_DECODETABLE = new byte[128];
+    static {
+        for (int i = 0; i < S_DECODETABLE.length; i++) {
+            S_DECODETABLE[i] = Byte.MAX_VALUE; // 127
+        }
+        for (int i = 0; i < S_BASE64CHAR.length; i++) {
+            // 0 to 63
+            S_DECODETABLE[S_BASE64CHAR[i]] = (byte)i;
+        }
+    }
+
+    private static int decode0(char[] ibuf, byte[] obuf, int wp) {
+        int outlen = 3;
+        if (ibuf[3] == S_BASE64PAD) {
+            outlen = 2;
+        }
+        if (ibuf[2] == S_BASE64PAD) {
+            outlen = 1;
+        }
+        int b0 = S_DECODETABLE[ibuf[0]];
+        int b1 = S_DECODETABLE[ibuf[1]];
+        int b2 = S_DECODETABLE[ibuf[2]];
+        int b3 = S_DECODETABLE[ibuf[3]];
+        switch (outlen) {
+        case 1:
+            obuf[wp] = (byte)(b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+            return 1;
+        case 2:
+            obuf[wp++] = (byte)(b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+            obuf[wp] = (byte)(b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
+            return 2;
+        case 3:
+            obuf[wp++] = (byte)(b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+            obuf[wp++] = (byte)(b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
+            obuf[wp] = (byte)(b2 << 6 & 0xc0 | b3 & 0x3f);
+            return 3;
+        default:
+            throw new RuntimeException("Couldn't decode.");
+        }
+    }
+
+    /**
+     *
+     */
+    public static byte[] decode(char[] data, int off, int len) {
+        char[] ibuf = new char[4];
+        int ibufcount = 0;
+        byte[] obuf = new byte[len / 4 * 3 + 3];
+        int obufcount = 0;
+        for (int i = off; i < off + len; i++) {
+            char ch = data[i];
+            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+                ibuf[ibufcount++] = ch;
+                if (ibufcount == ibuf.length) {
+                    ibufcount = 0;
+                    obufcount += decode0(ibuf, obuf, obufcount);
+                }
+            }
+        }
+        if (obufcount == obuf.length) {
+            return obuf;
+        }
+        byte[] ret = new byte[obufcount];
+        System.arraycopy(obuf, 0, ret, 0, obufcount);
+        return ret;
+    }
+
+    /**
+     *
+     */
+    public static byte[] decode(String data) {
+        char[] ibuf = new char[4];
+        int ibufcount = 0;
+        byte[] obuf = new byte[data.length() / 4 * 3 + 3];
+        int obufcount = 0;
+        for (int i = 0; i < data.length(); i++) {
+            char ch = data.charAt(i);
+            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+                ibuf[ibufcount++] = ch;
+                if (ibufcount == ibuf.length) {
+                    ibufcount = 0;
+                    obufcount += decode0(ibuf, obuf, obufcount);
+                }
+            }
+        }
+        if (obufcount == obuf.length) {
+            return obuf;
+        }
+        byte[] ret = new byte[obufcount];
+        System.arraycopy(obuf, 0, ret, 0, obufcount);
+        return ret;
+    }
+
+    /**
+     *
+     */
+    public static void decode(char[] data, int off, int len, OutputStream ostream) throws IOException {
+        char[] ibuf = new char[4];
+        int ibufcount = 0;
+        byte[] obuf = new byte[3];
+        for (int i = off; i < off + len; i++) {
+            char ch = data[i];
+            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+                ibuf[ibufcount++] = ch;
+                if (ibufcount == ibuf.length) {
+                    ibufcount = 0;
+                    int obufcount = decode0(ibuf, obuf, 0);
+                    ostream.write(obuf, 0, obufcount);
+                }
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    public static void decode(String data, OutputStream ostream) throws IOException {
+        char[] ibuf = new char[4];
+        int ibufcount = 0;
+        byte[] obuf = new byte[3];
+        for (int i = 0; i < data.length(); i++) {
+            char ch = data.charAt(i);
+            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+                ibuf[ibufcount++] = ch;
+                if (ibufcount == ibuf.length) {
+                    ibufcount = 0;
+                    int obufcount = decode0(ibuf, obuf, 0);
+                    ostream.write(obuf, 0, obufcount);
+                }
+            }
+        }
+    }
+
+    /**
+     * Returns base64 representation of specified byte array.
+     */
+    public static String encode(byte[] data) {
+        return encode(data, 0, data.length);
+    }
+
+    /**
+     * Returns base64 representation of specified byte array.
+     */
+    public static String encode(byte[] data, int off, int len) {
+        if (len <= 0) {
+            return "";
+        }
+        char[] out = new char[len / 3 * 4 + 4];
+        int rindex = off;
+        int windex = 0;
+        int rest = len - off;
+        while (rest >= 3) {
+            int i = ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+                    + (data[rindex + 2] & 0xff);
+            out[windex++] = S_BASE64CHAR[i >> 18];
+            out[windex++] = S_BASE64CHAR[(i >> 12) & 0x3f];
+            out[windex++] = S_BASE64CHAR[(i >> 6) & 0x3f];
+            out[windex++] = S_BASE64CHAR[i & 0x3f];
+            rindex += 3;
+            rest -= 3;
+        }
+        if (rest == 1) {
+            int i = data[rindex] & 0xff;
+            out[windex++] = S_BASE64CHAR[i >> 2];
+            out[windex++] = S_BASE64CHAR[(i << 4) & 0x3f];
+            out[windex++] = S_BASE64PAD;
+            out[windex++] = S_BASE64PAD;
+        } else if (rest == 2) {
+            int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+            out[windex++] = S_BASE64CHAR[i >> 10];
+            out[windex++] = S_BASE64CHAR[(i >> 4) & 0x3f];
+            out[windex++] = S_BASE64CHAR[(i << 2) & 0x3f];
+            out[windex++] = S_BASE64PAD;
+        }
+        return new String(out, 0, windex);
+    }
+
+    /**
+     * Outputs base64 representation of the specified byte array to a byte
+     * stream.
+     */
+    public static void encode(byte[] data, int off, int len, OutputStream ostream) throws IOException {
+        if (len <= 0) {
+            return;
+        }
+        byte[] out = new byte[4];
+        int rindex = off;
+        int rest = len - off;
+        while (rest >= 3) {
+            int i = ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+                    + (data[rindex + 2] & 0xff);
+            out[0] = (byte)S_BASE64CHAR[i >> 18];
+            out[1] = (byte)S_BASE64CHAR[(i >> 12) & 0x3f];
+            out[2] = (byte)S_BASE64CHAR[(i >> 6) & 0x3f];
+            out[3] = (byte)S_BASE64CHAR[i & 0x3f];
+            ostream.write(out, 0, 4);
+            rindex += 3;
+            rest -= 3;
+        }
+        if (rest == 1) {
+            int i = data[rindex] & 0xff;
+            out[0] = (byte)S_BASE64CHAR[i >> 2];
+            out[1] = (byte)S_BASE64CHAR[(i << 4) & 0x3f];
+            out[2] = (byte)S_BASE64PAD;
+            out[3] = (byte)S_BASE64PAD;
+            ostream.write(out, 0, 4);
+        } else if (rest == 2) {
+            int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+            out[0] = (byte)S_BASE64CHAR[i >> 10];
+            out[1] = (byte)S_BASE64CHAR[(i >> 4) & 0x3f];
+            out[2] = (byte)S_BASE64CHAR[(i << 2) & 0x3f];
+            out[3] = (byte)S_BASE64PAD;
+            ostream.write(out, 0, 4);
+        }
+    }
+
+    /**
+     * Outputs base64 representation of the specified byte array to a character
+     * stream.
+     */
+    public static void encode(byte[] data, int off, int len, Writer writer) throws IOException {
+        if (len <= 0) {
+            return;
+        }
+        char[] out = new char[4];
+        int rindex = off;
+        int rest = len - off;
+        int output = 0;
+        while (rest >= 3) {
+            int i = ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+                    + (data[rindex + 2] & 0xff);
+            out[0] = S_BASE64CHAR[i >> 18];
+            out[1] = S_BASE64CHAR[(i >> 12) & 0x3f];
+            out[2] = S_BASE64CHAR[(i >> 6) & 0x3f];
+            out[3] = S_BASE64CHAR[i & 0x3f];
+            writer.write(out, 0, 4);
+            rindex += 3;
+            rest -= 3;
+            output += 4;
+            if (output % 76 == 0) {
+                writer.write("\n");
+            }
+        }
+        if (rest == 1) {
+            int i = data[rindex] & 0xff;
+            out[0] = S_BASE64CHAR[i >> 2];
+            out[1] = S_BASE64CHAR[(i << 4) & 0x3f];
+            out[2] = S_BASE64PAD;
+            out[3] = S_BASE64PAD;
+            writer.write(out, 0, 4);
+        } else if (rest == 2) {
+            int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+            out[0] = S_BASE64CHAR[i >> 10];
+            out[1] = S_BASE64CHAR[(i >> 4) & 0x3f];
+            out[2] = S_BASE64CHAR[(i << 2) & 0x3f];
+            out[3] = S_BASE64PAD;
+            writer.write(out, 0, 4);
+        }
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/Base64.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/Base64.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/Base64.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/CachedOutputStream.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/CachedOutputStream.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/CachedOutputStream.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,149 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.cxf.aegis.DatabindingException;
+
+public class CachedOutputStream extends OutputStream {
+    private OutputStream currentStream;
+    private int threshold;
+    private int totalLength = 0;
+    private boolean inmem = false;
+    private File tempFile = null;
+    private File outputDir;
+
+    public CachedOutputStream(int threshold, File outputDir) throws IOException {
+        this.threshold = threshold;
+        this.outputDir = outputDir;
+
+        if (threshold <= 0) {
+            createFileOutputStream();
+        } else {
+            currentStream = new ByteArrayOutputStream();
+            inmem = true;
+        }
+    }
+
+    @Override
+    public void close() throws IOException {
+        currentStream.close();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        return currentStream.equals(obj);
+    }
+
+    @Override
+    public void flush() throws IOException {
+        currentStream.flush();
+    }
+
+    @Override
+    public int hashCode() {
+        return currentStream.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return currentStream.toString();
+    }
+
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+        this.totalLength += len;
+        if (inmem && totalLength > threshold) {
+            switchToFile();
+        }
+
+        currentStream.write(b, off, len);
+    }
+
+    private void switchToFile() throws IOException {
+        byte[] bytes = ((ByteArrayOutputStream)currentStream).toByteArray();
+
+        createFileOutputStream();
+
+        currentStream.write(bytes);
+        inmem = false;
+    }
+
+    private void createFileOutputStream() throws IOException {
+        if (outputDir == null) {
+            tempFile = File.createTempFile("att", "tmp");
+        } else {
+            tempFile = File.createTempFile("att", "tmp", outputDir);
+        }
+
+        currentStream = new BufferedOutputStream(new FileOutputStream(tempFile));
+    }
+
+    @Override
+    public void write(byte[] b) throws IOException {
+        this.totalLength += b.length;
+        if (inmem && totalLength > threshold) {
+            switchToFile();
+        }
+
+        currentStream.write(b);
+    }
+
+    @Override
+    public void write(int b) throws IOException {
+        this.totalLength++;
+        if (inmem && totalLength > threshold) {
+            switchToFile();
+        }
+
+        currentStream.write(b);
+    }
+
+    public File getTempFile() {
+        return tempFile;
+    }
+
+    public InputStream getInputStream() {
+        if (inmem) {
+            return new ByteArrayInputStream(((ByteArrayOutputStream)currentStream).toByteArray());
+        } else {
+            try {
+                return new FileInputStream(tempFile);
+            } catch (FileNotFoundException e) {
+                throw new DatabindingException("Cached file was deleted!!!", e);
+            }
+        }
+    }
+
+    public void dispose() {
+        if (!inmem) {
+            tempFile.delete();
+        }
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/CachedOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/CachedOutputStream.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/FastStack.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/FastStack.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/FastStack.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/FastStack.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+import java.util.ArrayList;
+import java.util.EmptyStackException;
+
+public class FastStack<T> extends ArrayList<T> {
+    public void push(T o) {
+        add(o);
+    }
+
+    public Object pop() {
+        if (empty()) {
+            throw new EmptyStackException();
+        }
+
+        return remove(size() - 1);
+    }
+
+    public boolean empty() {
+        return size() == 0;
+    }
+
+    public Object peek() {
+        if (empty()) {
+            throw new EmptyStackException();
+        }
+
+        return get(size() - 1);
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/FastStack.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/FastStack.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/JavaUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/JavaUtils.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/JavaUtils.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/JavaUtils.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+import java.text.Collator;
+import java.util.Arrays;
+import java.util.Locale;
+
+public class JavaUtils {
+
+    /** Collator for comparing the strings */
+    static final Collator englishCollator = Collator.getInstance(Locale.ENGLISH);
+
+    /** Use this character as suffix */
+    static final char keywordPrefix = '_';
+
+    /**
+     * These are java keywords as specified at the following URL (sorted
+     * alphabetically).
+     * http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308
+     * Note that false, true, and null are not strictly keywords; they are
+     * literal values, but for the purposes of this array, they can be treated
+     * as literals. ****** PLEASE KEEP THIS LIST SORTED IN ASCENDING ORDER
+     * ******
+     */
+    static final String keywords[] = {"abstract", "assert", "boolean", "break", "byte", "case", "catch",
+                                      "char", "class", "const", "continue", "default", "do", "double",
+                                      "else", "extends", "false", "final", "finally", "float", "for", "goto",
+                                      "if", "implements", "import", "instanceof", "int", "interface", "long",
+                                      "native", "new", "null", "package", "private", "protected", "public",
+                                      "return", "short", "static", "strictfp", "super", "switch",
+                                      "synchronized", "this", "throw", "throws", "transient", "true", "try",
+                                      "void", "volatile", "while"};
+
+    /**
+     * checks if the input string is a valid java keyword.
+     * 
+     * @return boolean true/false
+     */
+    public static boolean isJavaKeyword(String keyword) {
+        return (Arrays.binarySearch(keywords, keyword, englishCollator) >= 0);
+    }
+
+    /**
+     * Turn a java keyword string into a non-Java keyword string. (Right now
+     * this simply means appending an underscore.)
+     */
+    public static String makeNonJavaKeyword(String keyword) {
+        return keywordPrefix + keyword;
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/JavaUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/JavaUtils.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/JavaUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,374 @@
+/*
+ * This file contains software licensed under the Aapache License:
+ * 
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.aegis.DatabindingException;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+/**
+ * Namespace utilities.
+ * 
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ * @author <a href="mailto:poutsma@mac.com">Arjen Poutsma</a>
+ */
+public class NamespaceHelper {
+    /**
+     * Create a unique namespace uri/prefix combination.
+     * 
+     * @param nsUri
+     * @return The namespace with the specified URI. If one doesn't exist, one
+     *         is created.
+     */
+    public static String getUniquePrefix(Element element, String namespaceURI) {
+        String prefix = getPrefix(element, namespaceURI);
+
+        if (prefix == null) {
+            prefix = getUniquePrefix(element);
+            element.addNamespaceDeclaration(Namespace.getNamespace(prefix, namespaceURI));
+        }
+        return prefix;
+    }
+
+    public static String getPrefix(Element element, String namespaceURI) {
+        if (element.getNamespaceURI().equals(namespaceURI)) {
+            return element.getNamespacePrefix();
+        }
+
+        List namespaces = element.getAdditionalNamespaces();
+
+        for (Iterator itr = namespaces.iterator(); itr.hasNext();) {
+            Namespace ns = (Namespace)itr.next();
+
+            if (ns.getURI().equals(namespaceURI)) {
+                return ns.getPrefix();
+            }
+        }
+
+        if (element.getParentElement() != null) {
+            return getPrefix(element.getParentElement(), namespaceURI);
+        } else {
+            return null;
+        }
+    }
+
+    public static void getPrefixes(Element element, String namespaceURI, List<String> prefixes) {
+        if (element.getNamespaceURI().equals(namespaceURI)) {
+            prefixes.add(element.getNamespacePrefix());
+        }
+
+        List namespaces = element.getAdditionalNamespaces();
+
+        for (Iterator itr = namespaces.iterator(); itr.hasNext();) {
+            Namespace ns = (Namespace)itr.next();
+
+            if (ns.getURI().equals(namespaceURI)) {
+                prefixes.add(ns.getPrefix());
+            }
+        }
+
+        if (element.getParentElement() != null) {
+            getPrefixes(element.getParentElement(), namespaceURI, prefixes);
+        }
+    }
+
+    private static String getUniquePrefix(Element el) {
+        int n = 1;
+
+        while (true) {
+            String nsPrefix = "ns" + n;
+
+            if (el.getNamespace(nsPrefix) == null) {
+                return nsPrefix;
+            }
+
+            n++;
+        }
+    }
+
+    /**
+     * Create a unique namespace uri/prefix combination.
+     * 
+     * @param nsUri
+     * @return The namespace with the specified URI. If one doesn't exist, one
+     *         is created.
+     * @throws XMLStreamException
+     */
+    public static String getUniquePrefix(XMLStreamWriter writer, String namespaceURI, boolean declare)
+        throws XMLStreamException {
+        String prefix = writer.getNamespaceContext().getPrefix(namespaceURI);
+        if (prefix == null) {
+            prefix = getUniquePrefix(writer);
+
+            if (declare) {
+                writer.setPrefix(prefix, namespaceURI);
+                writer.writeNamespace(prefix, namespaceURI);
+            }
+        }
+
+        return prefix;
+    }
+
+    public static String getUniquePrefix(XMLStreamWriter writer) {
+        int n = 1;
+
+        while (true) {
+            String nsPrefix = "ns" + n;
+
+            if (writer.getNamespaceContext().getNamespaceURI(nsPrefix) == null) {
+                return nsPrefix;
+            }
+
+            n++;
+        }
+    }
+
+    /**
+     * Generates the name of a XML namespace from a given class name and
+     * protocol. The returned namespace will take the form
+     * <code>protocol://domain</code>, where <code>protocol</code> is the
+     * given protocol, and <code>domain</code> the inversed package name of
+     * the given class name. <p/> For instance, if the given class name is
+     * <code>org.codehaus.xfire.services.Echo</code>, and the protocol is
+     * <code>http</code>, the resulting namespace would be
+     * <code>http://services.xfire.codehaus.org</code>.
+     * 
+     * @param className the class name
+     * @param protocol the protocol (eg. <code>http</code>)
+     * @return the namespace
+     */
+    public static String makeNamespaceFromClassName(String className, String protocol) {
+        int index = className.lastIndexOf(".");
+
+        if (index == -1) {
+            return protocol + "://" + "DefaultNamespace";
+        }
+
+        String packageName = className.substring(0, index);
+
+        StringTokenizer st = new StringTokenizer(packageName, ".");
+        String[] words = new String[st.countTokens()];
+
+        for (int i = 0; i < words.length; ++i) {
+            words[i] = st.nextToken();
+        }
+
+        StringBuffer sb = new StringBuffer(80);
+
+        for (int i = words.length - 1; i >= 0; --i) {
+            String word = words[i];
+
+            // seperate with dot
+            if (i != words.length - 1) {
+                sb.append('.');
+            }
+
+            sb.append(word);
+        }
+
+        return protocol + "://" + sb.toString();
+    }
+
+    /**
+     * Method makePackageName
+     * 
+     * @param namespace
+     * @return
+     */
+    public static String makePackageName(String namespace) {
+
+        String hostname = null;
+        String path = "";
+
+        // get the target namespace of the document
+        try {
+            URL u = new URL(namespace);
+
+            hostname = u.getHost();
+            path = u.getPath();
+        } catch (MalformedURLException e) {
+            if (namespace.indexOf(":") > -1) {
+                hostname = namespace.substring(namespace.indexOf(":") + 1);
+
+                if (hostname.indexOf("/") > -1) {
+                    hostname = hostname.substring(0, hostname.indexOf("/"));
+                }
+            } else {
+                hostname = namespace;
+            }
+        }
+
+        // if we didn't file a hostname, bail
+        if (hostname == null) {
+            return null;
+        }
+
+        // convert illegal java identifier
+        hostname = hostname.replace('-', '_');
+        path = path.replace('-', '_');
+
+        // chomp off last forward slash in path, if necessary
+        if ((path.length() > 0) && (path.charAt(path.length() - 1) == '/')) {
+            path = path.substring(0, path.length() - 1);
+        }
+
+        // tokenize the hostname and reverse it
+        StringTokenizer st = new StringTokenizer(hostname, ".:");
+        String[] words = new String[st.countTokens()];
+
+        for (int i = 0; i < words.length; ++i) {
+            words[i] = st.nextToken();
+        }
+
+        StringBuffer sb = new StringBuffer(namespace.length());
+
+        for (int i = words.length - 1; i >= 0; --i) {
+            addWordToPackageBuffer(sb, words[i], (i == words.length - 1));
+        }
+
+        // tokenize the path
+        StringTokenizer st2 = new StringTokenizer(path, "/");
+
+        while (st2.hasMoreTokens()) {
+            addWordToPackageBuffer(sb, st2.nextToken(), false);
+        }
+
+        return sb.toString();
+    }
+
+    /**
+     * Massage <tt>word</tt> into a form suitable for use in a Java package
+     * name. Append it to the target string buffer with a <tt>.</tt> delimiter
+     * iff <tt>word</tt> is not the first word in the package name.
+     * 
+     * @param sb the buffer to append to
+     * @param word the word to append
+     * @param firstWord a flag indicating whether this is the first word
+     */
+    private static void addWordToPackageBuffer(StringBuffer sb, String word, boolean firstWord) {
+
+        if (JavaUtils.isJavaKeyword(word)) {
+            word = JavaUtils.makeNonJavaKeyword(word);
+        }
+
+        // separate with dot after the first word
+        if (!firstWord) {
+            sb.append('.');
+        }
+
+        // prefix digits with underscores
+        if (Character.isDigit(word.charAt(0))) {
+            sb.append('_');
+        }
+
+        // replace periods with underscores
+        if (word.indexOf('.') != -1) {
+            char[] buf = word.toCharArray();
+
+            for (int i = 0; i < word.length(); i++) {
+                if (buf[i] == '.') {
+                    buf[i] = '_';
+                }
+            }
+
+            word = new String(buf);
+        }
+
+        sb.append(word);
+    }
+
+    /**
+     * Reads a QName from the element text. Reader must be positioned at the
+     * start tag.
+     * 
+     * @param reader
+     * @return
+     * @throws XMLStreamException
+     */
+    public static QName readQName(XMLStreamReader reader) throws XMLStreamException {
+        String value = reader.getElementText();
+        if (value == null) {
+            return null;
+        }
+
+        int index = value.indexOf(":");
+
+        if (index == -1) {
+            return new QName(value);
+        }
+
+        String prefix = value.substring(0, index);
+        String localName = value.substring(index + 1);
+        String ns = reader.getNamespaceURI(prefix);
+
+        if (ns == null || localName == null) {
+            throw new DatabindingException("Invalid QName in mapping: " + value);
+        }
+
+        return new QName(ns, localName, prefix);
+    }
+
+    public static QName createQName(NamespaceContext nc, String value) {
+        if (value == null) {
+            return null;
+        }
+        int index = value.indexOf(':');
+        if (index == -1) {
+            return new QName(nc.getNamespaceURI(""), value, "");
+        } else {
+            String prefix = value.substring(0, index);
+            String localName = value.substring(index + 1);
+            String ns = nc.getNamespaceURI(prefix);
+            return new QName(ns, localName, prefix);
+        }
+    }
+
+    public static QName createQName(Element e, String value, String defaultNamespace) {
+        if (value == null) {
+            return null;
+        }
+
+        int index = value.indexOf(":");
+
+        if (index == -1) {
+            return new QName(defaultNamespace, value);
+        }
+
+        String prefix = value.substring(0, index);
+        String localName = value.substring(index + 1);
+        String ns = e.getNamespace(prefix).getURI();
+
+        if (ns == null || localName == null) {
+            throw new DatabindingException("Invalid QName in mapping: " + value);
+        }
+
+        return new QName(ns, localName, prefix);
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/STAXUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/STAXUtils.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/STAXUtils.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/STAXUtils.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,688 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.util.stax.DepthXMLStreamReader;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+
+/**
+ * Common StAX utilities.
+ * 
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ * @since Oct 26, 2004
+ */
+public class STAXUtils {
+    private static final String XML_NS = "http://www.w3.org/2000/xmlns/";
+
+    private final static Log logger = LogFactory.getLog(STAXUtils.class);
+
+    private final static XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+    private final static XMLOutputFactory xmlOututFactory = XMLOutputFactory.newInstance();
+    private static boolean inFactoryConfigured;
+
+    private final static Map<String, Object> factories = new HashMap<String, Object>();
+
+    /**
+     * Returns true if currently at the start of an element, otherwise move
+     * forwards to the next element start and return true, otherwise false is
+     * returned if the end of the stream is reached.
+     */
+    public static boolean skipToStartOfElement(XMLStreamReader in) throws XMLStreamException {
+        for (int code = in.getEventType(); code != XMLStreamConstants.END_DOCUMENT; code = in.next()) {
+            if (code == XMLStreamConstants.START_ELEMENT) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static boolean toNextElement(DepthXMLStreamReader dr) {
+        if (dr.getEventType() == XMLStreamConstants.START_ELEMENT) {
+            return true;
+        }
+
+        if (dr.getEventType() == XMLStreamConstants.END_ELEMENT) {
+            return false;
+        }
+
+        try {
+            int depth = dr.getDepth();
+
+            for (int event = dr.getEventType(); dr.getDepth() >= depth && dr.hasNext(); event = dr.next()) {
+                if (event == XMLStreamConstants.START_ELEMENT && dr.getDepth() == depth + 1) {
+                    return true;
+                } else if (event == XMLStreamConstants.END_ELEMENT) {
+                    depth--;
+                }
+            }
+
+            return false;
+        } catch (XMLStreamException e) {
+            throw new DatabindingException("Couldn't parse stream.", e);
+        }
+    }
+
+    public static boolean skipToStartOfElement(DepthXMLStreamReader in) throws XMLStreamException {
+        for (int code = in.getEventType(); code != XMLStreamConstants.END_DOCUMENT; code = in.next()) {
+            if (code == XMLStreamConstants.START_ELEMENT) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Copies the reader to the writer. The start and end document methods must
+     * be handled on the writer manually. TODO: if the namespace on the reader
+     * has been declared previously to where we are in the stream, this probably
+     * won't work.
+     * 
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    public static void copy(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+        int read = 0; // number of elements read in
+        int event = reader.getEventType();
+
+        while (reader.hasNext()) {
+            switch (event) {
+            case XMLStreamConstants.START_ELEMENT:
+                read++;
+                writeStartElement(reader, writer);
+                break;
+            case XMLStreamConstants.END_ELEMENT:
+                writer.writeEndElement();
+                read--;
+                if (read <= 0) {
+                    return;
+                }
+                break;
+            case XMLStreamConstants.CHARACTERS:
+                writer.writeCharacters(reader.getText());
+                break;
+            case XMLStreamConstants.START_DOCUMENT:
+            case XMLStreamConstants.END_DOCUMENT:
+            case XMLStreamConstants.ATTRIBUTE:
+            case XMLStreamConstants.NAMESPACE:
+                break;
+            case XMLStreamConstants.CDATA:
+                writer.writeCData(reader.getText());
+                break;
+            default:
+                break;
+            }
+            event = reader.next();
+        }
+    }
+
+    private static void writeStartElement(XMLStreamReader reader, XMLStreamWriter writer)
+        throws XMLStreamException {
+        String local = reader.getLocalName();
+        String uri = reader.getNamespaceURI();
+        String prefix = reader.getPrefix();
+        if (prefix == null) {
+            prefix = "";
+        }
+
+        String boundPrefix = writer.getPrefix(uri);
+        boolean writeElementNS = false;
+        if (boundPrefix == null || !prefix.equals(boundPrefix)) {
+            writeElementNS = true;
+        }
+
+        // Write out the element name
+        if (uri != null && uri.length() > 0) {
+            if (prefix.length() == 0) {
+
+                writer.writeStartElement(local);
+                writer.setDefaultNamespace(uri);
+
+            } else {
+                writer.writeStartElement(prefix, local, uri);
+                writer.setPrefix(prefix, uri);
+            }
+        } else {
+            writer.writeStartElement(reader.getLocalName());
+        }
+
+        // Write out the namespaces
+        for (int i = 0; i < reader.getNamespaceCount(); i++) {
+            String nsURI = reader.getNamespaceURI(i);
+            String nsPrefix = reader.getNamespacePrefix(i);
+
+            // Why oh why does the RI suck so much?
+            if (nsURI == null) {
+                nsURI = "";
+            }
+            if (nsPrefix == null) {
+                nsPrefix = "";
+            }
+
+            if (nsPrefix.length() == 0) {
+                writer.writeDefaultNamespace(nsURI);
+            } else {
+                writer.writeNamespace(nsPrefix, nsURI);
+            }
+
+            if (uri != null && nsURI.equals(uri) && nsPrefix.equals(prefix)) {
+                writeElementNS = false;
+            }
+        }
+
+        // Check if the namespace still needs to be written.
+        // We need this check because namespace writing works
+        // different on Woodstox and the RI.
+        if (writeElementNS && uri != null) {
+            if (prefix == null || prefix.length() == 0) {
+                writer.writeDefaultNamespace(uri);
+            } else {
+                writer.writeNamespace(prefix, uri);
+            }
+        }
+
+        // Write out attributes
+        for (int i = 0; i < reader.getAttributeCount(); i++) {
+            String ns = reader.getAttributeNamespace(i);
+            String nsPrefix = reader.getAttributePrefix(i);
+            if (ns == null || ns.length() == 0) {
+                writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
+            } else if (nsPrefix == null || nsPrefix.length() == 0) {
+                writer.writeAttribute(reader.getAttributeNamespace(i), reader.getAttributeLocalName(i),
+                                      reader.getAttributeValue(i));
+            } else {
+                writer.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader
+                    .getAttributeLocalName(i), reader.getAttributeValue(i));
+            }
+
+        }
+    }
+
+    public static void writeDocument(Document d, XMLStreamWriter writer, boolean repairing)
+        throws XMLStreamException {
+        writeDocument(d, writer, true, repairing);
+    }
+
+    public static void writeDocument(Document d, XMLStreamWriter writer, boolean writeProlog,
+                                     boolean repairing) throws XMLStreamException {
+        if (writeProlog) {
+            writer.writeStartDocument();
+        }
+
+        Element root = d.getDocumentElement();
+        writeElement(root, writer, repairing);
+
+        if (writeProlog) {
+            writer.writeEndDocument();
+        }
+    }
+
+    /**
+     * Writes an Element to an XMLStreamWriter. The writer must already have
+     * started the doucment (via writeStartDocument()). Also, this probably
+     * won't work with just a fragment of a document. The Element should be the
+     * root element of the document.
+     * 
+     * @param e
+     * @param writer
+     * @throws XMLStreamException
+     */
+    public static void writeElement(Element e, XMLStreamWriter writer, boolean repairing)
+        throws XMLStreamException {
+        String prefix = e.getPrefix();
+        String ns = e.getNamespaceURI();
+        String localName = e.getLocalName();
+
+        if (prefix == null) {
+            prefix = "";
+        }
+        if (localName == null) {
+            localName = e.getNodeName();
+
+            if (localName == null) {
+                throw new IllegalStateException("Element's local name cannot be null!");
+            }
+        }
+
+        String decUri = writer.getNamespaceContext().getNamespaceURI(prefix);
+        boolean declareNamespace = (decUri == null || !decUri.equals(ns));
+
+        if (ns == null || ns.length() == 0) {
+            writer.writeStartElement(localName);
+        } else {
+            writer.writeStartElement(prefix, localName, ns);
+        }
+
+        NamedNodeMap attrs = e.getAttributes();
+        for (int i = 0; i < attrs.getLength(); i++) {
+            Node attr = attrs.item(i);
+
+            String name = attr.getNodeName();
+            String attrPrefix = "";
+            int prefixIndex = name.indexOf(':');
+            if (prefixIndex != -1) {
+                attrPrefix = name.substring(0, prefixIndex);
+                name = name.substring(prefixIndex + 1);
+            }
+
+            if (attrPrefix.equals("xmlns")) {
+                writer.writeNamespace(name, attr.getNodeValue());
+                if (name.equals(prefix) && attr.getNodeValue().equals(ns)) {
+                    declareNamespace = false;
+                }
+            } else {
+                if (name.equals("xmlns") && attrPrefix.equals("")) {
+                    writer.writeNamespace("", attr.getNodeValue());
+                    if (attr.getNodeValue().equals(ns)) {
+                        declareNamespace = false;
+                    }
+                } else {
+                    writer.writeAttribute(attrPrefix, attr.getNamespaceURI(), name, attr.getNodeValue());
+                }
+            }
+        }
+
+        if (declareNamespace && repairing) {
+            writer.writeNamespace(prefix, ns);
+        }
+
+        NodeList nodes = e.getChildNodes();
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Node n = nodes.item(i);
+            writeNode(n, writer, repairing);
+        }
+
+        writer.writeEndElement();
+    }
+
+    public static void writeNode(Node n, XMLStreamWriter writer, boolean repairing) throws XMLStreamException {
+        if (n instanceof Element) {
+            writeElement((Element)n, writer, repairing);
+        } else if (n instanceof Text) {
+            writer.writeCharacters(((Text)n).getNodeValue());
+        } else if (n instanceof CDATASection) {
+            writer.writeCData(((CDATASection)n).getData());
+        } else if (n instanceof Comment) {
+            writer.writeComment(((Comment)n).getData());
+        } else if (n instanceof EntityReference) {
+            writer.writeEntityRef(((EntityReference)n).getNodeValue());
+        } else if (n instanceof ProcessingInstruction) {
+            ProcessingInstruction pi = (ProcessingInstruction)n;
+            writer.writeProcessingInstruction(pi.getTarget(), pi.getData());
+        }
+    }
+
+    public static Document read(DocumentBuilder builder, XMLStreamReader reader, boolean repairing)
+        throws XMLStreamException {
+        Document doc = builder.newDocument();
+
+        readDocElements(doc, reader, repairing);
+
+        return doc;
+    }
+
+    /**
+     * @param parent
+     * @return
+     */
+    private static Document getDocument(Node parent) {
+        return (parent instanceof Document) ? (Document)parent : parent.getOwnerDocument();
+    }
+
+    /**
+     * @param parent
+     * @param reader
+     * @return
+     * @throws XMLStreamException
+     */
+    private static Element startElement(Node parent, XMLStreamReader reader, boolean repairing)
+        throws XMLStreamException {
+        Document doc = getDocument(parent);
+
+        Element e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName());
+
+        if (reader.getPrefix() != null) {
+            e.setPrefix(reader.getPrefix());
+        }
+
+        parent.appendChild(e);
+
+        for (int ns = 0; ns < reader.getNamespaceCount(); ns++) {
+            String uri = reader.getNamespaceURI(ns);
+            String prefix = reader.getNamespacePrefix(ns);
+
+            declare(e, uri, prefix);
+        }
+
+        for (int att = 0; att < reader.getAttributeCount(); att++) {
+            String name = reader.getAttributeLocalName(att);
+            String prefix = reader.getAttributePrefix(att);
+            if (prefix != null && prefix.length() > 0) {
+                name = prefix + ":" + name;
+            }
+
+            Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name);
+            attr.setValue(reader.getAttributeValue(att));
+            e.setAttributeNode(attr);
+        }
+
+        reader.next();
+
+        readDocElements(e, reader, repairing);
+
+        if (repairing && !isDeclared(e, reader.getNamespaceURI(), reader.getPrefix())) {
+            declare(e, reader.getNamespaceURI(), reader.getPrefix());
+        }
+
+        return e;
+    }
+
+    private static boolean isDeclared(Element e, String namespaceURI, String prefix) {
+        Attr att;
+        if (prefix != null && prefix.length() > 0) {
+            att = e.getAttributeNodeNS(XML_NS, "xmlns:" + prefix);
+        } else {
+            att = e.getAttributeNode("xmlns");
+        }
+
+        if (att != null && att.getNodeValue().equals(namespaceURI)) {
+            return true;
+        }
+
+        if (e.getParentNode() instanceof Element) {
+            return isDeclared((Element)e.getParentNode(), namespaceURI, prefix);
+        }
+
+        return false;
+    }
+
+    /**
+     * @param parent
+     * @param reader
+     * @throws XMLStreamException
+     */
+    public static void readDocElements(Node parent, XMLStreamReader reader, boolean repairing)
+        throws XMLStreamException {
+        Document doc = getDocument(parent);
+
+        int event = reader.getEventType();
+
+        while (reader.hasNext()) {
+            switch (event) {
+            case XMLStreamConstants.START_ELEMENT:
+                startElement(parent, reader, repairing);
+
+                if (parent instanceof Document) {
+                    if (reader.hasNext()) {
+                        reader.next();
+                    }
+                    return;
+                }
+
+                break;
+            case XMLStreamConstants.END_ELEMENT:
+                return;
+            case XMLStreamConstants.NAMESPACE:
+                break;
+            case XMLStreamConstants.ATTRIBUTE:
+                break;
+            case XMLStreamConstants.CHARACTERS:
+                if (parent != null) {
+                    parent.appendChild(doc.createTextNode(reader.getText()));
+                }
+
+                break;
+            case XMLStreamConstants.COMMENT:
+                if (parent != null) {
+                    parent.appendChild(doc.createComment(reader.getText()));
+                }
+
+                break;
+            case XMLStreamConstants.CDATA:
+                parent.appendChild(doc.createCDATASection(reader.getText()));
+
+                break;
+            case XMLStreamConstants.PROCESSING_INSTRUCTION:
+                parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData()));
+
+                break;
+            case XMLStreamConstants.ENTITY_REFERENCE:
+                parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData()));
+
+                break;
+            default:
+                break;
+            }
+
+            if (reader.hasNext()) {
+                event = reader.next();
+            }
+        }
+    }
+
+    private static void declare(Element node, String uri, String prefix) {
+        if (prefix != null && prefix.length() > 0) {
+            node.setAttributeNS(XML_NS, "xmlns:" + prefix, uri);
+        } else {
+            if (uri != null /* && uri.length() > 0 */) {
+                node.setAttributeNS(XML_NS, "xmlns", uri);
+            }
+        }
+    }
+
+    /**
+     * @param out
+     * @param encoding
+     * @return
+     */
+    public static XMLStreamWriter createXMLStreamWriter(OutputStream out, String encoding, Context ctx) {
+        XMLOutputFactory factory = getXMLOutputFactory(ctx);
+
+        if (encoding == null) {
+            encoding = "UTF-8";
+        }
+
+        try {
+            XMLStreamWriter writer = factory.createXMLStreamWriter(out, encoding);
+
+            return writer;
+        } catch (XMLStreamException e) {
+            throw new DatabindingException("Couldn't parse stream.", e);
+        }
+    }
+
+    /**
+     * @return
+     */
+    public static XMLOutputFactory getXMLOutputFactory(Context ctx) {
+        if (ctx == null) {
+            return xmlOututFactory;
+        }
+
+        Object outFactoryObj = ctx.get(XMLOutputFactory.class.getName());
+
+        if (outFactoryObj instanceof XMLOutputFactory) {
+            return (XMLOutputFactory)outFactoryObj;
+        } else if (outFactoryObj instanceof String) {
+            String outFactory = (String)outFactoryObj;
+            XMLOutputFactory xof = (XMLOutputFactory)factories.get(outFactory);
+            if (xof == null) {
+                xof = (XMLOutputFactory)createFactory(outFactory, ctx);
+                factories.put(outFactory, xof);
+            }
+            return xof;
+        }
+
+        return xmlOututFactory;
+    }
+
+    /**
+     * @return
+     */
+    public static XMLInputFactory getXMLInputFactory(Context ctx) {
+        if (ctx == null) {
+            return xmlInputFactory;
+        }
+
+        Object inFactoryObj = ctx.get(XMLInputFactory.class.getName());
+
+        if (inFactoryObj instanceof XMLInputFactory) {
+            return (XMLInputFactory)inFactoryObj;
+        } else if (inFactoryObj instanceof String) {
+            String inFactory = (String)inFactoryObj;
+            XMLInputFactory xif = (XMLInputFactory)factories.get(inFactory);
+            if (xif == null) {
+                xif = (XMLInputFactory)createFactory(inFactory, ctx);
+                configureFactory(xif, ctx);
+                factories.put(inFactory, xif);
+            }
+            return xif;
+        }
+
+        if (!inFactoryConfigured) {
+            configureFactory(xmlInputFactory, ctx);
+            inFactoryConfigured = true;
+        }
+
+        return xmlInputFactory;
+    }
+
+    private static Boolean getBooleanProperty(Context ctx, String name) {
+        Object value = ctx.get(name);
+        if (value != null) {
+            return Boolean.valueOf(value.toString());
+
+        }
+        return null;
+    }
+
+    /**
+     * @param xif
+     * @param ctx
+     */
+    private static void configureFactory(XMLInputFactory xif, Context ctx) {
+        Boolean value = getBooleanProperty(ctx, XMLInputFactory.IS_VALIDATING);
+        if (value != null) {
+            xif.setProperty(XMLInputFactory.IS_VALIDATING, value);
+        }
+        value = getBooleanProperty(ctx, XMLInputFactory.IS_NAMESPACE_AWARE);
+        if (value != null) {
+            xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, value);
+        }
+
+        value = getBooleanProperty(ctx, XMLInputFactory.IS_COALESCING);
+        if (value != null) {
+            xif.setProperty(XMLInputFactory.IS_COALESCING, value);
+        }
+
+        value = getBooleanProperty(ctx, XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES);
+        if (value != null) {
+            xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, value);
+        }
+
+        value = getBooleanProperty(ctx, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
+        if (value != null) {
+            xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, value);
+        }
+    }
+
+    /**
+     * @param factoryClass
+     * @return
+     */
+    private static Object createFactory(String factory, Context ctx) {
+        Class factoryClass = null;
+        try {
+            factoryClass = ClassLoaderUtils.loadClass(factory, ctx.getClass());
+            return factoryClass.newInstance();
+        } catch (Exception e) {
+            logger.error("Can't create factory for class : " + factory, e);
+            throw new DatabindingException("Can't create factory for class : " + factory);
+        }
+    }
+
+    /**
+     * @param in
+     * @param encoding
+     * @param ctx
+     * @return
+     */
+    public static XMLStreamReader createXMLStreamReader(InputStream in, String encoding, Context ctx) {
+        XMLInputFactory factory = getXMLInputFactory(ctx);
+
+        if (encoding == null) {
+            encoding = "UTF-8";
+        }
+
+        try {
+            return factory.createXMLStreamReader(in, encoding);
+        } catch (XMLStreamException e) {
+            throw new DatabindingException("Couldn't parse stream.", e);
+        }
+    }
+
+    public static XMLStreamReader createXMLStreamReader(Reader reader) {
+        return createXMLStreamReader(reader, null);
+    }
+
+    /**
+     * @param reader
+     * @return
+     */
+    public static XMLStreamReader createXMLStreamReader(Reader reader, Context context) {
+        XMLInputFactory factory = getXMLInputFactory(context);
+
+        try {
+            return factory.createXMLStreamReader(reader);
+        } catch (XMLStreamException e) {
+            throw new DatabindingException("Couldn't parse stream.", e);
+        }
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/STAXUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/STAXUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+import java.lang.reflect.Method;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Helps when constructing, or using services.
+ * 
+ * @author Arjen Poutsma
+ */
+public class ServiceUtils {
+    private ServiceUtils() {
+
+    }
+
+    /**
+     * Generates a suitable service name from a given class. The returned name
+     * is the simple name of the class, i.e. without the package name.
+     * 
+     * @param clazz the class.
+     * @return the name.
+     */
+    public static String makeServiceNameFromClassName(Class clazz) {
+        String name = clazz.getName();
+        int last = name.lastIndexOf(".");
+        if (last != -1) {
+            name = name.substring(last + 1);
+        }
+
+        int inner = name.lastIndexOf("$");
+        if (inner != -1) {
+            name = name.substring(inner + 1);
+        }
+
+        return name;
+    }
+
+    public static QName makeQualifiedNameFromClass(Class clazz) {
+        String namespace = NamespaceHelper.makeNamespaceFromClassName(clazz.getName(), "http");
+        String localPart = makeServiceNameFromClassName(clazz);
+        return new QName(namespace, localPart);
+    }
+
+    public static String getMethodName(Method m) {
+        StringBuffer sb = new StringBuffer();
+        sb.append(m.getDeclaringClass().getName());
+        sb.append('.');
+        sb.append(m.getName());
+        sb.append('(');
+        Class[] params = m.getParameterTypes();
+        for (int i = 0; i < params.length; i++) {
+            Class param = params[i];
+            sb.append(param.getName());
+            if (i < params.length - 1) {
+                sb.append(", ");
+            }
+        }
+        sb.append(')');
+        return sb.toString();
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/UID.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/UID.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/UID.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/UID.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+import java.util.Random;
+
+/**
+ * @author Hani Suleiman Date: Jun 10, 2005 Time: 3:20:28 PM
+ */
+public class UID {
+    private static int counter;
+    private static Random random = new Random(System.currentTimeMillis());
+
+    public static String generate() {
+        return String.valueOf(System.currentTimeMillis()) + counter++ + random.nextInt();
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/UID.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/UID.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/XmlConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/XmlConstants.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/XmlConstants.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/XmlConstants.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util;
+
+/**
+ * SOAP constants from the specs.
+ * 
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ * @since Feb 18, 2004
+ */
+public class XmlConstants {
+    /** Document styles. */
+
+    public static final String WSDL11_NS = "http://schemas.xmlsoap.org/wsdl/";
+    
+    public static final String WSDL11_SOAP_NS = "http://schemas.xmlsoap.org/wsdl/soap/";
+
+    /**
+     * Constant used to specify a rpc binding style.
+     */
+    public static final String STYLE_RPC = "rpc";
+
+    /**
+     * Constant used to specify a document binding style.
+     */
+    public static final String STYLE_DOCUMENT = "document";
+
+    /**
+     * Constant used to specify a wrapped binding style.
+     */
+    public static final String STYLE_WRAPPED = "wrapped";
+
+    /**
+     * Constant used to specify a message binding style.
+     */
+    public static final String STYLE_MESSAGE = "message";
+
+    /**
+     * Constant used to specify a literal binding use.
+     */
+    public static final String USE_LITERAL = "literal";
+
+    /**
+     * Constant used to specify a encoded binding use.
+     */
+    public static final String USE_ENCODED = "encoded";
+
+    /**
+     * XML Schema Namespace.
+     */
+    public static final String XSD = "http://www.w3.org/2001/XMLSchema";
+    public static final String XSD_PREFIX = "xsd";
+
+    public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
+    public static final String XSI_PREFIX = "xsi";
+
+    public static final String MEP_ROBUST_IN_OUT = "urn:xfire:mep:in-out";
+    public static final String MEP_IN = "urn:xfire:mep:in";
+
+    public static final String SOAP_ACTION = "SOAPAction";
+
+    /**
+     * Whether or not MTOM should be enabled for each service.
+     */
+    public static final String MTOM_ENABLED = "mtom-enabled";
+
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/XmlConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/XmlConstants.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateFormat.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateFormat.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateFormat.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateFormat.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2003, 2004  The Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cxf.aegis.util.date;
+
+/**
+ * <p>
+ * An instance of {@link java.text.Format}, which may be used to parse and
+ * format <code>xs:date</code> values.
+ * </p>
+ */
+public class XsDateFormat extends XsDateTimeFormat {
+    private static final long serialVersionUID = 3832621764093030707L;
+
+    /**
+     * Creates a new instance.
+     */
+    public XsDateFormat() {
+        super(true, false);
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateFormat.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateFormat.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,296 @@
+/*
+ * Copyright 2003, 2004  The Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cxf.aegis.util.date;
+
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.ParsePosition;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+/**
+ * <p>
+ * An instance of {@link java.text.Format}, which may be used to parse and
+ * format <code>xs:dateTime</code> values.
+ * </p>
+ */
+public class XsDateTimeFormat extends Format {
+    private static final long serialVersionUID = 3258131340871479609L;
+
+    final boolean parseDate;
+
+    final boolean parseTime;
+
+    XsDateTimeFormat(boolean pParseDate, boolean pParseTime) {
+        parseDate = pParseDate;
+        parseTime = pParseTime;
+    }
+
+    /**
+     * Creates a new instance.
+     */
+    public XsDateTimeFormat() {
+        this(true, true);
+    }
+
+    private int parseInt(String pString, int pOffset, StringBuffer pDigits) {
+        int length = pString.length();
+        pDigits.setLength(0);
+        while (pOffset < length) {
+            char c = pString.charAt(pOffset);
+            if (Character.isDigit(c)) {
+                pDigits.append(c);
+                ++pOffset;
+            } else {
+                break;
+            }
+        }
+        return pOffset;
+    }
+
+    @Override
+    public Object parseObject(String pString, ParsePosition pParsePosition) {
+        if (pString == null) {
+            throw new NullPointerException("The String argument must not be null.");
+        }
+        if (pParsePosition == null) {
+            throw new NullPointerException("The ParsePosition argument must not be null.");
+        }
+        int offset = pParsePosition.getIndex();
+        int length = pString.length();
+
+        boolean isMinus = false;
+        StringBuffer digits = new StringBuffer();
+        int year, month, mday;
+        if (parseDate) {
+            // Sign
+            if (offset < length) {
+                char c = pString.charAt(offset);
+                if (c == '+') {
+                    ++offset;
+                } else if (c == '-') {
+                    ++offset;
+                    isMinus = true;
+                }
+            }
+
+            offset = parseInt(pString, offset, digits);
+            if (digits.length() < 4) {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+            year = Integer.parseInt(digits.toString());
+
+            if (offset < length && pString.charAt(offset) == '-') {
+                ++offset;
+            } else {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+
+            offset = parseInt(pString, offset, digits);
+            if (digits.length() != 2) {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+            month = Integer.parseInt(digits.toString());
+
+            if (offset < length && pString.charAt(offset) == '-') {
+                ++offset;
+            } else {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+
+            offset = parseInt(pString, offset, digits);
+            if (digits.length() != 2) {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+            mday = Integer.parseInt(digits.toString());
+
+            if (parseTime) {
+                if (offset < length && pString.charAt(offset) == 'T') {
+                    ++offset;
+                } else {
+                    pParsePosition.setErrorIndex(offset);
+                    return null;
+                }
+            }
+        } else {
+            year = month = mday = 0;
+        }
+
+        int hour, minute, second, millis;
+        if (parseTime) {
+            offset = parseInt(pString, offset, digits);
+            if (digits.length() != 2) {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+            hour = Integer.parseInt(digits.toString());
+
+            if (offset < length && pString.charAt(offset) == ':') {
+                ++offset;
+            } else {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+
+            offset = parseInt(pString, offset, digits);
+            if (digits.length() != 2) {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+            minute = Integer.parseInt(digits.toString());
+
+            if (offset < length && pString.charAt(offset) == ':') {
+                ++offset;
+            } else {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+
+            offset = parseInt(pString, offset, digits);
+            if (digits.length() != 2) {
+                pParsePosition.setErrorIndex(offset);
+                return null;
+            }
+            second = Integer.parseInt(digits.toString());
+
+            if (offset < length && pString.charAt(offset) == '.') {
+                ++offset;
+                offset = parseInt(pString, offset, digits);
+                if (digits.length() > 0) {
+                    int cut = Math.min(3, digits.length());
+                    millis = Integer.parseInt(digits.substring(0, cut).toString());
+                } else {
+                    millis = 0;
+                }
+            } else {
+                millis = 0;
+            }
+        } else {
+            hour = minute = second = millis = 0;
+        }
+
+        digits.setLength(0);
+        digits.append("GMT");
+        if (offset < length) {
+            char c = pString.charAt(offset);
+            if (c == 'Z') {
+                // Ignore UTC, it is the default
+                ++offset;
+            } else if (c == '+' || c == '-') {
+                digits.append(c);
+                ++offset;
+                for (int i = 0; i < 5; i++) {
+                    if (offset >= length) {
+                        pParsePosition.setErrorIndex(offset);
+                        return null;
+                    }
+                    c = pString.charAt(offset);
+                    if ((i != 2 && Character.isDigit(c)) || (i == 2 && c == ':')) {
+                        digits.append(c);
+                    } else {
+                        pParsePosition.setErrorIndex(offset);
+                        return null;
+                    }
+                    ++offset;
+                }
+            }
+        }
+
+        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(digits.toString()));
+        cal.set(isMinus ? -year : year, parseDate ? month - 1 : month, mday, hour, minute, second);
+        cal.set(Calendar.MILLISECOND, millis);
+        pParsePosition.setIndex(offset);
+        return cal;
+    }
+
+    private void append(StringBuffer pBuffer, int pNum, int pMinLen) {
+        String s = Integer.toString(pNum);
+        for (int i = s.length(); i < pMinLen; i++) {
+            pBuffer.append('0');
+        }
+        pBuffer.append(s);
+    }
+
+    @Override
+    public StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos) {
+        if (pCalendar == null) {
+            throw new NullPointerException("The Calendar argument must not be null.");
+        }
+        if (pBuffer == null) {
+            throw new NullPointerException("The StringBuffer argument must not be null.");
+        }
+        if (pPos == null) {
+            throw new NullPointerException("The FieldPosition argument must not be null.");
+        }
+
+        Calendar cal = (Calendar)pCalendar;
+        if (parseDate) {
+            int year = cal.get(Calendar.YEAR);
+            if (year < 0) {
+                pBuffer.append('-');
+                year = -year;
+            }
+            append(pBuffer, year, 4);
+            pBuffer.append('-');
+            append(pBuffer, cal.get(Calendar.MONTH) + 1, 2);
+            pBuffer.append('-');
+            append(pBuffer, cal.get(Calendar.DAY_OF_MONTH), 2);
+            if (parseTime) {
+                pBuffer.append('T');
+            }
+        }
+        if (parseTime) {
+            append(pBuffer, cal.get(Calendar.HOUR_OF_DAY), 2);
+            pBuffer.append(':');
+            append(pBuffer, cal.get(Calendar.MINUTE), 2);
+            pBuffer.append(':');
+            append(pBuffer, cal.get(Calendar.SECOND), 2);
+            int millis = cal.get(Calendar.MILLISECOND);
+            if (millis > 0) {
+                pBuffer.append('.');
+                append(pBuffer, millis, 3);
+            }
+        }
+        TimeZone tz = cal.getTimeZone();
+        // JDK 1.4: int offset = tz.getOffset(cal.getTimeInMillis());
+        int offset = cal.get(Calendar.ZONE_OFFSET);
+        if (tz.inDaylightTime(cal.getTime())) {
+            offset += cal.get(Calendar.DST_OFFSET);
+        }
+        if (offset == 0) {
+            pBuffer.append('Z');
+        } else {
+            if (offset < 0) {
+                pBuffer.append('-');
+                offset = -offset;
+            } else {
+                pBuffer.append('+');
+            }
+            int minutes = offset / (60 * 1000);
+            int hours = minutes / 60;
+            minutes -= hours * 60;
+            append(pBuffer, hours, 2);
+            pBuffer.append(':');
+            append(pBuffer, minutes, 2);
+        }
+        return pBuffer;
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsTimeFormat.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsTimeFormat.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsTimeFormat.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsTimeFormat.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2003, 2004  The Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cxf.aegis.util.date;
+
+/**
+ * <p>
+ * An instance of {@link java.text.Format}, which may be used to parse and
+ * format <code>xs:time</code> values.
+ * </p>
+ */
+public class XsTimeFormat extends XsDateTimeFormat {
+    private static final long serialVersionUID = 3906931187925727282L;
+
+    /**
+     * Creates a new instance.
+     */
+    public XsTimeFormat() {
+        super(false, true);
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsTimeFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsTimeFormat.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsTimeFormat.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/package.html
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/package.html?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/package.html (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/package.html Wed Mar  7 12:20:07 2007
@@ -0,0 +1,29 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements. See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership. The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License. You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied. See the License for the
+   specific language governing permissions and limitations
+   under the License.
+-->
+<html>
+<body>
+<p>
+These classes are from the Apache WS-Commons project. They are included
+here for convenience only. Sources can be found here:
+</p>
+<p>
+<a href="http://svn.apache.org/viewcvs.cgi/webservices/commons/trunk/util">http://svn.apache.org/viewcvs.cgi/webservices/commons/trunk/util</a>
+</p>
+</body>
+</html>

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/package.html
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html



Mime
View raw message