[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Moxy mapping

Hi Magnus,

There are a couple of options:

1.  Create an XMLDirectMapping from an attribute on your object to the XPath "gml:Surface/@gml:id"
If the data corresponds to a property on your object then you can just create a mapping for it.  With the XPath above it will put the attribute on the same "gml:Surface" element created by your other mapping.

2.  Create an XMLTransformationMapping
If the data does not exist in your object and you want to create it with code you could use a transformation mapping.

        XMLTransformationMapping idMapping = new XMLTransformationMapping();
        idMapping.setAttributeName("someAttribute");     
        // AttributeTransformers are used to build to build the property value for the domain object.
        idMapping.setAttributeTransformer(new IdAttributeTransformer());
        // FieldTransformers are used to build the XML document.
        idMapping.addFieldTransformer("gml:Surface/@gml:id", new IdFieldTransformer());

IdAttributeTransformer is required to implement org.eclipse.persistence.mappings.transformers.AttributeTransformer and IdFieldTransformer is required to implement org.eclipse.persistence.mappings.transformers.FieldTransformer.


-Blaise

Magnus Heino wrote:

Hi.

I have this mapping:

        XMLDirectMapping interior = new XMLDirectMapping();
        interior.setAttributeName("interior");
        interior.setField(new XMLField("gml:Surface/gml:patches/gml:PolygonPatch/gml:interior/gml:LinearRing/gml:posList/text()"));
        interior.setSetMethodName("setInterior");
        interior.setGetMethodName("getInterior");
        position.addMapping(interior);


Reading xml documents works just fine.

When I write the xml however, gml:Surface is required to have a gml:id attribute. Is there any way to control this?

Thanks!

/Magnus Heino

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users