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); }
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); }
/** * Accumulate all namespace declarations in a single {@link Namespace} instance. * This includes the Document-level {@link Namespace} but also all Bundle-level {@link Namespace}s. * * <p>This method is particular useful before serialization to XML since JAXB doesn't offer us the * means to generate prefix declaration in inner Elements. Hence, all namespaces need to be declared * at the root of the xml document. * * @param document Document from which Namespaces are accumulated * @return a new instance of {@link Namespace} */ static public Namespace accumulateAllNamespaces(Document document) { Namespace res=new Namespace(document.getNamespace()); for (Bundle b: pu.getNamedBundle(document)) { Namespace ns=b.getNamespace(); if (ns!=null) res.extendWith(ns); } return res; }
/** * Accumulate all namespace declarations in a single {@link Namespace} instance. * This includes the Document-level {@link Namespace} but also all Bundle-level {@link Namespace}s. * * <p>This method is particular useful before serialization to XML since JAXB doesn't offer us the * means to generate prefix declaration in inner Elements. Hence, all namespaces need to be declared * at the root of the xml document. * * @param document Document from which Namespaces are accumulated * @return a new instance of {@link Namespace} */ static public Namespace accumulateAllNamespaces(Document document) { Namespace res=new Namespace(document.getNamespace()); for (Bundle b: pu.getNamedBundle(document)) { Namespace ns=b.getNamespace(); if (ns!=null) res.extendWith(ns); } return res; }
/** * 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); } } }
public void makeDocAndTest(Statement[] stment, Bundle[] bundles, String file, Statement[] opt, boolean check) { Document doc = pFactory.newDocument(); for (int i = 0; i < stment.length; i++) { doc.getStatementOrBundle().add(stment[i]); } if (bundles != null) { for (int j = 0; j < bundles.length; j++) { doc.getStatementOrBundle().add(bundles[j]); } } updateNamespaces(doc); if (bundles!=null) { for (int j = 0; j < bundles.length; j++) { bundles[j].getNamespace().setParent(doc.getNamespace()); } } String file1 = (opt == null) ? file : file + "-S"; compareDocAndFile(doc, file1, check); if ((opt != null) && doOptional(opt)) { String file2 = file + "-M"; doc.getStatementOrBundle().addAll(Arrays.asList(opt)); compareDocAndFile(doc, file2, check); } }
public void makeDocAndTest(Statement[] stment, Bundle[] bundles, String file, Statement[] opt, boolean check) { Document doc = pFactory.newDocument(); for (int i = 0; i < stment.length; i++) { doc.getStatementOrBundle().add(stment[i]); } if (bundles != null) { for (int j = 0; j < bundles.length; j++) { doc.getStatementOrBundle().add(bundles[j]); } } updateNamespaces(doc); if (bundles!=null) { for (int j = 0; j < bundles.length; j++) { bundles[j].getNamespace().setParent(doc.getNamespace()); } } String file1 = (opt == null) ? file : file + "-S"; compareDocAndFile(doc, file1, check); if ((opt != null) && doOptional(opt)) { String file2 = file + "-M"; doc.getStatementOrBundle().addAll(Arrays.asList(opt)); compareDocAndFile(doc, file2, check); } }
public void makeDocAndTest(Statement[] stment, Bundle[] bundles, String file, Statement[] opt, boolean check) { Document doc = pFactory.newDocument(); for (int i = 0; i < stment.length; i++) { doc.getStatementOrBundle().add(stment[i]); } if (bundles != null) { for (int j = 0; j < bundles.length; j++) { doc.getStatementOrBundle().add(bundles[j]); } } updateNamespaces(doc); if (bundles!=null) { for (int j = 0; j < bundles.length; j++) { bundles[j].getNamespace().setParent(doc.getNamespace()); } } String file1 = (opt == null) ? file : file + "-S"; compareDocAndFile(doc, file1, check); if ((opt != null) && doOptional(opt)) { String file2 = file + "-M"; doc.getStatementOrBundle().addAll(Arrays.asList(opt)); compareDocAndFile(doc, file2, check); } }
public Document makePC1GraphAndSpecialization(ProvFactory pFactory) { Document graph = pFactory.newDocument(); String bName = "b123"; // needs to be generated Bundle bun = makePC1FullGraph(pFactory, bName); graph.getStatementOrBundle().add(bun); bun.setNamespace(Namespace.gatherNamespaces(bun)); Hashtable<String, String> namespaces = new Hashtable<String, String>(); // currently, no prefix used, all qnames map to PC1_NS namespaces.put("_", EX_NS); // new default namespace namespaces.put("xsd", NamespacePrefixMapper.XSD_NS); namespaces.put(EX_PREFIX, EX_NS); namespaces.put(DOT_PREFIX, DOT_NS); Entity bunEntity = pFactory.newEntity(bun.getId()); Entity a = pFactory.newEntity(new org.openprovenance.prov.xml.QualifiedName(EX_NS, globalA1.getId().getLocalPart(),null)); MentionOf ctx = pFactory.newMentionOf(a.getId(), globalA1.getId(), bunEntity.getId()); a.getOther().add(pFactory.newOther(DOT_NS, DOT_PREFIX, "color", "blue", name.XSD_STRING)); graph.getStatementOrBundle().add(bunEntity); graph.getStatementOrBundle().add(a); graph.getStatementOrBundle().add(ctx); graph.setNamespace(Namespace.gatherNamespaces(graph)); graph.getNamespace().extendWith(bun.getNamespace()); return graph; }