本文整理汇总了Java中org.apache.xerces.xs.XSModel类的典型用法代码示例。如果您正苦于以下问题:Java XSModel类的具体用法?Java XSModel怎么用?Java XSModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XSModel类属于org.apache.xerces.xs包,在下文中一共展示了XSModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importFromXsd
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
protected void importFromXsd(String text) throws Exception {
XSModel xsModel = new XSParser().parseString(text, "");
XSInstance xsInstance = new XSInstance();
xsInstance.minimumElementsGenerated = 1;
xsInstance.maximumElementsGenerated = 1;
xsInstance.generateOptionalElements = Boolean.TRUE;
XSNamedMap map = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION);
QName rootElement = new QName(map.item(0).getNamespace(), map.item(0).getName(), XMLConstants.DEFAULT_NS_PREFIX);
StringWriter writer = new StringWriter();
XMLDocument sampleXml = new XMLDocument(new StreamResult(writer), true, 4, null);
xsInstance.generate(xsModel, rootElement, sampleXml);
String xml = writer.toString();
listener.onImport(xml);
}
示例2: toXSModel
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
public XSModel toXSModel(XSGrammar[] grammars) {
if (grammars == null || grammars.length == 0)
return toXSModel();
int len = grammars.length;
boolean hasSelf = false;
for (int i = 0; i < len; i++) {
if (grammars[i] == this) {
hasSelf = true;
break;
}
}
SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len+1];
for (int i = 0; i < len; i++)
gs[i] = (SchemaGrammar)grammars[i];
if (!hasSelf)
gs[len] = this;
return new XSModelImpl(gs);
}
示例3: getSchemaInformation
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
/**
* [schema information]
* @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_information">XML Schema Part 1: Structures [schema information]</a>
* @return The schema information property if it's the validation root,
* null otherwise.
*/
public synchronized XSModel getSchemaInformation() {
if (fSchemaInformation == null && fGrammars != null) {
fSchemaInformation = new XSModelImpl(fGrammars);
}
return fSchemaInformation;
}
示例4: toXSModel
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
public XSModel toXSModel(short schemaVersion) {
ArrayList list = new ArrayList();
for (int i = 0; i < fGrammars.length; i++) {
for (Entry entry = fGrammars[i] ; entry != null ; entry = entry.next) {
if (entry.desc.getGrammarType().equals(XMLGrammarDescription.XML_SCHEMA)) {
list.add(entry.grammar);
}
}
}
int size = list.size();
if (size == 0) {
return toXSModel(new SchemaGrammar[0], schemaVersion);
}
SchemaGrammar[] gs = (SchemaGrammar[])list.toArray(new SchemaGrammar[size]);
return toXSModel(gs, schemaVersion);
}
示例5: processPSVISchemaInformation
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
private void processPSVISchemaInformation(ElementPSVI elemPSVI) {
if (elemPSVI == null)
return;
XSModel schemaInfo = elemPSVI.getSchemaInformation();
XSNamespaceItemList schemaNamespaces =
schemaInfo == null ? null : schemaInfo.getNamespaceItems();
if (schemaNamespaces == null || schemaNamespaces.getLength() == 0) {
sendElementEvent("psv:schemaInformation");
}
else {
sendIndentedElement("psv:schemaInformation");
for (int i = 0; i < schemaNamespaces.getLength(); i++) {
processPSVINamespaceItem(schemaNamespaces.item(i));
}
sendUnIndentedElement("psv:schemaInformation");
}
}
示例6: getXSModel
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
private XSModel getXSModel(String... files) {
myFixture.configureByFiles(files);
XmlFile file = (XmlFile)myFixture.getFile();
ValidateXmlActionHandler handler = new ValidateXmlActionHandler(false) {
@Override
protected SAXParser createParser() throws SAXException, ParserConfigurationException {
SAXParser parser = super.createParser();
parser.getXMLReader().setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE, true);
return parser;
}
};
handler.setErrorReporter(new TestErrorReporter(handler));
handler.doValidate(file);
XMLGrammarPool grammarPool = ValidateXmlActionHandler.getGrammarPool(file);
assert grammarPool != null;
Grammar[] grammars = grammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
XSGrammar grammar = (XSGrammar)grammars[0];
return grammar.toXSModel();
}
示例7: createContentDFA
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
@Nullable
public static XmlContentDFA createContentDFA(@NotNull XmlTag parentTag) {
final PsiFile file = parentTag.getContainingFile().getOriginalFile();
if (!(file instanceof XmlFile)) return null;
XSModel xsModel = ApplicationManager.getApplication().runReadAction(new NullableComputable<XSModel>() {
@Override
public XSModel compute() {
return getXSModel((XmlFile)file);
}
});
if (xsModel == null) {
return null;
}
XSElementDeclaration decl = getElementDeclaration(parentTag, xsModel);
if (decl == null) {
return null;
}
return new XsContentDFA(decl, parentTag);
}
示例8: findElementDeclarationsForName
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
public Set<XSElementDeclaration> findElementDeclarationsForName(String namespace, String name) {
Set<XSElementDeclaration> result=new LinkedHashSet<XSElementDeclaration>();
if (schemaInformation==null) {
log.warn("No SchemaInformation specified, cannot find namespaces for ["+namespace+"]:["+name+"]");
return null;
}
for (XSModel model:schemaInformation) {
XSNamedMap components = model.getComponents(XSConstants.ELEMENT_DECLARATION);
for (int i=0;i<components.getLength();i++) {
XSElementDeclaration item=(XSElementDeclaration)components.item(i);
if ((namespace==null || namespace.equals(item.getNamespace())) && (name==null || name.equals(item.getName()))) {
if (DEBUG) log.debug("name ["+item.getName()+"] found in namespace ["+item.getNamespace()+"]");
result.add(item);
}
}
}
return result;
}
示例9: testImports
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
public void testImports() {
try {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
URI ns1 = new URI("gme://caGrid.caBIG/1.0/gov.nih.nci.cagrid.metadata.dataservice");
schemas.add(XSDUtil.createSchema(ns1, new File("test/resources/schema/cagrid/data/data.xsd")));
URI ns2 = new URI("gme://caGrid.caBIG/1.0/gov.nih.nci.cagrid.metadata.common");
schemas.add(XSDUtil.createSchema(ns2, new File("test/resources/schema/cagrid/common/common.xsd")));
XSModel model = loadSchemas(schemas, null);
// TODO: why is this 4, and not 3? how can we prevent it from
// processing schemas from imports that we've already processed
assertEquals(4, model.getNamespaceItems().getLength());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例10: testImports
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
public void testImports() {
try {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
URI ns1 = new URI("gme://caGrid.caBIG/1.0/gov.nih.nci.cagrid.metadata.dataservice");
schemas.add(XSDUtil.createSchema(ns1, new File("src/test/resources/schema/cagrid/data/data.xsd")));
URI ns2 = new URI("gme://caGrid.caBIG/1.0/gov.nih.nci.cagrid.metadata.common");
schemas.add(XSDUtil.createSchema(ns2, new File("src/test/resources/schema/cagrid/common/common.xsd")));
XSModel model = loadSchemas(schemas, null);
// TODO: why is this 4, and not 3? how can we prevent it from
// processing schemas from imports that we've already processed
assertEquals(4, model.getNamespaceItems().getLength());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例11: loadMissingTaxonomyFromKnownSchemas
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
private XbrlTaxonomy loadMissingTaxonomyFromKnownSchemas(String namespace, String name) throws XbrlException, IOException{
XSNamedMap elementDeclarations = null;
if(missingSchemaElementDeclarations.containsKey(namespace))
elementDeclarations = missingSchemaElementDeclarations.get(namespace);
else if(knownSchemaMapping.containsKey(namespace)){
XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
schemaLoader.setEntityResolver(loader);
schemaLoader.setFeature("http://apache.org/xml/features/generate-synthetic-annotations", true);
//URI targetLink = loader.getBaseURIResolver().getBaseURI().resolve(knownSchemaMapping.get(namespace));
String cachedFilePath = this.loader.getFileCache().getCachedFilePath(knownSchemaMapping.get(namespace));
String uri = new File(cachedFilePath).toURI().toString();
XSModel xbrlSchemaModel = schemaLoader.loadURI(uri);
schemaToNamespaceMap.put(knownSchemaMapping.get(namespace), namespace);
elementDeclarations = xbrlSchemaModel.getComponents(XSConstants.ELEMENT_DECLARATION);
if(elementDeclarations != null)
missingSchemaElementDeclarations.put(namespace, elementDeclarations);
}
if(elementDeclarations != null){
XSElementDeclaration elementDec = (XSElementDeclaration)elementDeclarations.itemByName(namespace, name);
if(elementDec != null){
XbrlTaxonomy xbrlTaxonomy = parseXbrlTaxonomy(elementDec);
if(xbrlTaxonomy != null){
xbrlConceptCache.put(xbrlTaxonomy.getIdentifier(), xbrlTaxonomy);
return xbrlTaxonomy;
}
}
}
return null;
}
示例12: testXercesGrammar
import org.apache.xerces.xs.XSModel; //导入依赖的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());
}
示例13: testXercesIncomplete
import org.apache.xerces.xs.XSModel; //导入依赖的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());
}
示例14: getSimpleDatatypeFor
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
public static Datatype getSimpleDatatypeFor(String schemaAsString,
String typeName, String typeURI) throws EXIException {
XSDGrammarsBuilder xsdGB = XSDGrammarsBuilder.newInstance();
ByteArrayInputStream bais = new ByteArrayInputStream(
schemaAsString.getBytes());
xsdGB.loadGrammars(bais);
xsdGB.toGrammars();
XSModel xsModel = xsdGB.getXSModel();
XSTypeDefinition td = xsModel.getTypeDefinition(typeName, typeURI);
assertTrue("SimpleType expected",
td.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE);
Datatype dt = xsdGB.getDatatype((XSSimpleTypeDefinition) td);
return dt;
}
示例15: getSchema
import org.apache.xerces.xs.XSModel; //导入依赖的package包/类
public XSModel getSchema(){
Path path = this;
while(path!=null){
if(path.schema!=null)
return path.schema;
path = path.parent;
}
return null;
}