Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping for enums. #644

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.switchyard.serial.graph.node;

import org.switchyard.common.type.Classes;
import org.switchyard.serial.graph.Graph;

/**
* A node representing a Enum value.
*/
@SuppressWarnings("serial")
public class EnumNode implements Node {

private String _enumType;
private String _valueName;

/**
* Default constructor.
*/
public EnumNode() {
}

/**
* Gets the enum type.
*
* @return the enum type
*/
public String getEnumType() {
return _enumType;
}

/**
* Sets the enum type.
*
* @param enumType
* the enum type
*/
public void setEnumType(String enumType) {
_enumType = enumType;
}

/**
* Gets the enum value name.
*
* @return the enum value name
*/
public String getValueName() {
return _valueName;
}

/**
* Sets the enum value name.
*
* @param valueName
* the enum value name
*/
public void setValueName(String valueName) {
_valueName = valueName;
}

/**
* {@inheritDoc}
*/
@Override
public void compose(Object obj, Graph graph) {
Enum<?> enumValue = (Enum<?>) obj;
setEnumType(enumValue.getClass().getName());
setValueName(enumValue.name());
}

/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object decompose(Graph graph) {
Class enumClass = Classes.forName(getEnumType(), getClass().getClassLoader(), Thread.currentThread().getContextClassLoader());
return Enum.valueOf(enumClass, getValueName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public static Integer build(Object obj, Graph graph) {
return id;
}
Class<?> clazz = obj.getClass();
if (isSimple(clazz)) {
if (clazz.isEnum()) {
Node node = new EnumNode();
graph.putReference(id, node);
node.compose(obj, graph);
} else if (isSimple(clazz)) {
graph.putReference(id, obj);
} else if (isArray(clazz)) {
if (isSimple(clazz.getComponentType())) {
Expand Down Expand Up @@ -147,7 +151,7 @@ static boolean isQName(Class<?> clazz) {
}

static boolean isSimple(Class<?> clazz) {
if (clazz.isPrimitive() || clazz.isEnum()) {
if (clazz.isPrimitive()) {
return true;
}
for (Class<?> st : SIMPLE_TYPES) {
Expand Down