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

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


    if (mixed) return consumeMixed(l, index, subject, seq, ctx);
    return index;
  }

  public int toXML(Element elem, Resource rdf, int index, Set<Statement> pending, Context ctx) {
    Seq seq = rdf.getModel().getSeq(rdf);
    int max = maxOccurs.equals("unbounded")? Integer.MAX_VALUE : Integer.parseInt(maxOccurs);
    int start = index, occurs=0;
   
    while (occurs<max) {
      // record child components that have already been matched
      Set<element> matched = new HashSet<element>();
      // 'all' contains only elements
      nextContent: while (index < seq.size()) {
        index = produceMixed(seq,index,elem);
        for (int i = 0; element != null && i < element.length; i++) {
          if (matched.contains(element[i])) continue;
          int x = element[i].toXML(elem, rdf, index, pending,ctx);
          if (x>index) {
View Full Code Here


        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
View Full Code Here

    return index;
  }
 
  public int toXML(Element element, Resource rdf, int index, Set<Statement> pending, Context ctx) {
    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;
View Full Code Here

          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
                   
          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);
          return true;
        }
        else Gloze.logger.warn("undefined type: "+fullname);
      }
     
      stmt = m.createStatement(subject,prop,obj);     
      m.add(stmt);
      if (seq != null) seq.add(stmt.createReifiedStatement());     

      // we can't confuse a (single) simple rdf:value with an attribute
      Seq s = null;
      // Added extra condition - we should be able to turn off sequencing, risking confusion between attributes and object properties
      if (simple==null && ctx.isSequenced()) s = m.getSeq(obj.addProperty(RDF.type, RDF.Seq));

      // add attributes (and possibly define xmlns)
      NamedNodeMap nm = elem.getAttributes();
      for (int i=0; i<nm.getLength(); i++)
        noSchemaToRDF(obj, (Attr) nm.item(i),ctx);

      // add elements
      NodeList nl = elem.getChildNodes();
      for (int i=0; i<nl.getLength(); i++) {
        switch (nl.item(i).getNodeType()) {
        case Node.ELEMENT_NODE:
          Element e = (Element) nl.item(i);
          noSchemaToRDF(obj,e,s,ctx);
          break;
        case Node.TEXT_NODE:
          String value = ((Text) nl.item(i)).getNodeValue().trim();
          Literal lit = null;
          if (elem.hasAttributeNS(XML,"lang"))
            lit = m.createLiteral(value, elem.getAttributeNS(XML,"lang"));
          else
            lit = ctx.getModel().createLiteral(value);
         
          stmt = ctx.getModel().createStatement(obj,RDF.value,lit);
          if (!value.equals("")) {
            ctx.getModel().add(stmt);
            if (s!=null) s.add(stmt.createReifiedStatement());
          }
        }
      }
      return true;
    }
View Full Code Here

 
  /* drop XML element sequencing and mixing */

  public int toXML(Element element, Resource rdf, int index, Set<Statement> pending, Context ctx) {
    Document doc = element.getOwnerDocument();
    Seq seq = rdf.getModel().getSeq(rdf);
    Statement stmt = null;
    boolean qualify = !namespace.equals("##local");

    int max = maxOccurs.equals("unbounded")? Integer.MAX_VALUE : Integer.parseInt(maxOccurs);  
    int occurs = 0;
    for (; occurs<max ; occurs++, index++) {
      // consume mixed values
      index = produceMixed(seq,index,element);
      if (index<seq.size()) {
        stmt = (Statement) asStatement((Resource) seq.getObject(index+1));
        if (!toXML(element, stmt.getPredicate(), stmt.getObject(), qualify, ctx)) break;
      } else break;
    }
    // do any pending properties match?
    Set<Statement> done = new HashSet<Statement>();
View Full Code Here

  }

  private int textToXML(Element e, Resource rdf, int index, Set<Statement>pending, Context ctx) {
    Document doc = e.getOwnerDocument();
    // consume ordinal (indexed) statements
    Seq seq = rdf.getModel().getSeq(rdf);
    while (index<seq.size()) {
      Statement s = (Statement) asStatement((Resource) seq.getObject(index+1));
      if (s.getPredicate().equals(RDF.value))
        e.appendChild(doc.createTextNode(s.getLiteral().getString()));
      else return index;
      index++;
    }
View Full Code Here

      reification.addProperty(edmChild, bag);
    }

    List revNotes = profAttr.getRevisionNotes();
    if (!revNotes.isEmpty()) {
      Seq seq = model.createSeq(uri + "_" + property.getLocalName() + "_revNotesSeq");
      for (Iterator i = revNotes.iterator(); i.hasNext();)
        seq.add(i.next());
      reification.addProperty(edmRevNote, seq);
    }
  }
View Full Code Here

  public void testGetSeq()
  {
    final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/" + 170;
    model.createSeq(uri);
    final Seq s = model.getSeq(uri);
    Assert.assertEquals(uri, s.getURI());
    Assert.assertTrue(model.contains(s, RDF.type, RDF.Seq));
  }
View Full Code Here

    final Alt a = model.createAlt();
    final Literal tvLiteral = model.createLiteral("test 12 string 2");
    // Resource tvResObj = model.createResource( new ResTestObjF() );
    final Bag tvBag = model.createBag();
    final Alt tvAlt = model.createAlt();
    final Seq tvSeq = model.createSeq();
    //
    final Resource tvResource = model.createResource();
    Assert.assertEquals(tvLiteral, a.setDefault(tvLiteral).getDefault());
    Assert.assertEquals(tvLiteral, a.getDefaultLiteral());
    Assert.assertEquals(tvResource, a.setDefault(tvResource)
View Full Code Here

    Assert.assertTrue(model.contains(tv, RDF.type, RDF.Bag));
  }

  public void testCreateAnonSeq()
  {
    final Seq tv = model.createSeq();
    Assert.assertTrue(tv.isAnon());
    Assert.assertTrue(model.contains(tv, RDF.type, RDF.Seq));
  }
View Full Code Here

TOP

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

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.