本文整理汇总了Java中org.apache.xerces.xs.XSElementDeclaration.getTypeDefinition方法的典型用法代码示例。如果您正苦于以下问题:Java XSElementDeclaration.getTypeDefinition方法的具体用法?Java XSElementDeclaration.getTypeDefinition怎么用?Java XSElementDeclaration.getTypeDefinition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xerces.xs.XSElementDeclaration
的用法示例。
在下文中一共展示了XSElementDeclaration.getTypeDefinition方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findReference
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
/**
* Finds all the element and complexType references for the specified root element and populates a map entry with
* element names referenced by the element.
*
* @param elementDeclaration XSElementDeclaration : the root element
*/
private void findReference(XSElementDeclaration elementDeclaration) {
String elemName = elementDeclaration.getName();
String thisContext = elemName;
XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
if (null != typeDefinition) {
String typeDefName = typeDefinition.getName();
currentNodeNames.clear();
currentNodeNames.add(elementDeclaration.getName());
if (typeDefinition instanceof XSComplexTypeDefinition) {
addToSchemaMap(elemName, typeDefName);
if (null != typeDefName) {
thisContext = typeDefName;
}
XSParticle particle = ((XSComplexTypeDefinition) typeDefinition).getParticle();
findReferenceInParticle(thisContext, particle);
}
else {
addToSchemaMap(elemName, typeDefName);
if (null != typeDefName) {
thisContext = typeDefName;
}
}
}
}
示例2: findElementReference
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
/**
* Finds all the element and complexType references for the specified element and populates a map entry with element
* names referenced by the element.
*
* @param context the context.
* @param elementDeclaration the element declaration.
*/
private void findElementReference(String context,
XSElementDeclaration elementDeclaration) {
XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
if (null != typeDefinition) {
String typeDefName = typeDefinition.getName();
if (typeDefinition instanceof XSComplexTypeDefinition) {
addToSchemaMap(context, typeDefName);
if (null != typeDefName) {
context = typeDefName;
}
XSParticle particle = ((XSComplexTypeDefinition) typeDefinition).getParticle();
if (currentNodeNames.contains(typeDefName)) {
/* circular reference */
// currentNodeNames.add(typeDefName);
// findReferenceInParticle(context, particle);
}
else {
currentNodeNames.add(typeDefName);
findReferenceInParticle(context, particle);
}
}
else {
addToSchemaMap(context, typeDefName);
if (null != typeDefName) {
context = typeDefName;
}
currentNodeNames.add(typeDefName);
}
}
}
示例3: getValidSubTags
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
private Map<QName,XSParticle> getValidSubTags(XSElementDeclaration elmt) {
if (!(elmt.getTypeDefinition() instanceof XSComplexTypeDefinition)) {
return HashMap.empty();
}
XSComplexTypeDefinition type = (XSComplexTypeDefinition) elmt.getTypeDefinition();
if (type.getParticle() == null || !(type.getParticle().getTerm() instanceof XSModelGroup)) {
return HashMap.empty();
}
XSModelGroup group = (XSModelGroup) type.getParticle().getTerm();
if (group.getCompositor() != XSModelGroup.COMPOSITOR_SEQUENCE && group.getCompositor() != XSModelGroup.COMPOSITOR_CHOICE) {
return HashMap.empty();
}
// We don't care whether it's SEQUENCE or CHOICE, we only want to know what are the valid sub-elements at this level.
XSObjectList particles = group.getParticles();
Map<QName,XSParticle> content = HashMap.empty();
for (int j = 0; j < particles.getLength(); j++) {
XSParticle sub = (XSParticle) particles.get(j);
if (sub.getTerm() instanceof XSElementDeclaration) {
XSElementDeclaration term = (XSElementDeclaration) sub.getTerm();
content = content.put(new QName(term.getNamespace(), term.getName()), sub);
}
}
return content;
}
示例4: hasAttributes
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
private boolean hasAttributes(XSElementDeclaration elmt) {
if (elmt.getTypeDefinition() instanceof XSComplexTypeDefinition) {
//Yes, we don't need to wrap this in an object if no attributes can ever occur. But Jackson does, so we must do so too.
//A future format change could do the following to make the JSON a little nicer:
// XSComplexTypeDefinition def = (XSComplexTypeDefinition) elmt.getTypeDefinition();
// return def.getAttributeUses().getLength() > 0;
return true;
}
return false;
}
示例5: testXercesGrammar
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
public void testXercesGrammar() throws Exception {
XSModel xsModel = getXSModel("test.xml", "test.xsd");
XSElementDeclaration elementDeclaration = xsModel.getElementDeclaration("a", "");
XSComplexTypeDefinition typeDefinition = (XSComplexTypeDefinition)elementDeclaration.getTypeDefinition();
CMBuilder cmBuilder = new CMBuilder(new CMNodeFactory());
XSCMValidator validator = cmBuilder.getContentModel((XSComplexTypeDecl)typeDefinition, true);
int[] ints = validator.startContentModel();
Vector vector = validator.whatCanGoHere(ints);
XSElementDecl o = (XSElementDecl)vector.get(0);
assertEquals("b", o.getName());
}
示例6: testXercesIncomplete
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
public void testXercesIncomplete() throws Exception {
XSModel xsModel = getXSModel("testIncomplete.xml", "test.xsd");
XSElementDeclaration elementDeclaration = xsModel.getElementDeclaration("a", "");
XSComplexTypeDefinition typeDefinition = (XSComplexTypeDefinition)elementDeclaration.getTypeDefinition();
CMBuilder cmBuilder = new CMBuilder(new CMNodeFactory());
XSCMValidator validator = cmBuilder.getContentModel((XSComplexTypeDecl)typeDefinition, true);
int[] ints = validator.startContentModel();
Vector vector = validator.whatCanGoHere(ints);
XSElementDecl o = (XSElementDecl)vector.get(0);
assertEquals("b", o.getName());
}
示例7: getTypeDefinition
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
public XSTypeDefinition getTypeDefinition(PSVIProvider psviProvider) {
ElementPSVI elementPSVI = psviProvider.getElementPSVI();
if (DEBUG) log.debug("getTypeDefinition() elementPSVI ["+ToStringBuilder.reflectionToString(elementPSVI)+"]");
XSElementDeclaration elementDeclaration = elementPSVI.getElementDeclaration();
if (DEBUG) log.debug("getTypeDefinition() elementPSVI element declaration ["+ToStringBuilder.reflectionToString(elementDeclaration)+"]");
if (elementDeclaration==null) {
return null;
}
XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
if (DEBUG) log.debug("getTypeDefinition() elementDeclaration typeDefinition ["+ToStringBuilder.reflectionToString(typeDefinition)+"]");
return typeDefinition;
}
示例8: handleElementContents
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
public void handleElementContents(XSElementDeclaration elementDeclaration, N node) throws SAXException {
XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
if (typeDefinition==null) {
log.warn("handleElementContents typeDefinition is null");
handleSimpleTypedElement(elementDeclaration, null, node);
return;
}
switch (typeDefinition.getTypeCategory()) {
case XSTypeDefinition.SIMPLE_TYPE:
if (DEBUG) log.debug("handleElementContents typeDefinition.typeCategory is SimpleType, no child elements");
handleSimpleTypedElement(elementDeclaration, (XSSimpleTypeDefinition)typeDefinition, node);
return;
case XSTypeDefinition.COMPLEX_TYPE:
XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition;
switch (complexTypeDefinition.getContentType()) {
case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
if (DEBUG) log.debug("handleElementContents complexTypeDefinition.contentType is Empty, no child elements");
return;
case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
if (DEBUG) log.debug("handleElementContents complexTypeDefinition.contentType is Simple, no child elements (only characters)");
return;
case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
handleComplexTypedElement(elementDeclaration,node);
return;
default:
throw new IllegalStateException("handleElementContents complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["+complexTypeDefinition.getContentType()+"]");
}
default:
throw new IllegalStateException("handleElementContents typeDefinition.typeCategory is not SimpleType or ComplexType, but ["+typeDefinition.getTypeCategory()+"] class ["+typeDefinition.getClass().getName()+"]");
}
}
示例9: dumpElement
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
private static void dumpElement(String path, XSElementDeclaration element)
{
String output_path = "" + path + "/" + element.getName();
XSTypeDefinition type = element.getTypeDefinition();
if (type.getName().endsWith("Array"))
{
// System.err.println(element.getName() + " - " + type.getName()
// + " SKIPPED !");
return;
}
if (((type.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE)
|| ((XSComplexTypeDefinition) type)
.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE))
{
if (includesBaseType(type, "string")
|| includesBaseType(type, "integer")
|| includesBaseType(type, "boolean"))
{
// System.out.println(" <metadata name=\"" +
// element.getName() + "\" type=\"text/plain\" category=\"\">");
// System.out.println(" " +
// indexedName(element.getName())
// + " { local:values($doc" + output_path + ") }");
// System.out.println(" </metadata>,");
System.out.println(" local:getMetadata('" +
element.getName() + "', '" +
indexedName(element.getName()) + "',");
System.out.println(" $doc" + output_path + "),");
}
}
else
{
dumpParticle(output_path,
((XSComplexTypeDefinition)type).getParticle());
}
}
示例10: getElementDeclaration
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
@Nullable
private static XSElementDeclaration getElementDeclaration(XmlTag tag, XSModel xsModel) {
List<XmlTag> ancestors = new ArrayList<XmlTag>();
for (XmlTag t = tag; t != null; t = t.getParentTag()) {
ancestors.add(t);
}
Collections.reverse(ancestors);
XSElementDeclaration declaration = null;
SubstitutionGroupHandler fSubGroupHandler = new SubstitutionGroupHandler(new MyXSElementDeclHelper());
CMBuilder cmBuilder = new CMBuilder(new CMNodeFactory());
for (XmlTag ancestor : ancestors) {
if (declaration == null) {
declaration = xsModel.getElementDeclaration(ancestor.getLocalName(), ancestor.getNamespace());
if (declaration == null) return null;
else continue;
}
XSTypeDefinition typeDefinition = declaration.getTypeDefinition();
if (!(typeDefinition instanceof XSComplexTypeDecl)) {
return null;
}
XSCMValidator model = ((XSComplexTypeDecl)typeDefinition).getContentModel(cmBuilder);
int[] ints = model.startContentModel();
for (XmlTag subTag : ancestor.getParentTag().getSubTags()) {
QName qName = createQName(subTag);
Object o = model.oneTransition(qName, ints, fSubGroupHandler);
if (subTag == ancestor) {
if (o instanceof XSElementDecl) {
declaration = (XSElementDecl)o;
break;
}
else return null;
}
}
}
return declaration;
}
示例11: processElement
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
private Path processElement(Path parent, String path, XSElementDeclaration xsElement,
Map<String, List<XSElementDeclaration>> substitutions,
List<XSElementDeclaration> parents, int minOccurs, int maxOccurs) throws BagriException {
Path element = parent;
if (!xsElement.getAbstract()) {
path += xsElement.getNamespace() == null ? "/" + xsElement.getName() : "/{" + xsElement.getNamespace() + "}" + xsElement.getName();
element = modelMgr.translatePath(parent.getRoot(), path, NodeKind.element, parent.getPathId(), XQItemType.XQBASETYPE_ANYTYPE,
Occurrence.getOccurrence(minOccurs, maxOccurs));
logger.trace("processElement; element: {}; type: {}; got XDMPath: {}", path, xsElement.getTypeDefinition(), element);
}
List<XSElementDeclaration> subs = substitutions.get(xsElement.getName());
logger.trace("processElement; got {} substitutions for element: {}", subs == null ? 0 : subs.size(), xsElement.getName());
if (subs != null) {
for (XSElementDeclaration sub: subs) {
processElement(parent, path, sub, substitutions, parents, minOccurs, maxOccurs);
}
}
if (parents.contains(xsElement)) {
return element;
}
parents.add(xsElement);
Path text = null;
if (xsElement.getTypeDefinition().getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
XSComplexTypeDefinition ctd = (XSComplexTypeDefinition) xsElement.getTypeDefinition();
// TODO: process derivations..?
// element's attributes
XSObjectList xsAttrList = ctd.getAttributeUses();
for (int i = 0; i < xsAttrList.getLength(); i ++) {
processAttribute(element, path, (XSAttributeUse) xsAttrList.item(i));
}
element = processParticle(element, path, ctd.getParticle(), substitutions, parents);
if (ctd.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE ||
ctd.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_MIXED) {
path += "/text()";
text = modelMgr.translatePath(element.getRoot(), path, NodeKind.text, element.getPathId(), getBaseType(ctd.getSimpleType()),
Occurrence.getOccurrence(minOccurs, maxOccurs));
logger.trace("processElement; complex text: {}; type: {}; got XDMPath: {}", path, ctd.getBaseType(), text);
}
} else { //if (xsElementDecl.getTypeDefinition().getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
XSSimpleTypeDefinition std = (XSSimpleTypeDefinition) xsElement.getTypeDefinition();
path += "/text()";
text = modelMgr.translatePath(element.getRoot(), path, NodeKind.text, element.getPathId(), getBaseType(std),
Occurrence.getOccurrence(minOccurs, maxOccurs));
logger.trace("processElement; simple text: {}; type: {}; got XDMPath: {}", path, std, text);
}
if (text != null) {
element.setPostId(text.getPathId());
modelMgr.updatePath(element);
}
if (parent.getPostId() < element.getPostId()) {
parent.setPostId(element.getPostId());
modelMgr.updatePath(parent);
}
parents.remove(xsElement);
return element;
}
示例12: handleElement
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
public void handleElement(XSElementDeclaration elementDeclaration, N node) throws SAXException {
String name = elementDeclaration.getName();
String elementNamespace=elementDeclaration.getNamespace();
String qname=getQName(elementNamespace, name);
if (DEBUG) log.debug("handleNode() name ["+name+"] elementNamespace ["+elementNamespace+"]");
newLine();
AttributesImpl attributes=new AttributesImpl();
Map<String,String> nodeAttributes = getAttributes(elementDeclaration, node);
if (DEBUG) log.debug("node ["+name+"] search for attributeDeclaration");
XSTypeDefinition typeDefinition=elementDeclaration.getTypeDefinition();
XSObjectList attributeUses=getAttributeUses(typeDefinition);
if (attributeUses==null || attributeUses.getLength()==0) {
if (nodeAttributes!=null && nodeAttributes.size()>0) {
log.warn("node ["+name+"] found ["+nodeAttributes.size()+"] attributes, but no declared AttributeUses");
} else {
if (DEBUG) log.debug("node ["+name+"] no attributeUses, no attributes");
}
} else {
if (nodeAttributes==null || nodeAttributes.isEmpty()) {
log.warn("node ["+name+"] declared ["+attributeUses.getLength()+"] attributes, but no attributes found");
} else {
for (int i=0;i<attributeUses.getLength(); i++) {
XSAttributeUse attributeUse=(XSAttributeUse)attributeUses.item(i);
//if (DEBUG) log.debug("startElement ["+localName+"] attributeUse ["+ToStringBuilder.reflectionToString(attributeUse)+"]");
XSAttributeDeclaration attributeDeclaration=attributeUse.getAttrDeclaration();
if (DEBUG) log.debug("node ["+name+"] attributeDeclaration ["+ToStringBuilder.reflectionToString(attributeDeclaration)+"]");
XSSimpleTypeDefinition attTypeDefinition=attributeDeclaration.getTypeDefinition();
if (DEBUG) log.debug("node ["+name+"] attTypeDefinition ["+ToStringBuilder.reflectionToString(attTypeDefinition)+"]");
String attName=attributeDeclaration.getName();
if (nodeAttributes.containsKey(attName)) {
String value=nodeAttributes.remove(attName);
String uri=attributeDeclaration.getNamespace();
String attqname=getQName(uri,attName);
String type=null;
if (DEBUG) log.debug("node ["+name+"] adding attribute ["+attName+"] value ["+value+"]");
attributes.addAttribute(uri, attName, attqname, type, value);
}
}
}
}
if (isNil(elementDeclaration, node)) {
validatorHandler.startPrefixMapping(XSI_PREFIX_MAPPING, XML_SCHEMA_INSTANCE_NAMESPACE);
attributes.addAttribute(XML_SCHEMA_INSTANCE_NAMESPACE, XML_SCHEMA_NIL_ATTRIBUTE, XSI_PREFIX_MAPPING+":"+XML_SCHEMA_NIL_ATTRIBUTE, "xs:boolean", "true");
validatorHandler.startElement(elementNamespace, name, qname, attributes);
validatorHandler.endElement(elementNamespace, name, qname);
validatorHandler.endPrefixMapping(XSI_PREFIX_MAPPING);
} else {
validatorHandler.startElement(elementNamespace, name, qname, attributes);
handleElementContents(elementDeclaration, node);
validatorHandler.endElement(elementNamespace, name, qname);
}
// if (createdPrefix!=null) {
// validatorHandler.endPrefixMapping(createdPrefix);
// }
}
示例13: getBestChildElementPath
import org.apache.xerces.xs.XSElementDeclaration; //导入方法依赖的package包/类
public List<XSParticle> getBestChildElementPath(XSElementDeclaration elementDeclaration, N node, boolean silent) throws SAXException {
XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
if (typeDefinition==null) {
log.warn("getBestChildElementPath typeDefinition is null");
return null;
}
switch (typeDefinition.getTypeCategory()) {
case XSTypeDefinition.SIMPLE_TYPE:
if (DEBUG) log.debug("getBestChildElementPath typeDefinition.typeCategory is SimpleType, no child elements");
return null;
case XSTypeDefinition.COMPLEX_TYPE:
XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition;
switch (complexTypeDefinition.getContentType()) {
case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
if (DEBUG) log.debug("getBestChildElementPath complexTypeDefinition.contentType is Empty, no child elements");
return null;
case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
if (DEBUG) log.debug("getBestChildElementPath complexTypeDefinition.contentType is Simple, no child elements (only characters)");
return null;
case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
XSParticle particle = complexTypeDefinition.getParticle();
if (particle==null) {
throw new IllegalStateException("getBestChildElementPath complexTypeDefinition.particle is null for Element or Mixed contentType");
// log.warn("typeDefinition particle is null, is this a problem?");
// return null;
}
if (DEBUG) log.debug("typeDefinition particle ["+ToStringBuilder.reflectionToString(particle,ToStringStyle.MULTI_LINE_STYLE)+"]");
List<XSParticle> result=new LinkedList<XSParticle>();
List<String> failureReasons=new LinkedList<String>();
if (getBestMatchingElementPath(elementDeclaration, node, particle, result, failureReasons)) {
return result;
}
String msg="Cannot find path:";
for (String reason:failureReasons) {
msg+='\n'+reason;
}
if (!silent) {
handleError(msg);
}
return null;
default:
throw new IllegalStateException("getBestChildElementPath complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["+complexTypeDefinition.getContentType()+"]");
}
default:
throw new IllegalStateException("getBestChildElementPath typeDefinition.typeCategory is not SimpleType or ComplexType, but ["+typeDefinition.getTypeCategory()+"] class ["+typeDefinition.getClass().getName()+"]");
}
}