Login | About | Page IndexHome | Manual | Publications | Download | Support

Native Class

Native Java classes can be declared in a WebDSL application in order to interface with existing libraries and code. If you want to use just one native function, see native function interface.

The supported elements are properties, (static) methods, and constructors. The supported types are

  • WebDSL type - Java type
  • Int - int or Integer
  • Bool - boolean or Boolean
  • Float - float or Float
  • String - String

Both the primitive type and the object types such as int and Integer can be produced by the WebDSL call (so overloading between these types is a problem here).

Add Java classes to a nativejava/ dir next to your app file and jar files in lib/.

Example:

native class nativejava.TestSub as SubClass : SuperClass {
  prop :String
  getProp():String
  setProp(String)
  constructor()
}

native class  nativejava.TestSuper as SuperClass  {
  getProp():String
  static getStatic(): String
  returnList(): List<SubClass>
}

define page root() {
  var d : SuperClass := SubClass()  
  output(d.getProp())

  var s : SubClass := SubClass()
  init{
    s.setProp("test");
  }
  output(s.prop)

  output(SuperClass.getStatic())

  for(a: SubClass in d.returnList()){
    output(a.prop)
  } 
}

(Example taken from compiler tests, source

https://svn.strategoxt.org/repos/WebDSL/webdsls/trunk/test/succeed/native-classes.app
https://svn.strategoxt.org/repos/WebDSL/webdsls/trunk/test/succeed/nativejava/TestSub.java
https://svn.strategoxt.org/repos/WebDSL/webdsls/trunk/test/succeed/nativejava/TestSuper.java

)


powered by WebDSL