/*
* citygml4j - The Open Source Java API for CityGML
* https://github.com/citygml4j
*
* Copyright 2013-2017 Claus Nagel <claus.nagel@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.citygml4j.builder.jaxb.unmarshal.citygml.landuse;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import org.citygml4j.builder.jaxb.unmarshal.JAXBUnmarshaller;
import org.citygml4j.builder.jaxb.unmarshal.citygml.CityGMLUnmarshaller;
import net.opengis.citygml.landuse._1.LandUseType;
import org.citygml4j.model.citygml.CityGML;
import org.citygml4j.model.citygml.ade.ADEComponent;
import org.citygml4j.model.citygml.landuse.LandUse;
import org.citygml4j.model.gml.basicTypes.Code;
import org.citygml4j.model.module.citygml.LandUseModule;
import org.citygml4j.xml.io.reader.MissingADESchemaException;
public class LandUse100Unmarshaller {
private final LandUseModule module = LandUseModule.v1_0_0;
private final JAXBUnmarshaller jaxb;
private final CityGMLUnmarshaller citygml;
public LandUse100Unmarshaller(CityGMLUnmarshaller citygml) {
this.citygml = citygml;
jaxb = citygml.getJAXBUnmarshaller();
}
public CityGML unmarshal(JAXBElement<?> src) throws MissingADESchemaException {
return unmarshal(src.getValue());
}
public CityGML unmarshal(Object src) throws MissingADESchemaException {
if (src instanceof JAXBElement<?>)
return unmarshal((JAXBElement<?>)src);
CityGML dest = null;
if (src instanceof LandUseType)
dest = unmarshalLandUse((LandUseType)src);
return dest;
}
public void unmarshalLandUse(LandUseType src, LandUse dest) throws MissingADESchemaException {
citygml.getCore100Unmarshaller().unmarshalAbstractCityObject(src, dest);
if (src.isSetClazz())
dest.setClazz(new Code(src.getClazz()));
if (src.isSetFunction()) {
for (String function : src.getFunction())
dest.addFunction(new Code(function));
}
if (src.isSetUsage()) {
for (String usage : src.getUsage())
dest.addUsage(new Code(usage));
}
if (src.isSetLod0MultiSurface())
dest.setLod0MultiSurface(jaxb.getGMLUnmarshaller().unmarshalMultiSurfaceProperty(src.getLod0MultiSurface()));
if (src.isSetLod1MultiSurface())
dest.setLod1MultiSurface(jaxb.getGMLUnmarshaller().unmarshalMultiSurfaceProperty(src.getLod1MultiSurface()));
if (src.isSetLod2MultiSurface())
dest.setLod2MultiSurface(jaxb.getGMLUnmarshaller().unmarshalMultiSurfaceProperty(src.getLod2MultiSurface()));
if (src.isSetLod3MultiSurface())
dest.setLod3MultiSurface(jaxb.getGMLUnmarshaller().unmarshalMultiSurfaceProperty(src.getLod3MultiSurface()));
if (src.isSetLod4MultiSurface())
dest.setLod4MultiSurface(jaxb.getGMLUnmarshaller().unmarshalMultiSurfaceProperty(src.getLod4MultiSurface()));
}
public LandUse unmarshalLandUse(LandUseType src) throws MissingADESchemaException {
LandUse dest = new LandUse(module);
unmarshalLandUse(src, dest);
return dest;
}
public boolean assignGenericProperty(ADEComponent genericProperty, QName substitutionGroup, CityGML dest) {
String name = substitutionGroup.getLocalPart();
boolean success = true;
if (dest instanceof LandUse && name.equals("_GenericApplicationPropertyOfLandUse"))
((LandUse)dest).addGenericApplicationPropertyOfLandUse(genericProperty);
else
success = false;
return success;
}
}