@Test public void test1() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute(SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI); dbf.setAttribute(SCHEMA_SOURCE, Bug4966143.class.getResource("Bug4966143.xsd").toExternalForm()); Document document = dbf.newDocumentBuilder().parse(Bug4966143.class.getResource("Bug4966143.xml").toExternalForm()); TypeInfo type = document.getDocumentElement().getSchemaTypeInfo(); Assert.assertFalse(type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_UNION)); Assert.assertFalse(type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_LIST)); Assert.assertFalse(type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_RESTRICTION)); Assert.assertTrue(type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_EXTENSION)); Assert.assertTrue(type.isDerivedFrom("testNS", "Test", 0)); }
@Test public void test1() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute(SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI); dbf.setAttribute(SCHEMA_SOURCE, Bug4966138.class.getResource("test.xsd").toExternalForm()); Document document = dbf.newDocumentBuilder().parse(Bug4966138.class.getResource("test.xml").toExternalForm()); TypeInfo type = document.getDocumentElement().getSchemaTypeInfo(); String typeName = type.getTypeName(); System.out.println(typeName); Assert.assertNotNull(typeName); Assert.assertTrue(typeName.length() != 0, "returned typeName shouldn't be empty"); String typeNs = type.getTypeNamespace(); System.out.println(typeNs); Assert.assertNotNull(typeNs); Assert.assertTrue(typeNs.length() != 0, "returned typeNamespace shouldn't be empty"); }
/** * Check usage of TypeInfo interface introduced in DOM L3. * * @throws Exception If any errors occur. */ @Test public void testGetTypeInfo() throws Exception { String xmlFile = XML_DIR + "accountInfo.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); docBuilder.setErrorHandler(new MyErrorHandler()); Document document = docBuilder.parse(xmlFile); Element userId = (Element)document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "UserID").item(0); TypeInfo typeInfo = userId.getSchemaTypeInfo(); assertTrue(typeInfo.getTypeName().equals("nonNegativeInteger")); assertTrue(typeInfo.getTypeNamespace().equals(W3C_XML_SCHEMA_NS_URI)); Element role = (Element)document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Role").item(0); TypeInfo roletypeInfo = role.getSchemaTypeInfo(); assertTrue(roletypeInfo.getTypeName().equals("BuyOrSell")); assertTrue(roletypeInfo.getTypeNamespace().equals(PORTAL_ACCOUNT_NS)); }
/** * Check usage of TypeInfo interface introduced in DOM L3. * * @throws Exception If any errors occur. */ @Test(groups = {"readLocalFiles"}) public void testGetTypeInfo() throws Exception { String xmlFile = XML_DIR + "accountInfo.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); docBuilder.setErrorHandler(new MyErrorHandler()); Document document = docBuilder.parse(xmlFile); Element userId = (Element)document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "UserID").item(0); TypeInfo typeInfo = userId.getSchemaTypeInfo(); assertTrue(typeInfo.getTypeName().equals("nonNegativeInteger")); assertTrue(typeInfo.getTypeNamespace().equals(W3C_XML_SCHEMA_NS_URI)); Element role = (Element)document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Role").item(0); TypeInfo roletypeInfo = role.getSchemaTypeInfo(); assertTrue(roletypeInfo.getTypeName().equals("BuyOrSell")); assertTrue(roletypeInfo.getTypeNamespace().equals(PORTAL_ACCOUNT_NS)); }
protected boolean simpleTypeIsDerivedFrom(SimpleType simpleType, String typeNamespace, String typeName, int derivationMethod) { switch (derivationMethod) { case TypeInfo.DERIVATION_RESTRICTION: SimpleType baseType = simpleType.baseType; while (baseType != null) { if (baseType.name.getNamespaceURI().equals(typeNamespace) && baseType.name.getLocalPart().equals(typeName)) { return true; } baseType = baseType.baseType; } break; // TODO other methods } return false; }
public String getAttributeType(int index) { String attrType = null; Attr attr = (Attr)getAttributes().get(index); TypeInfo typeInfo = attr.getSchemaTypeInfo(); if (typeInfo != null) { attrType = typeInfo.getTypeName(); } if (attrType == null) { try { attrType = (String) attr.getUserData(SAAJConverter.OM_ATTRIBUTE_KEY); if (log.isDebugEnabled()) { log.debug("Retrieving attrType from UserData: " + attrType); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("An error occured while getting attrType: " + e.getMessage()); } } } return attrType; }
public String toJavaTypeName(XSObject xs, Map<String, NamespaceDesc> nsdMap) { String name = xs.getName(); if (name == null) { if (xs instanceof TypeInfo) { name = ((TypeInfo) xs).getTypeName(); if (name != null && name.startsWith("#")) { name = name.substring(1); } } } return model.toJavaTypeName(name, xs.getNamespace()); }
/** * Method getSchemaTypeInfo. * @return TypeInfo */ public TypeInfo getSchemaTypeInfo(){ if(needsSyncData()) { synchronizeData(); } return this; }
private TypeInfo getAttributeType( int index ) { checkState(false); if( index<0 || fAttributes.getLength()<=index ) throw new IndexOutOfBoundsException(Integer.toString(index)); Augmentations augs = fAttributes.getAugmentations(index); if (augs == null) return null; AttributePSVI psvi = (AttributePSVI)augs.getItem(Constants.ATTRIBUTE_PSVI); return getTypeInfoFromPSVI(psvi); }
/** * Method getSchemaTypeInfo. * * @return TypeInfo */ public TypeInfo getSchemaTypeInfo() { if (needsSyncData()) { synchronizeData(); } return this; }
@Test public void test1() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute(SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI); dbf.setAttribute(SCHEMA_SOURCE, Bug4966142.class.getResource("Bug4966142.xsd").toExternalForm()); Document document = dbf.newDocumentBuilder().parse(Bug4966142.class.getResource("Bug4966142.xml").toExternalForm()); TypeInfo type = document.getDocumentElement().getSchemaTypeInfo(); Assert.assertFalse(type.isDerivedFrom("testNS", "Test", TypeInfo.DERIVATION_UNION)); }
@Test public void test() throws Exception { TypeInfo typeInfo = getTypeOfRoot(SCHEMA_INSTANCE, "<?xml version='1.0'?>\n" + "<test1 xmlns=\"testNS\"><code/></test1>\n"); assertEquals(typeInfo.getTypeName(), "Test"); assertEquals(typeInfo.getTypeNamespace(), "testNS"); }
/** * <b>DOM</b>: Implements {@link org.w3c.dom.Element#getSchemaTypeInfo()}. */ public TypeInfo getSchemaTypeInfo() { if (typeInfo == null) { typeInfo = new ElementTypeInfo(); } return typeInfo; }
/** * <b>DOM</b>: Implements {@link org.w3c.dom.Attr#getSchemaTypeInfo()}. */ public TypeInfo getSchemaTypeInfo() { if (typeInfo == null) { typeInfo = new AttrTypeInfo(); } return typeInfo; }
public String getAttributeType(int index) { if (current != null) { NamedNodeMap attrs = current.getAttributes(); if (attrs == null) return null; Attr attr = (Attr) attrs.item(index); TypeInfo ti = attr.getSchemaTypeInfo(); return (ti == null) ? "CDATA" : ti.getTypeName(); } return super.getAttributeType(index); }
public TypeInfo getSchemaTypeInfo() { if (parent != null) { // DTD implementation DomDoctype doctype = (DomDoctype) parent.owner.getDoctype(); if (doctype != null) { return doctype.getAttributeTypeInfo(parent.getNodeName(), getNodeName()); } // TODO XML Schema implementation } return null; }
public TypeInfo getSchemaTypeInfo() { // DTD implementation DomDoctype doctype = (DomDoctype) owner.getDoctype(); if (doctype != null) { return doctype.getElementTypeInfo(getNodeName()); } // TODO XML Schema implementation return null; }
public TypeInfo getSchemaTypeInfo() { // dynamic load to support jre 1.4 and 1.5 try { Method m = element.getClass().getMethod("getSchemaTypeInfo", new Class[]{}); return (TypeInfo) m.invoke(element, ArrayUtil.OBJECT_EMPTY); } catch (Exception e) { throw new PageRuntimeException(Caster.toPageException(e)); } }