use of org.geotoolkit.wps.xml.v200.LiteralValue in project geotoolkit by Geomatys.
the class LiteralAdaptorTest method stringWPS2.
@Test
public void stringWPS2() {
final DomainMetadataType metaType = new DomainMetadataType("String", "http://www.w3.org/TR/xmlschema-2/#string");
final LiteralDataDomain domain = new LiteralDataDomain();
domain.setDataType(metaType);
final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
assertEquals(String.class, adaptor.getValueClass());
final DataOutput output = new DataOutput();
final LiteralValue lit = new LiteralValue();
lit.setValue("hello world");
final Data data = new Data(lit);
output.setData(data);
final Object result = adaptor.fromWPS2Input(output);
assertEquals("hello world", result);
}
use of org.geotoolkit.wps.xml.v200.LiteralValue in project geotoolkit by Geomatys.
the class LiteralAdaptorTest method booleanWPS2.
@Test
public void booleanWPS2() {
final DomainMetadataType metaType = new DomainMetadataType(null, "xs:boolean");
final LiteralDataDomain domain = new LiteralDataDomain();
domain.setDataType(metaType);
final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
assertEquals(Boolean.class, adaptor.getValueClass());
final DataOutput output = new DataOutput();
final LiteralValue lit = new LiteralValue();
lit.setValue("true");
final Data data = new Data(lit);
output.setData(data);
final Object result = adaptor.fromWPS2Input(output);
assertEquals(true, result);
}
use of org.geotoolkit.wps.xml.v200.LiteralValue in project geotoolkit by Geomatys.
the class WPSConvertersUtils method geojsonContentAsString.
/**
* Extract the GeoJSON content of a complex and return it as a String.
*
* Pre-condition : the complex must have exactly one content element
* Pre-condition : the content must be either of the type GeoJSONType, String
* or Node
*
* @param objContent the complex to read
* @return the complex content as a String
*/
public static String geojsonContentAsString(final Object objContent) {
ArgumentChecks.ensureNonNull("Data", objContent);
Object content = objContent;
if (content instanceof Data) {
List<Object> contents = ((Data) content).getContent();
if (contents == null || contents.isEmpty()) {
content = "";
} else if (contents.size() > 1) {
throw new UnconvertibleObjectException("We search for a single text content, but given data contains " + contents.size());
} else {
content = contents.get(0);
}
}
// Data can contain a literal value, so we test it after
if (content instanceof LiteralValue) {
content = ((LiteralValue) content).getValue();
} else if (content instanceof Node) {
// Otherwise, data could contain a Dom node (rarely), so we also test it
content = ((Node) content).getTextContent();
}
if (content instanceof String)
// TODO: remove CDATA ?
return (String) content;
throw new UnconvertibleObjectException("Cannot extract text content from source " + objContent.getClass().getName());
}
use of org.geotoolkit.wps.xml.v200.LiteralValue in project geotoolkit by Geomatys.
the class LiteralAdaptor method fromWPS2Input.
@Override
public T fromWPS2Input(DataOutput candidate) {
final Data data = candidate.getData();
final LiteralValue literalData = data.getLiteralData();
final String value = literalData.getValue();
return convert(value);
}
use of org.geotoolkit.wps.xml.v200.LiteralValue in project geotoolkit by Geomatys.
the class LiteralAdaptorTest method doubleWPS2.
@Test
public void doubleWPS2() {
final DomainMetadataType metaType = new DomainMetadataType(null, "xs:double");
final LiteralDataDomain domain = new LiteralDataDomain();
domain.setDataType(metaType);
final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
assertEquals(Double.class, adaptor.getValueClass());
final DataOutput output = new DataOutput();
final LiteralValue lit = new LiteralValue();
lit.setValue("3.14");
final Data data = new Data(lit);
output.setData(data);
final Object result = adaptor.fromWPS2Input(output);
assertEquals(3.14, (Double) result, DELTA);
}
Aggregations