📄 nodebridgeexec_rdf2xml.java
字号:
package it.itc.ectrl.normkit.dnorm_rdf2xml.impl;
import java.util.*;
import java.net.*;
import edu.unika.aifb.kaon.api.change.*;
import edu.unika.aifb.kaon.api.oimodel.*;
import edu.unika.aifb.kaon.api.KAONException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.xpath.XPathResult;
import it.itc.ectrl.normkit.common.NormMapModel.*;
import it.itc.ectrl.normkit.common.*;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
// an information to node bridge: inContextOf(PropertyNode) has to be added
// this bridge apparently doesn't address text nodes ... mainly because the RDF text nodes can't be uniquely identified ...
/**
* This class represents an execution of a Normalisation Bridge in the RDF->XML direction. Each instance of this class takes care for transformation of all instances of an RDFS concept into XML data.
* @author Oliver Fodor (fodor@itc.it)
*/
public class NodeBridgeExec_RDF2XML {
NodeBridge m_nodebridge;
D_Normalisation_RDF2XMLImpl m_d_norm;
String m_currentRDFInstance;
public NodeBridgeExec_RDF2XML (D_Normalisation_RDF2XMLImpl d_norm, NodeBridge nodebridge, String currentRDFInstance)
{
m_d_norm = d_norm;
m_nodebridge = nodebridge;
m_currentRDFInstance = currentRDFInstance;
}
/*
public Collection getTranslatedNodes() throws NormalisationException { // change to getTranslatedUniqueNode
Collection translatedNodes = new Vector();
if (m_nodebridge.getRelatedOntologyEntity() == CNOVocabulary.URI_RDFS_LITERAL)
return null;
else {
try {
//query for just those instances which are in context of the fromInstance
String instanceQuery;
//if (m_fromInstance != null) // this is probably never executed
// instanceQuery = "[" + m_nodebridge.getRelatedOntologyEntity() + "] AND SOME( INVERSE (<" + m_nodebridge.getContextProperty() + ">),{!" + m_fromInstance + "!})";
//else // root
instanceQuery = "[" + m_nodebridge.getRelatedOntologyEntity() + "]";
Collection instQueryResult = m_d_norm.getSourceModel().executeQuery(instanceQuery);
Iterator i = instQueryResult.iterator();
for(; i.hasNext(); ) {
Instance i_node = (Instance) i.next();
// REVISE THIS C_NORMENTRY seems to be unnecessary
C_NormalisationEntry normalisationEntry = new C_NormalisationEntry (i_node.getURI(), TransformationUtil.extractElementName(m_nodebridge.getRelatedXPathEntity()), m_nodebridge.getURI());
translatedNodes.add(normalisationEntry);
}
return translatedNodes;
} catch (Exception e) {
e.printStackTrace();
throw new NormalisationException("Exception while executng NodeBridge.", e);
}
}
}
*/
public String getTranslatedUniqueNode() throws NormalisationException { // change to getTranslatedUniqueNode
try {
if (m_nodebridge.getRelatedOntologyEntity() == CNOVocabulary.URI_RDFS_LITERAL)
return null;
else {
String instanceQuery = "[" + m_nodebridge.getRelatedOntologyEntity() + "]";
Collection instQueryResult = m_d_norm.getSourceModel().executeQuery(instanceQuery);
Iterator i = instQueryResult.iterator();
Instance i_node = (Instance) i.next();
return i_node.getURI();
}
} catch (Exception e) {
e.printStackTrace();
throw new NormalisationException("Exception while executing NodeBridge.", e);
}
}
protected void processNodeBridgeWithHasBridges() throws NormalisationException {
try {
Vector hasBridgesAttribToProcess = m_nodebridge.getOrderedHasBridgesAttrib();
Vector hasBridgesToProcess = m_nodebridge.getOrderedHasBridges();
//System.out.println("hasBridgesToProcess " + hasBridgesToProcess.size());
String currentPathBridgeURI;
String curentPathBridgeXPath;
String[] currentPathBridgeParameters;
String inlineNodeNameToFlush;
AttributesImpl attList = new AttributesImpl();
Collection pbResult;
Iterator bridgeIter;
Iterator instanceIter;
String currentXPath = m_nodebridge.getRelatedXPathEntity();
if (hasBridgesAttribToProcess != null) {
// process all bridges for nested attributes (in the order defined by XSD)
bridgeIter = hasBridgesAttribToProcess.iterator();
for (;bridgeIter.hasNext();) {
currentPathBridgeParameters = (String[]) bridgeIter.next();
currentPathBridgeURI = currentPathBridgeParameters[0];
curentPathBridgeXPath = currentPathBridgeParameters[1];
inlineNodeNameToFlush = TransformationUtil.extractElementName(curentPathBridgeXPath);
PathBridgeExec_RDF2XML pb_exec_attrib = new PathBridgeExec_RDF2XML(m_d_norm, m_d_norm.getNormMap().getPathBridge(currentPathBridgeURI), m_currentRDFInstance);
pbResult = pb_exec_attrib.getTranslatedPaths();
instanceIter = pbResult.iterator();
for (;instanceIter.hasNext();) {
Object [] result = (Object[])instanceIter.next();
if (result[1] instanceof java.lang.String) {
attList.addAttribute("", inlineNodeNameToFlush, inlineNodeNameToFlush, "string", (String)result[1]);
}
}
}
}
String nodeNameToFlush = TransformationUtil.extractElementName(currentXPath);
//m_targetDataWriter.startElement("", nodeNameToFlush, nodeNameToFlush, attList);
m_d_norm.flushStartElement("", nodeNameToFlush, nodeNameToFlush, attList);
if (hasBridgesToProcess!=null) {
bridgeIter = hasBridgesToProcess.iterator();
// bridgeIter = hasBridgesToProcess.keySet().iterator();
for (;bridgeIter.hasNext();) {
currentPathBridgeParameters = (String[]) bridgeIter.next();
currentPathBridgeURI = currentPathBridgeParameters[0];
curentPathBridgeXPath = currentPathBridgeParameters[1];
// curentPathBridgeXPath = ((String[])bridgeIter.next())[0];
//inlineNodeNameToFlush = TransformationUtil.extractElementName(curentPathBridgeXPath);
PathBridgeExec_RDF2XML pb_exec = new PathBridgeExec_RDF2XML(m_d_norm, m_d_norm.getNormMap().getPathBridge(currentPathBridgeURI), m_currentRDFInstance);
pbResult = pb_exec.getTranslatedPaths();
String[] pbXPathSegments = pb_exec.getPathSegments();
instanceIter = pbResult.iterator();
for (;instanceIter.hasNext();) {
Object [] result = (Object[])instanceIter.next();
if (result[1] instanceof java.lang.String) {
m_d_norm.recursivelyFlushSegments(pbXPathSegments, 0, (String)result[1]);
} else {
// find associated node bridge and go on
String followXPath = currentXPath + "/" + curentPathBridgeXPath;
String followInstanceNodeURI = ((Instance)result[1]).getURI();
String mapQuery = "[http://ectrl.itc.it/normkit/NormBridges#NodeBridge] AND SOME(<http://ectrl.itc.it/normkit/NormBridges#relatesXPathNode>='" + followXPath + "')";
Collection mapQueryResult = m_d_norm.getNormMap().getNormMapOIModel().executeQuery(mapQuery);
Iterator k = mapQueryResult.iterator();
for(; k.hasNext(); ) {
Instance nodeBridge = (Instance) k.next();
NodeBridge currentNB = m_d_norm.getNormMap().getNodeBridge(nodeBridge.getURI());
m_d_norm.processNodeBridgeWithHasBridges(currentNB, followInstanceNodeURI);
break;
}
}
}
}
}
//m_targetDataWriter.endElement(nodeNameToFlush);
m_d_norm.flushEndElement(nodeNameToFlush);
} catch (Exception e) {
e.printStackTrace();
throw new NormalisationException("Exception while building the output XML document.", e);
}
}
/*
private Set getSourceInstanceNodes() throws Exception {
Concept concept = m_d_norm.getSourceModel().getConcept(m_nodebridge.getRelatedOntologyEntity()); //// !!!!!!!! this are more than instances of the particular concept
return concept.getInstances();
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -