xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r643633 - in /xmlbeans/trunk: src/configschema/schema/ src/typeimpl/org/apache/xmlbeans/impl/schema/ src/xmlconfig/org/apache/xmlbeans/impl/config/ src/xmlpublic/org/apache/xmlbeans/ test/src/compile/scomp/common/mockobj/
Date Tue, 01 Apr 2008 22:54:15 GMT
Author: radup
Date: Tue Apr  1 15:53:58 2008
New Revision: 643633

URL: http://svn.apache.org/viewvc?rev=643633&view=rev
Log:
Fix for XMLBEANS-253: added more fine-grained control over XML to Java name mapping.

Modified:
    xmlbeans/trunk/src/configschema/schema/xmlconfig.xsd
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscJavaizer.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
    xmlbeans/trunk/src/xmlconfig/org/apache/xmlbeans/impl/config/BindingConfigImpl.java
    xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/BindingConfig.java
    xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestBindingConfig.java

Modified: xmlbeans/trunk/src/configschema/schema/xmlconfig.xsd
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/configschema/schema/xmlconfig.xsd?rev=643633&r1=643632&r2=643633&view=diff
==============================================================================
--- xmlbeans/trunk/src/configschema/schema/xmlconfig.xsd (original)
+++ xmlbeans/trunk/src/configschema/schema/xmlconfig.xsd Tue Apr  1 15:53:58 2008
@@ -120,6 +120,19 @@
     <xs:sequence/>
     <xs:attribute name="name" type="xs:QName"/>
     <xs:attribute name="javaname" type="xs:string"/>
+    <xs:attribute name="target" type="xb:qnametargetlist" default="type document-type
accessor-element accessor-attribute">
+        <xs:annotation>
+            <xs:documentation>
+              Specified on what type of Schema component does the qname mapping apply:
+                - type - on global types with that QName and "local" types contained within
attributes/elements
+                  with the specified name
+                - document-type - on "document" types generated from global elements/attributes
with
+                  the specified name
+                - accessor-element - on getters/setters generated from elements with the
specified name
+                - accessor-attribute - on getters/setters generated from attributes with
the specified name
+            </xs:documentation>
+        </xs:annotation>
+    </xs:attribute>
   </xs:complexType>
 
   <xs:simpleType name="namespacePrefixList">
@@ -253,5 +266,18 @@
 
      <xs:simpleType name="javaName">
          <xs:restriction base="xs:token" />
+     </xs:simpleType>
+
+     <xs:simpleType name="qnametargetlist">
+         <xs:list itemType="xb:qnametargetenum"/>
+     </xs:simpleType>
+
+     <xs:simpleType name="qnametargetenum">
+         <xs:restriction base="xs:token">
+             <xs:enumeration value="type"/>
+             <xs:enumeration value="document-type"/>
+             <xs:enumeration value="accessor-element"/>
+             <xs:enumeration value="accessor-attribute"/>
+         </xs:restriction>
      </xs:simpleType>
 </xs:schema>

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscJavaizer.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscJavaizer.java?rev=643633&r1=643632&r2=643633&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscJavaizer.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscJavaizer.java Tue Apr
 1 15:53:58 2008
@@ -92,7 +92,8 @@
         {
             SchemaTypeImpl sImpl = (SchemaTypeImpl)i.next();
             QName topName = findTopName(sImpl);
-            String pickedName = state.getJavaname(topName);
+            String pickedName = state.getJavaname(topName, sImpl.isDocumentType() ?
+                BindingConfig.QNAME_DOCUMENT_TYPE : BindingConfig.QNAME_TYPE);
             if (sImpl.isUnjavaized())
             {
                 sImpl.setFullJavaName(pickFullJavaClassName(usedNames, findTopName(sImpl),
pickedName, sImpl.isDocumentType(), sImpl.isAttributeType()));
@@ -390,7 +391,7 @@
             {
                 QName qname = sImpl.getContainerField().getName();
                 localname = qname.getLocalPart();
-                javaname = state.getJavaname(sImpl.getContainerField().getName());
+                javaname = state.getJavaname(sImpl.getContainerField().getName(), BindingConfig.QNAME_TYPE);
             }
             else
             {
@@ -458,7 +459,9 @@
             String theName;
 
             if (baseProp == null)
-                theName = pickJavaPropertyName(usedNames, propQName.getLocalPart(), state.getJavaname(propQName));
+                theName = pickJavaPropertyName(usedNames, propQName.getLocalPart(),
+                    state.getJavaname(propQName, sImpl.isAttribute() ? BindingConfig.QNAME_ACCESSOR_ATTRIBUTE
:
+                    BindingConfig.QNAME_ACCESSOR_ELEMENT));
             else
                 theName = baseProp.getJavaPropertyName();
 

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java?rev=643633&r1=643632&r2=643633&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java Tue Apr  1
15:53:58 2008
@@ -660,11 +660,11 @@
     /**
      * Looks up configured java name for the given qname.
      */
-    public String getJavaname(QName qname)
+    public String getJavaname(QName qname, int kind)
     {
         if (_config == null)
             return null;
-        return _config.lookupJavanameForQName(qname);
+        return _config.lookupJavanameForQName(qname, kind);
     }
 
     /* SPELLINGS ======================================================*/

Modified: xmlbeans/trunk/src/xmlconfig/org/apache/xmlbeans/impl/config/BindingConfigImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/xmlconfig/org/apache/xmlbeans/impl/config/BindingConfigImpl.java?rev=643633&r1=643632&r2=643633&view=diff
==============================================================================
--- xmlbeans/trunk/src/xmlconfig/org/apache/xmlbeans/impl/config/BindingConfigImpl.java (original)
+++ xmlbeans/trunk/src/xmlconfig/org/apache/xmlbeans/impl/config/BindingConfigImpl.java Tue
Apr  1 15:53:58 2008
@@ -19,6 +19,7 @@
 import org.apache.xmlbeans.impl.xb.xmlconfig.Extensionconfig;
 import org.apache.xmlbeans.impl.xb.xmlconfig.Nsconfig;
 import org.apache.xmlbeans.impl.xb.xmlconfig.Qnameconfig;
+import org.apache.xmlbeans.impl.xb.xmlconfig.Qnametargetenum;
 import org.apache.xmlbeans.BindingConfig;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlError;
@@ -46,7 +47,10 @@
     private Map _packageMapByUriPrefix; // uri prefix -> package
     private Map _prefixMapByUriPrefix;  // uri prefix -> name prefix
     private Map _suffixMapByUriPrefix;  // uri prefix -> name suffix
-    private Map _qnameMap;
+    private Map _qnameTypeMap;
+    private Map _qnameDocTypeMap;
+    private Map _qnameElemMap;
+    private Map _qnameAttMap;
 
     private List _interfaceExtensions;
     private List _prePostExtensions;
@@ -59,7 +63,10 @@
         _packageMapByUriPrefix = Collections.EMPTY_MAP;
         _prefixMapByUriPrefix = Collections.EMPTY_MAP;
         _suffixMapByUriPrefix = Collections.EMPTY_MAP;
-        _qnameMap = Collections.EMPTY_MAP;
+        _qnameTypeMap = Collections.EMPTY_MAP;
+        _qnameDocTypeMap = Collections.EMPTY_MAP;
+        _qnameElemMap = Collections.EMPTY_MAP;
+        _qnameAttMap = Collections.EMPTY_MAP;
         _interfaceExtensions = new ArrayList();
         _prePostExtensions = new ArrayList();
     }
@@ -77,7 +84,10 @@
         _packageMapByUriPrefix = new LinkedHashMap();
         _prefixMapByUriPrefix = new LinkedHashMap();
         _suffixMapByUriPrefix = new LinkedHashMap();
-        _qnameMap = new LinkedHashMap();
+        _qnameTypeMap = new LinkedHashMap();
+        _qnameDocTypeMap = new LinkedHashMap();
+        _qnameElemMap = new LinkedHashMap();
+        _qnameAttMap = new LinkedHashMap();
         _interfaceExtensions = new ArrayList();
         _prePostExtensions = new ArrayList();
 
@@ -98,7 +108,28 @@
             Qnameconfig[] qnc = config.getQnameArray();
             for (int j = 0; j < qnc.length; j++)
             {
-                _qnameMap.put(qnc[j].getName(), qnc[j].getJavaname());
+                List applyto = qnc[j].xgetTarget().xgetListValue();
+                QName name = qnc[j].getName();
+                String javaname = qnc[j].getJavaname();
+                for (int k = 0; k < applyto.size(); k++)
+                {
+                    Qnametargetenum a = (Qnametargetenum) applyto.get(k);
+                    switch (a.enumValue().intValue())
+                    {
+                    case Qnametargetenum.INT_TYPE:
+                        _qnameTypeMap.put(name, javaname);
+                        break;
+                    case Qnametargetenum.INT_DOCUMENT_TYPE:
+                        _qnameDocTypeMap.put(name, javaname);
+                        break;
+                    case Qnametargetenum.INT_ACCESSOR_ELEMENT:
+                        _qnameElemMap.put(name, javaname);
+                        break;
+                    case Qnametargetenum.INT_ACCESSOR_ATTRIBUTE:
+                        _qnameAttMap.put(name, javaname);
+                        break;
+                    }
+                }
             }
 
             Extensionconfig[] ext = config.getExtensionArray();
@@ -312,9 +343,29 @@
         return lookup(_suffixMap, _suffixMapByUriPrefix, uri);
     }
 
+    /** @deprecated replaced with {@link #lookupJavanameForQName(QName, int)} */
     public String lookupJavanameForQName(QName qname)
     {
-        return (String)_qnameMap.get(qname);
+        String result = (String)_qnameTypeMap.get(qname);
+        if (result != null)
+            return result;
+        return (String)_qnameDocTypeMap.get(qname);
+    }
+
+    public String lookupJavanameForQName(QName qname, int kind)
+    {
+        switch (kind)
+        {
+        case QNAME_TYPE:
+            return (String)_qnameTypeMap.get(qname);
+        case QNAME_DOCUMENT_TYPE:
+            return (String)_qnameDocTypeMap.get(qname);
+        case QNAME_ACCESSOR_ELEMENT:
+            return (String)_qnameElemMap.get(qname);
+        case QNAME_ACCESSOR_ATTRIBUTE:
+            return (String)_qnameAttMap.get(qname);
+        }
+        return null;
     }
 
     public InterfaceExtension[] getInterfaceExtensions()

Modified: xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/BindingConfig.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/BindingConfig.java?rev=643633&r1=643632&r2=643633&view=diff
==============================================================================
--- xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/BindingConfig.java (original)
+++ xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/BindingConfig.java Tue Apr  1 15:53:58
2008
@@ -21,13 +21,18 @@
  * The BindingConfig class is used during compilation to control the generation of java source
files.
  * The default BindingConfig does nothing, but sub-classes should provide more interesting
behavior.
  *
- * @see {@link XmlBeans#compileXmlBeans(String, SchemaTypeSystem, XmlObject[], BindingConfig,
SchemaTypeLoader, Filer, XmlOptions) XmlBeans.compileXmlBeans()}
+ * @see XmlBeans#compileXmlBeans(String, SchemaTypeSystem, XmlObject[], BindingConfig, SchemaTypeLoader,
Filer, XmlOptions) XmlBeans.compileXmlBeans()
  */
 public class BindingConfig
 {
     private static final InterfaceExtension[] EMPTY_INTERFACE_EXT_ARRAY = new InterfaceExtension[0];
     private static final PrePostExtension[] EMPTY_PREPOST_EXT_ARRAY = new PrePostExtension[0];
 
+    public static final int QNAME_TYPE = 1;
+    public static final int QNAME_DOCUMENT_TYPE = 2;
+    public static final int QNAME_ACCESSOR_ELEMENT = 3;
+    public static final int QNAME_ACCESSOR_ATTRIBUTE = 4;
+
     /**
      * Get the package name for a namespace or null.
      */
@@ -45,8 +50,18 @@
 
     /**
      * Get the java name for a QName or null.
+     * @deprecated replaced with {@link #lookupJavanameForQName(QName, int)}
      */
     public String lookupJavanameForQName(QName qname) { return null; }
+
+    /**
+     * Get the java name for a QName of a specific component kind, or null.
+     * @see #QNAME_TYPE
+     * @see #QNAME_TYPE_DOCUMENT
+     * @see #QNAME_METHOD_ELEMENT
+     * @see #QNAME_METHOD_ATTRIBUTE
+     */
+    public String lookupJavanameForQName(QName qname, int kind) { return null; }
 
     /**
      * Returns all configured InterfaceExtensions or an empty array.

Modified: xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestBindingConfig.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestBindingConfig.java?rev=643633&r1=643632&r2=643633&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestBindingConfig.java (original)
+++ xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestBindingConfig.java Tue Apr  1
15:53:58 2008
@@ -120,11 +120,19 @@
         return bindingConfig.lookupSuffixForNamespace(s);
     }
 
+    /** @deprecated */
     public String lookupJavanameForQName(QName qName)
     {
         System.out.println("lookupJavanameForQName: "+qName);
         islookupJavanameForQName = true;
         return bindingConfig.lookupJavanameForQName(qName);
+    }
+
+    public String lookupJavanameForQName(QName qName, int kind)
+    {
+        System.out.println("lookupJavanameForQName: "+qName);
+        islookupJavanameForQName = true;
+        return bindingConfig.lookupJavanameForQName(qName, kind);
     }
 
     public InterfaceExtension[] getInterfaceExtensions()



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org


Mime
View raw message