Scott,

read the error message. It says it all.

A field is required, and you didn't set it.

 - Godmar


On Mon, Jul 7, 2008 at 9:31 AM, Scott Purcell
<[EMAIL PROTECTED]> wrote:
>
> Thanks for the info, still trying to get my head around this.
>
> The actual example I am working with is the "invoice.xsd" that is included
> in the source. < found here:
> http://www.castor.org/srcgen-example.html#Running-the-XML-code-generator> It
> was analogous to what I am trying to achieve. So I took the invoice.xsd and
> simply ran source generator command like so:
> <
>
> java -cp %CP% org.exolab.castor.builder.SourceGeneratorMain -i invoice.xsd
> -package test
>
>
>
>
> That command created java files for each of the complex types and a
> directory named "descriptors" which also have java files in there.
>
> Could someone explain the difference between the src and the descriptors?
> What is each of their jobs? This is my first run with XML to java binding.
>
> Secondly, I decided to try and marshall this, so I created a Invoice item,
> and added ShipTo, Customer, Item, ItemAttributes, etc. objects to the
> invoice in an attempt to marshall the data like so: (see test class), but I
> am unable to get the "duration" to work. I get errors like so:
> see (error below).
>
> // test class
>    public static void main(String[] args) {
>
>
>         Item item = new Item();
>         item.setQuantity(100000);
>         item.setId("1");
>         item.setInStock(false);
>         item.setCategory("my_category");
>         item.setPrice(new BigDecimal("100.00"));
>
>         Address address = new Address();
>         address.setCity("my_city");
>         address.setState("MO");
>         address.setStreet1("76777777 mockingbird");
>         address.setStreet2("other street");
>         address.setZipCode("77779");
>
>         Customer customer = new Customer();
>         customer.setName("Scott");
>         customer.setPhone("300-300-3333");
>         customer.setAddress(address);
>
>         ShipTo shipto = new ShipTo();
>         shipto.setCustomer(customer);
>
>         ShippingMethod shipmethod = new ShippingMethod();
>         shipmethod.setCarrier("carrier");
>         shipmethod.setOption("UPS");
>
>         Invoice inv = new Invoice();
>         inv.setShippingMethod(shipmethod);
>         inv.setShipTo(shipto);
>         inv.addItem(item);
>
>
>         try {
>             FileWriter writer = new FileWriter("invoice.xml");
>             Marshaller.marshal(inv, writer);
>         } catch (Exception e) {
>             System.err.println(e.getMessage());
>             e.printStackTrace(System.err);
>         }
>     }
>
>
>
> error:
> The following exception occured while validating field: _shippingMethod of
> class: com.Invoice: The field '_estimatedDelivery' (whose xml name is
> 'estimated-delivery') is a required field of class 'com.ShippingMethod
> ValidationException: The following exception occured while validating field:
> _shippingMethod of class: com.Invoice: The field '_estimatedDelivery' (whose
> xml name is 'estimated-delivery') is a required field of class
> 'com.ShippingMethod;
>    - location of error: XPATH: /invoice
> The field '_estimatedDelivery' (whose xml name is 'estimated-delivery') is a
> required field of class 'com.ShippingMethod
>         at
> org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:278)
>         at
> org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1065)
>         at org.exolab.castor.xml.Validator.validate(Validator.java:135)
>         at org.exolab.castor.xml.Marshaller.validate(Marshaller.java:2594)
>         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:826)
>         at
> org.exolab.castor.xml.Marshaller.staticMarshal(Marshaller.java:798)
>         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:727)
>         at com.ExerciseInvoice.main(ExerciseInvoice.java:58)
> Caused by: ValidationException: The field '_estimatedDelivery' (whose xml
> name is 'estimated-delivery') is a required field of class
> 'com.ShippingMethod;
>    - location of error: XPATH: /shipping-method
>         at
> org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:210)
>         at
> org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1065)
>         at org.exolab.castor.xml.Validator.validate(Validator.java:135)
>         at
> org.exolab.castor.xml.FieldValidator.validateInstance(FieldValidator.java:326)
>         at
> org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:271)
>         ... 7 more
> Caused by: ValidationException: The field '_estimatedDelivery' (whose xml
> name is 'estimated-delivery') is a required field of class
> 'com.ShippingMethod;
>    - location of error: XPATH: /shipping-method
>         at
> org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:210)
>         at
> org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1065)
>         at org.exolab.castor.xml.Validator.validate(Validator.java:135)
>         at
> org.exolab.castor.xml.FieldValidator.validateInstance(FieldValidator.java:326)
>         at
> org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:271)
>         at
> org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1065)
>         at org.exolab.castor.xml.Validator.validate(Validator.java:135)
>         at org.exolab.castor.xml.Marshaller.validate(Marshaller.java:2594)
>         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:826)
>         at
> org.exolab.castor.xml.Marshaller.staticMarshal(Marshaller.java:798)
>         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:727)
>         at com.ExerciseInvoice.main(ExerciseInvoice.java:58)
>
>
> Any help???
> Thanks,
> Scott
>
>
>
>
> Werner Guttmann <[EMAIL PROTECTED]>
>
> 07/04/2008 02:15 AM
>
> Please respond to
> [email protected]
> To
> [email protected]
> cc
> Subject
> Re: [castor-user] How to Populate Binding Objects
>
>
>
>
> Scott,
>
> Scott Purcell wrote:
>> Hello,
>>
>> I have created a XSD document with many complex types, and have used the
>> XML Code generator (SourceGeneratorMain) to create java binding files.
>> This is all good and works well.
> Hmm ... let me try to understand one thing here. When you have used the
> XML code generator, you have turned off creastion of descriptor classes
> and turned on creation of a mapping file, correct ? If that's the case,
> why ? It should be the other way around. See below .....
>
> Please note, that a binding file is something completely different.
> The term 'binding file' is used in the context of code generation to
> overcome naming collisions.
>
>>
>> Now, I need to somehow (this is where my question lies) "instantiate" the
>> binding files, populate them, and then marshal the objects to XML. I am
>> not sure how this is accomplished? Could someone give me some insight as
>> to how this works?
>>
>> My workflow will be like so:
>> Once the binding files are created (which they are) I have the need to
>> instantiate the objects, populate them with different data and then
>> marshall the data to xml.
>
> Assuming that you have generated source code (including descriptor
> classes, that is) from your XML schema, here's what you have to do to
> marshal an object instance to XML.
>
> <code>
> XMLContext context = new XMLContext();
>
> Marsdaller marshaller = context.createMarshaller();
>
> YourObject yourObject = .... ;
>
> marshaller.marshal(yourObject);
> </code>
>
> If (and only if) you have the descriptor classes on your classpath,
> Castor will just marshal XML according to your definitions in your XMl
> schema.
>
> Does this make sense ?
>
> Werner
>>
>> Thanks,
>> Scott
>>
>>
>>
>>
>>
>> CONFIDENTIALITY NOTICE
>> This e-mail message and any attachments are only for the use of the
>> intended recipient and may contain information that is privileged,
>> confidential or exempt from disclosure under applicable law. If you are not
>> the intended recipient, any disclosure, distribution or other use of this
>> e-mail message or attachments is prohibited. If you have received this
>> e-mail message in error, please delete and notify the sender immediately.
>> Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
>
>
>
> CONFIDENTIALITY NOTICE
> This e-mail message and any attachments are only for the use of the intended
> recipient and may contain information that is privileged, confidential or
> exempt from disclosure under applicable law. If you are not the intended
> recipient, any disclosure, distribution or other use of this e-mail message
> or attachments is prohibited. If you have received this e-mail message in
> error, please delete and notify the sender immediately. Thank you.
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to