Exporting Constructors

18 views
Skip to first unread message

ihsan ciftci

unread,
Oct 26, 2011, 12:52:15 PM10/26/11
to gwtexporter
Suppose I have a class like that

public class MyPoint implements IGeometry, Cloneable
{
public MyPoint() { this(Double.NaN, Double.NaN);} //Export

public MyPoint(MyPoint point) { . . . } //Export

public MyPoint(Point2D point) { . . . } //No-export

public MyPoint(double... coordinates) { ... } //Export

}

I want to export some of its constructors.
How can I do that when the preferred way is to use ExportOverlay?
If it is not possible, with Exportable interface? No need to Export
IGeometry.

Manuel Carrasco Moñino

unread,
Oct 27, 2011, 11:37:54 AM10/27/11
to gwtex...@googlegroups.com
Not sure about what you want, anyway ExportOverlay can be used with
interfaces and classes implementing stub methods.
You can use the annotation @ExportConstructor or @ExportInstanceMethod
to change the original class behavior

Take a look to this example from the tests which I think could help you:

public static class Child {
private String name;
public Child(String cname) { name = cname; }
public String getName1() { return name; }
public String getName2(long l) { return name + l; }
public String getName3(Child c) { return c==null? "NULL" :c.getName1(); }

public String wrapped_method(long l) {return "" + l;}
}

public static class Mother {
Child child;
public void setChild(Child c) {child = c;}
public Child getChild() {return child;}
}

@ExportPackage("ex")
@Export("Child")
public static class XChild implements ExportOverlay<Child>{
public XChild(String s){}
@Export("name")
public String getName1() {return null;}
@Export("name")
public String getName2(long l) {return null;}
@Export("name")
public String getName3(Child c) {return null;}

@ExportConstructor
public static Child constructor(String name, String surname) {
return new Child(name + " " + surname);
}
@ExportInstanceMethod("foo")
public static String instanceMethod(Child instance, String name,
String surname, long l) {
return name + "-" + surname + "-Foo-" + l;
}

@ExportInstanceMethod("foo")
public static String instanceMethod(Child instance, String name) {
return name + "-Caa";
}
public String wrapped_method(long l) {return null;}
}

@ExportPackage("ex")
@Export("Mother")
public static class XMother implements ExportOverlay<Mother>{
public void setChild(Child c) {}
public Child getChild() {return null;}
}


var child = new $wnd.ex.Child("Bill");
var mother = new $wnd.ex.Mother();
mother.setChild(child);
p("Bill", mother.getChild().name());
p("Bill2", mother.getChild().name(2));
p("Joe", child.name(new $wnd.ex.Child("Joe")));
p("s1-s2-Foo-2", child.foo('s1', 's2', 2));
p("s1-Caa", child.foo('s1'));
p("null-Caa", child.foo(null));


- Manolo

Reply all
Reply to author
Forward
0 new messages