Search in sources :

Example 1 with GraphEntity

use of won.shacl2java.runtime.model.GraphEntity in project webofneeds by researchstudio-sat.

the class ToRdfUtils method getAsNode.

public static Node getAsNode(Object value) {
    if (value instanceof GraphEntity) {
        GraphEntity entity = (GraphEntity) value;
        entity.createNodeIfNecessary();
        return entity.getNode();
    }
    if (value instanceof Boolean || value instanceof Number || value instanceof String || value instanceof XSDDateTime) {
        return NodeFactory.createLiteralByValue(value, TypeMapper.getInstance().getTypeByValue(value));
    }
    if (value instanceof URI) {
        return NodeFactory.createURI(value.toString());
    }
    if (value instanceof Enum) {
        // if we created it, it has a getValue() method -> use that
        try {
            Method getValue = value.getClass().getMethod("getValue");
            if (getValue != null) {
                return getAsNode(getValue.invoke(value));
            }
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Error converting value {} to Node", value, e);
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Could not convert value {} to Node", value);
    }
    return null;
}
Also used : XSDDateTime(org.apache.jena.datatypes.xsd.XSDDateTime) Method(java.lang.reflect.Method) URI(java.net.URI) GraphEntity(won.shacl2java.runtime.model.GraphEntity)

Aggregations

Method (java.lang.reflect.Method)1 URI (java.net.URI)1 XSDDateTime (org.apache.jena.datatypes.xsd.XSDDateTime)1 GraphEntity (won.shacl2java.runtime.model.GraphEntity)1