diff options
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org')
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)));
|