Java Code Examples for org.apache.xmlbeans.XmlObject#schemaType()

The following examples show how to use org.apache.xmlbeans.XmlObject#schemaType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SosDecoderv20.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
private String parseResultValues(final XmlObject resultValues)
        throws DecodingException {
    if (resultValues.schemaType() == XmlString.type) {
        return ((XmlString) resultValues).getStringValue().trim();
    } else if (resultValues.schemaType() == XmlObject.type) {
        final Node resultValuesNode = resultValues.getDomNode();
        if (resultValuesNode.hasChildNodes()) {
            final NodeList childNodes = resultValuesNode.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                final Node childNode = childNodes.item(i);
                if (childNode.getNodeType() == Node.TEXT_NODE) {
                    return childNode.getNodeValue().trim();
                }
            }
        }
        throw new DecodingException(Sos2Constants.InsertResultParams.resultValues,
                "The value for the parameter '%s' is missing in the request!",
                Sos2Constants.InsertResultParams.resultValues);
    } else {
        throw new DecodingException("The requested resultValue type is not supported");
    }
}
 
Example 2
Source File: EbicsXmlFactory.java    From ebics-java-client with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
  * Qualifies a valid member of a substitution group. This method tries to use the
  * built-in {@link XmlObject#substitute(QName, SchemaType)} and if succesful returns
  * a valid substitution which is usable (not disconnected). If it fails, it uses
  * low-level {@link XmlCursor} manipulation to qualify the substitution group. Note
  * that if the latter is the case the resulting document is disconnected and should
  * no longer be manipulated. Thus, use it as a final step after all markup is included.
  *
  * If newType is null, this method will skip {@link XmlObject#substitute(QName, SchemaType)}
  * and directly use {@link XmlCursor}. This can be used, if you are sure that the substitute
  * is not in the list of (pre-compiled) valid substitutions (this is the case if a schema
  * uses another schema's type as a base for elements. E.g. om:Observation uses gml:_Feature
  * as the base type).
  *
  * @param xobj
  * 		the abstract element
  * @param newInstance
  * 		the new {@link QName} of the instance
  * @param newType the new schemaType. if null, cursors will be used and the resulting object
  * 		will be disconnected.
  * @return if successful applied {@link XmlObject#substitute(QName, SchemaType)} a living object with a
  * 		type == newType is returned. Otherwise null is returned as you can no longer manipulate the object.
  */
 public static XmlObject qualifySubstitutionGroup(XmlObject xobj, QName newInstance, SchemaType newType) {
   XmlObject	substitute = null;

   if (newType != null) {
     substitute = xobj.substitute(newInstance, newType);
     if (substitute != null && substitute.schemaType() == newType
  && substitute.getDomNode().getLocalName().equals(newInstance.getLocalPart()))
     {
return substitute;
     }
   }

   XmlCursor cursor = xobj.newCursor();
   cursor.setName(newInstance);
   QName qName = new QName("http://www.w3.org/2001/XMLSchema-instance", "type");
   cursor.removeAttribute(qName);
   cursor.toNextToken();
   if (cursor.isNamespace()) {
     cursor.removeXml();
   }

   cursor.dispose();

   return null;
 }
 
Example 3
Source File: EbicsXmlFactory.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Qualifies a valid member of a substitution group. This method tries to use the built-in {@link
 * XmlObject#substitute(QName, SchemaType)} and if succesful returns a valid substitution which is
 * usable (not disconnected). If it fails, it uses low-level {@link XmlCursor} manipulation to
 * qualify the substitution group. Note that if the latter is the case the resulting document is
 * disconnected and should no longer be manipulated. Thus, use it as a final step after all markup
 * is included.
 *
 * <p>If newType is null, this method will skip {@link XmlObject#substitute(QName, SchemaType)}
 * and directly use {@link XmlCursor}. This can be used, if you are sure that the substitute is
 * not in the list of (pre-compiled) valid substitutions (this is the case if a schema uses
 * another schema's type as a base for elements. E.g. om:Observation uses gml:_Feature as the base
 * type).
 *
 * @param xobj the abstract element
 * @param newInstance the new {@link QName} of the instance
 * @param newType the new schemaType. if null, cursors will be used and the resulting object will
 *     be disconnected.
 * @return if successful applied {@link XmlObject#substitute(QName, SchemaType)} a living object
 *     with a type == newType is returned. Otherwise null is returned as you can no longer
 *     manipulate the object.
 */
public static XmlObject qualifySubstitutionGroup(
    XmlObject xobj, QName newInstance, SchemaType newType) {
  XmlObject substitute = null;

  if (newType != null) {
    substitute = xobj.substitute(newInstance, newType);
    if (substitute != null
        && substitute.schemaType() == newType
        && substitute.getDomNode().getLocalName().equals(newInstance.getLocalPart())) {
      return substitute;
    }
  }

  XmlCursor cursor = xobj.newCursor();
  cursor.setName(newInstance);
  QName qName = new QName("http://www.w3.org/2001/XMLSchema-instance", "type");
  cursor.removeAttribute(qName);
  cursor.toNextToken();
  if (cursor.isNamespace()) {
    cursor.removeXml();
  }

  cursor.dispose();

  return null;
}
 
Example 4
Source File: OmDecoderv20.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
private ObservationValue<?> getResult(OMObservationType omObservation) throws DecodingException {
    XmlObject xbResult = omObservation.getResult();

    if (xbResult.schemaType() == XmlAnyTypeImpl.type) {
        // Template observation for InsertResultTemplate operation
        if (!xbResult.getDomNode().hasChildNodes()) {
            return new SingleObservationValue<>(new NilTemplateValue());
        } else {
            try {
                xbResult = XmlObject.Factory.parse(xbResult.xmlText(getXmlOptions()).trim());
            } catch (XmlException e) {
                LOGGER.error("Error while parsing NamedValueValue", e);
            }
        }
    }
    // // Template observation for InsertResultTemplate operation
    // if (omObservation.getResult().schemaType() == XmlAnyTypeImpl.type &&
    // !omObservation.getResult().getDomNode().hasChildNodes()) {
    // return new SingleObservationValue<String>(new NilTemplateValue());
    // }

    if (xbResult.schemaType() == XmlBoolean.type) {
        // TruthObservation
        XmlBoolean xbBoolean = (XmlBoolean) xbResult;
        BooleanValue booleanValue = new BooleanValue(xbBoolean.getBooleanValue());
        return new SingleObservationValue<>(booleanValue);
    } else if (xbResult.schemaType() == XmlInteger.type) {
        // CountObservation
        XmlInteger xbInteger = (XmlInteger) xbResult;
        CountValue countValue = new CountValue(Integer.parseInt(xbInteger.getBigIntegerValue().toString()));
        return new SingleObservationValue<>(countValue);
    } else if (xbResult.schemaType() == XmlString.type) {
        // TextObservation
        XmlString xbString = (XmlString) xbResult;
        TextValue stringValue = new TextValue(xbString.getStringValue());
        return new SingleObservationValue<>(stringValue);
    } else {
        // result elements with other encoding like SWE_ARRAY_OBSERVATION
        Object decodedObject = decodeXmlObject(xbResult);
        if (decodedObject instanceof ObservationValue) {
            return (ObservationValue<?>) decodedObject;
        } else if (decodedObject instanceof GmlMeasureType) {
            GmlMeasureType measureType = (GmlMeasureType) decodedObject;
            QuantityValue quantitiyValue = new QuantityValue(measureType.getValue(), measureType.getUnit());
            return new SingleObservationValue<>(quantitiyValue);
        } else if (decodedObject instanceof ReferenceType) {
            if (omObservation.isSetType() && omObservation.getType().isSetHref()
                    && omObservation.getType().getHref().equals(OmConstants.OBS_TYPE_REFERENCE_OBSERVATION)) {
                return new SingleObservationValue<>(new ReferenceValue((ReferenceType) decodedObject));
            }
            return new SingleObservationValue<>(new CategoryValue(((ReferenceType) decodedObject).getHref()));
        } else if (decodedObject instanceof Geometry) {
            return new SingleObservationValue<>(new GeometryValue((Geometry) decodedObject));
        } else if (decodedObject instanceof AbstractGeometry) {
            SingleObservationValue<Geometry> result = new SingleObservationValue<>();
            result.setValue(new GeometryValue(((AbstractGeometry) decodedObject).getGeometry()));
            return result;
        } else if (decodedObject instanceof SweDataArray) {
            return new SingleObservationValue<>(new SweDataArrayValue((SweDataArray) decodedObject));
        } else if (decodedObject instanceof SweDataRecord) {
            return new SingleObservationValue<>(new ComplexValue((SweDataRecord) decodedObject));
        }
        throw new DecodingException(Sos2Constants.InsertObservationParams.observation,
                "The requested result type '%s' is not supported by this service!",
                decodedObject.getClass().getSimpleName());
    }
}
 
Example 5
Source File: SOSAdapterByGET.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
private boolean isExceptionReportV11(XmlObject object) {
    return object.schemaType() == ExceptionReportDocument.type;
}
 
Example 6
Source File: SOSAdapterByGET.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
private boolean isExceptionReportV11(XmlObject object) {
    return object.schemaType() == ExceptionReportDocument.type;
}