📄 nodebridge.java
字号:
package it.itc.ectrl.normkit.common.NormMapModel;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.Vector;
import edu.unika.aifb.kaon.api.oimodel.Instance;
import edu.unika.aifb.kaon.api.KAONException;
import it.itc.ectrl.normkit.common.*;
import oracle.xml.parser.schema.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.Attr;
// this bridge apparently doesn't address text nodes ... mainly because the RDF text nodes can't be uniquely identified ...
/**
* Class representing a node bridge for the Normalisation Map. Node bridge defines correspondence between a XML node abstracted in XPath model and RDF node abstracted in an RDFS conceptual model.
* @author Oliver Fodor (fodor@itc.it)
*/
public class NodeBridge extends CNOEntity {
private String m_strURINodeBridge; // is this used at all?
private Set m_setURIHasBridges = new HashSet();
private String m_strXPathXMLEntity;
private String m_strURIOntologyEntity;
private String m_strURIContextPropertyNode;
// Map m_orderedHasBridgesAttribWithParameters = new HashMap();
Vector m_orderedHasBridgesWithParameters = new Vector();
Vector m_orderedHasBridgesAttribWithParameters = new Vector();
public NodeBridge(final NormMap normmap, Instance instance) {
super( normmap, instance );
}
public NodeBridge( final NormMap normmap, String strURI ) throws KAONException {
super( normmap, KAONUtils.addConceptInstanceToOIModel( normmap.m_oimodelCNOInstance,
CNOVocabulary.URI_CNO_NODE_BRIDGE,
strURI) );
}
/*
----------------------------------- parsing methods --------------------------------------------
*/
public void parse() throws Exception {
super.parse();
// relatesXPathEntity
m_strXPathXMLEntity = Parsing.readEventualPropertyLiteral(m_instance, CNOVocabulary.URI_CNO_RELATES_XPATH_NODE,
CNOErrors.ERROR_ONE_AND_ONLY_ONE_CONCEPT_SOURCE_ENTITY);
// relatesOntologyEntity
m_strURIOntologyEntity = Parsing.readEventualPropertyValue(m_instance, CNOVocabulary.URI_CNO_RELATES_RDFS_NODE,
CNOErrors.ERROR_ONE_AND_ONLY_ONE_CONCEPT_SOURCE_ENTITY);
// hasBridge
m_setURIHasBridges = Parsing.readPropertyValues(m_instance, CNOVocabulary.URI_CNO_HAS_BRIDGE,
CNOErrors.ERROR_ONE_AND_ONLY_ONE_CONCEPT_SOURCE_ENTITY);
// in context of
m_strURIContextPropertyNode = Parsing.readEventualPropertyValue(m_instance, CNOVocabulary.URI_CNO_IN_CONTEXT_OF,
CNOErrors.ERROR_ONE_AND_ONLY_ONE_CONCEPT_SOURCE_ENTITY);
}
/*
----------------------------------- getters & setters --------------------------------------------
*/
public Set getAllHasBridges() {
Set setHasBridges = new HashSet();
setHasBridges.addAll(m_setURIHasBridges);
return setHasBridges;
}
public String getRelatedXPathEntity() {
return m_strXPathXMLEntity;
}
public String getRelatedOntologyEntity() {
return m_strURIOntologyEntity;
}
public String getContextPropertyNode() {
if (m_strURIContextPropertyNode==null) return "";
else return m_strURIContextPropertyNode;
}
public String getContextProperty() {
if (m_strURIContextPropertyNode==null) return "";
else {
return m_normmap.getPropertyNode(m_strURIContextPropertyNode).getURIProperty();
}
}
public void setRelatedXPathEntity( String xpath ) throws NormalisationException {
if( m_strXPathXMLEntity != null && !m_strXPathXMLEntity.equals( "" ) )
throw new NormalisationException( CNOErrors.ERROR_ONE_AND_ONLY_ONE_SOURCE_ENTITY + " in " + toString() );
addPropertyValueToOIModel( CNOVocabulary.URI_CNO_RELATES_XPATH_NODE, xpath );
m_strXPathXMLEntity = xpath;
}
public void setRelatedOntologyEntity( String conceptURI ) throws NormalisationException {
if( m_strURIOntologyEntity != null && !m_strURIOntologyEntity.equals( "" ) )
throw new NormalisationException( CNOErrors.ERROR_ONE_AND_ONLY_ONE_CONCEPT_TARGET_ENTITY + " in " + toString() );
addPropertyValueToOIModel( CNOVocabulary.URI_CNO_RELATES_RDFS_NODE, conceptURI );
m_strURIOntologyEntity = conceptURI;
}
public void setInContextOf( String propertyNodeURI ) throws NormalisationException {
addPropertyValueToOIModel( CNOVocabulary.URI_CNO_IN_CONTEXT_OF, propertyNodeURI );
m_strURIContextPropertyNode = propertyNodeURI;
}
public void addHasBridge( String strURIBridge ) throws NormalisationException {
if( m_normmap.getPathBridge( strURIBridge ) == null )
throw new NormalisationException(CNOErrors.ERROR_INVALID_HAS_BRIDGE );
m_setURIHasBridges.add( strURIBridge );
addPropertyValueToOIModel( CNOVocabulary.URI_CNO_HAS_BRIDGE, strURIBridge );
}
protected void reparseHasBridgesToXMLSchemaDefinedOrder(XSDElement currentElementDeclaration, String currentXPath) throws NormalisationException {
try {
XSDNode[] nestedElms = null;
XSDAttribute[] nestedAtts = null;
XSDNode m_elmType = currentElementDeclaration.getType();
if (m_elmType.getNodeType()==1) { // CHECK THIS FOR OTHER TYPES!!!!
nestedElms = ((XSDComplexType) m_elmType).getElementSet();
nestedAtts = ((XSDComplexType) m_elmType).getAttributeDeclarations();
}
Map hasBridgesWithParameters = reparseHasBridgesToMap();
String currentPathBridgeURI;
Iterator iter;
// process all bridges for nested attributes (in the order defined by XSD)
if (nestedAtts!=null) {
for (int ai = 0; ai < nestedAtts.length; ai++) { //for nested atts
XSDAttribute attDeclaration = nestedAtts[ai];
currentPathBridgeURI = getPathBridgeURI("@" + attDeclaration.getName(), hasBridgesWithParameters);
if (currentPathBridgeURI != null) {
String[] currentParametersA = new String [3];
currentParametersA[0] = currentPathBridgeURI;
String[] tmpParamA = (String[])hasBridgesWithParameters.get(currentPathBridgeURI);
currentParametersA[1] = tmpParamA[0];
currentParametersA[2] = tmpParamA[1];
m_orderedHasBridgesAttribWithParameters.add(currentParametersA);
hasBridgesWithParameters.remove(currentPathBridgeURI);
}
}
}
if (nestedElms!=null) {
for (int i = 0; i < nestedElms.length; i++) { //for nested elements
XSDNode elmDeclaration = nestedElms[i];
currentPathBridgeURI = getPathBridgeURI(elmDeclaration.getName(), hasBridgesWithParameters);
if (currentPathBridgeURI != null) {
//System.out.println(elmDeclaration.getName());
String[] currentParameters = new String [3];
currentParameters[0] = currentPathBridgeURI;
String[] tmpParam = (String[])hasBridgesWithParameters.get(currentPathBridgeURI);
currentParameters[1] = tmpParam[0];
currentParameters[2] = tmpParam[1];
m_orderedHasBridgesWithParameters.add(currentParameters);
// m_orderedHasBridgesWithParameters.put(currentPathBridgeURI, hasBridgesWithParameters.get(currentPathBridgeURI));
hasBridgesWithParameters.remove(currentPathBridgeURI);
}
}
}
//System.out.println("m_orderedHasBridgesAttribWithParameters " + m_orderedHasBridgesAttribWithParameters.size());
//System.out.println("m_orderedHasBridgesWithParameters " + m_orderedHasBridgesWithParameters.size());
if (hasBridgesWithParameters.size() > 0) { // still some has bridges left
iter = hasBridgesWithParameters.keySet().iterator();
for (;iter.hasNext();) {
currentPathBridgeURI = (String) iter.next();
String[] currentParameters2 = new String [3];
currentParameters2[0] = currentPathBridgeURI;
currentParameters2[1] = ((String[])hasBridgesWithParameters.get(currentPathBridgeURI))[0];
currentParameters2[2] = ((String[])hasBridgesWithParameters.get(currentPathBridgeURI))[1];
m_orderedHasBridgesWithParameters.add(currentParameters2);
// m_orderedHasBridgesWithParameters.put(currentPathBridgeURI, hasBridgesWithParameters.get(currentPathBridgeURI));
// hasBridgesWithParameters.remove(currentPathBridgeURI);
}
}
} catch (Exception e) {
e.printStackTrace();
throw new NormalisationException("Exception while reparsing NodeBridge has bridges.", e);
}
}
private Map reparseHasBridgesToMap() throws NormalisationException {
try {
Map hasBridgesWithParameters = new HashMap();
Iterator i = m_setURIHasBridges.iterator();
for (;i.hasNext();) {
String pathBridgeURI = (String) i.next();
String [] pathBridgeParameters = new String[2];
pathBridgeParameters[0] = m_normmap.getPathBridge(pathBridgeURI).getRelatedXPath(); // XPath value
pathBridgeParameters[1] = m_normmap.getPathBridge(pathBridgeURI).getRelatedOPath(); // Ontology Path value
hasBridgesWithParameters.put(pathBridgeURI, pathBridgeParameters);
}
return hasBridgesWithParameters;
} catch (Exception e) {
e.printStackTrace();
throw new NormalisationException("Exception while reparsing NodeBridge has bridges.", e);
}
}
private String getPathBridgeURI(String xPathPrefix, Map hasBridgesWithParameters) throws NormalisationException {
try {
// Map hasBridgesWithParameters = reparseHasBridgesToMap();
Iterator i = hasBridgesWithParameters.keySet().iterator();
for (;i.hasNext();) {
String pathBridgeURI = (String) i.next();
String pathBridgeXPath = ((String[])hasBridgesWithParameters.get(pathBridgeURI))[0];
if ((pathBridgeXPath.equals(xPathPrefix)) || (pathBridgeXPath.startsWith(xPathPrefix + "/")))
return pathBridgeURI;
}
return null;
// throw new NormalisationException("Path Bridge targtting the given XPath not found.");
} catch (Exception e) {
e.printStackTrace();
throw new NormalisationException("Exception while reparsing NodeBridge has bridges.", e);
}
}
public Vector getOrderedHasBridges() {
return m_orderedHasBridgesWithParameters;
}
public Vector getOrderedHasBridgesAttrib() {
return m_orderedHasBridgesAttribWithParameters;
}
public Element getXSLTemplate(Document xslDoc) throws NormalisationException {
if (getRelatedOntologyEntity() == CNOVocabulary.URI_RDFS_LITERAL)
return null;
try {
Element currentRNode = xslDoc.createElementNS(CNOVocabulary.URI_XSL, CNOVocabulary.NS_PREFIX_XSL + ":template");
currentRNode.setAttribute("match", m_strXPathXMLEntity);
Element currentENode = TransformationUtil.createAndAppendXSLElement(xslDoc, currentRNode, "element", "name", getRelatedOntologyEntity().replaceFirst(m_normmap.getRelatedOntologyURI() + "#", CNOVocabulary.NS_PREFIX_DNORM + ":"));
Element currentNode = TransformationUtil.createAndAppendXSLElement(xslDoc, currentENode, "attribute", "name", "rdf:ID");
currentNode = TransformationUtil.createAndAppendXSLElement(xslDoc, currentNode, "value-of", "select", "generate-id()");
Iterator i = m_setURIHasBridges.iterator();
for (;i.hasNext();) {
String strURICurrentHB = (String) i.next();
PathBridge currentPB = m_normmap.getPathBridge(strURICurrentHB);
currentENode.appendChild(currentPB.getXSLTemplate(xslDoc));
}
return currentRNode;
} catch (Exception e) {
e.printStackTrace();
throw new NormalisationException("Exception reparsing NodeBridge to XSLT.", e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -