You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

206 lines
6.6 KiB

include yslt.yml2
tstylesheet {
include ./textutils.ysl2
include ./types_java.ysl2
template "/namespace[@name='pEp']" apply "struct|enum", 0;
template "struct" {
const "cname" call "toJava" with "type", "@name";
document("org/pEp/jniadapter/{$cname}.java", "text")
||
package org.pEp.jniadapter;
import java.util.ArrayList;
import java.util.Vector;
import java.util.Date;
import java.util.HashMap;
public class «$cname» implements AutoCloseable {
private long handle;
native long init();
native void release(long handle);
public «$cname»() {
handle = init();
}
private «$cname»(long h) {
handle = h;
}
public final void close() {
release(handle);
}
final protected long getHandle() {
return handle;
}
`` apply "enum", mode=inner
`` apply "*[name(.)!='enum']", mode=entry
}
||
}
template "enum" {
const "jname" call "toJava" with "type", "@name";
document("org/pEp/jniadapter/{$jname}.java", "text")
||
package org.pEp.jniadapter;
import java.util.HashMap;
`` apply ".", 0, mode=inner
||
}
template "enum", mode=inner {
const "jname" call "CamelCase" with "text", "@name";
||
public enum «$jname» {
`` apply "*", mode=value
;
static class Management {
public static final HashMap<Integer, «$jname»> tag =
new HashMap<Integer, «$jname»>();
}
public final int value;
«$jname»(int value) {
this.value = value;
fill(value);
}
private void fill(int value) {
Management.tag.put(value, this);
}
}
||
}
template "*", mode=entry {
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'"
||
private native «$itype» _get«$name»();
private native void _set«$name»(«$itype» value);
public «$type» get«$name»() {
return new «$type»(_get«$name»());
}
public void set«$name»(«$type» value) {
if(value != null)
_set«$name»(new «$itype»(value));
else
_set«$name»(null);
}
||
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<byte[],byte[]>
otherwise > _«$ename»
}
const "convget" choose {
when "$ctype = 'stringlist'" > AbstractEngine.toUTF16(i)
when "$ctype = 'stringpairlist'" > new Pair<String, String>(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<byte[],byte[]>(AbstractEngine.toUTF8(i.first), AbstractEngine.toUTF8(i.second))
otherwise > new _«$ename»(i)
}
||
private native «$itype» _get«$name»();
private native void _set«$name»(«$itype» value);
public «$type» get«$name»() {
«$itype» glist = _get«$name»();
if(glist != null){
«$type» list = new «$type»();
for («$iename» i : glist)
list.add(«$convget»);
return list;
}
return null;
}
public void set«$name»(«$type» value) {
if(value != null){
«$itype» list = new «$itype»();
for («$ename» i : value)
list.add(«$convset»);
_set«$name»(list);
}else{
_set«$name»(null);
}
}
||
}
when "$itype != $type"
||
private native «$itype» _get«$name»();
private native void _set«$name»(«$itype» value);
public «$type» get«$name»() {
«$itype» res = _get«$name»();
if(res != null)
return AbstractEngine.toUTF16(res);
else
return null;
}
public void set«$name»(«$type» value) {
if(value != null)
_set«$name»(AbstractEngine.toUTF8(value));
else
_set«$name»(null);
}
||
when "../enum[@name=$ctype]"
||
private native int _get«$name»();
public «$itype» get«$name»() {
return «$itype».Management.tag.get(_get«$name»());
}
private native void _set«$name»(int value);
public void set«$name»(«$itype» value) {
if(value != null)
_set«$name»(value.value);
else
_set«$name»(0);
}
||
otherwise
||
public native «$itype» get«$name»();
public native void set«$name»(«$itype» value);
||
}
}
template "*", mode=value {
const "name" call "toJava" with "type", "name(.)";
| «$name» («.»)`if "position()!=last()" > , `
}
}