Again refinements in Edm type management
This commit is contained in:
parent
848976bbbc
commit
027e135583
|
@ -25,10 +25,12 @@ import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.olingo.odata4.client.api.edm.xml.EnumType;
|
import org.apache.olingo.odata4.client.api.edm.xml.EnumType;
|
||||||
import org.apache.olingo.odata4.client.api.edm.xml.Member;
|
import org.apache.olingo.odata4.client.api.edm.xml.Member;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.Edm;
|
import org.apache.olingo.odata4.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
|
import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmMember;
|
import org.apache.olingo.odata4.commons.api.edm.EdmMember;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
|
import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
|
||||||
|
@ -37,6 +39,14 @@ import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeK
|
||||||
|
|
||||||
public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType {
|
public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType {
|
||||||
|
|
||||||
|
private static final EdmPrimitiveTypeKind[] VALID_UNDERLYING_TYPES = new EdmPrimitiveTypeKind[] {
|
||||||
|
EdmPrimitiveTypeKind.Byte,
|
||||||
|
EdmPrimitiveTypeKind.SByte,
|
||||||
|
EdmPrimitiveTypeKind.Int16,
|
||||||
|
EdmPrimitiveTypeKind.Int32,
|
||||||
|
EdmPrimitiveTypeKind.Int64
|
||||||
|
};
|
||||||
|
|
||||||
private final EdmPrimitiveType underlyingType;
|
private final EdmPrimitiveType underlyingType;
|
||||||
|
|
||||||
private final List<String> memberNames;
|
private final List<String> memberNames;
|
||||||
|
@ -49,9 +59,11 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType
|
||||||
if (xmlEnumType.getUnderlyingType() == null) {
|
if (xmlEnumType.getUnderlyingType() == null) {
|
||||||
this.underlyingType = EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance();
|
this.underlyingType = EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance();
|
||||||
} else {
|
} else {
|
||||||
this.underlyingType = EdmPrimitiveTypeKind.fromString(
|
this.underlyingType = EdmPrimitiveTypeKind.valueOfFQN(xmlEnumType.getUnderlyingType()).
|
||||||
xmlEnumType.getUnderlyingType()).getEdmPrimitiveTypeInstance();
|
getEdmPrimitiveTypeInstance();
|
||||||
// TODO: Should we validate that the underlying type is of byte, sbyte, in16, int32 or int64?
|
if (!ArrayUtils.contains(VALID_UNDERLYING_TYPES, this.underlyingType.getKind())) {
|
||||||
|
throw new EdmException("Not allowed as underlying type: " + this.underlyingType.getKind());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<? extends Member> xmlMembers = xmlEnumType.getMembers();
|
final List<? extends Member> xmlMembers = xmlEnumType.getMembers();
|
||||||
|
|
|
@ -38,10 +38,9 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition implements
|
||||||
|
|
||||||
super(edm, typeDefinitionName);
|
super(edm, typeDefinitionName);
|
||||||
this.typeDefinition = typeDefinition;
|
this.typeDefinition = typeDefinition;
|
||||||
// TODO: Should we check for edmNamespace in the underlying type name?
|
|
||||||
try {
|
try {
|
||||||
edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.fromString(
|
edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType()).
|
||||||
typeDefinition.getUnderlyingType()).getEdmPrimitiveTypeInstance();
|
getEdmPrimitiveTypeInstance();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
|
throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,13 +86,10 @@ public enum EdmPrimitiveTypeKind {
|
||||||
* @param value string value type.
|
* @param value string value type.
|
||||||
* @return <tt>EdmPrimitiveTypeKind</tt> object.
|
* @return <tt>EdmPrimitiveTypeKind</tt> object.
|
||||||
*/
|
*/
|
||||||
public static EdmPrimitiveTypeKind fromString(final String value) {
|
public static EdmPrimitiveTypeKind valueOfFQN(final String value) {
|
||||||
final String noNsValue = value.substring(4);
|
if (!value.startsWith(EdmPrimitiveType.EDM_NAMESPACE + ".")) {
|
||||||
for (EdmPrimitiveTypeKind edmSimpleType : EdmPrimitiveTypeKind.values()) {
|
throw new IllegalArgumentException(value + " does not look like an Edm primitive type");
|
||||||
if (edmSimpleType.name().equals(noNsValue)) {
|
|
||||||
return edmSimpleType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException(value);
|
return valueOf(value.substring(4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue