You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by "Nacho G. Mac Dowell (JIRA)" <ja...@ws.apache.org> on 2005/01/14 12:45:20 UTC

[jira] Created: (JAXME-47) When using default values initialization of vars doesn't work for all types

When using default values initialization of vars doesn't work for all types
---------------------------------------------------------------------------

         Key: JAXME-47
         URL: http://issues.apache.org/jira/browse/JAXME-47
     Project: JaxMe
        Type: Bug
  Components: JaxMe Core  
    Reporter: Nacho G. Mac Dowell


Consider the definition of the following element:

    <element name="elt">
        <complexType>
            <attribute name="a" default="1" type="decimal" />
            <attribute name="b" default="0" type="hexBinary" />
            <attribute name="c" default="none">
                <simpleType>
                    <union>
                        <simpleType>
                            <restriction base="NMTOKEN"/>
                        </simpleType>
                        <simpleType>
                            <restriction base="anyURI" />
                        </simpleType>
                    </union>
                </simpleType>
            </attribute>
            <attribute name="d" default="1" type="integer" />
            <attribute name="e" default="-1" type="nonPositiveInteger" />
            <attribute name="f" default="1" type="positiveInteger" />
            <attribute name="g" default="1" type="unsignedLong" />
        </complexType>
    </element>

When compiling the schema we get the following result:

  private java.math.BigDecimal A = 1;
  private byte[] B = 01;
  private java.lang.Object C = none;
  private java.math.BigInteger D = 1;
  private java.math.BigInteger E = -1;
  private java.math.BigInteger F = 1;
  private java.math.BigInteger G = 1;

having multiple compile errors.

Further investigation is required to determine exactly all cases.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


[jira] Commented: (JAXME-47) When using default values initialization of vars doesn't work for all types

Posted by "Nacho G. Mac Dowell (JIRA)" <ja...@ws.apache.org>.
     [ http://issues.apache.org/jira/browse/JAXME-47?page=comments#action_57715 ]
     
Nacho G. Mac Dowell commented on JAXME-47:
------------------------------------------

I noticed that the example I used for describing this bug still doesn't compile properly because of the hexBinary type. We could add a method to DataTypeConverterUtils like this:

public String transformArray(String className, String singleCast) {
   return "new " + className + "[]{" + actual + "}";
}

The previous comment was a bit confusing and so much code wasn't needed. The main routine would be (taking that pClass is the class we want to cast to):

final Method[] methods = DatatypeConverter.class.getMethods();
for (int i = 0; i < methods.length; i++) {
  if (methods[i].getName().startsWith("parse")
    && methods[i].getReturnType().equals(pClass)) {
      dataTypeConverter = DatatypeConverter.class.getName() + "."
      + methods[i].getName() + "(\"" + pDefaultValue + "\")";
  }
}

> When using default values initialization of vars doesn't work for all types
> ---------------------------------------------------------------------------
>
>          Key: JAXME-47
>          URL: http://issues.apache.org/jira/browse/JAXME-47
>      Project: JaxMe
>         Type: Bug
>   Components: JaxMe Core
>     Reporter: Nacho G. Mac Dowell

>
> Consider the definition of the following element:
>     <element name="elt">
>         <complexType>
>             <attribute name="a" default="1" type="decimal" />
>             <attribute name="b" default="0" type="hexBinary" />
>             <attribute name="c" default="none">
>                 <simpleType>
>                     <union>
>                         <simpleType>
>                             <restriction base="NMTOKEN"/>
>                         </simpleType>
>                         <simpleType>
>                             <restriction base="anyURI" />
>                         </simpleType>
>                     </union>
>                 </simpleType>
>             </attribute>
>             <attribute name="d" default="1" type="integer" />
>             <attribute name="e" default="-1" type="nonPositiveInteger" />
>             <attribute name="f" default="1" type="positiveInteger" />
>             <attribute name="g" default="1" type="unsignedLong" />
>         </complexType>
>     </element>
> When compiling the schema we get the following result:
>   private java.math.BigDecimal A = 1;
>   private byte[] B = 01;
>   private java.lang.Object C = none;
>   private java.math.BigInteger D = 1;
>   private java.math.BigInteger E = -1;
>   private java.math.BigInteger F = 1;
>   private java.math.BigInteger G = 1;
> having multiple compile errors.
> Further investigation is required to determine exactly all cases.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


[jira] Commented: (JAXME-47) When using default values initialization of vars doesn't work for all types

Posted by "Nacho G. Mac Dowell (JIRA)" <ja...@ws.apache.org>.
     [ http://issues.apache.org/jira/browse/JAXME-47?page=comments#action_57621 ]
     
Nacho G. Mac Dowell commented on JAXME-47:
------------------------------------------

This error can be solved adding a few more cases to getXMLField when it is a simpleType (I forgot to add this in the bug description...) like this:

if (!pController.isComplex()) {
        Object o = pController.getSimpleTypeSG().getInitialValue(pSource);
        if (o == null && pDefaultValue != null) {
          if (runtimeType.equals(StringSG.STRING_TYPE)) {
            o = "\"" + pDefaultValue + "\"";
          }
          else if (runtimeType.equals(IntegerSG.INTEGER_TYPE)) {
            o = "new java.math.BigInteger(\"" + pDefaultValue + "\")";
          }
(......DecimalSG...)
          else {
            o = pDefaultValue;
          }
        }
        if (o != null) {
          jf.addLine(o);
        }
      }

The thing is that I don't know how to initialize it when its runtimeType is Object (for example for the union type where it is not always possible to "solve" the runtimeType). If the type couldn't be deduced then it would probably be safe to consider it as a String. What do you think?

I have a proposal though: Would it be possible for the JS framework to be able to "initialize" a new field according to its type? I think this would be much clearer and IMHO it would enhance JS.

Another thought I had is that it would be nice if there was a properties file (or whatever) which maps xs to java object just to keep everything more compact (and easier to find...). Truly I don't know how this could be 
acheived or if it would be useful at all. Just a thought.

Regards,

Nacho



> When using default values initialization of vars doesn't work for all types
> ---------------------------------------------------------------------------
>
>          Key: JAXME-47
>          URL: http://issues.apache.org/jira/browse/JAXME-47
>      Project: JaxMe
>         Type: Bug
>   Components: JaxMe Core
>     Reporter: Nacho G. Mac Dowell

>
> Consider the definition of the following element:
>     <element name="elt">
>         <complexType>
>             <attribute name="a" default="1" type="decimal" />
>             <attribute name="b" default="0" type="hexBinary" />
>             <attribute name="c" default="none">
>                 <simpleType>
>                     <union>
>                         <simpleType>
>                             <restriction base="NMTOKEN"/>
>                         </simpleType>
>                         <simpleType>
>                             <restriction base="anyURI" />
>                         </simpleType>
>                     </union>
>                 </simpleType>
>             </attribute>
>             <attribute name="d" default="1" type="integer" />
>             <attribute name="e" default="-1" type="nonPositiveInteger" />
>             <attribute name="f" default="1" type="positiveInteger" />
>             <attribute name="g" default="1" type="unsignedLong" />
>         </complexType>
>     </element>
> When compiling the schema we get the following result:
>   private java.math.BigDecimal A = 1;
>   private byte[] B = 01;
>   private java.lang.Object C = none;
>   private java.math.BigInteger D = 1;
>   private java.math.BigInteger E = -1;
>   private java.math.BigInteger F = 1;
>   private java.math.BigInteger G = 1;
> having multiple compile errors.
> Further investigation is required to determine exactly all cases.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


[jira] Updated: (JAXME-47) When using default values initialization of vars doesn't work for all types

Posted by "Nacho G. Mac Dowell (JIRA)" <ja...@ws.apache.org>.
     [ http://issues.apache.org/jira/browse/JAXME-47?page=all ]

Nacho G. Mac Dowell updated JAXME-47:
-------------------------------------

    Attachment: defaultValues.patch

Patch for default values handling.

> When using default values initialization of vars doesn't work for all types
> ---------------------------------------------------------------------------
>
>          Key: JAXME-47
>          URL: http://issues.apache.org/jira/browse/JAXME-47
>      Project: JaxMe
>         Type: Bug
>   Components: JaxMe Core
>     Reporter: Nacho G. Mac Dowell
>  Attachments: defaultValues.patch
>
> Consider the definition of the following element:
>     <element name="elt">
>         <complexType>
>             <attribute name="a" default="1" type="decimal" />
>             <attribute name="b" default="0" type="hexBinary" />
>             <attribute name="c" default="none">
>                 <simpleType>
>                     <union>
>                         <simpleType>
>                             <restriction base="NMTOKEN"/>
>                         </simpleType>
>                         <simpleType>
>                             <restriction base="anyURI" />
>                         </simpleType>
>                     </union>
>                 </simpleType>
>             </attribute>
>             <attribute name="d" default="1" type="integer" />
>             <attribute name="e" default="-1" type="nonPositiveInteger" />
>             <attribute name="f" default="1" type="positiveInteger" />
>             <attribute name="g" default="1" type="unsignedLong" />
>         </complexType>
>     </element>
> When compiling the schema we get the following result:
>   private java.math.BigDecimal A = 1;
>   private byte[] B = 01;
>   private java.lang.Object C = none;
>   private java.math.BigInteger D = 1;
>   private java.math.BigInteger E = -1;
>   private java.math.BigInteger F = 1;
>   private java.math.BigInteger G = 1;
> having multiple compile errors.
> Further investigation is required to determine exactly all cases.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


[jira] Closed: (JAXME-47) When using default values initialization of vars doesn't work for all types

Posted by "Nacho G. Mac Dowell (JIRA)" <ja...@ws.apache.org>.
     [ http://issues.apache.org/jira/browse/JAXME-47?page=all ]
     
Nacho G. Mac Dowell closed JAXME-47:
------------------------------------


Applied patch on HEAD and v0_4.

> When using default values initialization of vars doesn't work for all types
> ---------------------------------------------------------------------------
>
>          Key: JAXME-47
>          URL: http://issues.apache.org/jira/browse/JAXME-47
>      Project: JaxMe
>         Type: Bug
>   Components: JaxMe Core
>     Reporter: Nacho G. Mac Dowell
>      Fix For: current (nightly)
>  Attachments: defaultValues.patch
>
> Consider the definition of the following element:
>     <element name="elt">
>         <complexType>
>             <attribute name="a" default="1" type="decimal" />
>             <attribute name="b" default="0" type="hexBinary" />
>             <attribute name="c" default="none">
>                 <simpleType>
>                     <union>
>                         <simpleType>
>                             <restriction base="NMTOKEN"/>
>                         </simpleType>
>                         <simpleType>
>                             <restriction base="anyURI" />
>                         </simpleType>
>                     </union>
>                 </simpleType>
>             </attribute>
>             <attribute name="d" default="1" type="integer" />
>             <attribute name="e" default="-1" type="nonPositiveInteger" />
>             <attribute name="f" default="1" type="positiveInteger" />
>             <attribute name="g" default="1" type="unsignedLong" />
>         </complexType>
>     </element>
> When compiling the schema we get the following result:
>   private java.math.BigDecimal A = 1;
>   private byte[] B = 01;
>   private java.lang.Object C = none;
>   private java.math.BigInteger D = 1;
>   private java.math.BigInteger E = -1;
>   private java.math.BigInteger F = 1;
>   private java.math.BigInteger G = 1;
> having multiple compile errors.
> Further investigation is required to determine exactly all cases.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


[jira] Resolved: (JAXME-47) When using default values initialization of vars doesn't work for all types

Posted by "Nacho G. Mac Dowell (JIRA)" <ja...@ws.apache.org>.
     [ http://issues.apache.org/jira/browse/JAXME-47?page=all ]
     
Nacho G. Mac Dowell resolved JAXME-47:
--------------------------------------

     Resolution: Fixed
    Fix Version: current (nightly)

Applied patch on HEAD and v0_4 20050417.

> When using default values initialization of vars doesn't work for all types
> ---------------------------------------------------------------------------
>
>          Key: JAXME-47
>          URL: http://issues.apache.org/jira/browse/JAXME-47
>      Project: JaxMe
>         Type: Bug
>   Components: JaxMe Core
>     Reporter: Nacho G. Mac Dowell
>      Fix For: current (nightly)
>  Attachments: defaultValues.patch
>
> Consider the definition of the following element:
>     <element name="elt">
>         <complexType>
>             <attribute name="a" default="1" type="decimal" />
>             <attribute name="b" default="0" type="hexBinary" />
>             <attribute name="c" default="none">
>                 <simpleType>
>                     <union>
>                         <simpleType>
>                             <restriction base="NMTOKEN"/>
>                         </simpleType>
>                         <simpleType>
>                             <restriction base="anyURI" />
>                         </simpleType>
>                     </union>
>                 </simpleType>
>             </attribute>
>             <attribute name="d" default="1" type="integer" />
>             <attribute name="e" default="-1" type="nonPositiveInteger" />
>             <attribute name="f" default="1" type="positiveInteger" />
>             <attribute name="g" default="1" type="unsignedLong" />
>         </complexType>
>     </element>
> When compiling the schema we get the following result:
>   private java.math.BigDecimal A = 1;
>   private byte[] B = 01;
>   private java.lang.Object C = none;
>   private java.math.BigInteger D = 1;
>   private java.math.BigInteger E = -1;
>   private java.math.BigInteger F = 1;
>   private java.math.BigInteger G = 1;
> having multiple compile errors.
> Further investigation is required to determine exactly all cases.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


[jira] Commented: (JAXME-47) When using default values initialization of vars doesn't work for all types

Posted by "Nacho G. Mac Dowell (JIRA)" <ja...@ws.apache.org>.
     [ http://issues.apache.org/jira/browse/JAXME-47?page=comments#action_57714 ]
     
Nacho G. Mac Dowell commented on JAXME-47:
------------------------------------------

If we make use of DataTypeConverter then we could easily provide a utility class that would gives us a String representation of the constructed default value. In other words, if runtimeType.getName() is BigInteger and pDefaultValue is "1" we want : javax.xml.bind.DatatypeConverter.parseInteger("1")

Let's take a look at a possible candidate:

import java.lang.reflect.Method;
import java.util.Hashtable;
import javax.xml.bind.DatatypeConverter;
import org.apache.ws.jaxme.js.JavaQName;

public class DataTypeConverterUtil {

  /**
   * Cache converters so we don't have to use reflection all the time.
   */
  private static final Hashtable cache = new Hashtable();

  /**
   * Returns a String representation of how to convert from a String
   * (pDefaultValue) to the provided JavaQName type. eg: it will return:
   * 
   * <code>javax.xml.bind.DatatypeConverter.parseInteger("1")</code>
   * 
   * if runtimeType.getName() is BigInteger and pDefaultValue is "1".
   * 
   * @param pRuntimeType
   *            the type
   * @param pDefaultValue
   *            the default value
   * @return a String representing the conversion
   */
  public static String getDataTypeConverter(JavaQName pRuntimeType,
      String pDefaultValue) {
    try {
      return getDataTypeConverter(Class.forName(pRuntimeType
          .getPackageName()
          + "." + pRuntimeType.getClassName()), pDefaultValue);
    } catch (ClassNotFoundException e) {
      //it is a simple type (or at least we hope so...)
      return pDefaultValue;
    }
  }

  /**
   * @see DataTypeConverterUtil#getDataTypeConverter(JavaQName, String)
   */
  public static String getDataTypeConverter(Class pClass, String pDefaultValue) {
    String dataTypeConverter = (String) cache.get(pClass);
    if (dataTypeConverter == null) {
      final Method[] methods = DatatypeConverter.class.getMethods();
      for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().startsWith("parse")
            && methods[i].getReturnType().equals(pClass)) {
          dataTypeConverter = DatatypeConverter.class.getName() + "."
              + methods[i].getName() + "(\"" + pDefaultValue
              + "\")";
        }
      }
      if (dataTypeConverter == null) {
        //it is most probably just an Object, let it be a String
        dataTypeConverter = "\"" + pDefaultValue + "\"";
      }
      cache.put(pClass.getName(), dataTypeConverter);
    }
    return dataTypeConverter;
  }
}

What do you think? Another good thing would be that the defaultValue is returned whenever the requested variable is null. This means that all vars are initialized to null and is the getter that checks if it is null. If it is, then return the cast. This is how RI works. This would require changing the signature of getXMLGetMethod and getXMLField in TypeSGChain so it is getXMLGetMethod which receives the default value.


> When using default values initialization of vars doesn't work for all types
> ---------------------------------------------------------------------------
>
>          Key: JAXME-47
>          URL: http://issues.apache.org/jira/browse/JAXME-47
>      Project: JaxMe
>         Type: Bug
>   Components: JaxMe Core
>     Reporter: Nacho G. Mac Dowell

>
> Consider the definition of the following element:
>     <element name="elt">
>         <complexType>
>             <attribute name="a" default="1" type="decimal" />
>             <attribute name="b" default="0" type="hexBinary" />
>             <attribute name="c" default="none">
>                 <simpleType>
>                     <union>
>                         <simpleType>
>                             <restriction base="NMTOKEN"/>
>                         </simpleType>
>                         <simpleType>
>                             <restriction base="anyURI" />
>                         </simpleType>
>                     </union>
>                 </simpleType>
>             </attribute>
>             <attribute name="d" default="1" type="integer" />
>             <attribute name="e" default="-1" type="nonPositiveInteger" />
>             <attribute name="f" default="1" type="positiveInteger" />
>             <attribute name="g" default="1" type="unsignedLong" />
>         </complexType>
>     </element>
> When compiling the schema we get the following result:
>   private java.math.BigDecimal A = 1;
>   private byte[] B = 01;
>   private java.lang.Object C = none;
>   private java.math.BigInteger D = 1;
>   private java.math.BigInteger E = -1;
>   private java.math.BigInteger F = 1;
>   private java.math.BigInteger G = 1;
> having multiple compile errors.
> Further investigation is required to determine exactly all cases.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


[jira] Commented: (JAXME-47) When using default values initialization of vars doesn't work for all types

Posted by "Jochen Wiedmann (JIRA)" <ja...@ws.apache.org>.
     [ http://issues.apache.org/jira/browse/JAXME-47?page=comments#action_57622 ]
     
Jochen Wiedmann commented on JAXME-47:
--------------------------------------

This is how a union converts a string at runtime: For any possible type, in the order specified by the schema, it attempts to convert the string into the requested type. If no exception occurs, then the result is taken. If an exception occurs, then the next possible type is attempted. Finally, an exception is thrown, if no type was successfull.

The UnionTypeSG does this, by invoking all the types in order and let them create code. The returned code is surrounded with exception handlers.

In other words, the right thing to do for default values is as follows: The UntionTypeSG should invoke the internal SG's in order and let them convert the string. The result of the first one, that produces no error, is taken. If they all throw errors, then the value is invalid.


> When using default values initialization of vars doesn't work for all types
> ---------------------------------------------------------------------------
>
>          Key: JAXME-47
>          URL: http://issues.apache.org/jira/browse/JAXME-47
>      Project: JaxMe
>         Type: Bug
>   Components: JaxMe Core
>     Reporter: Nacho G. Mac Dowell

>
> Consider the definition of the following element:
>     <element name="elt">
>         <complexType>
>             <attribute name="a" default="1" type="decimal" />
>             <attribute name="b" default="0" type="hexBinary" />
>             <attribute name="c" default="none">
>                 <simpleType>
>                     <union>
>                         <simpleType>
>                             <restriction base="NMTOKEN"/>
>                         </simpleType>
>                         <simpleType>
>                             <restriction base="anyURI" />
>                         </simpleType>
>                     </union>
>                 </simpleType>
>             </attribute>
>             <attribute name="d" default="1" type="integer" />
>             <attribute name="e" default="-1" type="nonPositiveInteger" />
>             <attribute name="f" default="1" type="positiveInteger" />
>             <attribute name="g" default="1" type="unsignedLong" />
>         </complexType>
>     </element>
> When compiling the schema we get the following result:
>   private java.math.BigDecimal A = 1;
>   private byte[] B = 01;
>   private java.lang.Object C = none;
>   private java.math.BigInteger D = 1;
>   private java.math.BigInteger E = -1;
>   private java.math.BigInteger F = 1;
>   private java.math.BigInteger G = 1;
> having multiple compile errors.
> Further investigation is required to determine exactly all cases.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org