summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org
diff options
context:
space:
mode:
authorwjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68>2009-04-18 15:48:01 +0000
committerwjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68>2009-04-18 15:48:01 +0000
commit8f70a12249558f8b342a57740b6d6423ea23da57 (patch)
treeccfea4c62bf67c2d5827943e3128b6e415c1a87c /branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org
parent001f5d05380840d811c85547c361ae0fde5a35a1 (diff)
General improvements
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@766345 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org')
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java7
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java22
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java56
3 files changed, 55 insertions, 30 deletions
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java
index 2fe9ae38b9..a2cf71a053 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java
@@ -62,6 +62,7 @@ public class ErlangInvoker implements Invoker {
} else {
// NOTE: don't throw exception if not declared
// TODO: externalize message?
+ msg.setBody(null);
logger
.log(Level.WARNING, "Problem while sending/receiving data",
e);
@@ -82,7 +83,11 @@ public class ErlangInvoker implements Invoker {
node.setCookie(binding.getCookie());
}
tmpMbox = node.createMbox();
- Object[] args = msg.getBody();
+ // obtain args, make sure they aren't null
+ // NOTE: sending message with no content (but only with senders PID)
+ // is possible
+ Object[] args = (Object[]) (msg.getBody() != null ? msg.getBody()
+ : new Object[0]);
Method jmethod = ((JavaOperation) msg.getOperation())
.getJavaMethod();
// create and send msg with self pid in the beginning
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java
index 26b772f5e3..9e292fe3bb 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java
@@ -152,10 +152,8 @@ public class ServiceExecutor implements Runnable {
&& operation.getOutputType().getPhysical()
.isArray()) {
// output type is array
- Annotation[][] outNotes = new Annotation[][] { jmethod
- .getAnnotations() };
- response = TypeHelpersProxy.toErlangAsList(result,
- outNotes);
+ response = TypeHelpersProxy.toErlangAsResultList(
+ result, jmethod.getAnnotations());
} else if (operation.getOutputType() == null) {
// output type is void, create empty reply
Object[] arrArg = new Object[] {};
@@ -248,8 +246,7 @@ public class ServiceExecutor implements Runnable {
msgNoSender = msg.getMsg();
}
} catch (Exception e) {
- // TODO: check when this exception can occur
- e.printStackTrace();
+ logger.log(Level.WARNING, "Unexpected error", e);
}
if (operations == null) {
@@ -294,10 +291,8 @@ public class ServiceExecutor implements Runnable {
&& matchedOperation.getOutputType().getPhysical()
.isArray()) {
// result type is array
- Annotation[][] outNotes = new Annotation[][] { jmethod
- .getAnnotations() };
- response = TypeHelpersProxy.toErlangAsList(result,
- outNotes);
+ response = TypeHelpersProxy.toErlangAsResultList(
+ result, jmethod.getAnnotations());
} else if (matchedOperation.getOutputType() != null) {
// result type is not array and not void
response = TypeHelpersProxy.toErlang(result, jmethod
@@ -330,13 +325,10 @@ public class ServiceExecutor implements Runnable {
e1.printStackTrace();
}
} else {
- // unknown/unhandled error
- // TODO: decide what to do with this exception
- e.printStackTrace();
+ logger.log(Level.WARNING, "Unexpected error", e);
}
} catch (Exception e) {
- // FIXME: log this problem? use linking feature? send error?
- e.printStackTrace();
+ logger.log(Level.WARNING, "Unexpected error", e);
}
} else {
// TODO: externalize message?
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)));