Author: rjung Date: Wed Jan 28 19:29:46 2015 New Revision: 1655438 URL: http://svn.apache.org/r1655438 Log: Use a slightly less artificial example for the new feature.
Modified: tomcat/trunk/webapps/docs/jndi-resources-howto.xml Modified: tomcat/trunk/webapps/docs/jndi-resources-howto.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/jndi-resources-howto.xml?rev=1655438&r1=1655437&r2=1655438&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/jndi-resources-howto.xml (original) +++ tomcat/trunk/webapps/docs/jndi-resources-howto.xml Wed Jan 28 19:29:46 2015 @@ -339,70 +339,78 @@ writer.println("foo = " + bean.getFoo() <source><![CDATA[package com.mycompany; -public class MyBean { +import java.net.InetAddress; +import java.net.UnknownHostException; - private byte foo[] = null; +public class MyBean2 { - public byte[] getFoo() { - return (this.foo); + private InetAddress local = null; + + public InetAddress getLocal() { + return local; } - public void setFoo(byte foo[]) { - this.foo = foo; + public void setLocal(InetAddress ip) { + local = ip; } - public void setFoo(String value) { - this.foo = value.getBytes(); + public void setLocal(String localHost) { + try { + local = InetAddress.getByName(localHost); + } catch (UnknownHostException ex) { + } } - private byte bar[] = null; + private InetAddress remote = null; - public byte[] getBar() { - return (this.bar); + public InetAddress getRemote() { + return remote; } - public void setBar(byte bar[]) { - this.bar = bar; + public void setRemote(InetAddress ip) { + remote = ip; } - public void init(String value) { - this.bar = value.getBytes(); + public void host(String remoteHost) { + try { + remote = InetAddress.getByName(remoteHost); + } catch (UnknownHostException ex) { + } } - } }]]></source> - <p>The bean has two properties, both are of type <code>byte[]</code>. - The first property <code>foo</code> has a setter taking a string argument. - By default the Tomcat BeanFactory would try to use the automatically - detected setter with the same argument type as the property type and - then throw a NamingException, because it is not prepared to convert - the given string attribute value to <code>byte[]</code>. + <p>The bean has two properties, both are of type <code>InetAddress</code>. + The first property <code>local</code> has an additional setter taking a + string argument. By default the Tomcat BeanFactory would try to use the + automatically detected setter with the same argument type as the property + type and then throw a NamingException, because it is not prepared to convert + the given string attribute value to <code>InetAddress</code>. We can tell the Tomcat BeanFactory to use the other setter like that:</p> <source><![CDATA[<Context ...> ... <Resource name="bean/MyBeanFactory" auth="Container" - type="com.mycompany.MyBean" + type="com.mycompany.MyBean2" factory="org.apache.naming.factory.BeanFactory" - forceString="foo" - foo="xyz"/> + forceString="local" + local="localhost"/> ... </Context>]]></source> - <p>The bean property <code>bar</code> can also be set from a string, - but one has to use the non-standard method name <code>init</code>. - To set <code>foo</code> and <code>bar</code> use the following + <p>The bean property <code>remote</code> can also be set from a string, + but one has to use the non-standard method name <code>host</code>. + To set <code>local</code> and <code>remote</code> use the following configuration:</p> <source><![CDATA[<Context ...> ... <Resource name="bean/MyBeanFactory" auth="Container" - type="com.mycompany.MyBean" + type="com.mycompany.MyBean2" factory="org.apache.naming.factory.BeanFactory" - forceString="foo,bar=init" - foo="xyz" - bar="123"/> + forceString="local,remote=host" + local="localhost" + remote="tomcat.apache.org"/> ... </Context>]]></source> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org