javaxmljaxbfilterfunction

Creating different operators in JaxB?


I'm using the OGC schemas from https://github.com/highsource/ogc-schemas.

I'm looking at the unmarshalled object structure from deserializing XML to the JaxB object.

I'm trying to construct a custom object to serialize to XML using JaxB.

The filter schema is seen http://schemas.opengis.net/filter/2.0/filter.xsd

I'm unmarshalling the object like so:

JAXBElement<FilterType> filter = (JAXBElement<FilterType>) unmarshal.unmarshal(new File("Filter01.xml"));

Now, I'm looking at the internal objects and see that I have different filter types. I want to create a filter type that is a binarylogicaloperator and initialize it with the proper data. The initialization part of this is what is confusing to me.

IE:

BinaryLogicOpType blop = new BinaryLogicOpType();


Solution

  • Something along the lines:

    ObjectFactory objectFactory = new ObjectFactory()
    BinaryLogicOpType _or = new BinaryLogicOpType();
    JAXBElement<BinaryLogicOpType> root = objectFactory.createOr(_or);
    
    BinaryComparisonOpType weightIsLessThan100 = new BinaryComparisonOpType();
    _or.getOps()
      .add(objectFactory.createPropertyIsLessThan(weightIsLessThan100));
    
    JAXBElement<String> weightValueReference = 
        objectFactory.createValueReference("weight");
    LiteralType _100 = new LiteralType();
    _100.getContent().add(100);
    JAXBElement<LiteralType> _100Literal = objectFactory.createLiteral(_100);
    
    weightIsLessThan100.getExpression().add(weightValueReference);
    weightIsLessThan100.getExpression().add(_100Literal);
    

    And so on.