All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openprovenance.prov.sql.SQLValueConverter Maven / Gradle / Ivy

Go to download

Java Objects representing the PROV model, XML serialiser/deserialiser for them, and ORM mapping generated by HyperJaxb.

The newest version!
package org.openprovenance.prov.sql;
import org.openprovenance.prov.model.Name;
import org.openprovenance.prov.model.QualifiedName;
import javax.xml.datatype.XMLGregorianCalendar;

public class SQLValueConverter  {
    
    static Name name=ProvFactory.getFactory().getName();

    static public AValue convertToAValue(QualifiedName datatype, Object value) {
	if (datatype.equals(name.XSD_STRING)) {
	    AValue res=new AValue();
	    res.setString((String) value);
	    return res;
	}
	if (datatype.equals(name.XSD_INT)) {
	    AValue res=new AValue();
	    res.setLong(((Integer) value).longValue());
	    return res;
	}
	if (datatype.equals(name.XSD_LONG)) {
	    AValue res=new AValue();
	    res.setLong((Long) value);
	    return res;
	}
	if (datatype.equals(name.XSD_SHORT)) {
	    AValue res=new AValue();
	    res.setLong(((Short) value).longValue());
	    return res;
	}
	if (datatype.equals(name.XSD_DOUBLE)) {
	    AValue res=new AValue();
	    res.setDouble((Double) value);
	    return res;
	}
	if (datatype.equals(name.XSD_FLOAT)) {
	    AValue res=new AValue();
	    res.setFloat((Float) value);
	    return res;
	}
	if (datatype.equals(name.XSD_DECIMAL)) {
	    AValue res=new AValue();
//	    res.setDecimal((java.math.BigDecimal) value);
	    return res;
	}
	if (datatype.equals(name.XSD_BOOLEAN)) {
	    AValue res=new AValue();
//	    res.setBoolean((Boolean) value);
	    return res;
	}
	if (datatype.equals(name.XSD_BYTE)) {
	    AValue res=new AValue();
	    res.setLong(((Byte) value).longValue());
	    return res;
	}
	if (datatype.equals(name.XSD_UNSIGNED_INT)) {
	    AValue res=new AValue();
	    res.setLong((Long) value);
	    return res;
	}
	if (datatype.equals(name.XSD_UNSIGNED_SHORT)) {
	    AValue res=new AValue();
	    //throw new UnsupportedOperationException();
	    return res;
	}
	if (datatype.equals(name.XSD_UNSIGNED_BYTE)) {
	    AValue res=new AValue();
	    //throw new UnsupportedOperationException();
	    return res;
	}
	if (datatype.equals(name.XSD_UNSIGNED_LONG)) {
	    AValue res=new AValue();
	    //res.setUnsignedInt((Long) value);
	    return res;
	}
	if (datatype.equals(name.XSD_INTEGER)) {
	    AValue res=new AValue();
	    //throw new UnsupportedOperationException();
	    return res;
	}
	if (datatype.equals(name.XSD_NON_NEGATIVE_INTEGER)) {
	    AValue res=new AValue();
	    //throw new UnsupportedOperationException();
	    return res;
	}
	if (datatype.equals(name.XSD_NON_POSITIVE_INTEGER)) {
	    AValue res=new AValue();
	    //throw new UnsupportedOperationException();
	    return res;
	}
	if (datatype.equals(name.XSD_POSITIVE_INTEGER)) {
	    AValue res=new AValue();
	    //throw new UnsupportedOperationException();
	    return res;
	}
	if (datatype.equals(name.XSD_ANY_URI)) {
	    AValue res=new AValue();
//	    res.setAnyURI( value.toString());
	    return res;
	}
	if (datatype.equals(name.PROV_QUALIFIED_NAME)) {
	    AValue res=new AValue();
	    res.setQualifiedName((org.openprovenance.prov.sql.QualifiedName) value); 
	    return res;
	}
	if (datatype.equals(name.XSD_DATETIME)) {
	    AValue res=new AValue();
	    res.setDateTime((XMLGregorianCalendar) value);
	    return res;
	}
        if (datatype.equals(name.XSD_GYEAR)) {
	    AValue res=new AValue();
	    res.setGYear((XMLGregorianCalendar) value);
	    return res;
        }
	
	
	if ((datatype.equals("rdf:XMLLiteral"))
	    || (datatype.equals("xsd:normalizedString"))
	    || (datatype.equals("xsd:token"))
	    || (datatype.equals("xsd:language"))
	    || (datatype.equals("xsd:Name"))
	    || (datatype.equals("xsd:NCName"))
	    || (datatype.equals("xsd:NMTOKEN"))
	    || (datatype.equals("xsd:hexBinary"))
	    || (datatype.equals("xsd:base64Binary"))) {

	    return null;
	}

	return null;
    }



    public static Object convertFromAValue(AValue target) {
	Object o;
	if ((o=target.getString())!=null) {
	    return o;
	}
	if ((o=target.getQualifiedName())!=null) {
	    return o;
	}
	if ((o=target.getFloat())!=null) {
	    return o;
	}
	if ((o=target.getDouble())!=null) {
	    return o;
	}
	if ((o=target.getDateTime())!=null) {
	    return o;
	}
	if ((o=target.getLong())!=null) {
		return o;
	}
	if ((o=target.getGYear())!=null) {
		return o;
	}

	return null;
    }
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy