[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jibx-cvs
Subject:    [Jibx-cvs] core/build/src/org/jibx/schema/codegen/custom
From:       Dennis Sosnoski <dsosnoski () users ! sourceforge ! net>
Date:       2009-04-16 11:39:09
Message-ID: E1LuPvx-0003UX-GE () fdv4jf1 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Update of /cvsroot/jibx/core/build/src/org/jibx/schema/codegen/custom
In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv13329/src/org/jibx/schema/codegen/custom


Modified Files:
	GlobalExtension.java SchemaRootBase.java SchemaExtension.java 
Log Message:
Added <schema-type> customization to allow overrides to the default handling of \
predefined schema datatypes.

Index: GlobalExtension.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/schema/codegen/custom/GlobalExtension.java,v
 retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** GlobalExtension.java	30 Mar 2009 11:19:59 -0000	1.13
--- GlobalExtension.java	16 Apr 2009 11:39:07 -0000	1.14
***************
*** 23,26 ****
--- 23,27 ----
  
  import java.util.ArrayList;
+ import java.util.Map;
  
  import org.apache.log4j.Logger;
***************
*** 78,81 ****
--- 79,91 ----
      
      /**
+      * Get map from schema type local name to type information.
+      *
+      * @return map
+      */
+     public Map getSchemaTypes() {
+         return m_schemaExtension.getSchemaTypes();
+     }
+     
+     /**
       * Get name converter used for this component.
       *

Index: SchemaExtension.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/schema/codegen/custom/SchemaExtension.java,v
 retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SchemaExtension.java	30 Mar 2009 11:19:59 -0000	1.2
--- SchemaExtension.java	16 Apr 2009 11:39:07 -0000	1.3
***************
*** 22,25 ****
--- 22,27 ----
  package org.jibx.schema.codegen.custom;
  
+ import java.util.Map;
+ 
  import org.jibx.schema.codegen.PackageHolder;
  import org.jibx.schema.codegen.extend.ClassDecorator;
***************
*** 37,40 ****
--- 39,45 ----
      private final SchemaCustom m_custom;
      
+     /** Map from schema type name to Java type information. */
+     private Map m_schemaTypes;
+     
      /** Name converter instance (<code>null</code> if none set at level). */
      private NameConverter m_nameConverter;
***************
*** 70,73 ****
--- 75,79 ----
      public SchemaExtension(SchemaElement schema, SchemaCustom custom, PackageHolder \
pack) {  super(schema);
+         m_schemaTypes = custom.getSchemaTypes();
          m_nameConverter = custom.getNameConverter();
          m_decorators = custom.getClassDecorators();
***************
*** 92,95 ****
--- 98,110 ----
      
      /**
+      * Get map from schema type local name to type information.
+      *
+      * @return map
+      */
+     public Map getSchemaTypes() {
+         return m_schemaTypes;
+     }
+     
+     /**
       * Get name converter used for this component.
       *

Index: SchemaRootBase.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/schema/codegen/custom/SchemaRootBase.java,v
 retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** SchemaRootBase.java	30 Mar 2009 11:19:59 -0000	1.21
--- SchemaRootBase.java	16 Apr 2009 11:39:07 -0000	1.22
***************
*** 30,37 ****
--- 30,39 ----
  
  import org.jibx.runtime.EnumSet;
+ import org.jibx.runtime.IAliasable;
  import org.jibx.runtime.IUnmarshaller;
  import org.jibx.runtime.IUnmarshallingContext;
  import org.jibx.runtime.JiBXException;
  import org.jibx.runtime.impl.UnmarshallingContext;
+ import org.jibx.schema.codegen.JavaType;
  import org.jibx.schema.codegen.extend.DefaultNameConverter;
  import org.jibx.schema.codegen.extend.ClassDecorator;
***************
*** 40,43 ****
--- 42,46 ----
  import org.jibx.schema.validation.ProblemLocation;
  import org.jibx.schema.validation.ValidationContext;
+ import org.jibx.util.ChainedMap;
  import org.jibx.util.ReflectionUtilities;
  import org.jibx.util.StringArray;
***************
*** 119,122 ****
--- 122,128 ----
      private Boolean m_structureOptional;
      
+     /** Map from schema type name to Java type information (lazy create, \
<code>null</code> if not used at level). */ +     private Map m_schemaTypes;
+     
      /** Name converter instance (<code>null</code> if none set at level). */
      private NameConverter m_nameConverter;
***************
*** 503,506 ****
--- 509,541 ----
  
      /**
+      * Add schema type handling override.
+      *
+      * @param type
+      */
+     private void addSchemaType(JavaType type) {
+         if (m_schemaTypes == null) {
+             m_schemaTypes = new ChainedMap(getSchemaTypes());
+         }
+         m_schemaTypes.put(type.getSchemaName(), type);
+     }
+ 
+     /**
+      * Get map from schema type local name to type information.
+      *
+      * @return map
+      */
+     Map getSchemaTypes() {
+         SchemaRootBase root = this;
+         while (root != null) {
+             if (root.m_schemaTypes != null) {
+                 return root.m_schemaTypes;
+             } else {
+                 root = root.getRootParent();
+             }
+         }
+         return JavaType.getTypeMap();
+     }
+     
+     /**
       * Set name converter to be used.
       *
***************
*** 515,519 ****
          m_nameConverter = nconv;
      }
!     
      /**
       * Get name converter.
--- 550,554 ----
          m_nameConverter = nconv;
      }
! 
      /**
       * Get name converter.
***************
*** 608,611 ****
--- 643,710 ----
  
      /**
+      * Unmarshaller for schema-type elements.
+      */
+     public static class SchemaTypeUnmarshaller implements IUnmarshaller
+     {
+         /** Actual element name used in binding. */
+         private static String ELEMENT_NAME = "schema-type";
+         
+         /** Enumeration of allowed attribute names */
+         public static final StringArray s_allowedAttributes = new StringArray(new \
String[] { "check-method", +             "deserializer", "format-name", "java-class", \
"serializer", "type-name" }); +         
+         /**
+          * Check for element present.
+          *
+          * @param ictx
+          * @return <code>true</code> if present, <code>false</code> if not
+          * @throws JiBXException on error
+          */
+         public boolean isPresent(IUnmarshallingContext ictx) throws JiBXException {
+             return ictx.isAt(null, ELEMENT_NAME);
+         }
+ 
+         /**
+          * Unmarshal instance of element.
+          *
+          * @param obj ignored (new instance always created)
+          * @param ictx
+          * @return unmarshalled instance
+          * @throws JiBXException on error
+          */
+         public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws \
JiBXException { +             
+             // position to start tag and create instance to unmarshal
+             ValidationContext vctx = (ValidationContext)ictx.getUserContext();
+             UnmarshallingContext ctx = (UnmarshallingContext)ictx;
+             ctx.parseToStartTag(null, ELEMENT_NAME);
+             
+             // accumulate attribute values for constructor
+             String check = ctx.attributeText(null, "check-method", null);
+             String dser = ctx.attributeText(null, "deserializer", null);
+             String format = ctx.attributeText(null, "format-name", null);
+             String jclas = ctx.attributeText(null, "java-class");
+             String ser = ctx.attributeText(null, "serializer", null);
+             String stype = ctx.attributeText(null, "type-name");
+             
+             // look through all attributes of current element
+             for (int i = 0; i < ctx.getAttributeCount(); i++) {
+                 
+                 // check if nonamespace attribute is in the allowed set
+                 String name = ctx.getAttributeName(i);
+                 if (ctx.getAttributeNamespace(i).length() == 0) {
+                     if (s_allowedAttributes.indexOf(name) < 0) {
+                         vctx.addWarning("Undefined attribute " + name, \
ctx.getStackTop()); +                     }
+                 }
+             }
+             
+             // skip content, and create and return object instance
+             ctx.skipElement();
+             return new JavaType(stype, null, jclas, format, ser, dser, check);
+         }
+     }
+ 
+     /**
       * Unmarshaller for extension elements. This expects to find a 'class' \
                attribute giving the name of the class to be
       * created, along with other attributes used to set properties on an instance \
of the class. The latter attributes


------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Jibx-cvs mailing list
Jibx-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic