geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r329036 [2/7] - in /geronimo/trunk/sandbox/freeorb: ./ geronimo-orb/ geronimo-orb/src/ geronimo-orb/src/main/ geronimo-orb/src/main/java/ geronimo-orb/src/main/java/org/ geronimo-orb/src/main/java/org/apache/ geronimo-orb/src/main/java/org/...
Date Fri, 28 Oct 2005 02:00:22 GMT
Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/RepositoryID.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/RepositoryID.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/RepositoryID.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/RepositoryID.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,171 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.geronimo.corba.util.StringUtil;
+
+
+public abstract class RepositoryID {
+
+    static final Log log = LogFactory.getLog(RepositoryID.class);
+
+    public static String idToClassName(String repid) {
+        // debug
+        if (log.isDebugEnabled()) {
+            log.debug("idToClassName " + repid);
+        }
+
+        if (repid.startsWith("IDL:")) {
+
+            String id = repid;
+
+            try {
+                int end = id.lastIndexOf(':');
+                String s = end < 0
+                           ? id.substring(4)
+                           : id.substring(4, end);
+
+                StringBuffer bb = new StringBuffer();
+
+                //
+                // reverse order of dot-separated name components up
+                // till the first slash.
+                //
+                int firstSlash = s.indexOf('/');
+                if (firstSlash > 0) {
+                    String prefix = s.substring(0, firstSlash);
+                    String[] elems = StringUtil.split(prefix, '.');
+
+                    for (int i = elems.length - 1; i >= 0; i--) {
+                        bb.append(fixName(elems[i]));
+                        bb.append('.');
+                    }
+
+                    s = s.substring(firstSlash + 1);
+                }
+
+                //
+                // Append slash-separated name components ...
+                //
+                String[] elems = StringUtil.split(s, '/');
+                for (int i = 0; i < elems.length; i++) {
+                    bb.append(fixName(elems[i]));
+                    if (i != elems.length - 1)
+                        bb.append('.');
+                }
+
+                String result = bb.toString();
+
+                if (log.isDebugEnabled()) {
+                    log.debug("idToClassName " + repid + " => " + result);
+                }
+
+                return result;
+            }
+            catch (IndexOutOfBoundsException ex) {
+                log.error("idToClass", ex);
+                return null;
+            }
+
+        } else if (repid.startsWith("RMI:")) {
+            int end = repid.indexOf(':', 4);
+            return end < 0
+                   ? repid.substring(4)
+                   : repid.substring(4, end);
+        }
+
+        return null;
+    }
+
+    static String fixName(String name) {
+
+        if (keyWords.contains(name)) {
+            StringBuffer buf = new StringBuffer();
+            buf.append('_');
+            buf.append(name);
+            return buf.toString();
+        }
+
+        String result = name;
+        String current = name;
+
+        boolean match = true;
+        while (match) {
+
+            int len = current.length();
+            match = false;
+
+            for (int i = 0; i < reservedPostfixes.length; i++) {
+                if (current.endsWith(reservedPostfixes[i])) {
+                    StringBuffer buf = new StringBuffer();
+                    buf.append('_');
+                    buf.append(result);
+                    result = buf.toString();
+
+                    int resultLen = reservedPostfixes[i].length();
+                    if (len > resultLen)
+                        current = current.substring(0,
+                                                    len - resultLen);
+                    else
+                        current = "";
+
+                    match = true;
+                    break;
+                }
+            }
+
+        }
+
+        return name;
+    }
+
+    static final java.util.Set keyWords = new java.util.HashSet();
+    static final String[] reservedPostfixes = new String[]{
+            "Helper",
+            "Holder",
+            "Operations",
+            "POA",
+            "POATie",
+            "Package",
+            "ValueFactory"
+    };
+
+    static {
+        String[] words = {
+                "abstract", "boolean", "break", "byte", "case", "catch",
+                "char", "class", "clone", "const", "continue", "default",
+                "do", "double", "else", "equals", "extends", "false",
+                "final", "finalize", "finally", "float", "for",
+                "getClass", "goto", "hashCode", "if", "implements",
+                "import", "instanceof", "int", "interface", "long",
+                "native", "new", "notify", "notifyAll", "null", "package",
+                "private", "protected", "public", "return", "short",
+                "static", "super", "switch", "synchronized", "this",
+                "throw", "throws", "toString", "transient", "true", "try",
+                "void", "volatile", "wait", "while"
+        };
+
+        for (int i = 0; i < words.length; i++) {
+            keyWords.add(words[i]);
+        }
+    }
+
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/SingletonORB.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/SingletonORB.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/SingletonORB.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/SingletonORB.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,175 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba;
+
+import org.apache.geronimo.corba.dii.EnvironmentImpl;
+import org.apache.geronimo.corba.dii.ExceptionListImpl;
+import org.apache.geronimo.corba.dii.NamedValueImpl;
+
+
+public class SingletonORB extends AbstractORB {
+
+    /**
+     * Public no-arg constructor
+     */
+    public SingletonORB() {
+    }
+
+    private void illegalSingletonOperation() {
+        throw new org.omg.CORBA.NO_IMPLEMENT(
+                "illegal operation on singleton ORB");
+    }
+
+    public String[] list_initial_services() {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public org.omg.CORBA.Object resolve_initial_references(String name)
+            throws org.omg.CORBA.ORBPackage.InvalidName
+    {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public void register_initial_reference(String name, org.omg.CORBA.Object obj)
+            throws org.omg.CORBA.ORBPackage.InvalidName
+    {
+        illegalSingletonOperation();
+    }
+
+    public String object_to_string(org.omg.CORBA.Object object) {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public org.omg.CORBA.Object string_to_object(String str) {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public org.omg.CORBA.NVList create_list(int count) {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public org.omg.CORBA.NVList create_operation_list(org.omg.CORBA.Object oper) {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public org.omg.CORBA.NamedValue create_named_value(String name,
+                                                       org.omg.CORBA.Any value, int flags)
+    {
+        return new NamedValueImpl(name, value, flags);
+    }
+
+    public org.omg.CORBA.ExceptionList create_exception_list() {
+        return new ExceptionListImpl();
+    }
+
+    public org.omg.CORBA.ContextList create_context_list() {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public org.omg.CORBA.Context get_default_context() {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public org.omg.CORBA.Environment create_environment() {
+        return new EnvironmentImpl();
+    }
+
+    public void send_multiple_requests_oneway(org.omg.CORBA.Request[] requests) {
+        illegalSingletonOperation();
+    }
+
+    public void send_multiple_requests_deferred(org.omg.CORBA.Request[] requests) {
+        illegalSingletonOperation();
+    }
+
+    public boolean poll_next_response() {
+        illegalSingletonOperation();
+        return false;
+    }
+
+    public org.omg.CORBA.Request get_next_response()
+            throws org.omg.CORBA.WrongTransaction
+    {
+        illegalSingletonOperation();
+        return null;
+    }
+
+
+    public boolean work_pending() {
+        illegalSingletonOperation();
+        return false;
+    }
+
+    public void perform_work() {
+        illegalSingletonOperation();
+    }
+
+    public void run() {
+        illegalSingletonOperation();
+    }
+
+    public void shutdown(boolean wait_for_completion) {
+        illegalSingletonOperation();
+    }
+
+    public void destroy() {
+        illegalSingletonOperation();
+    }
+
+    public org.omg.CORBA.Any create_any() {
+        return new org.freeorb.AnyImpl(this);
+    }
+
+    public org.omg.CORBA.portable.OutputStream create_output_stream() {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    public void connect(org.omg.CORBA.Object obj) {
+        illegalSingletonOperation();
+    }
+
+    public void disconnect(org.omg.CORBA.Object obj) {
+        illegalSingletonOperation();
+    }
+
+    public org.omg.CORBA.Policy create_policy(int policy_type,
+                                              org.omg.CORBA.Any val) throws org.omg.CORBA.PolicyError
+    {
+        illegalSingletonOperation();
+        return null;
+    }
+
+    protected void set_parameters(String[] args, java.util.Properties props) {
+        illegalSingletonOperation();
+    }
+
+    protected void set_parameters(java.applet.Applet app,
+                                  java.util.Properties props)
+    {
+        illegalSingletonOperation();
+    }
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/TypeCodeImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/TypeCodeImpl.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/TypeCodeImpl.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/TypeCodeImpl.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,605 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba;
+
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import org.omg.CORBA.Any;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.TypeCodePackage.BadKind;
+import org.omg.CORBA.TypeCodePackage.Bounds;
+
+
+class TypeCodeImpl extends TypeCode {
+
+    public static class EquivalenceContext {
+
+        Map eqmap = new IdentityHashMap();
+
+        void add(TypeCode t1, TypeCode t2) {
+            _add(t1, t2);
+            _add(t2, t1);
+        }
+
+        private void _add(TypeCode t1, TypeCode t2) {
+            Map eqset = (Map) eqmap.get(t1);
+            if (eqset == null) {
+                eqset = new IdentityHashMap();
+                eqmap.put(t1, eqset);
+            }
+
+            Integer count = (Integer) eqset.get(t2);
+            if (count == null) {
+                count = new Integer(1);
+                eqset.put(t2, count);
+            } else {
+                eqset.put(t2, new Integer(count.intValue() + 1));
+            }
+        }
+
+        void remove(TypeCode t1, TypeCode t2) {
+
+            _remove(t1, t2);
+            _remove(t2, t1);
+
+        }
+
+        private void _remove(TypeCode t1, TypeCode t2) {
+            Map eqset = (Map) eqmap.get(t1);
+
+            if (eqset == null) return;
+
+            Integer count = (Integer) eqset.get(t2);
+            if (count == null) return;
+
+            int value = count.intValue();
+            if (value == 1) {
+                eqset.remove(t2);
+            } else {
+                eqset.put(t2, new Integer(value - 1));
+            }
+        }
+
+        boolean contains(TypeCode t1, TypeCode t2) {
+            return _contains(t1, t2) || _contains(t2, t1);
+        }
+
+        private boolean _contains(TypeCode t1, TypeCode t2) {
+            Map eqset = (Map) eqmap.get(t1);
+            if (eqset.containsKey(t2)) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+    }
+
+    TCKind kind;
+
+    // objref, struct, enum, alias, value, valuebox, native,
+    // abstract_interface and except
+    String id;
+    String name;
+
+    // struct, enum, value, except...
+    String[] memberNames;
+    TypeCodeImpl[] memberTypes;
+
+    // union
+    Any[] labels;
+    TypeCodeImpl discriminatorType;
+
+    // string, wstring, sequence, array
+    int length;
+
+    TypeCodeImpl contentType;
+
+    // fixed
+    short fixedDigits;
+    short fixedScale;
+
+    // value
+    short[] memberVisibility;
+    short typeModifier;
+    TypeCodeImpl concreteBaseType;
+
+    String recursiveId;
+    // TypeCodeImpl recursiveResolved;
+
+    //
+    // Public API
+    //
+    public boolean equal(TypeCode tc) {
+
+        if (tc == null)
+            return false;
+
+        if (tc == this)
+            return true;
+
+        return equal(tc, new EquivalenceContext());
+    }
+
+
+    //
+    // Public API
+    //
+    public boolean equal(TypeCode tc, EquivalenceContext ctx) {
+
+        if (tc == null)
+            return false;
+
+        if (tc == this)
+            return true;
+
+        if (ctx.contains(this, tc)) {
+            return true;
+        }
+
+        if (kind != tc.kind())
+            return false;
+
+        try {
+            ctx.add(this, tc);
+            return __equal(tc, ctx);
+        }
+        catch (BadKind e) {
+            return false;
+        }
+        catch (Bounds e) {
+            return false;
+        }
+        finally {
+            ctx.remove(this, tc);
+        }
+    }
+
+    protected boolean __equal(TypeCode tc, EquivalenceContext ctx) throws BadKind, Bounds {
+
+        switch (kind.value()) {
+            case TCKind._tk_objref:
+            case TCKind._tk_struct:
+            case TCKind._tk_union:
+            case TCKind._tk_enum:
+            case TCKind._tk_alias:
+            case TCKind._tk_value:
+            case TCKind._tk_value_box:
+            case TCKind._tk_native:
+            case TCKind._tk_abstract_interface:
+            case TCKind._tk_except:
+                if (id.length() != 0 || tc.id().length() != 0) {
+                    return id.equals(tc.id());
+
+                } else if (name.length() != 0 || tc.name().length() != 0) {
+                    if (!name.equals(tc.name()))
+                        return false;
+                }
+        }
+
+        switch (kind.value()) {
+            case TCKind._tk_struct:
+            case TCKind._tk_union:
+            case TCKind._tk_value:
+            case TCKind._tk_except:
+            case TCKind._tk_enum:
+                if (memberNames.length != tc.member_count())
+                    return false;
+
+                for (int i = 0; i < memberNames.length; i++) {
+                    String name1 = memberNames[i];
+                    String name2 = tc.member_name(i);
+
+                    if (name1.length() != 0 || name2.length() != 0) {
+                        if (!name1.equals(name2))
+                            return false;
+                    }
+                }
+        }
+
+
+        switch (kind.value()) {
+            case TCKind._tk_struct:
+            case TCKind._tk_union:
+            case TCKind._tk_value:
+            case TCKind._tk_except:
+                if (memberTypes.length != tc.member_count())
+                    return false;
+
+                for (int i = 0; i < memberTypes.length; i++) {
+                    TypeCodeImpl type1 = memberTypes[i];
+                    TypeCode type2 = tc.member_type(i);
+
+                    if (!type1.equal(type2, ctx))
+                        return false;
+                }
+        }
+
+        if (kind.value() == TCKind._tk_union) {
+            if (labels.length != tc.member_count())
+                return false;
+
+            for (int i = 0; i < labels.length; i++) {
+
+                if (labels[i] instanceof AnyImpl) {
+
+                    if (! ((AnyImpl) labels[i]).equal(tc.member_label(i), ctx))
+                        return false;
+
+                } else {
+
+                    if (! labels[i].equal(tc.member_label(i)))
+                        return false;
+                }
+            }
+
+            if (! discriminatorType.equal(tc.discriminator_type(), ctx))
+                return false;
+        }
+
+        switch (kind.value()) {
+            case TCKind._tk_string:
+            case TCKind._tk_wstring:
+            case TCKind._tk_sequence:
+            case TCKind._tk_array:
+                if (length != tc.length())
+                    return false;
+        }
+
+        switch (kind.value()) {
+            case TCKind._tk_sequence:
+            case TCKind._tk_array:
+            case TCKind._tk_value_box:
+            case TCKind._tk_alias:
+                if (!contentType.equal(tc.content_type()))
+                    return false;
+        }
+
+        if (kind.value() == TCKind._tk_fixed) {
+            if (fixedScale != tc.fixed_scale()
+                || fixedDigits != tc.fixed_digits())
+            {
+                return false;
+            }
+        }
+
+        if (kind.value() == TCKind._tk_value) {
+            if (memberVisibility.length != tc.member_count())
+                return false;
+
+            for (int i = 0; i < memberVisibility.length; i++) {
+                if (memberVisibility[i] != tc.member_visibility(i)) {
+                    return false;
+                }
+            }
+
+            if (typeModifier != tc.type_modifier())
+                return false;
+
+            if (concreteBaseType != null || tc.concrete_base_type() != null) {
+
+                if (concreteBaseType == null || tc.concrete_base_type() == null) {
+                    return false;
+                }
+
+                if (!concreteBaseType.equal(tc.concrete_base_type()))
+                    return false;
+            }
+        }
+
+        return true;
+    }
+
+    public TypeCode content_type()
+            throws BadKind
+    {
+        if (!(kind == org.omg.CORBA.TCKind.tk_sequence ||
+              kind == org.omg.CORBA.TCKind.tk_array ||
+              kind == org.omg.CORBA.TCKind.tk_value_box ||
+              kind == org.omg.CORBA.TCKind.tk_alias))
+            throw new BadKind();
+
+        return contentType;
+    }
+
+    public String name()
+            throws BadKind
+    {
+        return name;
+    }
+
+    public String id() {
+        // objref, struct, unionm enum, alias, value, valuebox, native,
+        // abstract_interface, except
+        return id;
+    }
+
+    public int member_count()
+            throws BadKind
+    {
+        return memberNames.length;
+    }
+
+    public String member_name(int idx)
+            throws BadKind, Bounds
+    {
+        // struct, union, value, except
+
+        try {
+            return memberNames[idx];
+        }
+        catch (ArrayIndexOutOfBoundsException ex) {
+            throw new Bounds();
+        }
+    }
+
+    public TypeCode member_type(int idx)
+            throws BadKind, Bounds
+    {
+        try {
+            return memberTypes[idx];
+        }
+        catch (ArrayIndexOutOfBoundsException ex) {
+            throw new Bounds();
+        }
+    }
+
+    public org.omg.CORBA.Any member_label(int idx)
+            throws BadKind, Bounds
+    {
+        if (kind != TCKind.tk_union)
+            throw new BadKind();
+
+        try {
+            return labels[idx];
+        }
+        catch (ArrayIndexOutOfBoundsException ex) {
+            throw new Bounds();
+        }
+    }
+
+    public org.omg.CORBA.TypeCode concrete_base_type()
+            throws BadKind
+    {
+        if (kind != TCKind.tk_value)
+            throw new BadKind();
+
+        return concreteBaseType;
+    }
+
+    public short type_modifier()
+            throws BadKind
+    {
+        if (kind != TCKind.tk_value)
+            throw new BadKind();
+
+        return typeModifier;
+    }
+
+    public short member_visibility(int index)
+            throws BadKind, Bounds
+    {
+        if (kind != TCKind.tk_value)
+            throw new BadKind();
+
+        if (index < 0 || index > memberVisibility.length)
+            throw new Bounds();
+
+        return memberVisibility[index];
+    }
+
+    public int length()
+            throws BadKind
+    {
+        return length;
+    }
+
+    public int default_index()
+            throws BadKind
+    {
+        if (kind != TCKind.tk_union)
+            throw new BadKind();
+
+        for (int i = 0; i < labels.length; i++) {
+            TypeCode tc = labels[i].type();
+            if (tc.kind() == TCKind.tk_octet)
+                return i;
+        }
+
+        return -1;
+    }
+
+    public TypeCode discriminator_type()
+            throws BadKind
+    {
+        if (kind != TCKind.tk_union)
+            throw new BadKind();
+
+        return discriminatorType;
+    }
+
+    public TCKind kind() {
+        return kind;
+    }
+
+    void __resolveRecursive() {
+        Map codes = new HashMap();
+        __resolveRecursive(codes);
+    }
+
+    private TypeCodeImpl __resolveRecursive(Map codes) {
+
+        if (recursiveId == null && id != null && !id.equals("")) {
+            codes.put(id, this);
+        }
+
+        if (memberTypes != null) {
+            for (int i = 0; i < memberTypes.length; i++)
+                memberTypes[i] = memberTypes[i].__resolveRecursive(codes);
+        }
+
+        if (labels != null) {
+            for (int i = 0; i < labels.length; i++) {
+                TypeCodeImpl tc = (TypeCodeImpl) labels[i].type();
+                if (tc != null)
+                    labels[i].type(tc.__resolveRecursive(codes));
+            }
+        }
+
+        if (discriminatorType != null) {
+            discriminatorType = discriminatorType.__resolveRecursive(codes);
+        }
+
+        if (contentType != null) {
+            contentType = contentType.__resolveRecursive(codes);
+        }
+
+        if (concreteBaseType != null) {
+            concreteBaseType = concreteBaseType.__resolveRecursive(codes);
+        }
+
+        // now resolve...
+        if (recursiveId != null) {
+            TypeCodeImpl recursiveResolved = (TypeCodeImpl) codes.get(recursiveId);
+
+            if (recursiveResolved == null)
+                throw new org.omg.CORBA.BAD_TYPECODE
+                        ("cannot resolve recursive typecode " + recursiveId);
+
+            return recursiveResolved;
+        } else {
+            return this;
+        }
+    }
+
+    public short fixed_digits()
+            throws BadKind
+    {
+        if (kind.value() != TCKind._tk_fixed) {
+            throw new BadKind();
+        }
+
+        return fixedDigits;
+    }
+
+    public short fixed_scale()
+            throws BadKind
+    {
+        if (kind.value() != TCKind._tk_fixed) {
+            throw new BadKind();
+        }
+
+        return fixedScale;
+    }
+
+    public String toString() {
+        switch (kind.value()) {
+            case TCKind._tk_null:
+                return "null";
+            case TCKind._tk_void:
+                return "void";
+            case TCKind._tk_short:
+                return "short";
+            case TCKind._tk_long:
+                return "long";
+            case TCKind._tk_longlong:
+                return "longlong";
+            case TCKind._tk_ushort:
+                return "ushort";
+            case TCKind._tk_ulong:
+                return "ulong";
+            case TCKind._tk_ulonglong:
+                return "ulonglong";
+            case TCKind._tk_float:
+                return "float";
+            case TCKind._tk_double:
+                return "double";
+            case TCKind._tk_longdouble:
+                return "longdouble";
+            case TCKind._tk_boolean:
+                return "boolean";
+            case TCKind._tk_char:
+                return "char";
+            case TCKind._tk_wchar:
+                return "wchar";
+            case TCKind._tk_octet:
+                return "octet";
+            case TCKind._tk_any:
+                return "any";
+            case TCKind._tk_TypeCode:
+                return "TypeCode";
+            case TCKind._tk_Principal:
+                return "Principal";
+            case TCKind._tk_fixed:
+                return "fixed{digits=" + fixedDigits + "; scale=" + fixedScale + "}";
+
+            case TCKind._tk_objref:
+                return "objref{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_abstract_interface:
+                return "abstract_interface{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_native:
+                return "native{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_struct:
+                return "struct{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_except:
+                return "except{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_union:
+                return "union{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_enum:
+                return "enum{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_value:
+                return "value{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_value_box:
+                return "valuebox{id=" + id + "; name=" + name + "}";
+
+            case TCKind._tk_string:
+                return "string{length=" + length + "}";
+
+            case TCKind._tk_wstring:
+                return "wstring{length=" + length + "}";
+
+            case TCKind._tk_sequence:
+                return "sequence{length=" + length + "; type" + contentType + "}";
+
+            case TCKind._tk_array:
+                return "array{length=" + length + "; type" + contentType + "}";
+
+            default:
+                throw new org.omg.CORBA.NO_IMPLEMENT();
+        }
+
+    }
+
+    public TypeCode get_compact_typecode() {
+        throw new org.omg.CORBA.NO_IMPLEMENT();
+    }
+
+    public boolean equivalent(TypeCode tc) {
+        return equals(tc);
+    }
+}
+

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/TypeCodeUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/TypeCodeUtil.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/TypeCodeUtil.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/TypeCodeUtil.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,779 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba;
+
+import org.omg.CORBA.StructMember;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.UnionMember;
+import org.omg.CORBA.VM_ABSTRACT;
+import org.omg.CORBA.ValueMember;
+
+import org.apache.geronimo.corba.io.EncapsulationInputStream;
+import org.apache.geronimo.corba.io.EncapsulationOutputStream;
+import org.apache.geronimo.corba.io.InputStreamBase;
+import org.apache.geronimo.corba.io.OutputStreamBase;
+
+
+public class TypeCodeUtil {
+
+    static TypeCodeImpl create_struct_tc(String id, String name,
+                                         StructMember[] members)
+    {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_struct;
+        tc.id = id;
+        tc.name = name;
+
+        tc.memberNames = new String[members.length];
+        tc.memberTypes = new TypeCodeImpl[members.length];
+
+        for (int i = 0; i < members.length; i++) {
+            tc.memberNames[i] = members[i].name;
+            tc.memberTypes[i] = (TypeCodeImpl) members[i].type;
+        }
+
+        tc.__resolveRecursive();
+        return tc;
+    }
+
+    static TypeCodeImpl create_union_tc(String id, String name,
+                                        TypeCode discriminator_type, UnionMember[] members)
+    {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_union;
+        tc.id = id;
+        tc.name = name;
+
+        tc.discriminatorType = (TypeCodeImpl) discriminator_type;
+
+        tc.memberNames = new String[members.length];
+        tc.memberTypes = new TypeCodeImpl[members.length];
+        tc.labels = new AnyImpl[members.length];
+
+        for (int i = 0; i < members.length; i++) {
+            tc.memberNames[i] = members[i].name;
+            tc.memberTypes[i] = (TypeCodeImpl) members[i].type;
+            tc.labels[i] = members[i].label;
+        }
+
+        tc.__resolveRecursive();
+        return tc;
+    }
+
+    static TypeCodeImpl create_enum_tc(String id, String name, String[] members) {
+        TypeCodeImpl tc = new TypeCodeImpl();
+
+        tc.kind = TCKind.tk_enum;
+        tc.id = id;
+        tc.name = name;
+        tc.memberNames = new String[members.length];
+        for (int i = 0; i < members.length; i++) {
+            tc.memberNames[i] = members[i];
+        }
+
+        return tc;
+    }
+
+    static TypeCodeImpl create_alias_tc(String id, String name,
+                                        TypeCode original_type)
+    {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_alias;
+        tc.id = id;
+        tc.name = name;
+        tc.contentType = (TypeCodeImpl) original_type;
+        return tc;
+    }
+
+    static TypeCodeImpl create_exception_tc(String id, String name,
+                                            StructMember[] members)
+    {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_except;
+        tc.id = id;
+        tc.name = name;
+
+        tc.memberNames = new String[members.length];
+        tc.memberTypes = new TypeCodeImpl[members.length];
+
+        for (int i = 0; i < members.length; i++) {
+            tc.memberNames[i] = members[i].name;
+            tc.memberTypes[i] = (TypeCodeImpl) members[i].type;
+        }
+
+        tc.__resolveRecursive();
+        return tc;
+    }
+
+    static TypeCodeImpl create_interface_tc(String id, String name) {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_objref;
+        tc.id = id;
+        tc.name = name;
+        return tc;
+    }
+
+    static TypeCodeImpl create_string_tc(int bound) {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_string;
+        tc.length = bound;
+        return tc;
+    }
+
+    static TypeCodeImpl create_wstring_tc(int bound) {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_wstring;
+        tc.length = bound;
+        return tc;
+    }
+
+    static TypeCodeImpl create_fixed_tc(short digits, short scale) {
+        throw new org.omg.CORBA.NO_IMPLEMENT();
+    }
+
+    static TypeCodeImpl create_sequence_tc(int bound, TypeCode element_type) {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_sequence;
+        tc.length = bound;
+        tc.contentType = (TypeCodeImpl) element_type;
+        return tc;
+    }
+
+    static TypeCodeImpl create_recursive_sequence_tc(int bound, int offset) {
+        throw new org.omg.CORBA.NO_IMPLEMENT("deprecated");
+    }
+
+    static TypeCodeImpl create_array_tc(int length, TypeCode element_type) {
+        throw new org.omg.CORBA.NO_IMPLEMENT();
+    }
+
+    static TypeCodeImpl create_value_tc(String id, String name,
+                                        short type_modifier, TypeCode concrete_base,
+                                        org.omg.CORBA.ValueMember[] members)
+    {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_value;
+        tc.id = id;
+        tc.name = name;
+        tc.typeModifier = type_modifier;
+        tc.concreteBaseType = (TypeCodeImpl) concrete_base;
+        int count = members.length;
+        tc.memberNames = new String[count];
+        tc.memberTypes = new TypeCodeImpl[count];
+        tc.memberVisibility = new short[count];
+
+        for (int i = 0; i < count; i++) {
+            tc.memberNames[i] = members[i].name;
+            tc.memberTypes[i] = (TypeCodeImpl) members[i].type;
+            tc.memberVisibility[i] = members[i].access;
+        }
+
+        if (count > 0) {
+            tc.__resolveRecursive();
+        }
+
+        return tc;
+    }
+
+    static TypeCodeImpl create_value_box_tc(String id, String name,
+                                            TypeCode boxed_type)
+    {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_value_box;
+        tc.id = id;
+        tc.name = name;
+        tc.contentType = (TypeCodeImpl) boxed_type;
+
+        return tc;
+    }
+
+    static TypeCodeImpl create_native_tc(String id, String name) {
+        throw new org.omg.CORBA.NO_IMPLEMENT();
+    }
+
+    static TypeCodeImpl create_recursive_tc(String id) {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.recursiveId = id;
+
+        return tc;
+    }
+
+    static TypeCodeImpl create_abstract_interface_tc(String id, String name) {
+        TypeCodeImpl tc = new TypeCodeImpl();
+        tc.kind = TCKind.tk_abstract_interface;
+
+        tc.id = id;
+        tc.name = name;
+
+        return tc;
+    }
+
+    static TypeCodeImpl[] primitives = new TypeCodeImpl[TCKind._tk_abstract_interface + 1];
+
+    static TypeCodeImpl get_primitive_tc(TCKind kind) {
+        int value = kind.value();
+
+        if (primitives[value] != null)
+            return primitives[value];
+
+        TypeCodeImpl tc = null;
+
+        switch (value) {
+            case TCKind._tk_null:
+            case TCKind._tk_void:
+            case TCKind._tk_short:
+            case TCKind._tk_long:
+            case TCKind._tk_ushort:
+            case TCKind._tk_ulong:
+            case TCKind._tk_float:
+            case TCKind._tk_double:
+            case TCKind._tk_boolean:
+            case TCKind._tk_char:
+            case TCKind._tk_octet:
+            case TCKind._tk_any:
+            case TCKind._tk_TypeCode:
+            case TCKind._tk_Principal:
+            case TCKind._tk_string:
+            case TCKind._tk_longlong:
+            case TCKind._tk_ulonglong:
+            case TCKind._tk_longdouble:
+            case TCKind._tk_wchar:
+            case TCKind._tk_wstring:
+            case TCKind._tk_fixed:
+                tc = new TypeCodeImpl();
+                tc.kind = kind;
+                break;
+
+            case TCKind._tk_objref:
+                tc = create_interface_tc("IDL:omg.org/CORBA/Object:1.0", "Object");
+                break;
+
+            case TCKind._tk_value:
+                tc = create_value_tc("IDL:omg.org/CORBA/ValueBase:1.0",
+                                     "ValueBase", VM_ABSTRACT.value, null, new ValueMember[0]);
+                break;
+
+            default:
+                throw new org.omg.CORBA.BAD_TYPECODE();
+        }
+
+        primitives[value] = tc;
+
+        return tc;
+    }
+
+    public static TypeCodeImpl read(InputStreamBase in,
+                                    InputStreamBase toplevel, java.util.Map map)
+    {
+        TypeCodeImpl tc;
+        int kind = in.read_ulong();
+        int pos = toplevel.__stream_position() - 4;
+        // boolean swap;
+
+        if (kind == -1) {
+            int offset = in.read_long();
+            int position = pos + 4 + offset;
+
+            position += (position & 3); // align ?
+
+            tc = (TypeCodeImpl) map.get(new Integer(position));
+            if (tc == null) {
+                throw new org.omg.CORBA.MARSHAL("invalid TypeCode indirection");
+            } else {
+                map.put(new Integer(pos), tc);
+                return tc;
+            }
+        }
+
+        EncapsulationInputStream encap_in;
+
+        switch (kind) {
+            case TCKind._tk_null:
+            case TCKind._tk_void:
+            case TCKind._tk_short:
+            case TCKind._tk_long:
+            case TCKind._tk_longlong:
+            case TCKind._tk_ushort:
+            case TCKind._tk_ulong:
+            case TCKind._tk_ulonglong:
+            case TCKind._tk_float:
+            case TCKind._tk_double:
+            case TCKind._tk_longdouble:
+            case TCKind._tk_boolean:
+            case TCKind._tk_char:
+            case TCKind._tk_wchar:
+            case TCKind._tk_octet:
+            case TCKind._tk_any:
+            case TCKind._tk_TypeCode:
+            case TCKind._tk_Principal:
+                tc = get_primitive_tc(TCKind.from_int(kind));
+                break;
+
+            case TCKind._tk_fixed:
+                tc = create_fixed_tc(in.read_ushort(), in.read_short());
+                break;
+
+            case TCKind._tk_objref:
+                encap_in = in.__open_encapsulation();
+                try {
+                    tc = create_interface_tc(encap_in.read_string(), encap_in
+                            .read_string());
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+                break;
+
+            case TCKind._tk_abstract_interface:
+                encap_in = in.__open_encapsulation();
+                try {
+                    tc = create_abstract_interface_tc(encap_in.read_string(),
+                                                      encap_in.read_string());
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+                in.__close_encapsulation(encap_in);
+                break;
+
+            case TCKind._tk_native:
+                encap_in = in.__open_encapsulation();
+                try {
+                    tc = create_native_tc(encap_in.read_string(), encap_in
+                            .read_string());
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+                break;
+
+            case TCKind._tk_struct:
+            case TCKind._tk_except: {
+                encap_in = in.__open_encapsulation();
+                try {
+
+                    tc = new TypeCodeImpl();
+                    map.put(new Integer(pos), tc);
+                    tc.kind = TCKind.from_int(kind);
+                    tc.id = encap_in.read_string();
+                    tc.name = encap_in.read_string();
+                    int count = encap_in.read_ulong();
+                    tc.memberNames = new String[count];
+                    tc.memberTypes = new TypeCodeImpl[count];
+                    for (int i = 0; i < count; i++) {
+                        tc.memberNames[i] = encap_in.read_string();
+                        tc.memberTypes[i] = read(encap_in, toplevel, map);
+                    }
+
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+
+                break;
+            }
+
+            case TCKind._tk_union: {
+                encap_in = in.__open_encapsulation();
+                try {
+
+                    tc = new TypeCodeImpl();
+                    map.put(new Integer(pos), tc);
+                    tc.kind = TCKind.tk_union;
+                    tc.id = encap_in.read_string();
+                    tc.name = encap_in.read_string();
+                    tc.discriminatorType = read(encap_in, toplevel, map);
+                    int index = encap_in.read_long();
+                    int count = encap_in.read_ulong();
+                    tc.labels = new AnyImpl[count];
+                    tc.memberNames = new String[count];
+                    tc.memberTypes = new TypeCodeImpl[count];
+
+                    for (int i = 0; i < count; i++) {
+                        tc.labels[i] = new AnyImpl(encap_in.__orb());
+                        if (i == index) {
+                            AnyImpl scrap = new AnyImpl(encap_in.__orb());
+                            scrap.read_value(encap_in, tc.discriminatorType);
+                            tc.labels[i].insert_octet((byte) 0);
+                        } else {
+                            tc.labels[i].read_value(encap_in, tc.discriminatorType);
+                        }
+
+                        tc.memberNames[i] = encap_in.read_string();
+                        tc.memberTypes[i] = read(encap_in, toplevel, map);
+                    }
+
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+
+                break;
+            }
+
+            case TCKind._tk_enum: {
+                encap_in = in.__open_encapsulation();
+                try {
+                    String id = encap_in.read_string();
+                    String name = encap_in.read_string();
+                    int count = encap_in.read_ulong();
+                    String[] names = new String[count];
+                    for (int i = 0; i < count; i++)
+                        names[i] = encap_in.read_string();
+                    tc = create_enum_tc(id, name, names);
+
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+
+                break;
+            }
+
+            case TCKind._tk_string:
+                tc = create_string_tc(in.read_ulong());
+                break;
+
+            case TCKind._tk_wstring:
+                tc = create_wstring_tc(in.read_ulong());
+                break;
+
+            case TCKind._tk_sequence:
+            case TCKind._tk_array:
+
+                encap_in = in.__open_encapsulation();
+                try {
+                    tc = new TypeCodeImpl();
+                    map.put(new Integer(pos), tc);
+
+                    tc.kind = TCKind.from_int(kind);
+                    tc.contentType = read(encap_in, toplevel, map);
+                    tc.length = encap_in.read_ulong();
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+
+                break;
+
+            case TCKind._tk_alias:
+                encap_in = in.__open_encapsulation();
+                try {
+                    tc = create_alias_tc(encap_in.read_string(), encap_in
+                            .read_string(), read(encap_in, toplevel, map));
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+                // in.__swap (swap);
+                break;
+
+            case TCKind._tk_value:
+                encap_in = in.__open_encapsulation();
+                try {
+
+                    tc = new TypeCodeImpl();
+                    map.put(new Integer(pos), tc);
+                    tc.kind = TCKind.tk_value;
+                    tc.id = encap_in.read_string();
+                    tc.name = encap_in.read_string();
+                    tc.typeModifier = encap_in.read_short();
+                    tc.concreteBaseType = read(encap_in, toplevel, map);
+                    if (tc.concreteBaseType.kind() == TCKind.tk_null) {
+                        tc.concreteBaseType = null;
+                    }
+                    int count = encap_in.read_ulong();
+                    tc.memberNames = new String[count];
+                    tc.memberTypes = new TypeCodeImpl[count];
+                    tc.memberVisibility = new short[count];
+
+                    for (int i = 0; i < count; i++) {
+                        tc.memberNames[i] = encap_in.read_string();
+                        tc.memberTypes[i] = read(encap_in, toplevel, map);
+                        tc.memberVisibility[i] = encap_in.read_short();
+                    }
+
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+
+                break;
+
+            case TCKind._tk_value_box:
+                encap_in = in.__open_encapsulation();
+                try {
+
+                    tc = create_value_box_tc(encap_in.read_string(), encap_in
+                            .read_string(), read(encap_in, toplevel, map));
+                }
+                finally {
+                    in.__close_encapsulation(encap_in);
+                }
+
+                break;
+
+            default:
+                throw new org.omg.CORBA.NO_IMPLEMENT("read_TypeCode kind=" + kind
+                                                     + "(" + Integer.toHexString(kind) + ")");
+        }
+
+        map.put(new Integer(pos), tc);
+        return tc;
+    }
+
+    static final int EMPTY_TC = 1;
+
+    static final int SIMPLE_TC = 2;
+
+    static final int COMPLEX_TC = 3;
+
+    static final int[] typecode_type = new int[]{EMPTY_TC, // null
+            EMPTY_TC, // void
+            EMPTY_TC, // short
+            EMPTY_TC, // long
+            EMPTY_TC, // ushort
+            EMPTY_TC, // ulong
+            EMPTY_TC, // float
+            EMPTY_TC, // double
+            EMPTY_TC, // boolean
+            EMPTY_TC, // char
+            EMPTY_TC, // octet
+            EMPTY_TC, // any
+            EMPTY_TC, // TypeCode
+            EMPTY_TC, // Principal
+
+            COMPLEX_TC, // objref
+            COMPLEX_TC, // struct
+            COMPLEX_TC, // union
+
+            COMPLEX_TC, // enum
+            SIMPLE_TC, // string
+            COMPLEX_TC, // sequence
+            COMPLEX_TC, // array
+            COMPLEX_TC, // alias
+            COMPLEX_TC, // except
+
+            EMPTY_TC, // longlong
+            EMPTY_TC, // ulonglong
+            EMPTY_TC, // longdouble
+            EMPTY_TC, // wchar
+
+            SIMPLE_TC, // wstring
+            SIMPLE_TC, // fixed
+            COMPLEX_TC, // value
+            COMPLEX_TC, // value_box
+
+            COMPLEX_TC, // abstract_interface
+    };
+
+    public static void write(OutputStreamBase out, TypeCode tc, java.util.Map map)
+            throws org.omg.CORBA.TypeCodePackage.BadKind,
+                   org.omg.CORBA.TypeCodePackage.Bounds
+    {
+
+        EncapsulationOutputStream eout;
+        Integer pos = (Integer) map.get(tc);
+        if (pos != null) {
+            out.write_long(-1);
+            out.write_long(pos.intValue() - out.__stream_position());
+        } else {
+            org.omg.CORBA.TCKindHelper.write(out, tc.kind());
+            pos = new Integer(out.__stream_position() - 4);
+
+            switch (tc.kind().value()) {
+                case TCKind._tk_null:
+                case TCKind._tk_void:
+                case TCKind._tk_short:
+                case TCKind._tk_long:
+                case TCKind._tk_longlong:
+                case TCKind._tk_ushort:
+                case TCKind._tk_ulong:
+                case TCKind._tk_ulonglong:
+                case TCKind._tk_float:
+                case TCKind._tk_double:
+                case TCKind._tk_longdouble:
+                case TCKind._tk_boolean:
+                case TCKind._tk_char:
+                case TCKind._tk_wchar:
+                case TCKind._tk_octet:
+                case TCKind._tk_any:
+                case TCKind._tk_TypeCode:
+                case TCKind._tk_Principal:
+                    break;
+
+                case TCKind._tk_fixed:
+                    map.put(tc, pos);
+                    out.write_ushort(tc.fixed_digits());
+                    out.write_short(tc.fixed_scale());
+                    break;
+
+                case TCKind._tk_objref:
+                case TCKind._tk_abstract_interface:
+                case TCKind._tk_native:
+                    map.put(tc, pos);
+                    eout = out.__open_encapsulation();
+                    eout.write_string(tc.id());
+                    eout.write_string(tc.name());
+                    out.__close_encapsulation(eout);
+                    break;
+
+                case TCKind._tk_struct:
+                case TCKind._tk_except:
+                    map.put(tc, pos);
+                    eout = out.__open_encapsulation();
+                    eout.write_string(tc.id());
+                    eout.write_string(tc.name());
+                    eout.write_ulong(tc.member_count());
+                    for (int i = 0; i < tc.member_count(); i++) {
+                        eout.write_string(tc.member_name(i));
+                        // recurse
+                        write(eout, tc.member_type(i), map);
+                    }
+                    out.__close_encapsulation(eout);
+                    break;
+
+                case TCKind._tk_union: {
+                    map.put(tc, pos);
+                    eout = out.__open_encapsulation();
+                    eout.write_string(tc.id());
+                    eout.write_string(tc.name());
+
+                    // write discriminator
+                    TypeCodeImpl disc = (TypeCodeImpl) tc.discriminator_type();
+                    write(eout, disc, map);
+
+                    int index = tc.default_index();
+                    eout.write_long(index);
+                    eout.write_ulong(tc.member_count());
+
+                    for (int i = 0; i < tc.member_count(); i++) {
+
+                        if (i == index) {
+                            switch (disc.kind().value()) {
+                                case TCKind._tk_short:
+                                case TCKind._tk_ushort:
+                                    eout.write_short((short) 0);
+                                    break;
+
+                                case TCKind._tk_long:
+                                case TCKind._tk_ulong:
+                                    eout.write_long(0);
+                                    break;
+
+                                case TCKind._tk_longlong:
+                                case TCKind._tk_ulonglong:
+                                    eout.write_longlong(0);
+                                    break;
+
+                                case TCKind._tk_boolean:
+                                    eout.write_boolean(false);
+                                    break;
+
+                                case TCKind._tk_char:
+                                    eout.write_char((char) 0);
+                                    break;
+
+                                case TCKind._tk_enum:
+                                    eout.write_ulong(0);
+                                    break;
+
+                                default:
+                                    throw new org.omg.CORBA.BAD_TYPECODE();
+
+                            }
+                        } else {
+                            tc.member_label(i).write_value(eout);
+                        }
+
+                        eout.write_string(tc.member_name(i));
+                        write(eout, tc.member_type(i), map);
+                    }
+
+                    out.__close_encapsulation(eout);
+                    break;
+                }
+
+                case TCKind._tk_enum:
+                    map.put(tc, pos);
+                    eout = out.__open_encapsulation();
+                    eout.write_string(tc.id());
+                    eout.write_string(tc.name());
+                    eout.write_ulong(tc.member_count());
+                    for (int i = 0; i < tc.member_count(); i++) {
+                        eout.write_string(tc.member_name(i));
+                    }
+                    out.__close_encapsulation(eout);
+                    break;
+
+                case TCKind._tk_string:
+                case TCKind._tk_wstring:
+                    out.write_ulong(tc.length());
+                    break;
+
+                case TCKind._tk_sequence:
+                case TCKind._tk_array:
+                    map.put(tc, pos);
+                    eout = out.__open_encapsulation();
+                    write(out, tc.content_type(), map);
+                    out.write_ulong(tc.length());
+                    out.__close_encapsulation(eout);
+                    break;
+
+                case TCKind._tk_value: {
+                    map.put(tc, pos);
+
+                    TypeCode base = tc.concrete_base_type();
+                    if (base == null) {
+                        base = get_primitive_tc(TCKind.tk_null);
+                    }
+
+                    eout = out.__open_encapsulation();
+
+                    eout.write_string(tc.id());
+                    eout.write_string(tc.name());
+                    eout.write_short(tc.type_modifier());
+                    write(eout, base, map);
+                    eout.write_ulong(tc.member_count());
+                    for (int i = 0; i < tc.member_count(); i++) {
+                        eout.write_string(tc.member_name(i));
+                        write(eout, tc.member_type(i), map);
+                        eout.write_short(tc.member_visibility(i));
+                    }
+                    out.__close_encapsulation(eout);
+                    break;
+                }
+
+                case TCKind._tk_value_box:
+                    map.put(tc, pos);
+                    eout = out.__open_encapsulation();
+
+                    eout.write_string(tc.id());
+                    eout.write_string(tc.name());
+
+                    write(eout, tc.content_type(), map);
+
+                    out.__close_encapsulation(eout);
+                    break;
+
+                default:
+                    throw new org.omg.CORBA.NO_IMPLEMENT();
+            }
+        }
+    }
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/ByteBufferReader.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/ByteBufferReader.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/ByteBufferReader.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/ByteBufferReader.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,91 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.cdr;
+
+import java.nio.ByteBuffer;
+
+import EDU.oswego.cs.dl.util.concurrent.Semaphore;
+
+
+public class ByteBufferReader {
+
+    Semaphore full;
+
+    Semaphore empty;
+
+    int readpos;
+
+    int writepos;
+
+    ByteBuffer storage;
+
+    ByteBufferReader(ByteBuffer buf) {
+        storage = buf;
+        full = new Semaphore(buf.remaining());
+        empty = new Semaphore(0);
+    }
+
+    void readSome() {
+        int howmuch = (int) full.permits();
+        int howmany = acquire(full, Math.min(howmuch, 1));
+
+        if (readpos < writepos) {
+
+            int first_write = Math.min(howmany, storage.limit() - writepos);
+
+            storage.position(writepos);
+            storage.limit(writepos + first_write);
+
+            ByteBuffer buf1 = storage.slice();
+
+            storage.position(0);
+
+            int howmuchread;
+            if (first_write == howmany) {
+                storage.limit(storage.capacity());
+                howmuchread = single_read(buf1);
+            } else {
+                int second_write = howmany - first_write;
+                storage.limit(second_write);
+                ByteBuffer buf2 = storage.slice();
+                howmuchread = vector_read(buf1, buf2);
+            }
+
+            if (howmuchread < howmany) {
+                full.release(howmany - howmuchread);
+            }
+            empty.release(howmuchread);
+
+            writepos = (writepos + howmuchread) % storage.capacity();
+
+        }
+    }
+
+    private int acquire(Semaphore sem, int howmany) {
+        for (int l = 0; l < howmany; l++) {
+            try {
+                sem.acquire();
+            }
+            catch (InterruptedException ex) {
+                return l;
+            }
+        }
+
+        return howmany;
+    }
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/CDRInputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/CDRInputStream.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/CDRInputStream.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/CDRInputStream.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,109 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.cdr;
+
+import java.nio.ByteBuffer;
+
+import org.omg.CORBA_2_3.portable.InputStream;
+
+import org.apache.geronimo.corba.AbstractORB;
+import org.apache.geronimo.corba.ORB;
+import org.apache.geronimo.corba.io.GIOPVersion;
+
+
+public abstract class CDRInputStream extends InputStream {
+
+    private ByteBuffer buf;
+
+    private GIOPVersion giop_version;
+
+    private ORB orb;
+
+    public CDRInputStream(ORB orb, ByteBuffer buf, GIOPVersion version,
+                          InputStreamController ctrl)
+    {
+        this.giop_version = version;
+        this.orb = orb;
+        this.buf = buf;
+    }
+
+    protected final int computeAlignment(int align) {
+        if (align > 1) {
+            int incr = buf.position() & (align - 1);
+            if (incr != 0)
+                return align - incr;
+        }
+
+        return 0;
+    }
+
+    public int getSize() {
+        return buf.position();
+    }
+
+    void alignAndCheck(int size, int align) {
+        int a = computeAlignment(align);
+        buf.position(buf.position() + a);
+
+        if (buf.remaining() < size) {
+            grow(size);
+        }
+    }
+
+    public int read_long() {
+        alignAndCheck(4, 4);
+        return buf.getInt();
+    }
+
+    public void __readEndian() {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Create an inputstream that reads data from the given byte array
+     */
+    public static CDRInputStream create(byte[] data) {
+        return create(ByteBuffer.wrap(data));
+    }
+
+    public static CDRInputStream create(ByteBuffer buf) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public int __get_input_position() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public long __beginEncapsulation() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public void __endEncapsulation(long encap_state) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public AbstractORB __get_orb() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/CDROutputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/CDROutputStream.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/CDROutputStream.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/CDROutputStream.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,53 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.cdr;
+
+import org.omg.CORBA_2_3.portable.OutputStream;
+
+
+public abstract class CDROutputStream extends OutputStream {
+
+    public void __writeEndian() {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Allocate a dynamic in-memory output stream
+     */
+    public static CDROutputStream create() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /**  */
+    public int __get_output_position() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public long __beginEncapsulation() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public void __finishEncapsulation(long encap_state) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/InputStreamController.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/InputStreamController.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/InputStreamController.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/cdr/InputStreamController.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,22 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.cdr;
+
+public interface InputStreamController {
+
+    void underrun();
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/BufferedOutputChannel.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/BufferedOutputChannel.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/BufferedOutputChannel.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/BufferedOutputChannel.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,64 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.channel;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+
+public class BufferedOutputChannel extends OutputChannel {
+
+    ByteArrayOutputStream bao = new ByteArrayOutputStream();
+    DataOutputStream dout = new DataOutputStream(bao);
+
+    public void writeByte(byte b) throws IOException {
+        dout.writeByte(b);
+    }
+
+    public void writeInt(int i) throws IOException {
+        dout.writeInt(i);
+    }
+
+    public void writeLong(long l) throws IOException {
+        dout.writeLong(l);
+    }
+
+    public void skip(int count) throws IOException {
+        for (int i = 0; i < count; i++) {
+            dout.write(0);
+        }
+    }
+
+    public OutputChannelMarker mark(MarkHandler handler) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void writeTo(OutputChannel ch) throws IOException {
+        bao.writeTo(ch);
+    }
+
+    public void relinquish() {
+        // do nothing //
+    }
+
+    public void writeShort(short s) throws IOException {
+        dout.writeShort(s);
+    }
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/ChannelClosedException.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/ChannelClosedException.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/ChannelClosedException.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/ChannelClosedException.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.channel;
+
+import java.io.IOException;
+
+
+/**
+ * issed in response to a write into an OutputChannel which has been closed
+ */
+public class ChannelClosedException extends IOException {
+
+    public ChannelClosedException() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+    public ChannelClosedException(String s) {
+        super(s);
+        // TODO Auto-generated constructor stub
+    }
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/FilterInputChannel.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/FilterInputChannel.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/FilterInputChannel.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/FilterInputChannel.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,67 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.channel;
+
+import java.io.IOException;
+import java.nio.ByteOrder;
+
+
+public class FilterInputChannel extends InputChannel {
+
+    protected final InputChannel ch;
+
+    FilterInputChannel(InputChannel ch) {
+        this.ch = ch;
+    }
+
+    public byte readByte() throws IOException {
+        return ch.readByte();
+    }
+
+    public int readInt() throws IOException {
+        return ch.readInt();
+    }
+
+    public long readLong() throws IOException {
+        return ch.readLong();
+    }
+
+    public void skip(int count) throws IOException {
+        ch.skip(count);
+    }
+
+    public boolean isClosed() {
+        return ch.isClosed();
+    }
+
+    public int read(byte[] data, int off, int len) throws IOException {
+        return ch.read(data, off, len);
+    }
+
+    public short readShort() throws IOException {
+        return ch.readShort();
+    }
+
+    public void setOrder(ByteOrder order) {
+        ch.setOrder(order);
+    }
+
+    public void relinquish() {
+        ch.relinquish();
+    }
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/FilterOutputChannel.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/FilterOutputChannel.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/FilterOutputChannel.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/FilterOutputChannel.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,62 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.channel;
+
+import java.io.IOException;
+
+
+public class FilterOutputChannel extends OutputChannel {
+
+    final protected OutputChannel ch;
+
+    protected FilterOutputChannel(OutputChannel ch) {
+        this.ch = ch;
+    }
+
+    public void writeByte(byte b) throws IOException {
+        ch.writeByte(b);
+    }
+
+    public void writeInt(int i) throws IOException {
+        ch.writeInt(i);
+    }
+
+    public void writeShort(short s) throws IOException {
+        ch.writeShort(s);
+    }
+
+    public void writeLong(long l) throws IOException {
+        ch.writeLong(l);
+    }
+
+    public void skip(int count) throws IOException {
+        ch.skip(count);
+    }
+
+    public OutputChannelMarker mark(MarkHandler handler) {
+        return ch.mark(handler);
+    }
+
+    public void write(byte[] b, int off, int len) throws IOException {
+        ch.write(b, off, len);
+    }
+
+    public void relinquish() {
+        ch.relinquish();
+    }
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/IOSemaphore.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/IOSemaphore.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/IOSemaphore.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/IOSemaphore.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,177 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.channel;
+
+import org.apache.geronimo.corba.concurrency.IOSemaphoreClosedException;
+
+
+/**
+ * An IOSemaphore is used for buffered IO.
+ * <p/>
+ * The special feature of the IOSemaphore is that it can be "closed,"
+ * after which no more permits can be released.  When an IOSemaphore is
+ * closed, existing permits can be acquired.  Successive attempts
+ * to acquire more permits yields an IOSemaphoreClosedException.
+ */
+
+public class IOSemaphore {
+
+    private int permits;
+
+    private boolean isClosed;
+
+    public IOSemaphore(int permits) {
+        super();
+        this.permits = permits;
+    }
+
+    public synchronized boolean isClosed() {
+        return isClosed;
+    }
+
+    public void acquire() throws IOSemaphoreClosedException {
+        acquire(1);
+    }
+
+    /**
+     * acquire at least one, and maximum <code>max</code> permits.
+     *
+     * @param max
+     * @return
+     * @throws IOSemaphoreClosedException
+     * @throws IOSemaphoreClosedException
+     */
+
+    public int acquireSome(int max) throws IOSemaphoreClosedException {
+        return acquireSome(1, max, 0);
+    }
+
+    public synchronized int acquireSome(int min, int max, long time) throws IOSemaphoreClosedException {
+
+        // the fast track //
+        if (permits >= 1) {
+            int howmany = Math.min(permits, max);
+            permits -= howmany;
+            return howmany;
+        }
+
+        long now = System.currentTimeMillis();
+
+        long end;
+        if (time == 0) {
+            end = Long.MAX_VALUE;
+        } else {
+            end = now + Math.min(time, Long.MAX_VALUE - now);
+        }
+
+        while (permits < min) {
+            if (isClosed) {
+                throw new IOSemaphoreClosedException(permits);
+            }
+
+            now = System.currentTimeMillis();
+            long rest = end - now;
+            try {
+                wait(rest);
+            }
+            catch (InterruptedException e) {
+                // clear interrupted flag
+                Thread.interrupted();
+
+            }
+
+        }
+
+        int howmany = Math.min(permits, max);
+        permits -= howmany;
+        return howmany;
+    }
+
+    public void acquire(int i) throws IOSemaphoreClosedException {
+        attempt(i, 0L);
+    }
+
+    public synchronized boolean attempt(int i, long time)
+            throws IOSemaphoreClosedException
+    {
+
+        // the fast track //
+        if (permits >= i) {
+            permits -= i;
+            return true;
+        }
+
+        long now = System.currentTimeMillis();
+
+        long end;
+        if (time == 0) {
+            end = Long.MAX_VALUE;
+        } else {
+            end = now + Math.min(time, Long.MAX_VALUE - now);
+        }
+
+        while (permits < i) {
+            if (isClosed) {
+                throw new IOSemaphoreClosedException(permits);
+            }
+
+            now = System.currentTimeMillis();
+            long rest = end - now;
+            try {
+                wait(rest);
+            }
+            catch (InterruptedException e) {
+                // clear interrupted flag
+                Thread.interrupted();
+
+            }
+
+        }
+        permits -= i;
+
+        return true;
+    }
+
+    public void release() throws IOSemaphoreClosedException {
+        release(1);
+    }
+
+    public synchronized void release(int i) throws IOSemaphoreClosedException {
+        if (isClosed) {
+            throw new IOSemaphoreClosedException(permits);
+        }
+
+        permits += i;
+        notifyAll();
+    }
+
+    public synchronized void close() {
+        isClosed = true;
+        notifyAll();
+    }
+
+    public synchronized int availablePermits() {
+        return permits;
+    }
+
+    public synchronized void releaseIfNotClosed(int amount) {
+        if (!isClosed) {
+            permits += amount;
+            notifyAll();
+        }
+    }
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/InputChannel.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/InputChannel.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/InputChannel.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/InputChannel.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,52 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.channel;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteOrder;
+
+
+public abstract class InputChannel extends InputStream {
+
+    public abstract byte readByte() throws IOException;
+
+    public abstract short readShort() throws IOException;
+
+    public abstract int readInt() throws IOException;
+
+    public abstract long readLong() throws IOException;
+
+    public abstract void skip(int count) throws IOException;
+
+    public int read() throws IOException {
+        try {
+            return readByte();
+        }
+        catch (EOFException ex) {
+            return -1;
+        }
+    }
+
+    public abstract boolean isClosed();
+
+    public abstract void relinquish();
+
+    public abstract void setOrder(ByteOrder order);
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/InputHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/InputHandler.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/InputHandler.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/InputHandler.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,27 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.channel;
+
+
+public interface InputHandler {
+
+    /**
+     * Input is available
+     */
+    void inputAvailable(Transport transport);
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/MarkHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/MarkHandler.java?rev=329036&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/MarkHandler.java (added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/main/java/org/apache/geronimo/corba/channel/MarkHandler.java Thu Oct 27 19:00:06 2005
@@ -0,0 +1,26 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  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.geronimo.corba.channel;
+
+import java.io.IOException;
+
+
+public interface MarkHandler {
+
+    void bufferFull(OutputChannelMarker state) throws IOException;
+
+}



Mime
View raw message