FYI. Maybe useful for WSDL 2.0 http binding stuff .. I know we have our
own now but just wanted to make sure we're aware of this.
Sanjiva.
--
Sanjiva Weerawarana, Ph.D.
Founder & Director; Lanka Software Foundation; http://www.opensource.lk/
Founder, Chairman & CEO; WSO2, Inc.; http://www.wso2.com/
Member; Apache Software Foundation; http://www.apache.org/
Visiting Lecturer; University of Moratuwa; http://www.cse.mrt.ac.lk/
--- Begin Message ---
I've added support for URI/IRI Templates to the IRI module based on
http://bitworking.org/projects/URI-Templates/draft-gregorio-uritemplate-02.html
Examples:
Template instances are immutable and threadsafe.
private static final Template template =
new
Template("http://example.org{-opt|/~|user}{user}{-opt|/-/|categories}{-listjoin|/|categories}{-opt|?|foo,bar}{-join|&|foo,bar}");
Templates can be resolved from a Map, from Java object getters and
fields, or from a custom Context implementation
Map<String,Object> map = new HashMap();
map.put("user","james");
map.put("categories", new String[] {"a","b","c"});
map.put("foo", "abc");
map.put("bar", "xyz");
System.out.println(template.expand(map));
> http://example.org/~james/-/a/b/c?foo=abc&bar=xyz
The Java object approach will examine the public fields and getters of
passed in java objects.
public static class MyObject {
public String user = "james";
public List getCategories() {
List<String> list =
new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
return list;
}
public Foo[] getFoo() {
return new Foo[] {
new Foo(),
new Foo()
};
}
public String getBar() {
return "xyz";
}
}
private static class Foo {
public String toString() { return "abcæ"; }
}
MyObject myObject = new MyObject();
System.out.println(template.expand(myObject,true));
> http://example.org/~james/-/a/b/c?foo=abc%C3%A6&foo=abc%C3%A6&bar=xyz
The custom Context implementation approach allows template variables to
be resolved dynamically,
CachingContext context = new CachingContext() {
private static final long serialVersionUID = 4896250661828139020L;
protected <T> T resolveActual(String var) {
if (var.equals("user")) return (T)"james";
else if (var.equals("categories"))
return (T)new String[] {"a","b","c"};
else if (var.equals("foo")) return (T)"abc";
else if (var.equals("bar")) return (T)"xyz";
else return null;
}
public Iterator<String> iterator() {
return Arrays.asList(
new String[] {"user","categories","foo","bar"}).iterator();
}
};
System.out.println(template.expand(context));
> http://example.org/~james/-/a/b/c?foo=abc&bar=xyz
The implementation will continue to evolve as the URI Template spec evolves.
- James
--- End Message ---
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]