[jboss-svn-commits] JBoss Common SVN: r2730 - jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Mar 7 04:14:27 EST 2008


Author: adrian at jboss.org
Date: 2008-03-07 04:14:27 -0500 (Fri, 07 Mar 2008)
New Revision: 2730

Added:
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/WrapperBeanAdapter.java
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/WrapperBeanAdapterFactory.java
Log:
[JBXB-128] - Add a WrapperBeanAdapter to support the @JBossXmlGroupText's wrapping of CDATA

Added: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/WrapperBeanAdapter.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/WrapperBeanAdapter.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/WrapperBeanAdapter.java	2008-03-07 09:14:27 UTC (rev 2730)
@@ -0,0 +1,83 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.xb.builder.runtime;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.xb.spi.BeanAdapter;
+
+/**
+ * WrapperBeanAdapter.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class WrapperBeanAdapter extends BeanAdapter
+{
+   /** The wrapped bean adapter */
+   private BeanAdapter wrapped;
+   
+   /** The not wrapped value */
+   private Object notWrapped;
+   
+   /**
+    * Create a new WrapperBeanAdapter.
+    * 
+    * @param beanAdapterFactory our factory
+    * @param wrapped the wrapped adapter
+    */
+   public WrapperBeanAdapter(WrapperBeanAdapterFactory beanAdapterFactory, BeanAdapter wrapped)
+   {
+      super(beanAdapterFactory);
+      this.wrapped = wrapped;
+   }
+
+   @Override
+   protected WrapperBeanAdapterFactory getBeanAdapterFactory()
+   {
+      return (WrapperBeanAdapterFactory) super.getBeanAdapterFactory();
+   }
+
+   @Override
+   public Object get(PropertyInfo propertyInfo) throws Throwable
+   {
+      return wrapped.get(propertyInfo);
+   }
+
+   @Override
+   public Object getValue()
+   {
+      if (notWrapped != null)
+         return notWrapped;
+      else
+         return wrapped.getValue();
+   }
+
+   @Override
+   public void set(PropertyInfo propertyInfo, Object child) throws Throwable
+   {
+      Class<?> stopWrapping = getBeanAdapterFactory().getStopWrapping(); 
+      if (child != null && stopWrapping != null && stopWrapping.isInstance(child))
+         notWrapped = child;
+      else
+         wrapped.set(propertyInfo, child);
+   }
+}

Added: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/WrapperBeanAdapterFactory.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/WrapperBeanAdapterFactory.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/WrapperBeanAdapterFactory.java	2008-03-07 09:14:27 UTC (rev 2730)
@@ -0,0 +1,109 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.xb.builder.runtime;
+
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.xb.spi.BeanAdapter;
+import org.jboss.xb.spi.BeanAdapterFactory;
+
+/**
+ * WrapperBeanAdapterFactory.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class WrapperBeanAdapterFactory extends BeanAdapterFactory
+{
+   /** The wrapped bean adapter factory */
+   private BeanAdapterFactory wrapped;
+   
+   /** The type to stop wrapping at */
+   private Class<?> stopWrapping;
+   
+   /**
+    * Create a new WrapperBeanAdapterFactory.
+    * 
+    * @param wrapped the wrapped factory
+    * @param stopWrapping the stop wrapping type
+    */
+   public WrapperBeanAdapterFactory(BeanAdapterFactory wrapped, Class<?> stopWrapping)
+   {
+      this.wrapped = wrapped;
+      this.stopWrapping = stopWrapping;
+   }
+
+   /**
+    * The type to stop wrapping at
+    * 
+    * @return the stop wrapping type
+    */
+   public Class<?> getStopWrapping()
+   {
+      return stopWrapping;
+   }
+
+   @Override
+   public WrapperBeanAdapter newInstance()
+   {
+      BeanAdapter adapter = wrapped.newInstance();
+      return new WrapperBeanAdapter(this, adapter);
+   }
+
+   @Override
+   public void addProperty(QName name, AbstractPropertyHandler propertyHandler)
+   {
+      throw new UnsupportedOperationException("addProperty");
+   }
+
+   @Override
+   public String getAvailable()
+   {
+      return wrapped.getAvailable();
+   }
+
+   @Override
+   public Map<QName, AbstractPropertyHandler> getProperties()
+   {
+      return wrapped.getProperties();
+   }
+
+   @Override
+   public AbstractPropertyHandler getPropertyHandler(QName name)
+   {
+      return wrapped.getPropertyHandler(name);
+   }
+
+   @Override
+   public AbstractPropertyHandler getWildcardHandler()
+   {
+      return wrapped.getWildcardHandler();
+   }
+
+   @Override
+   public void setWildcardHandler(AbstractPropertyHandler wildcardHandler)
+   {
+      throw new UnsupportedOperationException("addProperty");
+   }
+}




More information about the jboss-svn-commits mailing list