private Namespace decodePrefixes(JsonObject bundleStructure) { Namespace ns = new Namespace(); // prefixes prov and xsd are implicit in prov-json ns.addKnownNamespaces(); JsonObject prefixes = getObjectAndRemove(bundleStructure, PROV_JSON_PREFIX); if (prefixes != null) { for (Map.Entry<String, JsonElement> pair : prefixes.entrySet()) { String prefix = pair.getKey(); String uri = pair.getValue().getAsString(); if (prefix.equals("default")) { ns.registerDefault(uri); } else { ns.register(prefix, uri); } } } return ns; }
/** * @param name the QName to convert to string * @param child argument used just for the purpose of debugging when throwing an exception * @return a string representation of the QualifiedName */ public String qualifiedNameToString(QName name, Namespace child) { if ((getDefaultNamespace()!=null) && (getDefaultNamespace().equals(name.getNamespaceURI()))) { return name.getLocalPart(); } else { String pref=getNamespaces().get(name.getNamespaceURI()); if (pref!=null) { return pref + ":" + name.getLocalPart(); } else { if (parent!=null) { return parent.qualifiedNameToString(name,this); } else throw new QualifiedNameException("unknown qualified name " + name + " with namespace " + toString() + ((child==null)? "" : (" and " + child))); } } }
public NamespacePrefixMapper(Namespace nss) { if (nss!=null) { this.defaultNamespace=nss.getDefaultNamespace(); } String xsd_prefix=nss.getNamespaces().get(XSD_NS); this.nss=new HashMap<String, String>(nss.getPrefixes()); // don't modify the received map this.nss.put(xsd_prefix, DOMProcessing.XSD_NS_FOR_XML); //System.out.println("PREFIXES IS " + nss); //System.out.println("DEFAULT " + defaultNamespace); }
public NamespaceGatherer() { ns.addKnownNamespaces(); ns.setDefaultNamespace(null); }
public void unregisterDeafult(String namespace) { String val=getDefaultNamespace(); if (val!=null){ if (val.equals(namespace)) { setDefaultNamespace(null); } } }
public NamespaceGatherer(Hashtable<String, String> prefixes, String defaultNamespace) { ns.getPrefixes().putAll(prefixes); //TODO create inverse map! ns.setDefaultNamespace(defaultNamespace); }
public void testNamespaces1 () { Activity a1=pFactory.newActivity(q("a1")); Document doc=pFactory.newDocument(); doc.getStatementOrBundle().add(a1); Namespace nss=Namespace.gatherNamespaces(doc); //System.out.println("Default ns is: " + nss.getDefaultNamespace()); //System.out.println("All ns: " + nss.getPrefixes()); assertNull(nss.getDefaultNamespace()); assertTrue(nss.getPrefixes().size()==3); assertTrue(nss.check("prov", NamespacePrefixMapper.PROV_NS)); assertTrue(nss.check("ex", EXAMPLE_NS)); assertTrue(nss.check("xsd", NamespacePrefixMapper.XSD_NS)); }
public Bundle doAction(Bundle b, ProvUtilities u) { List<Statement> sRecords = new LinkedList<Statement>(); QualifiedName bundleId=b.getId(); Namespace old=Namespace.getThreadNamespace(); Namespace bundleNamespace; if (b.getNamespace()!=null) { bundleNamespace=new Namespace(b.getNamespace()); } else { bundleNamespace=new Namespace(); } bundleNamespace.setParent(new Namespace(old)); //ensure to make a copy of old, since setting might otherwise create a loop Namespace.withThreadNamespace(bundleNamespace); c.startBundle(bundleId, b.getNamespace()); for (Statement s : u.getStatement(b)) { sRecords.add((Statement) u.doAction(s, this)); } return c.newNamedBundle(bundleId, b.getNamespace(), sRecords); }
localNamespace.addKnownNamespaces(); localNamespace.setParent(namespace); namespace=localNamespace.getParent(); return c.newNamedBundle(bundleId,localNamespace,records3); String iri1=unwrap(getTokenString(ast.getChild(1))); if (pre!=null) { // should not occur namespace.register(pre, iri1); namespace.registerDefault(iri1); return null;
public void writeDocument(org.openprovenance.prov.model.Document doc, String file) { Namespace.withThreadNamespace(doc.getNamespace()); System.out.println("saving document ... "); @SuppressWarnings("unused") Document doc2 = u.persist((org.openprovenance.prov.sql.Document) doc); dbKeys.put(file, ((org.openprovenance.prov.sql.Document) doc).getPk()); System.out.println("saved document " + ((org.openprovenance.prov.sql.Document) doc).getPk() + " for " + file); }
protected synchronized Namespace initialValue () { return new Namespace(); } };
/** * After reading a document, this method should be called to ensure that Namespaces are properly chained. * @param document a {@link Document} to update */ public void updateNamespaces(Document document) { Namespace rootNamespace = Namespace.gatherNamespaces(document); document.setNamespace(rootNamespace); for (org.openprovenance.prov.model.Bundle bu: utils.getBundle(document)) { Namespace ns=bu.getNamespace(); if (ns!=null) { ns.setParent(rootNamespace); } else { ns=new Namespace(); ns.setParent(rootNamespace); bu.setNamespace(ns); } } }
/** * Extends this Namespace with all the prefix/namespace registration of the Namespace received as argument. * @param ns the {@link Namespace} whose prefix/namespace registration are added to this {@link Namespace}. */ public void extendWith(Namespace ns) { if (ns==null) return; if (ns.getDefaultNamespace()!=null) { registerDefault(ns.getDefaultNamespace()); } for (String prefix: ns.prefixes.keySet()) { register(prefix, ns.prefixes.get(prefix)); } }
public Document toDocument () { List<Statement> ll=new LinkedList<Statement>(); add1DValues(ll,variables); add2Dvalues(ll,attributes); Document dummy=pf.newDocument(null,ll,new LinkedList<Bundle>()); Document result=pf.newDocument(pf.newNamespace(Namespace.gatherNamespaces(dummy)),ll,new LinkedList<Bundle>()); return result; }
public Document expander(Document docIn, Bindings bindings1) { Bundle bun = (Bundle) docIn.getStatementOrBundle().get(0); Groupings grp1 = Groupings.fromDocument(docIn); logger.debug("expander: Found groupings " + grp1); Bundle bun1 = (Bundle) expand(bun, bindings1, grp1).get(0); Document doc1 = pf.newDocument(); doc1.getStatementOrBundle().add(bun1); bun1.setNamespace(Namespace.gatherNamespaces(bun1)); doc1.setNamespace(new Namespace()); return doc1; }
protected QualifiedName convertURIToQualifiedName(URI uri) { QualifiedName qualifiedName; String uriNamespace = uri.getNamespace(); String prefix=namespace.getNamespaces().get(uriNamespace); String uriLocalName = qnU.escapeProvLocalName(uri.getLocalName()); if (prefix!=null) { qualifiedName = pFactory.newQualifiedName(uriNamespace, uriLocalName, prefix); } else { String defaultNS=namespace.getDefaultNamespace(); if ((defaultNS!=null) && (defaultNS.equals(uriNamespace))) { qualifiedName = pFactory.newQualifiedName(uriNamespace, uriLocalName,null); } else { namespace.newPrefix(uriNamespace); String pref=namespace.getNamespaces().get(uriNamespace); qualifiedName = pFactory.newQualifiedName(uriNamespace, uriLocalName, pref); } } return qualifiedName; }
private QualifiedName stringToQualifiedName(String attr1) { return namespace.stringToQualifiedName(attr1,pFactory); }
public void addSeed(Document doc, long seed, String name) { Namespace namespace = doc.getNamespace(); QualifiedName qn = namespace.stringToQualifiedName(name, pf); for (StatementOrBundle statement : doc.getStatementOrBundle()) { if (statement instanceof Identifiable) { Identifiable ss = (Identifiable) statement; if ((ss.getId() != null) && (ss.getId().equals(qn))) { namespace.register(TERM_PREFIX, TERM_NS); namespace.addKnownNamespaces(); ((HasOther) ss).getOther() .add(pf.newOther(TERM_NS, "seed", TERM_PREFIX, seed, pf.getName().XSD_LONG)); return; } } } }
public void addKnownNamespaces() { getPrefixes().put("prov",NamespacePrefixMapper.PROV_NS); getNamespaces().put(NamespacePrefixMapper.PROV_NS,"prov"); getPrefixes().put("xsd",NamespacePrefixMapper.XSD_NS); getNamespaces().put(NamespacePrefixMapper.XSD_NS,"xsd"); }
id = currentNamespace.stringToQualifiedName(idStr, pf); Namespace ns = decodePrefixes(attributeMap); currentNamespace = ns; currentNamespace.setParent(documentNamespace); id = currentNamespace.stringToQualifiedName(idStr, pf); @SuppressWarnings("rawtypes") Collection statements = decodeBundle(attributeMap); List<Attribute> attributes = (List<Attribute>) ll; for (Map.Entry<String, JsonElement> aPair : attributeMap.entrySet()) { QualifiedName attributeName = currentNamespace.stringToQualifiedName(aPair.getKey(),pf); JsonElement element = aPair.getValue(); values = pickMultiValues(element);