diff options
author | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-18 15:48:01 +0000 |
---|---|---|
committer | wjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-18 15:48:01 +0000 |
commit | 8f70a12249558f8b342a57740b6d6423ea23da57 (patch) | |
tree | ccfea4c62bf67c2d5827943e3128b6e415c1a87c /branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java | |
parent | 001f5d05380840d811c85547c361ae0fde5a35a1 (diff) |
General improvements
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@766345 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java index 380abb852b..2ab29490e3 100644 --- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java +++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java @@ -72,13 +72,23 @@ public class TypeHelpersProxy { for (int i = 0; i < notes.length; i++) {
typeHelper = primitiveTypes.get(notes[i].annotationType());
if (typeHelper != null) {
- // annotation found, check if it points to array
- // FIXME: check if annotation points to proper type
- // ie. ErlangAtom -> String. If not, then log? exception?
- if (forClass.isArray()) {
- typeHelper = new AnnotatedListTypeHelper(notes);
+ // get type which is annotated, reduce array if needed
+ Class<?> annotatedType = forClass;
+ while (annotatedType.isArray()) {
+ annotatedType = annotatedType.getComponentType();
+ }
+ if (notes[i].annotationType().equals(ErlangAtom.class)
+ && !annotatedType.equals(String.class)) {
+ // NOTE: @ErlangAtom atom will be ignored if not annotates
+ // string
+ typeHelper = null;
+ } else {
+ // check if annotation points to array
+ if (forClass.isArray()) {
+ typeHelper = new AnnotatedListTypeHelper(notes);
+ }
+ break;
}
- break;
}
}
// check for standard types
@@ -145,24 +155,42 @@ public class TypeHelpersProxy { * Creates Erlang list basing on unknown Java arrays
*
* @param array
+ * @param notes
* @return
*/
public static OtpErlangList toErlangAsList(Object array,
Annotation[][] notes) {
+ return toErlangAsList(array, notes, false);
+ }
+
+ /**
+ * Creates Erlang list of result elements
+ *
+ * @param array
+ * @param notes
+ * @return
+ */
+ public static OtpErlangList toErlangAsResultList(Object array,
+ Annotation[] notes) {
+ return toErlangAsList(array, new Annotation[][] { notes }, true);
+ }
+
+ /**
+ *
+ * @param array
+ * @param notes
+ * @param isArray
+ * @return
+ */
+ private static OtpErlangList toErlangAsList(Object array,
+ Annotation[][] notes, boolean isArray) {
OtpErlangList result = null;
if (array != null) {
List<OtpErlangObject> attrsList = new ArrayList<OtpErlangObject>();
int i = 0;
while (true) {
try {
- // FIXME: if notes.length == 1 then its used to annotate
- // array. Clean up.
- Annotation[] currNotes = null;
- if (notes.length == 1) {
- currNotes = notes[0];
- } else {
- currNotes = notes[i];
- }
+ Annotation[] currNotes = isArray ? notes[0] : notes[i];
TypeHelper helper = getTypeHelper(Array.get(array, i)
.getClass(), currNotes);
attrsList.add(helper.toErlang(Array.get(array, i)));
|