[jboss-svn-commits] JBoss Common SVN: r3361 - in jbossxb/trunk/src: main/java/org/jboss/xb/builder and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 9 18:07:49 EDT 2009


Author: alex.loubyansky at jboss.com
Date: 2009-07-09 18:07:49 -0400 (Thu, 09 Jul 2009)
New Revision: 3361

Added:
   jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlTransient.java
   jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlTransients.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/Base.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/ExtendedBase.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/ExtendedJBossObject.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/package-info.java
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/test/
   jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/test/JBossXmlTransientTypeAndPropertiesUnitTestCase.java
Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
Log:
prototyping JBossXmlTransient(s) on package level

Added: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlTransient.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlTransient.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlTransient.java	2009-07-09 22:07:49 UTC (rev 3361)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A JBossXmlTransient.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at Target(ElementType.PACKAGE)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface JBossXmlTransient
+{
+   Class<?> type();
+   
+   String[] properties() default {};
+}

Added: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlTransients.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlTransients.java	                        (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlTransients.java	2009-07-09 22:07:49 UTC (rev 3361)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A JBossXmlTransients.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at Target(ElementType.PACKAGE)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface JBossXmlTransients
+{
+   JBossXmlTransient[] value();
+}

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java	2009-07-09 13:16:22 UTC (rev 3360)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java	2009-07-09 22:07:49 UTC (rev 3361)
@@ -63,6 +63,7 @@
 import org.jboss.reflect.spi.ArrayInfo;
 import org.jboss.reflect.spi.ClassInfo;
 import org.jboss.reflect.spi.EnumInfo;
+import org.jboss.reflect.spi.FieldInfo;
 import org.jboss.reflect.spi.MethodInfo;
 import org.jboss.reflect.spi.PackageInfo;
 import org.jboss.reflect.spi.TypeInfo;
@@ -88,6 +89,8 @@
 import org.jboss.xb.annotations.JBossXmlNsPrefix;
 import org.jboss.xb.annotations.JBossXmlPreserveWhitespace;
 import org.jboss.xb.annotations.JBossXmlSchema;
+import org.jboss.xb.annotations.JBossXmlTransient;
+import org.jboss.xb.annotations.JBossXmlTransients;
 import org.jboss.xb.annotations.JBossXmlType;
 import org.jboss.xb.annotations.JBossXmlValue;
 import org.jboss.xb.binding.JBossXBRuntimeException;
@@ -179,6 +182,9 @@
    
    private boolean useUnorderedSequence;
    private boolean sequencesRequirePropOrder;
+
+   /** transient property names by type name */
+   private Map<String, Set<String>> jbossXmlTransients = Collections.emptyMap();
    
    /**
     * Create a new JBossXBNoSchemaBuilder.
@@ -309,6 +315,33 @@
          JBossXmlAdaptedType adaptedType = packageInfo.getUnderlyingAnnotation(JBossXmlAdaptedType.class);
          if (adaptedType != null)
             generateAdaptedType(adaptedType);
+         
+         JBossXmlTransient[] xmlTransients = null;
+         JBossXmlTransients transientsAnnotation = packageInfo.getUnderlyingAnnotation(JBossXmlTransients.class);
+         if(transientsAnnotation == null)
+         {
+            JBossXmlTransient transientAnnotation = packageInfo.getUnderlyingAnnotation(JBossXmlTransient.class);
+            if(transientAnnotation != null)
+               xmlTransients = new JBossXmlTransient[]{transientAnnotation};
+         }
+         else
+            xmlTransients = transientsAnnotation.value();
+
+         if(xmlTransients != null)
+         {
+            jbossXmlTransients = new HashMap<String, Set<String>>();
+            for(JBossXmlTransient xmlTransient : xmlTransients)
+            {
+               Set<String> properties;
+               if(xmlTransient.properties().length == 0)
+                  properties = Collections.emptySet();
+               else
+                  properties= new HashSet<String>(Arrays.asList(xmlTransient.properties()));
+               jbossXmlTransients.put(xmlTransient.type().getName(), properties);
+               if(trace)
+                  log.trace("JBossXmlTransient type=" + xmlTransient.type().getName() + ", properties=" + properties);
+            }
+         }
       }
    }
 
@@ -1007,6 +1040,34 @@
                   continue;
                }
 
+               ClassInfo declaringClass;
+               MethodInfo methodInfo = property.getGetter();
+               if(methodInfo == null)
+               {
+                  FieldInfo fieldInfo = property.getFieldInfo();
+                  if(fieldInfo == null)
+                  {
+                     methodInfo = property.getSetter();
+                     if(methodInfo == null)
+                        throw new JBossXBRuntimeException("Couldn't get access to getter, setter or field info for type=" + beanInfo.getName() + " property=" + property.getName());
+                     else
+                        declaringClass = methodInfo.getDeclaringClass();
+                  }
+                  else
+                     declaringClass = fieldInfo.getDeclaringClass();
+               }
+               else
+                  declaringClass = methodInfo.getDeclaringClass();
+               
+               Set<String> transientProps = jbossXmlTransients.get(declaringClass.getName());
+               if(transientProps != null && (transientProps.isEmpty() || transientProps.contains(property.getName())))
+               {
+                  if(trace)
+                     log.trace("Ignore JBossXmlTransient property for type=" + beanInfo.getName() + " property=" + property.getName());
+                  pop();
+                  continue;
+               }
+
                if (trace)
                   log.trace("Element for type=" + beanInfo.getName() + " property=" + property.getName());
                propertyNames.add(property.getName());

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/Base.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/Base.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/Base.java	2009-07-09 22:07:49 UTC (rev 3361)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.xb.builder.object.jbossxmltransient.support;
+
+/**
+ * A Base.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class Base
+{
+   private String a;
+   private String b;
+   
+   public String getA()
+   {
+      return a;
+   }
+   
+   public void setA(String a)
+   {
+      this.a = a;
+   }
+   
+   public String getB()
+   {
+      return b;
+   }
+   
+   public void setB(String b)
+   {
+      this.b = b;
+   }
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/ExtendedBase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/ExtendedBase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/ExtendedBase.java	2009-07-09 22:07:49 UTC (rev 3361)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.xb.builder.object.jbossxmltransient.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * A ExtendedB.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+ at XmlType(propOrder={})
+public class ExtendedBase extends Base
+{
+
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/ExtendedJBossObject.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/ExtendedJBossObject.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/ExtendedJBossObject.java	2009-07-09 22:07:49 UTC (rev 3361)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.xb.builder.object.jbossxmltransient.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.util.JBossObject;
+
+/**
+ * A Root.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+public class ExtendedJBossObject extends JBossObject
+{
+
+}

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/package-info.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/package-info.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/support/package-info.java	2009-07-09 22:07:49 UTC (rev 3361)
@@ -0,0 +1,32 @@
+/*
+* 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.
+*/
+ at JBossXmlTransients({
+   // mark specific property in the type as transient
+   @JBossXmlTransient(type = JBossObject.class, properties={"classShortName"}),
+   // not specifying properties will make them all transient in the type
+   @JBossXmlTransient(type = Base.class)
+})
+package org.jboss.test.xb.builder.object.jbossxmltransient.support;
+
+import org.jboss.util.JBossObject;
+import org.jboss.xb.annotations.JBossXmlTransient;import org.jboss.xb.annotations.JBossXmlTransients;
+

Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/test/JBossXmlTransientTypeAndPropertiesUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/test/JBossXmlTransientTypeAndPropertiesUnitTestCase.java	                        (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmltransient/test/JBossXmlTransientTypeAndPropertiesUnitTestCase.java	2009-07-09 22:07:49 UTC (rev 3361)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.xb.builder.object.jbossxmltransient.test;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.builder.object.jbossxmltransient.support.ExtendedBase;
+import org.jboss.test.xb.builder.object.jbossxmltransient.support.ExtendedJBossObject;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ModelGroupBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.builder.JBossXBBuilder;
+
+/**
+ * A JBossXmlTransientTypeAndPropertiesUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossXmlTransientTypeAndPropertiesUnitTestCase extends AbstractBuilderTest
+{
+   public JBossXmlTransientTypeAndPropertiesUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testExtendedJBossObject() throws Exception
+   {
+      SchemaBinding schema = JBossXBBuilder.build(ExtendedJBossObject.class, true);
+      ElementBinding root = schema.getElement(new QName("root"));
+      assertNotNull(root);
+      ParticleBinding particle = root.getType().getParticle();
+      assertNotNull(particle);
+      ModelGroupBinding group = (ModelGroupBinding) particle.getTerm();
+      assertTrue(group.getParticles().isEmpty());
+   }
+   
+   public void testAllProperties() throws Exception
+   {
+      SchemaBinding schema = JBossXBBuilder.build(ExtendedBase.class, true);
+      ElementBinding root = schema.getElement(new QName("root"));
+      assertNotNull(root);
+      ParticleBinding particle = root.getType().getParticle();
+      assertNotNull(particle);
+      ModelGroupBinding group = (ModelGroupBinding) particle.getTerm();
+      assertTrue(group.getParticles().isEmpty());
+   }
+}




More information about the jboss-svn-commits mailing list