Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » 2 levels of xsd:redefine
2 levels of xsd:redefine [message #596569] Mon, 26 September 2005 18:13
Eclipse User
Originally posted by: abanerjee.vitria.com

Hi Ed,

With your help I was able to resolve the a single level of xsd:redefine.
However 2 levels of xsd:redefine does not work.

I am appending the sample program and the 4 schemas for your reference.
The 1st is the parent schema. It includes the 2nd schema which redefines
the 3rd which redefines the 4th.

The sample program prints out all the resolved elements of CompleType -
ClaimType. Am I missing something?

Thanks in advance,
-Anindita.

import org.eclipse.emf.ecore.resource.*;
import org.eclipse.xsd.util.*;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xsd.*;
import java.util.*;
import java.io.File;

public class TestRedefine {
private XSDSchema schema_;
public TestRedefine() {
}

void checkComplexTypeForElement(XSDComplexTypeDefinition complexType) {
if (complexType.getContentType() instanceof XSDParticle ) {
XSDModelGroup modelGrp =
(XSDModelGroup)((XSDParticle)complexType.getContentType()).g etTerm();
checkModelGroupForElement(modelGrp, "");
} else
System.out.println("complexType.getContentType(): " +
complexType.getContentType().getClass().getName());
}

XSDElementDeclaration checkModelGroupForElement(XSDModelGroup modelGroup,
String tab) {
tab = tab + " ";
List particles = modelGroup.getParticles();
System.out.println(tab + "Size of particles is " + particles.size());

XSDElementDeclaration xsElement = null;

for (Iterator iter = particles.iterator(); iter.hasNext();) {
XSDTerm term = ((XSDParticle)iter.next()).getTerm();
if (term instanceof XSDElementDeclaration) {
System.out.println(tab + "FOUND ELEMENT: " +
((XSDElementDeclaration)term).getName());
} else if (term instanceof XSDModelGroup) {
xsElement = checkModelGroupForElement((XSDModelGroup)term, tab);
} else
System.out.println(tab + "wildcard group:" + term);
}
return xsElement;
}

XSDComplexTypeDefinition getComplexType(String memberName) {
List allTypes = schema_.getTypeDefinitions();
for (Iterator iter = allTypes.iterator(); iter.hasNext();) {
XSDTypeDefinition typedef = (XSDTypeDefinition)iter.next();
if ((typedef instanceof XSDComplexTypeDefinition) &&
typedef.getName().equals(memberName))
return (XSDComplexTypeDefinition)typedef;
}
return null;
}

XSDSchema loadSchema(String fname) throws Exception {

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
new XSDResourceFactoryImpl());

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
Boolean.TRUE);
URI uri = URI.createURI(fname);
XSDResourceImpl xsdSchemaResouce = (XSDResourceImpl)
resourceSet.getResource(uri, true);

for (Iterator resources = resourceSet.getResources().iterator();
resources.hasNext(); ) {
Resource resource = (Resource)resources.next();
if (resource instanceof XSDResourceImpl) {
XSDResourceImpl xsdResource = (XSDResourceImpl)resource;
schema_ = xsdResource.getSchema();
return schema_;
}
}
return null;
}

public static void main(String[] args) {
try {
String fname = args[0];
File file = new File(fname);
TestRedefine sch = new TestRedefine();
sch.loadSchema(file.toURL().toString());
XSDComplexTypeDefinition claim = sch.getComplexType("ClaimType");
sch.checkComplexTypeForElement(claim);
} catch (Exception e) {
e.printStackTrace();
}
}
}
------------------------------------------------------------ -
Schema 1:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="ClaimType.xsd"/>
<xsd:element name="Claim" type="ClaimType"/>
</xsd:schema>
------------------------------------------------------------ -
Schema 2:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:redefine schemaLocation="two/ClaimType.xsd">
<xsd:complexType name="ClaimType">
<xsd:complexContent>
<xsd:extension base="ClaimType">
<xsd:sequence>
<xsd:element name="NewEncounterFlag" type="xsd:boolean" minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:redefine>
</xsd:schema>
------------------------------------------------------------ -
Schema 3:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:redefine schemaLocation="../one/ClaimType.xsd">
<xsd:complexType name="ClaimType">
<xsd:complexContent>
<xsd:extension base="ClaimType">
<xsd:sequence>
<xsd:element name="EncounterFlag" type="xsd:boolean" minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:redefine>
</xsd:schema>
------------------------------------------------------------ -
Schema 4:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="ClaimType">
<xsd:sequence>
<xsd:element name="AccidentCountryCode" type="xsd:string" minOccurs="0"/>
<xsd:element name="AccidentDateTime" type="xsd:dateTime" minOccurs="0"/>
<xsd:element name="AccidentStateCode" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Previous Topic:Unable to generate group instance in Java class
Next Topic:2 levels of xsd:redefine
Goto Forum:
  


Current Time: Thu Sep 18 13:53:04 GMT 2014

Powered by FUDForum. Page generated in 0.18175 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software