From 1a08fa368238ecee208f1d7567ff61aa1f00a858 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 25 Jun 2020 22:52:48 +0200 Subject: [PATCH] Added interface for Message, Identity, Blob --- src/foundation/pEp/jniadapter/Blob.java | 2 +- .../pEp/jniadapter/BlobInterface.java | 5 ++ src/foundation/pEp/jniadapter/Identity.java | 2 +- .../pEp/jniadapter/IdentityInterface.java | 5 ++ src/gen_java_Message.ysl2 | 79 ++++++++++++++++++- 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 src/foundation/pEp/jniadapter/BlobInterface.java create mode 100644 src/foundation/pEp/jniadapter/IdentityInterface.java diff --git a/src/foundation/pEp/jniadapter/Blob.java b/src/foundation/pEp/jniadapter/Blob.java index f246e0c..dffd60f 100644 --- a/src/foundation/pEp/jniadapter/Blob.java +++ b/src/foundation/pEp/jniadapter/Blob.java @@ -2,7 +2,7 @@ package foundation.pEp.jniadapter; import java.io.Serializable; -public class Blob implements Serializable { +public class Blob implements BlobInterface, Serializable { public byte[] data; public String mime_type; public String filename; diff --git a/src/foundation/pEp/jniadapter/BlobInterface.java b/src/foundation/pEp/jniadapter/BlobInterface.java new file mode 100644 index 0000000..d52e7c7 --- /dev/null +++ b/src/foundation/pEp/jniadapter/BlobInterface.java @@ -0,0 +1,5 @@ +package foundation.pEp.jniadapter; + +public interface BlobInterface { + +} diff --git a/src/foundation/pEp/jniadapter/Identity.java b/src/foundation/pEp/jniadapter/Identity.java index 756102c..3f72b90 100644 --- a/src/foundation/pEp/jniadapter/Identity.java +++ b/src/foundation/pEp/jniadapter/Identity.java @@ -2,7 +2,7 @@ package foundation.pEp.jniadapter; import java.io.Serializable; -public class Identity implements Serializable{ +public class Identity implements IdentityInterface, Serializable { public String address; public String fpr; public String user_id; diff --git a/src/foundation/pEp/jniadapter/IdentityInterface.java b/src/foundation/pEp/jniadapter/IdentityInterface.java new file mode 100644 index 0000000..93e0d29 --- /dev/null +++ b/src/foundation/pEp/jniadapter/IdentityInterface.java @@ -0,0 +1,5 @@ +package foundation.pEp.jniadapter; + +public interface IdentityInterface { + public Rating getRating(); +} diff --git a/src/gen_java_Message.ysl2 b/src/gen_java_Message.ysl2 index a16658a..19b0a94 100644 --- a/src/gen_java_Message.ysl2 +++ b/src/gen_java_Message.ysl2 @@ -18,7 +18,7 @@ tstylesheet { import java.util.HashMap; import java.io.Serializable; - public class «$cname» implements AutoCloseable, Serializable { + public class «$cname» implements MessageInterface, AutoCloseable, Serializable { private static final long serialVersionUID = 2119420428331150924L; private long handle; @@ -60,6 +60,20 @@ tstylesheet { `` apply "*[name(.)!='enum']", mode=entry } || + document("foundation/pEp/jniadapter/{$cname}Interface.java", "text") + || + package foundation.pEp.jniadapter; + + import foundation.pEp.jniadapter.Message.Direction; + import java.util.Date; + import java.util.Vector; + import java.util.ArrayList; + + public interface «$cname»Interface { + public String encodeMIME(); + `` apply "*[name(.)!='enum']", mode=interface + } + || } template "enum|exception" { @@ -244,6 +258,69 @@ tstylesheet { } } + template "*", mode=interface { + const "ctype", "name(.)"; + const "type" call "toJava" with "type", "name(.)"; + const "itype" call "toIntermediate" with "type", "name(.)"; + const "name" call "toJava" with "type", "name(*[position()=1])"; + + choose { + when "$ctype = 'identity'" + || + public «$type» get«$name»(); + public void set«$name»(«$type» value); + || + + when "$ctype = 'identitylist' or $ctype = 'bloblist' or $ctype = 'stringlist' or $ctype = 'stringpairlist'" + { + const "ename", "substring-after(substring($type,1,string-length($type)-1), '<')"; + const "iename" choose { + when "$ctype = 'stringlist'" > byte[] + when "$ctype = 'stringpairlist'" > Pair + otherwise > _«$ename» + } + const "convget" choose { + when "$ctype = 'stringlist'" > AbstractEngine.toUTF16(i) + when "$ctype = 'stringpairlist'" > new Pair(AbstractEngine.toUTF16(i.first), AbstractEngine.toUTF16(i.second)) + otherwise > new «$ename»(i) + } + const "convset" choose { + when "$ctype = 'stringlist'" > AbstractEngine.toUTF8(i) + when "$ctype = 'stringpairlist'" > new Pair(AbstractEngine.toUTF8(i.first), AbstractEngine.toUTF8(i.second)) + otherwise > new _«$ename»(i) + } + || + public «$type» get«$name»(); + public void set«$name»(«$type» value); + || + } + + when "$itype != $type" + || + public «$type» get«$name»(); + public void set«$name»(«$type» value); + || + + when "$itype != $type" + || + public «$type» get«$name»(); + public void set«$name»(«$type» value); + || + + when "../enum[@name=$ctype]" + || + public «$itype» get«$name»(); + public void set«$name»(«$itype» value); + || + + otherwise + || + public «$itype» get«$name»(); + public void set«$name»(«$itype» value); + || + } + } + template "*", mode=value { const "name" call "toJava" with "type", "name(.)"; | «$name» («.»)`if "position()!=last()" > , `