complextypedefinition.java
来自「normkit is a set of tools supporting ont」· Java 代码 · 共 216 行
JAVA
216 行
package it.itc.ectrl.normkit.cnorm.XSModel;
import oracle.xml.parser.schema.*;
import java.util.*;
import it.itc.ectrl.normkit.cnorm.impl.C_NormalisationImpl;
import it.itc.ectrl.normkit.cnorm.heuristics.*;
import it.itc.ectrl.normkit.common.*;
/**
* Class representing a complex type definition component within a XML Schema to the Normalisation process.
* @author Oliver Fodor (fodor@itc.it)
*/
public class ComplexTypeDefinition extends XSDComponent {
XSDComplexType m_complexType;
XSDNode m_parentNode;
int m_hashCode;
/**
* Creates an instance of this class and associates it with given C-Normalisation process and XML Schema infoset component (XDK).
*/
public ComplexTypeDefinition(XSDComplexType complexType, C_NormalisationImpl c_norm, XSDNode parent) throws Exception {
super (c_norm);
m_complexType = complexType;
m_hashCode = TransformationUtil.getHashCode(m_complexType);
m_parentNode = parent;
// System.out.println("CONTENT of " + m_complexType.getName() + " " + m_complexType.getContent());
// initializeWorkaround();
}
protected void initialize() throws Exception { // this can be set up by reading some definition file
ComplexType2Class myHeuristic = new ComplexType2Class(this, m_c_norm);
associateNormalisationHeuristic((NormalisationHeuristic) myHeuristic);
}
/*
protected void initializeWorkaround() throws Exception {
int content = m_complexType.getContent()
switch(content) {
case 12: // '\f'
// elementOnly
break;
case 13: // '\r'
// mixed
break;
case 10: // '\n'
// empty
break;
case 11: // '\013'
// textOnly
break;
}
if (content == 13) {
ComplexTypeMixed2Literal myHeuristic = new ComplexTypeMixed2Literal(this, m_c_norm);
else
ComplexType2Class myHeuristic = new ComplexType2Class(this, m_c_norm);
associateNormalisationHeuristic((NormalisationHeuristic) myHeuristic);
}
*/
public void processNestedElements() throws Exception {
if (!isMixed()) {
XSDNode[] nestedElms = m_complexType.getElementSet();
processNestedElements(nestedElms);
}
}
public void processNestedElements(XSDNode[] nestedElms) throws Exception {
int length = 0;
if (nestedElms!=null) length = nestedElms.length;
for (int i = 0; i < length; i++) {
if (!(nestedElms[i] instanceof XSDElement)) {
if (nestedElms[i] instanceof XSDGroup) {
Vector nodes = ((XSDGroup)nestedElms[i]).getNodeVector();
for(Enumeration enum = nodes.elements(); enum.hasMoreElements();) {
XSDNode node = (XSDNode)enum.nextElement();
}
XSDNode[] groupMembers = new XSDNode[nodes.size()];
groupMembers = (XSDNode[])nodes.toArray(groupMembers);
processNestedElements(groupMembers);
} else { // xs:any, only??
// add new heuristic Any2LiteralProperty, instantiate it and run
}
} else {
XSDElement elm = (XSDElement)nestedElms[i];
if (elm.getRefState() > 1) // new elm. declaration
// if (elm.getRefState() > 1 && !m_c_norm.isAllreadyNormalized(TransformationUtil.getHashCode(elm))) // this is a really stupid workaround for attribute groups
processLocalElementDeclaration(elm);
processNestedElement(elm);
}
}
}
public void processLocalElementDeclaration(XSDElement elm) throws Exception {
ElementDeclaration ed = new ElementDeclaration(elm, m_c_norm);
ed.runNormalisationHeuristics();
ed.processContext();
}
public void processNestedElement(XSDElement elm) throws Exception {
NestedElement elm_in = new NestedElement(elm, m_c_norm, m_complexType);
elm_in.runNormalisationHeuristics();
}
public void processNestedAttributes() throws Exception {
//if (!isMixed()) {
XSDAttribute[] nestedAtts = m_complexType.getAttributeDeclarations();
int length=nestedAtts.length;
for (int i = 0; i < length; i++) {
XSDAttribute att = (XSDAttribute)nestedAtts[i];
//System.out.println(att.getName() + " " + att.getRefState());
if (att.getRefState() > 1 && !m_c_norm.isAllreadyNormalized(TransformationUtil.getHashCode(att))) { // this is a really stupid workaround for attribute groups
// members of referenced AGs are simply returned by getAttributeDeclarations() without any remark about their origin ... so each time they appear as new declarations
// if (att.getRefState() > 1) // new att. declaration
processLocalAttributeDeclaration(att);
//System.out.println("Processing: " + att.getName());
}
processNestedAttribute(att);
}
//}
}
public void processLocalAttributeDeclaration(XSDAttribute att) throws Exception {
AttributeDeclaration ad = new AttributeDeclaration(att, m_c_norm);
ad.runNormalisationHeuristics();
}
public void processNestedAttribute(XSDAttribute att) throws Exception {
NestedAttribute att_in = new NestedAttribute(att, m_c_norm, m_complexType);
att_in.runNormalisationHeuristics();
}
public int getHashCode() {
return m_hashCode;
}
public String getName() {
return m_complexType.getName();
}
public String getParentsName() {
if (m_parentNode==null) return null;
else return m_parentNode.getName();
}
public boolean isMixed() {
if (m_complexType.getContent() == 13) return true;
else return false;
}
public boolean isSimple() {
if (m_complexType.getContent() == 11) return true;
else return false;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?