Skip to content
Permalink
Browse files
Add Enum support to FVD negotiation; Fix Enum transmission format
  • Loading branch information
ngmr committed Mar 18, 2016
1 parent 5ec4f36 commit bef8dcfdf6e9269aa81230e2fa9dfde06b1ef62a
Showing 6 changed files with 197 additions and 13 deletions.
@@ -27,4 +27,21 @@ public EnumDescriptor(Class<?> type, TypeRepository repo) {
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;
}
}
@@ -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 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);
@@ -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;
}
}
@@ -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;
}
}
@@ -121,7 +121,8 @@ protected TypeDescriptor computeValue(Class<?> type) {
} 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 ValueDescriptor getDescriptor(Class<?> clz, String repid,
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) {
@@ -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:");

0 comments on commit bef8dcf

Please sign in to comment.