Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 35696 invoked from network); 5 Oct 2006 06:41:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 Oct 2006 06:41:57 -0000 Received: (qmail 80391 invoked by uid 500); 5 Oct 2006 06:41:56 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 80356 invoked by uid 500); 5 Oct 2006 06:41:56 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 80344 invoked by uid 99); 5 Oct 2006 06:41:56 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Oct 2006 23:41:56 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:50438] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 5E/9F-20288-229A4254 for ; Wed, 04 Oct 2006 23:41:45 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 071841A981A; Wed, 4 Oct 2006 23:41:25 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r453113 - /geronimo/xbean/site/editing-custom-xml.html Date: Thu, 05 Oct 2006 06:41:24 -0000 To: scm@geronimo.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061005064125.071841A981A@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 @@ - + Download | JavaDocs | Source | Wiki | Mailing Lists | Support - + @@ -214,7 +214,7 @@   - + Home
@@ -222,7 +222,7 @@ Site
FAQ
Download - + @@ -253,7 +253,7 @@   - + Custom XML
@@ -261,7 +261,7 @@ XBean Ant Task
JAXB JNDI
AnDI - + @@ -292,7 +292,7 @@   - + Spring
@@ -301,7 +301,7 @@ OpenEJB
Jencks
ServiceMix - + @@ -332,13 +332,13 @@   - + Issues
Roadmap
Change log - + @@ -369,14 +369,14 @@   - + Wiki
Mailing Lists
Who We Are
Contributing - + @@ -407,7 +407,7 @@   - + Source Code
@@ -415,7 +415,7 @@ Source XRef
Test Source XRef
Release Procedure - + @@ -445,7 +445,19 @@

e.g. consider this example

+
+
<beans xmlns:p="http://xbean.apache.org/schemas/pizza">
 
+  <bean id="topping" class="java.lang.String">
+    <constructor-arg>
+      <value>Salami</value>
+    </constructor-arg>
+  </bean>
+
+  <p:pizza id="pizzaService" myTopping="#topping" cheese="##Edam" size="17"/>
+  
+</beans>
+

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"

@@ -455,15 +467,102 @@

Here's an example of what the user would configure:

+
+
<beans xmlns:x="http://xbean.apache.org/schemas/pizza">
 
+  <x:keg id="ml1000" remaining="1000 ml"/>
+  <x:keg id="pints5" remaining="5 pints"/>
+  <x:keg id="liter20" remaining="20 liter"/>
+  <x:keg id="empty" remaining="0"/>
+
+</beans>
+

Here's how the bean developer would setup the PropertyEditor for the "remaining" property:

+
+
/**
+ * @org.apache.xbean.XBean element="keg" 
+ * 
+ * Used to verify that property PropertyEditors work correctly.
+ * 
+ * @author chirino
+ */
+public class KegService {
+	
+    private long remaining;
+
+	/**
+	 * Gets the amount of beer remaining in the keg (in ml)
+	 * 
+	 * @param remaining
+	 */
+	public long getRemaining() {
+		return remaining;
+	}
+
+	/**
+	 * Sets the amount of beer remaining in the keg (in ml)
+	 * 
+     * @org.apache.xbean.Property propertyEditor="org.apache.xbean.spring.example.MilliLittersPropertyEditor"
+	 * @param remaining
+	 */
+	public void setRemaining(long remaining) {
+		this.remaining = remaining;
+	}
+	
+	public long dispense( long amount ) {
+		this.remaining -= amount;
+		return this.remaining;
+	}
 
+}
+

And here is how the PropertyEditor was implemented:

- +
+
/**
+ * 
+ * Used to verify that per property PropertyEditors work correctly.
+ * 
+ * @author chirino
+ */
+public class MilliLittersPropertyEditor extends PropertyEditorSupport {
+
+	public void setAsText(String text) throws IllegalArgumentException {
+
+		Pattern p = Pattern.compile("^(\\d+)\\s*(l(iter)?)?$", Pattern.CASE_INSENSITIVE);
+		Matcher m = p.matcher(text);
+		if( m.matches() ) {
+			setValue(new Long(Long.parseLong(m.group(1))*1000));
+			return;
+		}
+		
+		p = Pattern.compile("^(\\d+)\\s*(ml)?$", Pattern.CASE_INSENSITIVE);
+		m = p.matcher(text);
+		if( m.matches() ) {
+			setValue(new Long(Long.parseLong(m.group(1))));
+			return;
+		}
+
+		p = Pattern.compile("^(\\d+)\\s*pints?$", Pattern.CASE_INSENSITIVE);
+	    m = p.matcher(text);
+		if( m.matches() ) {
+			long pints = Long.parseLong(m.group(1));
+			setValue(new Long( (long)(pints * 1750) ));
+			return;
+		}
+		
+		throw new IllegalArgumentException("Could convert not to long (in ml) for "+ text);		
+	}
+
+	public String getAsText() {
+		Long value = (Long) getValue();
+		return (value != null ? value.toString() : "");
+	}
+}
+