Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.Statement


   
    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);
    else  {
      stmt = m.createStatement(subject, prop, object);
      m.add(stmt);
      // this can only be a sequence
      if (seq != null) seq.add(stmt.createReifiedStatement());     
    }   
    return true;   
  }
View Full Code Here


    if (value==null) {
      if (prop==RDF.value || type.endsWith("#ID")) return null;
      return m.createStatement(subject,prop,"");
    }
   
    Statement stmt = null;
    if (type.endsWith("#ID")) ;
    // ID is used to name the owning element - don't generate RDF
    // IDREF to globally named element
    else if (type.endsWith("#IDREF")) {
      Resource r = m.createResource(addFragment(ctx.getBaseMap(), value).toString());
View Full Code Here

      }
      else if (type!=null && type.equals(XSD_URI+"#NMTOKENS")) {
        v = listToString(r,elem,XSD.NMTOKEN.getURI(),ctx);
      }
      else if (r.hasProperty(RDF.value)) {
        Statement stmt = r.getProperty(RDF.value);
        if (type!=null && type.equals(XSD_URI+"#IDREF"))
          v = stmt.getResource().getLocalName();
        else if (stmt.getObject() instanceof Literal) v = stmt.getString();   
      }     
      else if (r.canAs(RDFList.class)) {
        v = listToString(r,elem,null,ctx);
      }
    }
View Full Code Here

      for (ResIterator classes = ont.listSubjectsWithProperty(RDF.type,type); classes.hasNext(); ) {
        Resource c = classes.nextResource();
        if (c.isAnon()) {
          // an orphan is anonymous and has no referee other than itself
          Resource r = null;
          Statement s = null;
          for (StmtIterator si = ont.listStatements(null,null,c); si.hasNext(); ) {
            s = si.nextStatement();
            r = s.getSubject();
            if (!r.equals(c)) break;
          }         
          if (r==null || r.equals(c)) {
            b = true;
            c.removeProperties();
View Full Code Here

  public boolean toXML(Element e, RDFNode rdf, Set<Statement> pending, Context ctx) {
    if (rdf instanceof Resource) {
      Resource r = ((Resource)rdf);
      // add simple content encoded as rdf:value
      Statement s = r.getProperty(RDF.value);
      if (extension!=null) extension.toXML(e,r,pending,ctx);
      else if (restriction!=null) restriction.toXML(e,r,pending,ctx);
      else if (s!=null && s.getObject() instanceof Literal) {
        Literal l = (Literal) s.getObject();
        e.appendChild(e.getOwnerDocument().createTextNode(l.getString()));
      }
      return true;
    }
    return false;
View Full Code Here

    if (c!=null) index = c.toRDF(subject,elem, index, seq, null, false, ctx);
    else { // it may be a schema type
      String type = expandQName(ctx.getDefaultNS(), base, m);
      if (type!=null && type.startsWith(schema.XSD_URI)) {
        // predefined schema datatype
        Statement stmt = schema.toRDFStatement(subject, elem, RDF.value, getValue(elem), type, ctx);
        if (stmt!=null) m.add(stmt);
      }
    }
   
    if (sequence!=null) index = sequence.toRDF(subject,elem,index,seq, mixed, ctx);
View Full Code Here

  public void toXML(Element e, Resource subject, Set<Statement> pending, Context ctx) {
    schema xs = (schema) this.get_owner();
    Document doc = e.getOwnerDocument();
    if (base != null) {
      String b = expandQName(ctx.getDefaultNS(),base, ctx.getModel());
      Statement s = subject.getProperty(RDF.value);
      if (s!=null) xs.toXMLText(e,s.getObject(),b,null,ctx);
      else if (b.equals(schema.ID) && !subject.isAnon())
        e.appendChild(doc.createTextNode(subject.getLocalName()));
    }
    // add attributes that extend simple content
    for (int i = 0; _attribute != null && i < _attribute.length; i++)
View Full Code Here

      // are all restrictions observed
      if (restrictions!=null)
        for (restriction r: restrictions)
          if (!r.isValid(value, null, l, ctx)) return false;

      Statement stmt = m.createStatement(subject, prop, l);
      m.add(stmt);
      if (seq != null) seq.add(stmt.createReifiedStatement());
      return true;
    }
    else return false;
  }
View Full Code Here

    String value = getValue(elem);
    if (value==null && _default != null) value = _default;
    String uri = createURI(m,ctx);
    Property prop = null;
    if (uri != null) prop = m.createProperty(uri);
    Statement stmt=null;
    // the element may be defined locally or globally (follow ref)
    element def = getDefinition(ctx.getModel(),ctx);
   
    // explicit xsi:type
    if (elem.hasAttributeNS(schema.XSI,"type")) {
      String t = elem.getAttributeNS(schema.XSI,"type");
      String fullname = expandQName(ctx.getDefaultNS(),t,elem,ctx.getModel());
      complexType c = ctx.getComplexType(fullname);
      if (c!=null) {
        String id = c.getID(elem,ctx);
        Resource o = id==null?m.createResource():m.createResource(addFragment(ctx.getBaseMap(), id).toString());
        stmt = m.createStatement(subject,prop,o);
        // the new resource, o, becomes the subject
       
        if (is_nillable()
         && elem.hasAttributeNS(schema.XSI,"nil")
         && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
          o.addProperty(RDF.value,RDF.nil);
       
        Seq subSeq = null;
        if (ctx.isSequenced() && elem.hasChildNodes() && c.needSeq(new HashSet<String>(), ctx))
          subSeq = m.getSeq(o.addProperty(RDF.type, RDF.Seq));
 
        int index = c.toRDF(o, elem, 0, subSeq,null,true,ctx);
        // mop up remaining values in sequence
        produceMixed(subSeq, index, elem);

        m.add(stmt);
        if (seq != null) seq.add(stmt.createReifiedStatement());
        return true;
      }
      else Gloze.logger.warn("undefined type: "+fullname);
    }
    // predefined schema datatype
    String type = expandQName(ctx.getDefaultNS(),def.getType(),m);
    if (type!=null && type.startsWith(schema.XSD_URI)) {
      if (is_nillable() && elem.hasAttributeNS(schema.XSI,"nil") && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
        stmt = m.createStatement(subject,prop,RDF.nil);
      else {
        if (type.equals(schema.XSD_URI+"#ID") && value!=null && !value.trim().equals("")) {
          Resource o = m.createResource(addFragment(ctx.getBaseMap(), value.trim()).toString());
          stmt = m.createStatement(subject,prop,o);
        }
        else stmt = schema.toRDFStatement(subject, elem, prop, value, type, ctx);
      }
    }

    // user defined simple type
    XMLBean t = def.get_type(ctx);
    if (t instanceof simpleType) {
      // an empty, as opposed to nil, element is null
      if (value==null) value = "";
      if (is_nillable() && elem.hasAttributeNS(schema.XSI,"nil") && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
        stmt = m.createStatement(subject,prop,RDF.nil);
     
      // if a simple type is nil there is no content or attributes
      // initialise restriction set according to level of restriction checking required
      else {
        Boolean b = ((simpleType) t).toRDF(subject, prop, elem, value, seq, null, ctx);
        if (!b) Gloze.logger.warn("cannot map value "+value+" into simpleType "+type);
      }
    }
    else if (t instanceof complexType) {
      // look for a global ID
      String id = ((complexType) t).getID(elem,ctx);
      Resource o = id==null?m.createResource():m.createResource(addFragment(ctx.getBaseMap(), id).toString());
      stmt = m.createStatement(subject,prop,o);
      // the new resource, o, becomes the subject
      if (is_nillable() && elem.hasAttributeNS(schema.XSI,"nil") && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
        o.addProperty(RDF.value,RDF.nil);

      Seq subSeq = null;
      if (ctx.isSequenced() && elem.hasChildNodes() && ((complexType) t).needSeq(new HashSet<String>(),ctx))
        subSeq = m.getSeq(o.addProperty(RDF.type, RDF.Seq));
     
      int index = ((complexType) t).toRDF(o, elem, 0, subSeq, null,true,ctx);
      // mop up remaining values in sequence
      produceMixed(subSeq, index, elem);
    }
    else if (value!=null && stmt==null){ // untyped!
      Literal l = m.createLiteral(schema.processWhitespace(elem,value,null,ctx));
      stmt = m.createStatement(subject,prop,l);     
    }
    else if (type==null){ // empty
      if (is_nillable() && elem.hasAttributeNS(schema.XSI,"nil") && elem.getAttributeNS(schema.XSI,"nil").equals("true"))
        stmt = m.createStatement(subject,prop,RDF.nil);
      // link to anonymous resource
      else stmt = m.createStatement(subject,prop,m.createResource());
    }

    // if the statement was boxed, only add the link to the box
    if (stmt !=null) {
      m.add(stmt);
      if (seq != null) seq.add(stmt.createReifiedStatement());
    }
    return true;
  }
View Full Code Here

    populate();
    Seq seq = rdf.getModel().getSeq(rdf);
    // iterated elements may occur multiple times (don't check they're done)
    int max = maxOccurs.equals("unbounded")?Integer.MAX_VALUE:Integer.parseInt(maxOccurs);   
    // consume properties in sequence
    Statement stmt = null;
    int occurs = 0;
    for (; occurs<max; occurs++, index++) {
      // consume mixed values
      index = produceMixed(seq,index,element);
      if (index<seq.size()) {
        // the object of _i is a reified statement
        stmt = (Statement) asStatement((Resource) seq.getObject(index+1));
        element e = substitute(stmt,ctx);
        if (e!=null) e.toXML(element, stmt.getObject(),ctx);
        else break;
      }
      else break;
    }
    // do any pending properties match?
    Set<Statement> done = new HashSet<Statement>();
    for (Iterator ui = pending.iterator(); occurs<max && ui.hasNext(); ) {
      stmt = (Statement) ui.next();
      element e = substitute(stmt,ctx);
      if (e!=null) {
        e.toXML(element, stmt.getObject(),ctx);
        occurs++;
        done.add(stmt);
      }
    }
    pending.removeAll(done);
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.Statement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.