Hi All Castor User,

I am very new to castor. I want to find out mapping for the following
requirement.

I have one class, for e.g Vehicle.

public class Vehicle {

    private Date purchaseDate;
    private String id;
    private List<VehicleType<?>> vehicleTypes;
}

VehicleType is an abstract class.

public abstract class VehicleType<T> {
private T type;

public T getType() {
        return type;
    }

    public void setType(T type) {
        this.type = type;
    }
}

There are many classes, for e.g

TruckType extends VehicleType<Truck> {
public Truck getType() {
        return super.getType() ;
    }
}

CarType extends VehicleType<Car> {
public Car getType() {
        return super.getType() ;
    }
}

BusType extends VehicleType<Bus> {
public Bus getType() {
        return super.getType() ;
    }
}

XSD file is as following

<xsd:complexType name=" Vehicle">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="truck-type" type="vehicleType" minOccurs="0"
maxOccurs="unbounded"/>
            <xsd:element name="car-type" type="vehicleType" minOccurs="0"
maxOccurs="unbounded"/>
            <xsd:element name="bus-type" type="vehicleType" minOccurs="0"
maxOccurs="unbounded"/>
        </xsd:choice>
        <xsd:attribute name="puchaseDate" type="xsd:date" use="required"/>
        <xsd:attribute name="id" type="xsd:string" use="required"/>
    </xsd:complexType>

    <xsd:complexType name="vehicleType">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
       .............
        </xsd:choice>
        <xsd:attribute name="id" type="xsd:string" use="required"/>
        <xsd:attribute name="type-id" type="xsd:string" use="required"/>
    </xsd:complexType>

XML will looked like

<Vehicle  id = "xyz" purchase-date="2009-12-23">
     <truck-type id="abc" type-id = "pqr">
      .........
      </truck-type>
     <car-type id="abc" type-id = "pqr">
       .........
      </car-type>
     <bus-type id="abc" type-id = "pqr">
       .........
      </bus-type>
</Vehicle>

Or
<Vehicle  id = "xyz" purchase-date="2009-12-23">
     <truck-type id="abc" type-id = "pqr">
      .........
      </truck-type>
     <car-type id="abc" type-id = "pqr">
       .........
      </car-type>
</Vehicle>

Or
<Vehicle  id = "xyz" purchase-date="2009-12-23">
     <truck-type id="abc" type-id = "pqr">
      .........
      </truck-type>
     <bus-type id="abc" type-id = "pqr">
       .........
      </bus-type>
</Vehicle>

Or
with any one of the truck, bus or car.

Mapping file
<class name="Vehicle">
        <psc:map-to xml="vehicle"/>
        <psc:field name="id" type="java.lang.String">
            <psc:bind-xml name="id" node="attribute"/>
        </psc:field>
        <psc:field name="purchaseDate" type="java.util.Date"
                   handler="handler.DateFieldHandler">
            <psc:bind-xml name="purchase-date" node="attribute"/>
        </psc:field>
      <field name="vehicleTypes" type="VehicleType"
                collection="arraylist" set-method="addVehicleType"
get-method="getVehicleTypes">
  ("===Here I don't have idea what will be the bind name====")


What should be the mapping file for the above requirement.

Thanks,
Jalpa

Reply via email to