[jboss-cvs] JBossAS SVN: r76109 - in projects/demos/trunk/ioc/src: main/org/jboss/demos/ioc/callback and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 22 12:47:22 EDT 2008


Author: alesj
Date: 2008-07-22 12:47:22 -0400 (Tue, 22 Jul 2008)
New Revision: 76109

Added:
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/AbstractEditor.java
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Checker.java
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/DoubleEditor.java
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Editor.java
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/LocaleEditor.java
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/LongEditor.java
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Parser.java
   projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/URLEditor.java
   projects/demos/trunk/ioc/src/resources/META-INF/callback-beans.xml
Log:
Callbacks example.

Added: projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/AbstractEditor.java
===================================================================
--- projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/AbstractEditor.java	                        (rev 0)
+++ projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/AbstractEditor.java	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.callback;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractEditor<T> implements Editor<T>
+{
+   protected void checkCondition(boolean condition, String value)
+   {
+      if (condition == false)
+         throw new IllegalArgumentException("Value is illegal: " + value);
+   }
+}
\ No newline at end of file

Added: projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Checker.java
===================================================================
--- projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Checker.java	                        (rev 0)
+++ projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Checker.java	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.callback;
+
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Checker
+{
+   private Set<Object> elements;
+
+   public Checker(Set<Object> elements)
+   {
+      this.elements = elements;
+   }
+
+   public void create() throws Throwable
+   {
+      Set<Object> expected = new HashSet<Object>();
+      expected.add(Long.parseLong("42"));
+      expected.add(3.14);
+      expected.add(new URL("http://www.jboss.org"));
+      expected.add(new Locale("SI"));
+      if (expected.equals(elements) == false)
+         throw new IllegalArgumentException("Illegal expected set: " + expected + "!=" + elements);
+   }
+}
\ No newline at end of file

Added: projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/DoubleEditor.java
===================================================================
--- projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/DoubleEditor.java	                        (rev 0)
+++ projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/DoubleEditor.java	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.callback;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DoubleEditor extends AbstractEditor<Double>
+{
+   public Double edit(String value)
+   {
+      checkCondition(value.indexOf('.') >= 0, value);
+      return Double.parseDouble(value);
+   }
+}
\ No newline at end of file

Added: projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Editor.java
===================================================================
--- projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Editor.java	                        (rev 0)
+++ projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Editor.java	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,30 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.callback;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface Editor<T>
+{
+   T edit(String value);   
+}

Added: projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/LocaleEditor.java
===================================================================
--- projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/LocaleEditor.java	                        (rev 0)
+++ projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/LocaleEditor.java	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.callback;
+
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LocaleEditor extends AbstractEditor<Locale>
+{
+   public Locale edit(String value)
+   {
+      checkCondition(value.length() <= 2, value);
+      return new Locale(value);
+   }
+}
\ No newline at end of file

Added: projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/LongEditor.java
===================================================================
--- projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/LongEditor.java	                        (rev 0)
+++ projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/LongEditor.java	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.callback;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LongEditor extends AbstractEditor<Long>
+{
+   public Long edit(String value)
+   {
+      checkCondition(value.indexOf('.') < 0, value);
+      return Long.parseLong(value);
+   }
+}

Added: projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Parser.java
===================================================================
--- projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Parser.java	                        (rev 0)
+++ projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/Parser.java	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,66 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.callback;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Parser
+{
+   private Set<Editor> editors = new HashSet<Editor>();
+
+   public Set<Object> parse(String... values)
+   {
+      Set<Object> list = new HashSet<Object>();
+      for (String value : values)
+         list.add(edit(value));
+      return list;
+   }
+
+   protected Object edit(String value)
+   {
+      for (Editor editor : editors)
+      {
+         try
+         {
+            return editor.edit(value);
+         }
+         catch(Exception ignored)
+         {
+         }
+      }
+      throw new IllegalArgumentException("No matching editor: " + value);
+   }
+
+   public void addEditor(Editor editor)
+   {
+      editors.add(editor);
+   }
+
+   public void removeEditor(Editor editor)
+   {
+      editors.remove(editor);
+   }
+}

Added: projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/URLEditor.java
===================================================================
--- projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/URLEditor.java	                        (rev 0)
+++ projects/demos/trunk/ioc/src/main/org/jboss/demos/ioc/callback/URLEditor.java	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.callback;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class URLEditor implements Editor<URL>
+{
+   public URL edit(String value)
+   {
+      try
+      {
+         return new URL(value);
+      }
+      catch (MalformedURLException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Copied: projects/demos/trunk/ioc/src/resources/META-INF/callback-beans.xml (from rev 76090, projects/demos/trunk/ioc/src/resources/META-INF/cycle-beans.xml)
===================================================================
--- projects/demos/trunk/ioc/src/resources/META-INF/callback-beans.xml	                        (rev 0)
+++ projects/demos/trunk/ioc/src/resources/META-INF/callback-beans.xml	2008-07-22 16:47:22 UTC (rev 76109)
@@ -0,0 +1,33 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+  <bean name="checker" class="org.jboss.demos.ioc.callback.Checker">
+    <constructor>
+      <parameter>
+        <value-factory bean="parser" method="parse">
+          <parameter>
+            <array elementClass="java.lang.Object">
+              <value>http://www.jboss.org</value>
+              <value>SI</value>
+              <value>3.14</value>
+              <value>42</value>
+            </array>
+          </parameter>
+        </value-factory>
+      </parameter>
+    </constructor>
+  </bean>
+
+  <bean name="editorA" class="org.jboss.demos.ioc.callback.DoubleEditor"/>
+
+  <bean name="editorB" class="org.jboss.demos.ioc.callback.LocaleEditor"/>
+
+  <bean name="parser" class="org.jboss.demos.ioc.callback.Parser">
+    <incallback method="addEditor" cardinality="4..n"/>
+    <uncallback method="removeEditor"/>
+  </bean>
+
+  <bean name="editorC" class="org.jboss.demos.ioc.callback.LongEditor"/>
+
+  <bean name="editorD" class="org.jboss.demos.ioc.callback.URLEditor"/>
+
+</deployment>




More information about the jboss-cvs-commits mailing list