geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject [18/51] [abbrv] geronimo-yoko git commit: Add Enum support to FVD negotiation; Fix Enum transmission format
Date Sun, 19 Feb 2017 01:49:35 GMT
Add Enum support to FVD negotiation; Fix Enum transmission format


Project: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/repo
Commit: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/commit/bef8dcfd
Tree: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/tree/bef8dcfd
Diff: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/diff/bef8dcfd

Branch: refs/heads/master
Commit: bef8dcfdf6e9269aa81230e2fa9dfde06b1ef62a
Parents: 5ec4f36
Author: Neil GM Richards <neil_richards@uk.ibm.com>
Authored: Fri Mar 18 12:10:06 2016 +0000
Committer: Neil GM Richards <neil_richards@uk.ibm.com>
Committed: Fri Mar 18 12:10:06 2016 +0000

----------------------------------------------------------------------
 .../apache/yoko/rmi/impl/EnumDescriptor.java    | 17 ++++++
 .../yoko/rmi/impl/EnumSubclassDescriptor.java   | 63 ++++++++++++++++----
 .../apache/yoko/rmi/impl/FVDEnumDescriptor.java | 57 ++++++++++++++++++
 .../rmi/impl/FVDEnumSubclassDescriptor.java     | 59 ++++++++++++++++++
 .../apache/yoko/rmi/impl/TypeRepository.java    | 12 +++-
 .../apache/yoko/rmi/impl/ValueDescriptor.java   |  2 +
 6 files changed, 197 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/bef8dcfd/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumDescriptor.java
----------------------------------------------------------------------
diff --git a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumDescriptor.java b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumDescriptor.java
index b5e9a0b..c1827b7 100644
--- a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumDescriptor.java
+++ b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumDescriptor.java
@@ -27,4 +27,21 @@ public class EnumDescriptor extends ValueDescriptor {
     final long getSerialVersionUID() {
         return 0L;
     }
+
+    @Override
+    protected final boolean isEnum() {
+        return true;
+    }
+
+    @Override
+    public final void init() {
+        super.init();
+        FieldDescriptor[] newFields = new FieldDescriptor[1];
+        for (FieldDescriptor field: _fields) {
+            if (!!!field.getJavaName().equals("name")) continue;
+            newFields[0] = field;
+            break;
+        }
+        _fields = newFields;
+    }
 }

http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/bef8dcfd/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumSubclassDescriptor.java
----------------------------------------------------------------------
diff --git a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumSubclassDescriptor.java
b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumSubclassDescriptor.java
index d9254b7..0aeed60 100644
--- a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumSubclassDescriptor.java
+++ b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumSubclassDescriptor.java
@@ -1,3 +1,21 @@
+/**
+ *
+ * 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.yoko.rmi.impl;
 
 import java.io.IOException;
@@ -7,33 +25,56 @@ import java.util.Map;
 import org.omg.CORBA.portable.IndirectionException;
 import org.omg.CORBA.portable.InputStream;
 
-public final class EnumSubclassDescriptor extends ValueDescriptor {
+public class EnumSubclassDescriptor extends ValueDescriptor {
     @SuppressWarnings("rawtypes")
     private final Class enumType;
 
     EnumSubclassDescriptor(Class<?> type, TypeRepository repository) {
         super(type, repository);
-        enumType = getEnumType(type);
+        enumType = type;
     }
 
-    private static Class<?> getEnumType(Class<?> type) {
-        while (!!!type.isEnum()) {
-            type = type.getSuperclass();
-        }
+    static Class<?> getEnumType(Class<?> type) {
+        if (!!!Enum.class.isAssignableFrom(type)) throw new IllegalArgumentException(type.getName()
+ " is not an Enum");
+        while (!!!type.isEnum()) type = type.getSuperclass();
         return type;
     }
 
     @Override
-    long getSerialVersionUID() {
+    public final void init() {
+        super.init();
+        _fields = new FieldDescriptor[0];
+    }
+
+    @Override
+    final long getSerialVersionUID() {
         return 0L;
     }
 
     @Override
-    public Serializable readValue(InputStream in, Map<Integer, Object> offsetMap, Integer
offset) {
+    protected final boolean isEnum() {
+        return true;
+    }
+
+    @Override
+    final public Serializable readValue(InputStream in, Map<Integer, Object> offsetMap,
Integer offset) {
         try {
-            // Shortcut to reading in just the fields of java.lang.Enum - ordinal and name
-            in.read_long(); // read in and ignore Enum ordinal
-            final String name = (String) ((org.omg.CORBA_2_3.portable.InputStream) in).read_value(String.class);
+            // Shortcut to reading in just the 'name' field of java.lang.Enum
+            String name = null;
+            try {
+                name = (String) ((org.omg.CORBA_2_3.portable.InputStream) in).read_value(String.class);
+            } catch (org.omg.CORBA.MARSHAL e) {
+                // Problem probably due to ordinal field data being sent
+                // This should be resolved by the 'if (name == null) {' block below, so this
+                // exception can be safely discarded.
+            }
+            if (name == null) {
+                // ordinal field may have been sent, causing the read of the name field to
fail
+                // If this is the case, the input stream cursor will now be at the start
of where the
+                // name field is located (the 4 bytes of the ordinal having now been read
in)
+                name = (String) ((org.omg.CORBA_2_3.portable.InputStream) in).read_value(String.class);
+            }
+
             @SuppressWarnings("unchecked")
             final Enum<?> value = (Enum<?>) Enum.valueOf(enumType, name);
             offsetMap.put(offset, value);

http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/bef8dcfd/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/FVDEnumDescriptor.java
----------------------------------------------------------------------
diff --git a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/FVDEnumDescriptor.java b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/FVDEnumDescriptor.java
new file mode 100644
index 0000000..b55e906
--- /dev/null
+++ b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/FVDEnumDescriptor.java
@@ -0,0 +1,57 @@
+/**
+ *
+ * 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.yoko.rmi.impl;
+
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.ValueDefPackage.FullValueDescription;
+
+public class FVDEnumDescriptor extends EnumDescriptor {
+    private final FullValueDescription fvd;
+    private final String repid;
+
+    FVDEnumDescriptor(FullValueDescription fvd, Class clazz, TypeRepository rep, String repid,
ValueDescriptor super_desc) {
+        super(clazz, rep);
+        this.fvd = fvd;
+        this.repid = repid;
+
+        init();
+
+        _super_descriptor = super_desc;
+    }
+
+    @Override
+    public String getRepositoryID() {
+        return repid;
+    }
+
+    @Override
+    FullValueDescription getFullValueDescription() {
+        return fvd;
+    }
+
+    @Override
+    TypeCode getTypeCode() {
+        return fvd.type;
+    }
+
+    @Override
+    public boolean isCustomMarshalled() {
+        return fvd.is_custom;
+    }
+}

http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/bef8dcfd/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/FVDEnumSubclassDescriptor.java
----------------------------------------------------------------------
diff --git a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/FVDEnumSubclassDescriptor.java
b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/FVDEnumSubclassDescriptor.java
new file mode 100644
index 0000000..d898dcd
--- /dev/null
+++ b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/FVDEnumSubclassDescriptor.java
@@ -0,0 +1,59 @@
+/**
+ *
+ * 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.yoko.rmi.impl;
+
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.ValueDefPackage.FullValueDescription;
+
+import java.util.Objects;
+
+public class FVDEnumSubclassDescriptor extends EnumSubclassDescriptor {
+    private final FullValueDescription fvd;
+    private final String repid;
+
+    FVDEnumSubclassDescriptor(FullValueDescription fvd, Class clazz, TypeRepository rep,
String repid, ValueDescriptor super_desc) {
+        super(EnumSubclassDescriptor.getEnumType(clazz), rep);
+        this.fvd = fvd;
+        this.repid = repid;
+
+        init();
+
+        _super_descriptor = super_desc;
+    }
+
+    @Override
+    public String getRepositoryID() {
+        return repid;
+    }
+
+    @Override
+    FullValueDescription getFullValueDescription() {
+        return fvd;
+    }
+
+    @Override
+    TypeCode getTypeCode() {
+        return fvd.type;
+    }
+
+    @Override
+    public boolean isCustomMarshalled() {
+        return fvd.is_custom;
+    }
+}

http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/bef8dcfd/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java
----------------------------------------------------------------------
diff --git a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java
index 33dda66..6ad6894 100755
--- a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java
+++ b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java
@@ -121,7 +121,8 @@ public class TypeRepository {
                 } else if (Enum.class == type) {
                     return new EnumDescriptor(type, repo);
                 } else if (Enum.class.isAssignableFrom(type)) {
-                    return new EnumSubclassDescriptor(type, repo);
+                    Class<?> enumType = EnumSubclassDescriptor.getEnumType(type);
+                    return ((enumType == type) ? new EnumSubclassDescriptor(type, repo) :
get(enumType));
                 } else if (type.isArray()) {
                     return ArrayDescriptor.get(type, repo);
                 } else if (!type.isInterface()
@@ -365,7 +366,14 @@ public class TypeRepository {
                     codebase);
         }
 
-        ValueDescriptor newDesc = new FVDValueDescriptor(fvd, clz, this, repid, super_desc);
+        final ValueDescriptor newDesc;
+        if ((super_desc != null) && super_desc.isEnum()) {
+            newDesc = new FVDEnumSubclassDescriptor(fvd, clz, this, repid, super_desc);
+        } else if (fvd.id.startsWith("RMI:java.lang.Enum:")) {
+            newDesc = new FVDEnumDescriptor(fvd, clz, this, repid, super_desc);
+        } else {
+            newDesc = new FVDValueDescriptor(fvd, clz, this, repid, super_desc);
+        }
         ConcurrentMap<String, ValueDescriptor> remoteDescMap = (clz == null) ? noTypeDescMap
: fvdDescMaps.get(clz);
         clzdesc = remoteDescMap.putIfAbsent(newDesc.getRepositoryID(), newDesc);
         if (clzdesc == null) {

http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/bef8dcfd/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueDescriptor.java
----------------------------------------------------------------------
diff --git a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueDescriptor.java b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueDescriptor.java
index ac5cfa4..ecedcbb 100755
--- a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueDescriptor.java
+++ b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueDescriptor.java
@@ -110,6 +110,8 @@ public class ValueDescriptor extends TypeDescriptor {
         super(type, repository);
     }
 
+    protected boolean isEnum() { return false; }
+
     public String getRepositoryID() {
         if (_repid == null) {
             StringBuilder buf = new StringBuilder("RMI:");


Mime
View raw message