You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/05/19 15:28:20 UTC
[31/50] [abbrv] git commit: [OLINGO-261] Simplifying enum handling
[OLINGO-261] Simplifying enum handling
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/6852f40e
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/6852f40e
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/6852f40e
Branch: refs/heads/master
Commit: 6852f40e6e05f1f15ac8fe77fc9fa5a28f4029ed
Parents: 25a6271
Author: Francesco Chicchiriccò <--global>
Authored: Wed May 14 13:43:06 2014 +0200
Committer: Stephan Klevenz <st...@sap.com>
Committed: Mon May 19 14:33:41 2014 +0200
----------------------------------------------------------------------
.../olingo/ext/proxy/utils/CoreUtils.java | 38 +++++++-------------
.../olingo/ext/pojogen/AbstractPOJOGenMojo.java | 16 ++-------
fit/src/test/resources/META-INF/enumTypes | 3 --
3 files changed, 15 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6852f40e/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
index 2601db3..e8fa91b 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
@@ -34,8 +34,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
import org.apache.olingo.client.api.v3.UnsupportedInV3Exception;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
@@ -240,6 +238,17 @@ public final class CoreUtils {
}
}
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private static Enum<?> enumValueToObject(final ODataEnumValue value, final Class<?> reference) {
+ final Namespace namespace = reference.getAnnotation(Namespace.class);
+ final EnumType enumType = reference.getAnnotation(EnumType.class);
+ if (value.getTypeName().equals(namespace.value() + "." + enumType.name())) {
+ return Enum.valueOf((Class<Enum>) reference, value.getValue());
+ }
+
+ return null;
+ }
+
private static Object primitiveValueToObject(final ODataPrimitiveValue value, final Class<?> reference) {
Object obj;
@@ -396,29 +405,6 @@ public final class CoreUtils {
}
}
- @SuppressWarnings({"unchecked", "rawtypes"})
- private static Enum<?> buildEnumInstance(final ODataEnumValue value) {
- try {
- for (String enumTypeName
- : StringUtils.split(IOUtils.toString(CoreUtils.class.getResourceAsStream("/META-INF/enumTypes")), '\n')) {
-
- final Class<Enum> enumClass =
- (Class<Enum>) Thread.currentThread().getContextClassLoader().loadClass(enumTypeName);
- if (enumClass != null) {
- final Namespace namespace = enumClass.getAnnotation(Namespace.class);
- final EnumType enumType = enumClass.getAnnotation(EnumType.class);
- if (value.getTypeName().equals(namespace.value() + "." + enumType.name())) {
- return Enum.valueOf(enumClass, value.getValue());
- }
- }
- }
- } catch (Exception e) {
- LOG.error("While trying to load enum for {}", value, e);
- }
-
- return null;
- }
-
@SuppressWarnings("unchecked")
public static Object getValueFromProperty(
final CommonEdmEnabledODataClient<?> client,
@@ -469,7 +455,7 @@ public final class CoreUtils {
res = collection;
} else if (property instanceof ODataProperty && ((ODataProperty) property).hasEnumValue()) {
- res = buildEnumInstance(((ODataProperty) property).getEnumValue());
+ res = enumValueToObject(((ODataProperty) property).getEnumValue(), internalRef);
} else {
res = primitiveValueToObject(property.getPrimitiveValue(), internalRef);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6852f40e/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
index ce566ee..250cf53 100644
--- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
+++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
@@ -84,8 +84,9 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
protected abstract String getVersion();
- protected File mkdir(final String path) {
- final File dir = new File(outputDirectory + File.separator + TOOL_DIR + File.separator + path);
+ protected File mkPkgDir(final String path) {
+ final File dir = new File(outputDirectory + File.separator + TOOL_DIR + File.separator
+ + basePackage.replace('.', File.separatorChar) + File.separator + path);
if (dir.exists()) {
if (!dir.isDirectory()) {
@@ -98,10 +99,6 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
return dir;
}
- protected File mkPkgDir(final String path) {
- return mkdir(basePackage.replace('.', File.separatorChar) + File.separator + path);
- }
-
protected void writeFile(final String name, final File path, final VelocityContext ctx, final Template template,
final boolean append) throws MojoExecutionException {
@@ -227,8 +224,6 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
namespaces.add(schema.getNamespace().toLowerCase());
}
- final StringBuilder enumTypeNames = new StringBuilder();
-
for (EdmSchema schema : edm.getSchemas()) {
createUtility(edm, schema, basePackage);
@@ -248,7 +243,6 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
// write types into types package
for (EdmEnumType enumType : schema.getEnumTypes()) {
final String className = utility.capitalize(enumType.getName());
- enumTypeNames.append(typesPkg).append('.').append(className).append('\n');
objs.clear();
objs.put("enumType", enumType);
parseObj(typesBaseDir, typesPkg, "enumType", className + ".java", objs);
@@ -324,9 +318,6 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
}
}
}
-
- final File metaInf = mkdir("META-INF");
- FileUtils.fileWrite(metaInf.getPath() + File.separator + "enumTypes", enumTypeNames.toString());
} catch (Exception t) {
getLog().error(t);
@@ -335,5 +326,4 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
: new MojoExecutionException("While executin mojo", t);
}
}
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6852f40e/fit/src/test/resources/META-INF/enumTypes
----------------------------------------------------------------------
diff --git a/fit/src/test/resources/META-INF/enumTypes b/fit/src/test/resources/META-INF/enumTypes
deleted file mode 100644
index c1e5365..0000000
--- a/fit/src/test/resources/META-INF/enumTypes
+++ /dev/null
@@ -1,3 +0,0 @@
-org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccessLevel
-org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Color
-org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CompanyCategory