public boolean toRDF(Node node, Resource subject, Property prop, String value, String type, Seq seq, Set<restriction> restrictions, Context ctx)
throws Exception {
if (type!=null && type.equals(XSD_URI+"#anySimpleType")) type = RDFS.Literal.getURI();
RDFDatatype dt = getDatatype(type);
Model m = ctx.getModel();
Statement stmt = null;
RDFNode object = null;
if (value==null) return true;
// are all restrictions observed
if (restrictions!=null)
for (restriction r: restrictions)
if (!r.isValid(value,type,ctx)) return false;
simpleType s = ctx.getSimpleType(type);
if (s!=null) return s.toRDF(subject,prop,node,value,seq,restrictions,ctx);
// this may be an ID embedded in element content
else if (type!=null && type.equals(XSD_URI+"#ID")) {
String uri = subject.isAnon()?null:subject.getURI();
String frag = addFragment(ctx.getBaseMap(), value).toString();
if (frag.equals(uri)) return true;
else object = m.createResource(frag);
}
else if (type!=null && type.equals(XSD_URI+"#IDREF"))
object = m.createResource(addFragment(ctx.getBaseMap(), value).toString());
else if (type!=null && type.equals(XSD_URI+"#IDREFS"))
object = toRDFList(node,value,XSD.IDREF.getURI(),null,ctx);
else if (type!=null && type.equals(XSD_URI+"#ENTITIES"))
object = toRDFList(node,value,XSD.ENTITY.getURI(),null,ctx);
else if (type!=null && (type.equals(XSD_URI+"#QName") || type.equals(XSD_URI+"#NOTATION")))
object = m.createResource(expandQName(ctx.getDefaultNS(),value,node,ctx.getModel()));
else if (type!=null && type.equals(XSD_URI+"#anyURI")) {
URI uri = null;
if (isValidURI(value)) uri = new URI(value);
// it may be a relative URI
// to avoid confusion it should begin with an initial name character
// ensure it isn't a QName
else if (value.indexOf(":")<0 && Character.isJavaIdentifierStart(value.charAt(0)))
uri = resolveBase(node, new URI(value), ctx);
if (uri!=null) object = m.createTypedLiteral(uri.toString(),dt);
else return false;
}
else if (type!=null && type.equals(XSD_URI+"#anySimpleType")) {
object = m.createTypedLiteral(value==null?"":value,dt);
}
else if (RDFS.Literal.getURI().equals(type)) {
object = m.createLiteral(value==null?"":value);
}
else if (value!=null && dt!=null && dt.isValid(value)) object = m.createTypedLiteral(value, dt);
else object = m.createLiteral(value==null?"":value);
if (object==null) return false;
// if no property is supplied just add the value to the sequence/list
if (prop==null && seq!=null) seq.add(object);