You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ch...@apache.org on 2006/10/05 08:41:24 UTC
svn commit: r453113 - /geronimo/xbean/site/editing-custom-xml.html
Author: chirino
Date: Wed Oct 4 23:41:24 2006
New Revision: 453113
URL: http://svn.apache.org/viewvc?view=rev&rev=453113
Log:
Latest export from confluence
Modified:
geronimo/xbean/site/editing-custom-xml.html
Modified: geronimo/xbean/site/editing-custom-xml.html
URL: http://svn.apache.org/viewvc/geronimo/xbean/site/editing-custom-xml.html?view=diff&rev=453113&r1=453112&r2=453113
==============================================================================
--- geronimo/xbean/site/editing-custom-xml.html (original)
+++ geronimo/xbean/site/editing-custom-xml.html Wed Oct 4 23:41:24 2006
@@ -100,11 +100,11 @@
<FONT color="#003366" face="Verdana, Helvetica, Arial">
-
+
<A href="download.html" title="Download">Download</A> | <SPAN class="nobr"><A href="http://geronimo.apache.org/xbean/dist/xbean-2.4/site/" title="Visit page outside Confluence" rel="nofollow">JavaDocs<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> | <A href="source.html" title="Source">Source</A> | <SPAN class="nobr"><A href="http://goopen.org/confluence/pages/listpages.action?key=XB" title="Visit page outside Confluence" rel="nofollow">Wiki<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> | <A href="lists.html" title="Lists">Mailing Lists</A> | <SPAN class="nobr"><A href="http://issues.apache.org/jira/browse/XBEAN" title="Visit page outside Confluence" rel="nofollow">Support<SUP><IMG class="rendericon" src="http://goopen.org/confluenc
e/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN>
- </FONT>
+ </FONT>
<IMG src="http://geronimo.apache.org/images/spacer.gif" width="4" height="1" border="0">
</DIV>
</TD>
@@ -214,7 +214,7 @@
<TD> </TD>
<TD class="sideNavSectionContent" align="left">
-
+
<A href="home.html" title="Home">Home</A><BR>
@@ -222,7 +222,7 @@
<A href="site.html" title="Site">Site</A><BR>
<A href="faq.html" title="FAQ">FAQ</A><BR>
<A href="download.html" title="Download">Download</A>
- </TD>
+ </TD>
</TR>
</TABLE>
</TD>
@@ -253,7 +253,7 @@
<TD> </TD>
<TD class="sideNavSectionContent" align="left">
-
+
<A href="custom-xml.html" title="Custom XML">Custom XML</A><BR>
@@ -261,7 +261,7 @@
<A href="xbean-ant-task.html" title="XBean Ant Task">XBean Ant Task</A><BR>
<A href="jaxb-jndi.html" title="A JNDI provider using JAXB2">JAXB JNDI</A><BR>
<A href="annotation-based-dependency-injection.html" title="Annotation based Dependency Injection">AnDI</A>
- </TD>
+ </TD>
</TR>
</TABLE>
</TD>
@@ -292,7 +292,7 @@
<TD> </TD>
<TD class="sideNavSectionContent" align="left">
-
+
<SPAN class="nobr"><A href="http://www.springframework.org/" title="Visit page outside Confluence" rel="nofollow">Spring<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
@@ -301,7 +301,7 @@
<SPAN class="nobr"><A href="http://openejb.org/" title="Visit page outside Confluence" rel="nofollow">OpenEJB<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<SPAN class="nobr"><A href="http://jencks.org/" title="Visit page outside Confluence" rel="nofollow">Jencks<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<SPAN class="nobr"><A href="http://servicemix.org/" title="Visit page outside Confluence" rel="nofollow">ServiceMix<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN>
- </TD>
+ </TD>
</TR>
</TABLE>
</TD>
@@ -332,13 +332,13 @@
<TD> </TD>
<TD class="sideNavSectionContent" align="left">
-
+
<SPAN class="nobr"><A href="http://issues.apache.org/jira/browse/XBEAN" title="Visit page outside Confluence" rel="nofollow">Issues<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<SPAN class="nobr"><A href="http://issues.apache.org/jira/browse/XBEAN?report=com.atlassian.jira.plugin.system.project:roadmap-panel" title="Visit page outside Confluence" rel="nofollow">Roadmap<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<SPAN class="nobr"><A href="http://issues.apache.org/jira/browse/XBEAN?report=com.atlassian.jira.plugin.system.project:changelog-panel" title="Visit page outside Confluence" rel="nofollow">Change log<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN>
- </TD>
+ </TD>
</TR>
</TABLE>
</TD>
@@ -369,14 +369,14 @@
<TD> </TD>
<TD class="sideNavSectionContent" align="left">
-
+
<SPAN class="nobr"><A href="http://goopen.org/confluence/pages/listpages.action?key=XB" title="Visit page outside Confluence" rel="nofollow">Wiki<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<A href="lists.html" title="Lists">Mailing Lists</A><BR>
<A href="contributor.html" title="Contributor">Who We Are</A><BR>
<A href="contributing.html" title="Contributing">Contributing</A>
- </TD>
+ </TD>
</TR>
</TABLE>
</TD>
@@ -407,7 +407,7 @@
<TD> </TD>
<TD class="sideNavSectionContent" align="left">
-
+
<A href="source.html" title="Source">Source Code</A><BR>
@@ -415,7 +415,7 @@
<SPAN class="nobr"><A href="http://geronimo.apache.org/xbean/dist/xbean-2.4/site/" title="Visit page outside Confluence" rel="nofollow">Source XRef<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<SPAN class="nobr"><A href="http://geronimo.apache.org/xbean/dist/xbean-2.4/site/" title="Visit page outside Confluence" rel="nofollow">Test Source XRef<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<A href="release-procedure.html" title="Release Procedure">Release Procedure</A>
- </TD>
+ </TD>
</TR>
</TABLE>
</TD>
@@ -445,7 +445,19 @@
<P>e.g. consider this example</P>
+<DIV class="code"><DIV class="codeContent">
+<PRE class="code-xml"><SPAN class="code-tag"><beans <SPAN class="code-keyword">xmlns:p</SPAN>=<SPAN class="code-quote">"http://xbean.apache.org/schemas/pizza"</SPAN>></SPAN>
+ <SPAN class="code-tag"><bean id=<SPAN class="code-quote">"topping"</SPAN> class=<SPAN class="code-quote">"java.lang.String"</SPAN>></SPAN>
+ <SPAN class="code-tag"><constructor-arg></SPAN>
+ <SPAN class="code-tag"><value></SPAN>Salami<SPAN class="code-tag"></value></SPAN>
+ <SPAN class="code-tag"></constructor-arg></SPAN>
+ <SPAN class="code-tag"></bean></SPAN>
+
+ <SPAN class="code-tag"><p:pizza id=<SPAN class="code-quote">"pizzaService"</SPAN> myTopping=<SPAN class="code-quote">"#topping"</SPAN> cheese=<SPAN class="code-quote">"##Edam"</SPAN> size=<SPAN class="code-quote">"17"</SPAN>/></SPAN>
+
+<SPAN class="code-tag"></beans></SPAN></PRE>
+</DIV></DIV>
<P>The topping bean is configured using the regular Spring way; the pizza bean is configured using XBean XML; however notice that the pizza bean is configured via the reference #topping. If you really do want to configure a property with a string which starts with # then escape it as ## as we are doing with the cheese property in this example. i.e. the cheese property will be set to the string "#Edam"</P>
@@ -455,15 +467,102 @@
<P>Here's an example of what the user would configure:</P>
+<DIV class="code"><DIV class="codeContent">
+<PRE class="code-xml"><SPAN class="code-tag"><beans <SPAN class="code-keyword">xmlns:x</SPAN>=<SPAN class="code-quote">"http://xbean.apache.org/schemas/pizza"</SPAN>></SPAN>
+ <SPAN class="code-tag"><x:keg id=<SPAN class="code-quote">"ml1000"</SPAN> remaining=<SPAN class="code-quote">"1000 ml"</SPAN>/></SPAN>
+ <SPAN class="code-tag"><x:keg id=<SPAN class="code-quote">"pints5"</SPAN> remaining=<SPAN class="code-quote">"5 pints"</SPAN>/></SPAN>
+ <SPAN class="code-tag"><x:keg id=<SPAN class="code-quote">"liter20"</SPAN> remaining=<SPAN class="code-quote">"20 liter"</SPAN>/></SPAN>
+ <SPAN class="code-tag"><x:keg id=<SPAN class="code-quote">"empty"</SPAN> remaining=<SPAN class="code-quote">"0"</SPAN>/></SPAN>
+
+<SPAN class="code-tag"></beans></SPAN></PRE>
+</DIV></DIV>
<P>Here's how the bean developer would setup the PropertyEditor for the "remaining" property:</P>
+<DIV class="code"><DIV class="codeContent">
+<PRE class="code-java">/**
+ * @org.apache.xbean.XBean element=<SPAN class="code-quote">"keg"</SPAN>
+ *
+ * Used to verify that property PropertyEditors work correctly.
+ *
+ * @author chirino
+ */
+<SPAN class="code-keyword">public</SPAN> class KegService {
+
+ <SPAN class="code-keyword">private</SPAN> <SPAN class="code-object">long</SPAN> remaining;
+
+ /**
+ * Gets the amount of beer remaining in the keg (in ml)
+ *
+ * @param remaining
+ */
+ <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">long</SPAN> getRemaining() {
+ <SPAN class="code-keyword">return</SPAN> remaining;
+ }
+
+ /**
+ * Sets the amount of beer remaining in the keg (in ml)
+ *
+ * @org.apache.xbean.Property propertyEditor=<SPAN class="code-quote">"org.apache.xbean.spring.example.MilliLittersPropertyEditor"</SPAN>
+ * @param remaining
+ */
+ <SPAN class="code-keyword">public</SPAN> void setRemaining(<SPAN class="code-object">long</SPAN> remaining) {
+ <SPAN class="code-keyword">this</SPAN>.remaining = remaining;
+ }
+
+ <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">long</SPAN> dispense( <SPAN class="code-object">long</SPAN> amount ) {
+ <SPAN class="code-keyword">this</SPAN>.remaining -= amount;
+ <SPAN class="code-keyword">return</SPAN> <SPAN class="code-keyword">this</SPAN>.remaining;
+ }
+}</PRE>
+</DIV></DIV>
<P>And here is how the PropertyEditor was implemented:</P>
-
+<DIV class="code"><DIV class="codeContent">
+<PRE class="code-java">/**
+ *
+ * Used to verify that per property PropertyEditors work correctly.
+ *
+ * @author chirino
+ */
+<SPAN class="code-keyword">public</SPAN> class MilliLittersPropertyEditor <SPAN class="code-keyword">extends</SPAN> PropertyEditorSupport {
+
+ <SPAN class="code-keyword">public</SPAN> void setAsText(<SPAN class="code-object">String</SPAN> text) <SPAN class="code-keyword">throws</SPAN> IllegalArgumentException {
+
+ Pattern p = Pattern.compile(<SPAN class="code-quote">"^(\\d+)\\s*(l(iter)?)?$"</SPAN>, Pattern.CASE_INSENSITIVE);
+ Matcher m = p.matcher(text);
+ <SPAN class="code-keyword">if</SPAN>( m.matches() ) {
+ setValue(<SPAN class="code-keyword">new</SPAN> <SPAN class="code-object">Long</SPAN>(<SPAN class="code-object">Long</SPAN>.parseLong(m.group(1))*1000));
+ <SPAN class="code-keyword">return</SPAN>;
+ }
+
+ p = Pattern.compile(<SPAN class="code-quote">"^(\\d+)\\s*(ml)?$"</SPAN>, Pattern.CASE_INSENSITIVE);
+ m = p.matcher(text);
+ <SPAN class="code-keyword">if</SPAN>( m.matches() ) {
+ setValue(<SPAN class="code-keyword">new</SPAN> <SPAN class="code-object">Long</SPAN>(<SPAN class="code-object">Long</SPAN>.parseLong(m.group(1))));
+ <SPAN class="code-keyword">return</SPAN>;
+ }
+
+ p = Pattern.compile(<SPAN class="code-quote">"^(\\d+)\\s*pints?$"</SPAN>, Pattern.CASE_INSENSITIVE);
+ m = p.matcher(text);
+ <SPAN class="code-keyword">if</SPAN>( m.matches() ) {
+ <SPAN class="code-object">long</SPAN> pints = <SPAN class="code-object">Long</SPAN>.parseLong(m.group(1));
+ setValue(<SPAN class="code-keyword">new</SPAN> <SPAN class="code-object">Long</SPAN>( (<SPAN class="code-object">long</SPAN>)(pints * 1750) ));
+ <SPAN class="code-keyword">return</SPAN>;
+ }
+
+ <SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalArgumentException(<SPAN class="code-quote">"Could convert not to <SPAN class="code-object">long</SPAN> (in ml) <SPAN class="code-keyword">for</SPAN> "</SPAN>+ text);
+ }
+
+ <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> getAsText() {
+ <SPAN class="code-object">Long</SPAN> value = (<SPAN class="code-object">Long</SPAN>) getValue();
+ <SPAN class="code-keyword">return</SPAN> (value != <SPAN class="code-keyword">null</SPAN> ? value.toString() : "");
+ }
+}</PRE>
+</DIV></DIV>