jaxb xjc mapping to existing domain objects

xynide

New Member
I have done a lot of searching and cannot find a concise example of how to map an XML schema to existing domain objects instead of creating brand new ones utilizing xjc. I have created a bindings(xjb) file but still can find no way of accomplishing this.If I have an existing domain Object that I want jaxb to use such as the following:\[code\]package com.blah.domain;class CustomerOffice{ private int id; private String name; private String phone;}\[/code\]and I have an XML Schema like the following:\[code\]<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:www="http://www.blah.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.blah.com" elementFormDefault="unqualified"> <xs:element name="Customer"> <xs:complexType> <xs:sequence> <xs:element name="id" type="xs:int" nillable="false" minOccurs="1" maxOccurs="1"/> <xs:element name="name" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="CustomerOffice" type="www:CustomerOffice" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="CustomerOffice"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="length" type="xs:int"/> </xs:sequence> </xs:complexType></xs:schema>\[/code\]If I go to generate the jaxb classes with xjc it will create a new class called Customer (which I want). It will also create a new class called CustomerOffice (which I don't want, I want it to use my existing domain object).So instead of the schema pointing to "type:www:CustomerOffice" I would want it to use the existing com.blah.domain.CustomerOffice.I tried to make this as simple an example as possible, any help is appreciated.
 
Back
Top