/** * 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; }
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; }