use of org.geotoolkit.xal.model.AddressIdentifier in project geotoolkit by Geomatys.
the class XalReader method readPostalServiceElements.
/**
* @return
* @throws XMLStreamException
*/
private PostalServiceElements readPostalServiceElements() throws XMLStreamException {
List<AddressIdentifier> addressIdentifiers = new ArrayList<AddressIdentifier>();
GenericTypedGrPostal endorsementLineCode = null;
GenericTypedGrPostal keyLineCode = null;
GenericTypedGrPostal barCode = null;
SortingCode sortingCode = null;
GenericTypedGrPostal addressLatitude = null;
GenericTypedGrPostal addressLatitudeDirection = null;
GenericTypedGrPostal addressLongitude = null;
GenericTypedGrPostal addressLongitudeDirection = null;
List<GenericTypedGrPostal> supplementaryPostalServiceData = new ArrayList<GenericTypedGrPostal>();
String type = reader.getAttributeValue(null, ATT_TYPE);
boucle: while (reader.hasNext()) {
switch(reader.next()) {
case XMLStreamConstants.START_ELEMENT:
final String eName = reader.getLocalName();
final String eUri = reader.getNamespaceURI();
if (URI_XAL.equals(eUri)) {
if (TAG_ADDRESS_IDENTIFIER.equals(eName)) {
addressIdentifiers.add(this.readAddressIdentifier());
} else if (TAG_ENDORSEMENT_LINE_CODE.equals(eName)) {
endorsementLineCode = this.readGenericTypedGrPostal();
} else if (TAG_KEY_LINE_CODE.equals(eName)) {
keyLineCode = this.readGenericTypedGrPostal();
} else if (TAG_BARCODE.equals(eName)) {
barCode = this.readGenericTypedGrPostal();
} else if (TAG_SORTING_CODE.equals(eName)) {
sortingCode = this.readSortingCode();
} else if (TAG_ADDRESS_LATITUDE.equals(eName)) {
addressLatitude = this.readGenericTypedGrPostal();
} else if (TAG_ADDRESS_LATITUDE_DIRECTION.equals(eName)) {
addressLatitudeDirection = this.readGenericTypedGrPostal();
} else if (TAG_ADDRESS_LONGITUDE.equals(eName)) {
addressLongitude = this.readGenericTypedGrPostal();
} else if (TAG_ADDRESS_LONGITUDE_DIRECTION.equals(eName)) {
addressLongitudeDirection = this.readGenericTypedGrPostal();
} else if (TAG_SUPPLEMENTARY_POSTAL_SERVICE_DATA.equals(eName)) {
supplementaryPostalServiceData.add(this.readGenericTypedGrPostal());
}
}
break;
case XMLStreamConstants.END_ELEMENT:
if (TAG_POSTAL_SERVICE_ELEMENTS.equals(reader.getLocalName()) && URI_XAL.contains(reader.getNamespaceURI())) {
break boucle;
}
break;
}
}
return XAL_FACTORY.createPostalServiceElements(addressIdentifiers, endorsementLineCode, keyLineCode, barCode, sortingCode, addressLatitude, addressLatitudeDirection, addressLongitude, addressLongitudeDirection, supplementaryPostalServiceData, type);
}
use of org.geotoolkit.xal.model.AddressIdentifier in project geotoolkit by Geomatys.
the class XalWriter method writePostalServiceElements.
/**
* @param postalServiceElements
* @throws XMLStreamException
*/
private void writePostalServiceElements(PostalServiceElements postalServiceElements) throws XMLStreamException {
writer.writeStartElement(URI_XAL, TAG_POSTAL_SERVICE_ELEMENTS);
if (postalServiceElements.getType() != null) {
writer.writeAttribute(ATT_TYPE, postalServiceElements.getType());
}
for (AddressIdentifier addressIdentifier : postalServiceElements.getAddressIdentifiers()) {
this.writeAddressIdentifier(addressIdentifier);
}
if (postalServiceElements.getEndorsementLineCode() != null) {
this.writeEndorsementLineCode(postalServiceElements.getEndorsementLineCode());
}
if (postalServiceElements.getKeyLineCode() != null) {
this.writeKeyLineCode(postalServiceElements.getKeyLineCode());
}
if (postalServiceElements.getBarcode() != null) {
this.writeBarcode(postalServiceElements.getBarcode());
}
if (postalServiceElements.getSortingCode() != null) {
this.writeSortingCode(postalServiceElements.getSortingCode());
}
if (postalServiceElements.getAddressLatitude() != null) {
this.writeAddressLatitude(postalServiceElements.getAddressLatitude());
}
if (postalServiceElements.getAddressLatitudeDirection() != null) {
this.writeAddressLatitudeDirection(postalServiceElements.getAddressLatitudeDirection());
}
if (postalServiceElements.getAddressLongitude() != null) {
this.writeAddressLongitude(postalServiceElements.getAddressLongitude());
}
if (postalServiceElements.getAddressLongitudeDirection() != null) {
this.writeAddressLongitudeDirection(postalServiceElements.getAddressLongitudeDirection());
}
for (GenericTypedGrPostal data : postalServiceElements.getSupplementaryPostalServiceData()) {
this.writeSupplementaryPostalServiceData(data);
}
writer.writeEndElement();
}
use of org.geotoolkit.xal.model.AddressIdentifier in project geotoolkit by Geomatys.
the class AddressTest method addressReadTest.
@Test
public void addressReadTest() throws IOException, XMLStreamException, XalException {
final XalReader reader = new XalReader();
reader.setInput(new File(pathToTestFile));
final Xal xalObjects = reader.read();
reader.dispose();
assertEquals("v", xalObjects.getVersion());
assertEquals(1, xalObjects.getAddressDetails().size());
final AddressDetails addressDetails0 = xalObjects.getAddressDetails().get(0);
assertEquals("addressType", addressDetails0.getAddressType());
assertEquals("currentStatus", addressDetails0.getCurrentStatus());
assertEquals("validFrom", addressDetails0.getValidFromDate());
assertEquals("validTo", addressDetails0.getValidToDate());
assertEquals("usage", addressDetails0.getUsage());
assertEquals("code", addressDetails0.getGrPostal().getCode());
assertEquals("key", addressDetails0.getAddressDetailsKey());
final PostalServiceElements postalServiceElements = addressDetails0.getPostalServiceElements();
assertEquals("typePostalServiceElement", postalServiceElements.getType());
assertEquals(2, postalServiceElements.getAddressIdentifiers().size());
final AddressIdentifier addressIdentifier0 = postalServiceElements.getAddressIdentifiers().get(0);
assertEquals("code34", addressIdentifier0.getGrPostal().getCode());
assertEquals("identifierType34", addressIdentifier0.getIdentifierType());
assertEquals("type34", addressIdentifier0.getType());
assertEquals("Hérault", addressIdentifier0.getContent());
final AddressIdentifier addressIdentifier1 = postalServiceElements.getAddressIdentifiers().get(1);
assertEquals("code11", addressIdentifier1.getGrPostal().getCode());
assertEquals("identifierType11", addressIdentifier1.getIdentifierType());
assertEquals("type11", addressIdentifier1.getType());
assertEquals("Aude", addressIdentifier1.getContent());
final GenericTypedGrPostal endorsementLineCode = postalServiceElements.getEndorsementLineCode();
assertEquals("code30", endorsementLineCode.getGrPostal().getCode());
assertEquals("type30", endorsementLineCode.getType());
assertEquals("Gard", endorsementLineCode.getContent());
final GenericTypedGrPostal keyLineCode = postalServiceElements.getKeyLineCode();
assertEquals("code64", keyLineCode.getGrPostal().getCode());
assertEquals("type64", keyLineCode.getType());
assertEquals("Pyrénées Atlantiques", keyLineCode.getContent());
final GenericTypedGrPostal barCode = postalServiceElements.getBarcode();
assertEquals("code66", barCode.getGrPostal().getCode());
assertEquals("type66", barCode.getType());
assertEquals("Pyrénées Orientales", barCode.getContent());
final SortingCode sortingCode = postalServiceElements.getSortingCode();
assertEquals("codeSortingCode", sortingCode.getGrPostal().getCode());
assertEquals("typeSortingCode", sortingCode.getType());
final GenericTypedGrPostal addressLatitude = postalServiceElements.getAddressLatitude();
assertEquals("codeAddressLatitude", addressLatitude.getGrPostal().getCode());
assertEquals("typeAddressLatitude", addressLatitude.getType());
assertEquals("Latitude", addressLatitude.getContent());
final GenericTypedGrPostal addressLatitudeDirection = postalServiceElements.getAddressLatitudeDirection();
assertEquals("codeLatitudeDirection", addressLatitudeDirection.getGrPostal().getCode());
assertEquals("typeLatitudeDirection", addressLatitudeDirection.getType());
assertEquals("LatitudeDirection", addressLatitudeDirection.getContent());
final GenericTypedGrPostal addressLongitude = postalServiceElements.getAddressLongitude();
assertEquals("codeLongitude", addressLongitude.getGrPostal().getCode());
assertEquals("typeLongitude", addressLongitude.getType());
assertEquals("Longitude", addressLongitude.getContent());
final GenericTypedGrPostal addressLongitudeDirection = postalServiceElements.getAddressLongitudeDirection();
assertEquals("codeLongitudeDirection", addressLongitudeDirection.getGrPostal().getCode());
assertEquals("typeLongitudeDirection", addressLongitudeDirection.getType());
assertEquals("LongitudeDirection", addressLongitudeDirection.getContent());
assertEquals(2, postalServiceElements.getSupplementaryPostalServiceData().size());
final GenericTypedGrPostal sps1 = postalServiceElements.getSupplementaryPostalServiceData().get(0);
assertEquals("codeSPS1", sps1.getGrPostal().getCode());
assertEquals("typeSPS1", sps1.getType());
assertEquals("First supplementary postal service data", sps1.getContent());
final GenericTypedGrPostal sps2 = postalServiceElements.getSupplementaryPostalServiceData().get(1);
assertEquals("codeSPS2", sps2.getGrPostal().getCode());
assertEquals("typeSPS2", sps2.getType());
assertEquals("Second supplementary postal service data", sps2.getContent());
final GenericTypedGrPostal address = addressDetails0.getAddress();
assertEquals("addressCode", address.getGrPostal().getCode());
assertEquals("addressType", address.getType());
assertEquals("Une adresse", address.getContent());
}
use of org.geotoolkit.xal.model.AddressIdentifier in project geotoolkit by Geomatys.
the class AddressTest method addressWriteTest.
@Test
public void addressWriteTest() throws IOException, XMLStreamException, ParserConfigurationException, SAXException, XalException {
final XalFactory xalFactory = DefaultXalFactory.getInstance();
final PostalServiceElements postalServiceElements = xalFactory.createPostalServiceElements();
final AddressIdentifier addressIdentifier0 = xalFactory.createAddressIdentifier();
addressIdentifier0.setGrPostal(xalFactory.createGrPostal("code34"));
addressIdentifier0.setIdentifierType("identifierType34");
addressIdentifier0.setType("type34");
addressIdentifier0.setContent("Hérault");
final AddressIdentifier addressIdentifier1 = xalFactory.createAddressIdentifier();
addressIdentifier1.setGrPostal(xalFactory.createGrPostal("code11"));
addressIdentifier1.setIdentifierType("identifierType11");
addressIdentifier1.setType("type11");
addressIdentifier1.setContent("Aude");
postalServiceElements.setAddressIdentifiers(Arrays.asList(addressIdentifier0, addressIdentifier1));
final GenericTypedGrPostal endorsementLineCode = xalFactory.createGenericTypedGrPostal();
endorsementLineCode.setGrPostal(xalFactory.createGrPostal("code30"));
endorsementLineCode.setType("type30");
endorsementLineCode.setContent("Gard");
postalServiceElements.setEndorsementLineCode(endorsementLineCode);
final GenericTypedGrPostal keyLineCode = xalFactory.createGenericTypedGrPostal();
keyLineCode.setGrPostal(xalFactory.createGrPostal("code64"));
keyLineCode.setType("type64");
keyLineCode.setContent("Pyrénées Atlantiques");
postalServiceElements.setKeyLineCode(keyLineCode);
final GenericTypedGrPostal barCode = xalFactory.createGenericTypedGrPostal();
barCode.setGrPostal(xalFactory.createGrPostal("code66"));
barCode.setType("type66");
barCode.setContent("Pyrénées Orientales");
postalServiceElements.setBarcode(barCode);
final SortingCode sortingCode = xalFactory.createSortingCode("typeSortingCode", xalFactory.createGrPostal("codeSortingCode"));
postalServiceElements.setSortingCode(sortingCode);
final GenericTypedGrPostal addressLatitude = xalFactory.createGenericTypedGrPostal();
addressLatitude.setGrPostal(xalFactory.createGrPostal("codeAddressLatitude"));
addressLatitude.setType("typeAddressLatitude");
addressLatitude.setContent("Latitude");
postalServiceElements.setAddressLatitude(addressLatitude);
final GenericTypedGrPostal addressLatitudeDirection = xalFactory.createGenericTypedGrPostal();
addressLatitudeDirection.setGrPostal(xalFactory.createGrPostal("codeLatitudeDirection"));
addressLatitudeDirection.setType("typeLatitudeDirection");
addressLatitudeDirection.setContent("LatitudeDirection");
postalServiceElements.setAddressLatitudeDirection(addressLatitudeDirection);
final GenericTypedGrPostal addressLongitude = xalFactory.createGenericTypedGrPostal();
addressLongitude.setGrPostal(xalFactory.createGrPostal("codeLongitude"));
addressLongitude.setType("typeLongitude");
addressLongitude.setContent("Longitude");
postalServiceElements.setAddressLongitude(addressLongitude);
final GenericTypedGrPostal addressLongitudeDirection = xalFactory.createGenericTypedGrPostal();
addressLongitudeDirection.setGrPostal(xalFactory.createGrPostal("codeLongitudeDirection"));
addressLongitudeDirection.setType("typeLongitudeDirection");
addressLongitudeDirection.setContent("LongitudeDirection");
postalServiceElements.setAddressLongitudeDirection(addressLongitudeDirection);
final GenericTypedGrPostal sps1 = xalFactory.createGenericTypedGrPostal();
sps1.setGrPostal(xalFactory.createGrPostal("codeSPS1"));
sps1.setType("typeSPS1");
sps1.setContent("First supplementary postal service data");
final GenericTypedGrPostal sps2 = xalFactory.createGenericTypedGrPostal();
sps2.setGrPostal(xalFactory.createGrPostal("codeSPS2"));
sps2.setType("typeSPS2");
sps2.setContent("Second supplementary postal service data");
postalServiceElements.setSupplementaryPostalServiceData(Arrays.asList(sps1, sps2));
postalServiceElements.setType("typePostalServiceElement");
final GenericTypedGrPostal address = xalFactory.createGenericTypedGrPostal();
address.setGrPostal(xalFactory.createGrPostal("addressCode"));
address.setType("addressType");
address.setContent("Une adresse");
final AddressDetails addressDetails = xalFactory.createAddressDetails();
addressDetails.setPostalServiceElements(postalServiceElements);
addressDetails.setAddress(address);
addressDetails.setAddressType("addressType");
addressDetails.setCurrentStatus("currentStatus");
addressDetails.setValidFromDate("validFrom");
addressDetails.setValidToDate("validTo");
addressDetails.setUsage("usage");
addressDetails.setGrPostal(xalFactory.createGrPostal("code"));
addressDetails.setAddressDetailsKey("key");
final Xal xal = xalFactory.createXal(Arrays.asList(addressDetails), "v");
final File temp = File.createTempFile("addressTest", ".xal");
temp.deleteOnExit();
final XalWriter writer = new XalWriter();
writer.setOutput(temp);
writer.write(xal);
writer.dispose();
DomCompare.compare(new File(pathToTestFile), temp);
}
Aggregations