public void addEmployeeDescriptor(boolean methodAccess) { XMLDescriptor descriptor = new XMLDescriptor(); descriptor.setJavaClass(Employee.class); descriptor.setDefaultRootElement("employee"); XMLDirectMapping idMapping = new XMLDirectMapping(); idMapping.setAttributeName("id"); idMapping.setXPath("@id"); descriptor.addMapping(idMapping); XMLDirectMapping firstNameMapping = new XMLDirectMapping(); firstNameMapping.setAttributeName("firstName"); firstNameMapping.setXPath("first-name/text()"); descriptor.addMapping(firstNameMapping); XMLDirectMapping lastNameMapping = new XMLDirectMapping(); lastNameMapping.setAttributeName("lastName"); lastNameMapping.setXPath("last-name/text()"); descriptor.addMapping(lastNameMapping); XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping(); addressMapping.setAttributeName("address"); addressMapping.setReferenceClass(Address.class); addressMapping.setXPath("address"); descriptor.addMapping(addressMapping); XMLCompositeCollectionMapping phoneMapping = new XMLCompositeCollectionMapping(); phoneMapping.setAttributeName("phoneNumbers"); phoneMapping.setReferenceClass(PhoneNumber.class); phoneMapping.setXPath("phone-numbers/number"); phoneMapping.setContainerPolicy(ContainerPolicy.buildPolicyFor(ArrayList.class)); descriptor.addMapping(phoneMapping); this.addDescriptor(descriptor); }
public XMLDescriptor addEmployeeDescriptor() { XMLDescriptor descriptor = new XMLDescriptor(); descriptor.setJavaClass(Employee.class); descriptor.setDefaultRootElement("employee"); XMLCompositeObjectMapping addr = new XMLCompositeObjectMapping(); addr.setAttributeName("address"); addr.setXPath("address"); addr.setReferenceClass(Address.class); descriptor.addMapping(addr); XMLCompositeCollectionMapping phone = new XMLCompositeCollectionMapping(); phone.setAttributeName("phoneNumbers"); phone.setXPath("phone-number"); phone.setReferenceClass(PhoneNumber.class); phone.useCollectionClass(ArrayList.class); descriptor.addMapping(phone); XMLAnyObjectMapping object = new XMLAnyObjectMapping(); object.setAttributeName("anyObject"); object.setXPath("any-object"); descriptor.addMapping(object); XMLAnyCollectionMapping anyCollection = new XMLAnyCollectionMapping(); anyCollection.setAttributeName("anyCollection"); anyCollection.setXPath("any-collection"); anyCollection.useCollectionClass(ArrayList.class); descriptor.addMapping(anyCollection); this.addDescriptor(descriptor); return descriptor; }
public ClassDescriptor buildWrapperDescriptor() { XMLDescriptor descriptor = new XMLDescriptor(); descriptor.setJavaClass(Wrapper.class); descriptor.setDefaultRootElement("myns:wrapper"); XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping(); mapping.setReferenceClass(Root.class); mapping.setAttributeName("theRoot"); mapping.setXPath("myns:root"); descriptor.addMapping(mapping); NamespaceResolver nr = new NamespaceResolver(); nr.put("myns", "www.example.com/some-dir/some.xsd"); nr.put("ns0", "www.example.com/test.xsd"); descriptor.setNamespaceResolver(nr); return descriptor; }