use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class AbstractWmlEncoderv20 method createObservationProcess.
/**
* Creates an WaterML 2.0 ObservationProcess XML object from SOS
* ObservationProcess object
*
* @param procedure
* SOS ObservationProcess
* @param context
* Additional values
* @return WaterML 2.0 ObservationProcess XML object
* @throws EncodingException
* If an error occurs
*/
protected ObservationProcessDocument createObservationProcess(ObservationProcess procedure, EncodingContext context) throws EncodingException {
XmlObject encodedObject = null;
try {
if (procedure.isSetXml()) {
encodedObject = XmlObject.Factory.parse(procedure.getXml());
checkAndAddIdentifier(procedure, ((ObservationProcessDocument) encodedObject).getObservationProcess());
} else {
encodedObject = ObservationProcessDocument.Factory.newInstance();
ObservationProcessType observationProcess = ((ObservationProcessDocument) encodedObject).addNewObservationProcess();
if (context.has(XmlBeansEncodingFlags.GMLID)) {
observationProcess.setId(PROCESS_ID_PREFIX + context.get(XmlBeansEncodingFlags.GMLID));
} else {
observationProcess.setId(PROCESS_ID_PREFIX + JavaHelper.generateID(procedure.toString()));
}
if (procedure.isSetIdentifier()) {
observationProcess.addNewIdentifier().set(encodeGML(procedure.getIdentifierCodeWithAuthority()));
}
if (procedure.isSetName()) {
for (final CodeType sosName : procedure.getName()) {
observationProcess.addNewName().set(encodeGML(sosName));
}
}
addProcessType(observationProcess, procedure);
addOriginatingProcess(observationProcess, procedure);
addAggregatingDuration(observationProcess, procedure);
addVerticalDatum(observationProcess, procedure);
addComment(observationProcess, procedure);
addProcessReference(observationProcess, procedure);
addInput(observationProcess, procedure);
addParameter(observationProcess, procedure);
}
} catch (final XmlException xmle) {
throw new EncodingException(xmle);
}
try {
LOGGER.debug("Encoded object {} is valid: {}", encodedObject.schemaType().toString(), XmlHelper.validateDocument(encodedObject));
} catch (DecodingException e) {
throw new EncodingException(e);
}
return (ObservationProcessDocument) encodedObject;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class ProcessTypeEncoder method createProcess.
protected ProcessType createProcess(Process process) throws EncodingException {
if (process.isSetXml()) {
XmlObject encodedObject = null;
try {
encodedObject = XmlObject.Factory.parse(process.getXml());
if (encodedObject instanceof ProcessType) {
ProcessType pt = (ProcessType) encodedObject;
checkForInspireId(pt, process);
return pt;
} else if (encodedObject instanceof ProcessDocument) {
return ((ProcessDocument) encodedObject).getProcess();
} else if (encodedObject instanceof ProcessPropertyType) {
return ((ProcessPropertyType) encodedObject).getProcess();
} else {
throw new UnsupportedEncoderInputException(this, process);
}
} catch (final XmlException xmle) {
throw new EncodingException(xmle);
}
} else {
ProcessType pt = ProcessType.Factory.newInstance();
if (!process.isSetGmlID()) {
process.setGmlId("p_" + JavaHelper.generateID(process.toString()));
}
pt.setId(process.getGmlId());
addInspireId(pt, process);
addName(pt, process);
addType(pt, process);
addDocumentation(pt, process);
addProcessParameter(pt, process);
addResponsibleParty(pt, process);
return pt;
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class FesDecoderv20 method parseTemporalFilterType.
/**
* parses a single temporal filter of the requests and returns SOS temporal
* filter
*
* @param xbTemporalOpsType
* XmlObject representing the temporal filter
* @return Returns SOS representation of temporal filter
*
* @throws DecodingException
* * if parsing of the element failed
*/
private TemporalFilter parseTemporalFilterType(TemporalOpsType xbTemporalOpsType) throws DecodingException {
TemporalFilter temporalFilter = new TemporalFilter();
try {
if (xbTemporalOpsType instanceof BinaryTemporalOpType) {
BinaryTemporalOpType btot = (BinaryTemporalOpType) xbTemporalOpsType;
if (btot.getValueReference() != null && !btot.getValueReference().isEmpty()) {
temporalFilter.setValueReference(btot.getValueReference().trim());
}
NodeList nodes = btot.getDomNode().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
if (nodes.item(i).getNamespaceURI() != null && !nodes.item(i).getLocalName().equals(FilterConstants.EN_VALUE_REFERENCE)) {
Object timeObject = decodeXmlObject(Factory.parse(nodes.item(i)));
if (timeObject instanceof Time) {
TimeOperator operator;
Time time = (Time) timeObject;
String localName = XmlHelper.getLocalName(xbTemporalOpsType);
if (localName.equals(TimeOperator2.After.name())) {
operator = TimeOperator.TM_After;
} else if (localName.equals(TimeOperator2.Before.name())) {
operator = TimeOperator.TM_Before;
} else if (localName.equals(TimeOperator2.Begins.name())) {
operator = TimeOperator.TM_Begins;
} else if (localName.equals(TimeOperator2.BegunBy.name())) {
operator = TimeOperator.TM_BegunBy;
} else if (localName.equals(TimeOperator2.TContains.name())) {
operator = TimeOperator.TM_Contains;
} else if (localName.equals(TimeOperator2.During.name())) {
operator = TimeOperator.TM_During;
} else if (localName.equals(TimeOperator2.EndedBy.name())) {
operator = TimeOperator.TM_EndedBy;
} else if (localName.equals(TimeOperator2.Ends.name())) {
operator = TimeOperator.TM_Ends;
} else if (localName.equals(TimeOperator2.TEquals.name())) {
operator = TimeOperator.TM_Equals;
} else if (localName.equals(TimeOperator2.Meets.name())) {
operator = TimeOperator.TM_Meets;
} else if (localName.equals(TimeOperator2.MetBy.name())) {
operator = TimeOperator.TM_MetBy;
} else if (localName.equals(TimeOperator2.TOverlaps.name())) {
operator = TimeOperator.TM_Overlaps;
} else if (localName.equals(TimeOperator2.OverlappedBy.name())) {
operator = TimeOperator.TM_OverlappedBy;
} else {
throw unsupportedTemporalOperator();
}
temporalFilter.setOperator(operator);
temporalFilter.setTime(time);
break;
} else {
throw new DecodingException(Sos2Constants.GetObservationParams.temporalFilter, "The requested temporal filter value is not supported by this SOS!");
}
}
}
} else {
throw unsupportedTemporalOperator();
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing temporal filter!", xmle);
}
return temporalFilter;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class AbstractGmlDecoderv321 method parseNamedValueValue.
protected NamedValue<?> parseNamedValueValue(XmlObject xml) throws DecodingException {
XmlObject xmlObject = xml;
if (xmlObject.schemaType() == XmlAnyTypeImpl.type) {
try {
xmlObject = XmlObject.Factory.parse(xml.xmlText().trim());
} catch (XmlException e) {
LOGGER.error("Error while parsing NamedValueValue", e);
}
}
Object value;
if (XmlBoolean.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlBoolean) xmlObject).getBooleanValue();
} else if (XmlString.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlString) xmlObject).getStringValue();
} else if (XmlInt.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlInt) xmlObject).getIntValue();
} else if (XmlInteger.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlInteger) xmlObject).getBigIntegerValue().intValue();
} else if (XmlDouble.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlDouble) xmlObject).getDoubleValue();
} else {
value = decodeXmlObject(xmlObject);
}
if (value instanceof BooleanValue) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue((BooleanValue) value);
return namedValue;
} else if (value instanceof SweBoolean) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue(new BooleanValue(((SweBoolean) value).getValue()));
return namedValue;
} else if (value instanceof Boolean) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue(new BooleanValue((Boolean) value));
return namedValue;
} else if (value instanceof CategoryValue) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue((CategoryValue) value);
return namedValue;
} else if (value instanceof SweCategory) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new CategoryValue(((SweCategory) value).getValue(), ((SweCategory) value).getCodeSpace()));
return namedValue;
} else if (value instanceof CountValue) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue((CountValue) value);
return namedValue;
} else if (value instanceof SweCount) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue(new CountValue(((SweCount) value).getValue()));
return namedValue;
} else if (value instanceof Integer) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue(new CountValue((Integer) value));
return namedValue;
} else if (value instanceof GeometryValue) {
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setValue((GeometryValue) value);
return namedValue;
} else if (value instanceof QuantityValue) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue((QuantityValue) value);
return namedValue;
} else if (value instanceof GmlMeasureType) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue(((GmlMeasureType) value).getValue(), ((GmlMeasureType) value).getUnit()));
return namedValue;
} else if (value instanceof SweQuantity) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue(((SweQuantity) value).getValue(), ((SweQuantity) value).getUom()));
return namedValue;
} else if (value instanceof Double) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue((Double) value));
return namedValue;
} else if (value instanceof TextValue) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue((TextValue) value);
return namedValue;
} else if (value instanceof SweText) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new TextValue(((SweText) value).getValue()));
return namedValue;
} else if (value instanceof String) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new TextValue((String) value));
return namedValue;
} else if (value instanceof AbstractGeometry) {
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setValue(new GeometryValue((AbstractGeometry) value));
return namedValue;
} else if (value instanceof org.n52.shetland.ogc.gml.ReferenceType) {
NamedValue<org.n52.shetland.ogc.gml.ReferenceType> namedValue = new NamedValue<>();
namedValue.setValue(new ReferenceValue((org.n52.shetland.ogc.gml.ReferenceType) value));
return namedValue;
} else if (value instanceof W3CHrefAttribute) {
NamedValue<W3CHrefAttribute> namedValue = new NamedValue<>();
namedValue.setValue(new HrefAttributeValue((W3CHrefAttribute) value));
return namedValue;
} else {
throw new UnsupportedDecoderInputException(this, xmlObject);
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method encodeResultEncoding.
private void encodeResultEncoding(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
ObjectNode jre = json.putObject(JSONConstants.RESULT_ENCODING);
SweAbstractEncoding encoding = null;
SosResultEncoding re = t.getResultEncoding();
if (re.isDecoded()) {
encoding = t.getResultEncoding().get().get();
} else {
try {
XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractEncoding.class);
Decoder<SweAbstractEncoding, XmlObject> decoder = this.decoderRepository.getDecoder(key);
if (decoder == null) {
throw new NoDecoderForKeyException(key);
}
encoding = decoder.decode(XmlObject.Factory.parse(re.getXml().get()));
} catch (XmlException | DecodingException ex) {
throw new EncodingException(ex);
}
}
if (encoding instanceof SweTextEncoding) {
encodeSweTextEncoding(encoding, jre);
} else {
LOG.warn("Unsupported encoding: {}", encoding == null ? null : encoding.getClass());
}
}
Aggregations