| 
| 2 levels of xsd:redefine [message #63789] | Mon, 26 September 2005 14: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>
 |  |  |  | 
| 
| Re: 2 levels of xsd:redefine [message #63817 is a reply to message #63789] | Mon, 26 September 2005 16:33   |  | 
| Eclipse User  |  |  |  |  | Originally posted by: merks.ca.ibm.com 
 Anindita,
 
 Could you provide a zip of the schemas, so that I don't have to figure
 out their file names and relative locations?  Or at least outline the
 path names...
 
 
 Anindita Banerjee wrote:
 
 > 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>
 >
 >
 |  |  |  | 
|  | 
|  | 
|  | 
|  | 
| 
| Re: 2 levels of xsd:redefine [message #63928 is a reply to message #63907] | Tue, 27 September 2005 13:47  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: merks.ca.ibm.com 
 Anindita,
 
 Other than the issue reported in
 https://bugs.eclipse.org/bugs/show_bug.cgi?id=106098 import and include
 should work fine in general.
 
 Anindita Banerjee wrote:
 
 > Ed,
 >
 > Thanks for the response. I was able to resolve element definitions
 > with more than 2 level of xsd:include and xsd:import. Do you know of
 > any bugs/limitations with multiple levels of xsd:import and xsd:include.
 >
 > Thanks,
 > -Anindita.
 >
 |  |  |  | 
| 
| Re: 2 levels of xsd:redefine [message #596582 is a reply to message #63789] | Mon, 26 September 2005 16:33  |  | 
| Eclipse User  |  |  |  |  | Anindita, 
 Could you provide a zip of the schemas, so that I don't have to figure
 out their file names and relative locations?  Or at least outline the
 path names...
 
 
 Anindita Banerjee wrote:
 
 > 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>
 >
 >
 |  |  |  | 
| 
| Re: 2 levels of xsd:redefine [message #596594 is a reply to message #63817] | Mon, 26 September 2005 16:46  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: abanerjee.vitria.com 
 Hi Ed,
 
 How do I attach a file to the posting?
 
 Schema 1 and Schema 2 should be in the current directory.
 
 Schema 3 should be a directory called "two" in the current directory.
 
 Schema 4 should be in a directory called "one" within the current
 directory.
 
 Schema 2, 3 and 4 should all be called ClaimType.xsd.
 
 Thanks,
 -Anindita.
 |  |  |  | 
| 
| Re: 2 levels of xsd:redefine [message #596601 is a reply to message #63840] | Mon, 26 September 2005 17:11  |  | 
| Eclipse User  |  |  |  |  | Anindita, 
 Okay.  I'll try to have a look tomorrow.
 
 
 Anindita Banerjee wrote:
 
 > Hi Ed,
 >
 > How do I attach a file to the posting?
 > Schema 1 and Schema 2 should be in the current directory.
 >
 > Schema 3 should be a directory called "two" in the current directory.
 >
 > Schema 4 should be in a directory called "one" within the current
 > directory.
 >
 > Schema 2, 3 and 4 should all be called ClaimType.xsd.
 >
 > Thanks,
 > -Anindita.
 >
 |  |  |  | 
| 
| Re: 2 levels of xsd:redefine [message #596607 is a reply to message #63840] | Tue, 27 September 2005 08:29  |  | 
| Eclipse User  |  |  |  |  | Anindita, 
 This looks like yet another manifestation of
 https://bugs.eclipse.org/bugs/show_bug.cgi?id=83055  This bug and all
 the problems associated with complex uses of redefine are something that
 I simply don't have time to fix.  You'll find that Xerces has bugs in
 this area too.  The whole concept of redefinition is far too loosely
 defined in the spec and coming up with a consistent model for the
 semantics is a challenge beyond my abilities as well as beyond my
 resource capacity.  Sorry.  :-(
 
 
 Anindita Banerjee wrote:
 
 > Hi Ed,
 >
 > How do I attach a file to the posting?
 > Schema 1 and Schema 2 should be in the current directory.
 >
 > Schema 3 should be a directory called "two" in the current directory.
 >
 > Schema 4 should be in a directory called "one" within the current
 > directory.
 >
 > Schema 2, 3 and 4 should all be called ClaimType.xsd.
 >
 > Thanks,
 > -Anindita.
 >
 |  |  |  | 
| 
| Re: 2 levels of xsd:redefine [message #596620 is a reply to message #63885] | Tue, 27 September 2005 13:42  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: abanerjee.vitria.com 
 Ed,
 
 Thanks for the response. I was able to resolve element definitions with
 more than 2 level of xsd:include and xsd:import. Do you know of any
 bugs/limitations with multiple levels of xsd:import and xsd:include.
 
 Thanks,
 -Anindita.
 |  |  |  | 
|  | 
Powered by 
FUDForum. Page generated in 0.07047 seconds