Lines 26-113
Link Here
|
26 |
import java.util.ArrayList; |
26 |
import java.util.ArrayList; |
27 |
|
27 |
|
28 |
public class NestedAttributeKeyProject extends Project { |
28 |
public class NestedAttributeKeyProject extends Project { |
29 |
public NestedAttributeKeyProject() { |
29 |
public NestedAttributeKeyProject() { |
30 |
addDescriptor(getRootDescriptor()); |
30 |
addDescriptor(getRootDescriptor()); |
31 |
addDescriptor(getEmployeeDescriptor()); |
31 |
addDescriptor(getEmployeeDescriptor()); |
32 |
addDescriptor(getAddressDescriptor()); |
32 |
addDescriptor(getAddressDescriptor()); |
33 |
} |
33 |
} |
34 |
|
34 |
|
35 |
private XMLDescriptor getRootDescriptor() { |
35 |
private XMLDescriptor getRootDescriptor() { |
36 |
XMLDescriptor descriptor = new XMLDescriptor(); |
36 |
XMLDescriptor descriptor = new XMLDescriptor(); |
37 |
descriptor.setJavaClass(Root.class); |
37 |
descriptor.setJavaClass(Root.class); |
38 |
descriptor.setDefaultRootElement("root"); |
38 |
descriptor.setDefaultRootElement("root"); |
39 |
// create employee mapping |
39 |
// create employee mapping |
40 |
XMLCompositeObjectMapping empMapping = new XMLCompositeObjectMapping(); |
40 |
XMLCompositeObjectMapping empMapping = new XMLCompositeObjectMapping(); |
41 |
empMapping.setAttributeName("employee"); |
41 |
empMapping.setAttributeName("employee"); |
42 |
empMapping.setXPath("employee"); |
42 |
empMapping.setXPath("employee"); |
43 |
empMapping.setReferenceClass(Employee.class); |
43 |
empMapping.setReferenceClass(Employee.class); |
44 |
descriptor.addMapping(empMapping); |
44 |
descriptor.addMapping(empMapping); |
45 |
// create address mapping |
45 |
// create address mapping |
46 |
XMLCompositeCollectionMapping addMapping = new XMLCompositeCollectionMapping(); |
46 |
XMLCompositeCollectionMapping addMapping = new XMLCompositeCollectionMapping(); |
47 |
addMapping.setAttributeName("addresses"); |
47 |
addMapping.setAttributeName("addresses"); |
48 |
addMapping.setXPath("address"); |
48 |
addMapping.setXPath("address"); |
49 |
addMapping.setReferenceClass(Address.class); |
49 |
addMapping.setReferenceClass(Address.class); |
50 |
descriptor.addMapping(addMapping); |
50 |
descriptor.addMapping(addMapping); |
51 |
return descriptor; |
51 |
return descriptor; |
52 |
} |
52 |
} |
53 |
|
53 |
|
54 |
private XMLDescriptor getEmployeeDescriptor() { |
54 |
private XMLDescriptor getEmployeeDescriptor() { |
55 |
XMLDescriptor descriptor = new XMLDescriptor(); |
55 |
XMLDescriptor descriptor = new XMLDescriptor(); |
56 |
descriptor.setJavaClass(Employee.class); |
56 |
descriptor.setJavaClass(Employee.class); |
57 |
descriptor.setDefaultRootElement("employee"); |
57 |
descriptor.setDefaultRootElement("employee"); |
58 |
// create id mapping |
58 |
// create id mapping |
59 |
XMLDirectMapping idMapping = new XMLDirectMapping(); |
59 |
XMLDirectMapping idMapping = new XMLDirectMapping(); |
60 |
idMapping.setAttributeName("id"); |
60 |
idMapping.setAttributeName("id"); |
61 |
idMapping.setXPath("@id"); |
61 |
idMapping.setXPath("@id"); |
62 |
descriptor.addMapping(idMapping); |
62 |
descriptor.addMapping(idMapping); |
63 |
// create name mapping |
63 |
// create name mapping |
64 |
XMLDirectMapping nameMapping = new XMLDirectMapping(); |
64 |
XMLDirectMapping nameMapping = new XMLDirectMapping(); |
65 |
nameMapping.setAttributeName("name"); |
65 |
nameMapping.setAttributeName("name"); |
66 |
nameMapping.setXPath("name/text()"); |
66 |
nameMapping.setXPath("name/text()"); |
67 |
descriptor.addMapping(nameMapping); |
67 |
descriptor.addMapping(nameMapping); |
68 |
// create address mapping |
68 |
// create address mapping |
69 |
XMLCollectionReferenceMapping addressMapping = new XMLCollectionReferenceMapping(); |
69 |
XMLCollectionReferenceMapping addressMapping = new XMLCollectionReferenceMapping(); |
70 |
addressMapping.useCollectionClass(ArrayList.class); |
70 |
addressMapping.useCollectionClass(ArrayList.class); |
71 |
addressMapping.setAttributeName("addresses"); |
71 |
addressMapping.setAttributeName("addresses"); |
72 |
addressMapping.setReferenceClass(Address.class); |
72 |
addressMapping.setXPath("addresses"); |
73 |
addressMapping.addSourceToTargetKeyFieldAssociation("addresses/address-ref/@address-city", "city/text()"); |
73 |
addressMapping.setReferenceClass(Address.class); |
74 |
addressMapping.addSourceToTargetKeyFieldAssociation("addresses/address-ref/@address-zip", "zip/text()"); |
74 |
addressMapping.addSourceToTargetKeyFieldAssociation("address-ref/@address-city", "city/text()"); |
|
|
75 |
addressMapping.addSourceToTargetKeyFieldAssociation("address-ref/@address-zip", "zip/text()"); |
75 |
addressMapping.setUsesSingleNode(false); |
76 |
addressMapping.setUsesSingleNode(false); |
76 |
descriptor.addMapping(addressMapping); |
77 |
descriptor.addMapping(addressMapping); |
77 |
return descriptor; |
78 |
return descriptor; |
78 |
} |
79 |
} |
79 |
|
80 |
|
80 |
private XMLDescriptor getAddressDescriptor() { |
81 |
private XMLDescriptor getAddressDescriptor() { |
81 |
XMLDescriptor descriptor = new XMLDescriptor(); |
82 |
XMLDescriptor descriptor = new XMLDescriptor(); |
82 |
descriptor.setJavaClass(Address.class); |
83 |
descriptor.setJavaClass(Address.class); |
83 |
descriptor.addPrimaryKeyFieldName("city/text()"); |
84 |
descriptor.addPrimaryKeyFieldName("city/text()"); |
84 |
descriptor.addPrimaryKeyFieldName("zip/text()"); |
85 |
descriptor.addPrimaryKeyFieldName("zip/text()"); |
85 |
descriptor.setDefaultRootElement("address"); |
86 |
descriptor.setDefaultRootElement("address"); |
86 |
// create id mapping |
87 |
// create id mapping |
87 |
XMLDirectMapping idMapping = new XMLDirectMapping(); |
88 |
XMLDirectMapping idMapping = new XMLDirectMapping(); |
88 |
idMapping.setAttributeName("id"); |
89 |
idMapping.setAttributeName("id"); |
89 |
idMapping.setXPath("@aid"); |
90 |
idMapping.setXPath("@aid"); |
90 |
descriptor.addMapping(idMapping); |
91 |
descriptor.addMapping(idMapping); |
91 |
// create street mapping |
92 |
// create street mapping |
92 |
XMLDirectMapping streetMapping = new XMLDirectMapping(); |
93 |
XMLDirectMapping streetMapping = new XMLDirectMapping(); |
93 |
streetMapping.setAttributeName("street"); |
94 |
streetMapping.setAttributeName("street"); |
94 |
streetMapping.setXPath("street/text()"); |
95 |
streetMapping.setXPath("street/text()"); |
95 |
descriptor.addMapping(streetMapping); |
96 |
descriptor.addMapping(streetMapping); |
96 |
// create city mapping |
97 |
// create city mapping |
97 |
XMLDirectMapping cityMapping = new XMLDirectMapping(); |
98 |
XMLDirectMapping cityMapping = new XMLDirectMapping(); |
98 |
cityMapping.setAttributeName("city"); |
99 |
cityMapping.setAttributeName("city"); |
99 |
cityMapping.setXPath("city/text()"); |
100 |
cityMapping.setXPath("city/text()"); |
100 |
descriptor.addMapping(cityMapping); |
101 |
descriptor.addMapping(cityMapping); |
101 |
// create country mapping |
102 |
// create country mapping |
102 |
XMLDirectMapping countryMapping = new XMLDirectMapping(); |
103 |
XMLDirectMapping countryMapping = new XMLDirectMapping(); |
103 |
countryMapping.setAttributeName("country"); |
104 |
countryMapping.setAttributeName("country"); |
104 |
countryMapping.setXPath("country/text()"); |
105 |
countryMapping.setXPath("country/text()"); |
105 |
descriptor.addMapping(countryMapping); |
106 |
descriptor.addMapping(countryMapping); |
106 |
// create zip mapping |
107 |
// create zip mapping |
107 |
XMLDirectMapping zipMapping = new XMLDirectMapping(); |
108 |
XMLDirectMapping zipMapping = new XMLDirectMapping(); |
108 |
zipMapping.setAttributeName("zip"); |
109 |
zipMapping.setAttributeName("zip"); |
109 |
zipMapping.setXPath("zip/text()"); |
110 |
zipMapping.setXPath("zip/text()"); |
110 |
descriptor.addMapping(zipMapping); |
111 |
descriptor.addMapping(zipMapping); |
111 |
return descriptor; |
112 |
return descriptor; |
112 |
} |
113 |
} |
113 |
} |
114 |
} |