On Apr 12, 2005 9:32 AM, Nacho G. Mac Dowell <[EMAIL PROTECTED]> wrote:

> class EnumerationSG
> 
>   public TypedValue getCastFromString(SimpleTypeSG pController, String
> pValue) throws SAXException {
>     for (int i = 0;  i < values.length;  i++) {
>       if (values[i].getValue().equals(pValue)) {
>         return new TypedValueImpl(qName + "." +values[i].getName(), qName);
>       }
>     }
>     return super.getCastFromString(pController, pValue);
>   }?

It *creates* a TypedValue, because the API forces it doing so. It
doesn't use it.


> If I didn't get it wrong, at the moment including TypedValue as an
> embeddable Java Source produces wrong output because it expects a full
> blown java string. IMHO if the responsability for generating a correct
> TypedValue is for the SG then I don't understand the need for
> TypedValue. How would it then be used?

As I said, the TypedValue isn't used in the classes generating static
content, like
enumerations, or default values. A typical use case is for the
ArrayPropertySG. Suggest
the following element definition:

    <xs:element name="foo" type="xs:int" maxOccurs="unbounded"/>

Suggest the code, which converts the string value "5" into an int and
adds the value to
an internal list. This code could look like the following:

    String sValue = "5";
    TypedValue value = simpleTypeSG.getCastFromString(jm, sValue, pData);
    if (value.getType().isPrimitive()) {
        value = ...; // Code that converts the primitive into an object
     }
     jm.addLine(field, ".add(", value, ");");

I am, of course, simplifying a little bit. For example, because the
Unmarshaller doesn't
access the internal list. However, in general that's how things look.




> If needed, wouldn't it be better to use the static methods of
> DataTypeConverter rather than creating a new one if it doesn't come as
> the last parameter?

The last parameter is, in essence, JMUnmarshaller.getDatatypeConverter(). We
*must* use that datatype converter, because the user may supply his own.


> Sorry if I'm asking too many questions, it's just that I'd like to see
> this feature done (plus help on this release ;-) ).

I'm glad you're asking. :-)

As for JAXME-47, I would think that it can be solved by implementing
UnionTypeSG.getCastFromString(pController, pValue) like this:

    for (int i = 0;  i < listOfInternalTypes.length;  i++) {
        try { return listOfInternalTypes[i].getCastFromString((pValue); }
        catch (Throwable ignore) {}
    }
    throw new IllegalArgumentException("Unable to convert value: " + pValue);


-- 
Outside of a dog, a book is man's best friend.
Inside of a dog, its too dark to read.
(Groucho Marx)

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to