Browse Source

Java part

JNI-44
Volker Birk 10 years ago
parent
commit
855dbf013b
  1. 35
      src/gen_java_Message.ysl2
  2. 21
      src/org/pEp/jniadapter/AbstractEngine.java
  3. 4
      src/types_java.ysl2

35
src/gen_java_Message.ysl2

@ -12,10 +12,12 @@ tstylesheet {
package org.pEp.jniadapter;
import java.util.ArrayList;
import java.util.Vector;
final public class «$cname» extends AbstractEngine {
public «$cname»() throws pEpException { }
`` apply "namespace/interface/method";
`` apply "interface|method"
}
||
}
@ -27,13 +29,13 @@ tstylesheet {
package org.pEp.jniadapter;
import java.util.ArrayList;
import java.util.Vector;
import java.util.Date;
import java.util.HashMap;
public class «$cname» {
`` apply "enum"
`` apply "*[name(.)!='enum']", mode=entry
}
||
}
@ -76,15 +78,32 @@ tstylesheet {
}
template "*", mode=entry {
const "type", "name(.)";
const "name", "name(*[position()=1])";
const "type" call "toJava" with "type", "name(.)";
const "itype" call "toIntermediate" with "type", "name(.)";
const "name" call "toJava" with "type", "name(*[position()=1])";
||
private native †$type _©$name();
private native void _©$name(†$type value);
choose {
when "$itype != $type"
||
private native «$itype» _get«$name»();
private native void _set«$name»(«$itype» value);
public «$type» get«$name»() {
return AbstractEngine.toUTF16(_get«$name»());
}
public void set«$name»(«$type» value) {
_set«$name»(AbstractEngine.toUTF8(value));
}
||
||
otherwise
||
public native «$itype» get«$name»();
public native void set«$name»(«$itype» value);
||
}
}
template "*", mode=value | «name(.)» («.»)`if "position()!=last()" > , `
}

21
src/org/pEp/jniadapter/AbstractEngine.java

@ -1,6 +1,7 @@
package org.pEp.jniadapter;
import java.util.ArrayList;
import java.util.Vector;
import java.io.UnsupportedEncodingException; import java.text.Normalizer;
abstract class AbstractEngine implements AutoCloseable { static {
@ -51,7 +52,16 @@ abstract class AbstractEngine implements AutoCloseable { static {
return result;
}
public static Vector<Pair<byte[], byte[]>> toUTF8(Vector<Pair<String, String>> list) {
Vector<Pair<byte[], byte[]>> result = new Vector<Pair<byte[], byte[]>>(list.size());
for (int i=0; i<list.size(); i++)
result.set(i, toUTF8(list.get(i)));
return result;
}
public static String toUTF16(byte[] utf8) {
try {
return new String(utf8, "UTF-8");
@ -80,6 +90,15 @@ abstract class AbstractEngine implements AutoCloseable { static {
return result;
}
public static Vector<Pair<String, String>> toUTF16(Vector<Pair<byte[], byte[]>> list) {
Vector<Pair<String, String>> result = new Vector<Pair<String, String>>(list.size());
for (int i=0; i<list.size(); i++)
result.set(i, toUTF16(list.get(i)));
return result;
}
public class _Identity {
public byte[] address;
public byte[] fpr;

4
src/types_java.ysl2

@ -12,7 +12,7 @@ function "toJava" {
when "$type='timestamp'" > Date
when "$type='encformat'" > MimeMessage.EncFormat
when "$type='bloblist'" > ArrayList<Blob>
when "$type='stringpairlist'" > ArrayList<Pair<String, String>>
when "$type='stringpairlist'" > Vector<Pair<String, String>>
when "$type='message'" > MimeMessage
otherwise call "CamelCase" with "text", "$type";
@ -24,7 +24,7 @@ function "toIntermediate" {
choose {
when "$type='stringlist'" > ArrayList<byte[]>
when "$type='stringpairlist'" > ArrayList<Pair<byte[], byte[]>>
when "$type='stringpairlist'" > Vector<Pair<byte[], byte[]>>
when "$type='string'" > byte[]
otherwise call "toJava" with "type", "$type";

Loading…
Cancel
Save