xs:redefine [message #63283] |
Wed, 14 September 2005 23:28 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Hi,
How can I resolve a redefined ComplexType so that it includes the elements
from redefined and original schema? The main schema attached below points
to the 2nd schema which redefines the 3rd schema. The
XSDComplexTypeDefintion corresponding to ClaimType points to the 2rd
schema. The content of the CompleType is instanceof XSDRedefine and I can
call redefine.getResolvedSchema() or redefine.getIncorporatedSchema() to
get the 3rd schema. What api can I use to get the contents of ClaimType
so that it includes the elements from schema 2 and schema 3.
Thanks in advance,
-Anindita.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="ClaimType.xsd"/>
<xsd:element name="Claim" type="ClaimType"/>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:redefine schemaLocation="../../../bom/Claim/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>
<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: xs:redefine [message #63355 is a reply to message #63283] |
Thu, 15 September 2005 10:13 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Anindita,
This question is slightly different.
XSDComplexTypeDefinition.getContentType returns either the particle or
the simple type representing the content type. In the case of a
particle, you can walk the XSDParticle.getTerm to get at the root
XSDModelGroup and then you can walk the XSDModelGroup.getParticles to
recursively visit the children. The term of a particle can be either an
XSDElementDeclaration, an XSDModelGroup, or an XSDWildcard. This content
type particle tree includes the all content inherited from based types.
Anindita Banerjee wrote:
> Hi,
>
> How can I resolve a redefined ComplexType so that it includes the
> elements from redefined and original schema? The main schema attached
> below points to the 2nd schema which redefines the 3rd schema. The
> XSDComplexTypeDefintion corresponding to �ClaimType� points to the 2rd
> schema. The content of the CompleType is instanceof XSDRedefine and I
> can call redefine.getResolvedSchema() or
> redefine.getIncorporatedSchema() to get the 3rd schema. What api can I
> use to get the contents of �ClaimType
> � so that it includes the elements from schema 2 and schema 3.
>
> Thanks in advance,
> -Anindita.
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:include schemaLocation="ClaimType.xsd"/>
> <xsd:element name="Claim" type="ClaimType"/>
> </xsd:schema>
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:redefine schemaLocation="../../../bom/Claim/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>
>
> <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: xs:redefine [message #63423 is a reply to message #63283] |
Thu, 15 September 2005 23:36 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Hi Ed,
I tried out the following code as per your suggestion but it doesn't work.
Am I missing something?
Thanks,
-Anindita.
/* complexType is "ClaimType" which has been redefined */
XSDComplexTypeContent compContentType = complexType.getContentType();
if (complexType.getContentType() instanceof XSDParticle ) {
XSDModelGroupDefinition modelGrp =
((XSDParticle)complexType.getContentType()).getTerm().resolv eModelGroupDefinition(complexType.getName());
List particles = modelGrp.getModelGroup().getParticles();
for (Iterator modelIter = particles.iterator();
modelIter.hasNext();) {
XSDParticleContent partContent =
((XSDParticle)modelIter.next()).getContent();
if (partContent instanceof XSDElementDeclaration) {
XSDElementDeclaration xsElement =
(XSDElementDeclaration)partContent;
System.out.println("===> " + xsElement.getName());
}
}
}
|
|
|
Re: xs:redefine [message #63445 is a reply to message #63423] |
Fri, 16 September 2005 10:01 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Anindita,
I noticed you did ((XSDParticle)modelIter.next()).getContent() not
getTerm() for the second level particle. You are also not walking the
content model recursively and in this example you will definitely hit
another model group at the second level of particles.
Anindita Banerjee wrote:
> Hi Ed,
> I tried out the following code as per your suggestion but it doesn't
> work. Am I missing something?
>
> Thanks,
> -Anindita.
>
> /* complexType is "ClaimType" which has been redefined */
> XSDComplexTypeContent compContentType = complexType.getContentType();
>
> if (complexType.getContentType() instanceof XSDParticle ) {
> XSDModelGroupDefinition modelGrp =
> ((XSDParticle)complexType.getContentType()).getTerm().resolv eModelGroupDefinition(complexType.getName());
>
> List particles = modelGrp.getModelGroup().getParticles();
>
> for (Iterator modelIter = particles.iterator();
> modelIter.hasNext();) {
> XSDParticleContent partContent =
> ((XSDParticle)modelIter.next()).getContent();
> if (partContent instanceof XSDElementDeclaration) {
> XSDElementDeclaration xsElement =
> (XSDElementDeclaration)partContent;
> System.out.println("===> " + xsElement.getName());
> }
> }
> }
>
>
|
|
|
Re: xs:redefine [message #63535 is a reply to message #63445] |
Wed, 21 September 2005 23:14 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Hi Ed,
I changed the code to recursively traverse the model group, but I am still
not able to get to the resolved complexType. In my particular case
modelGroup.getParticles() returns an empty list.
Thanks,
-Anindita.
XSDComplexTypeContent compContentType = complexType.getContentType();
if (complexType.getContentType() instanceof XSDParticle ) {
XSDModelGroup modelGrp =
(XSDParticle)complexType.getContentType()).getTerm().
resolveModelGroupDefinition(complexType.getName()).getModelG roup();
XSDElementDeclaration xsElement = checkModelGroupForElement(modelGrp);
.....
XSDElementDeclaration checkModelGroupForElement(XSDModelGroup modelGroup) {
List particles = modelGroup.getParticles();
XSDElementDeclaration xsElement = null;
for (Iterator iter = particles.iterator(); iter.hasNext();) {
XSDTerm term = ((XSDParticle)iter.next()).getTerm();
if (term instanceof XSDElementDeclaration) {
return (XSDElementDeclaration)term;
} else if (term instanceof XSDModelGroup) {
xsElement = checkModelGroupForElement((XSDModelGroup)term);
} else {
System.out.println("wildcard group:" + term);
}
}
return xsElement;
}
|
|
|
Re: xs:redefine [message #63556 is a reply to message #63535] |
Wed, 21 September 2005 23:59 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Anindita,
If you can demonstrate the problem with a reproducible test case, I can
most efficiently help. I've loaded the schemas and they all appear to
work, but I don't know the context in which you are trying to do your
processing. An all too common mistake is to load the schema with a
relative URI causing relative schemaLocation URIs to fail to resolve.
Modifying org.eclipse.xsd.example to turn it into a test case is pretty
easy and often people find that problem goes away when they do that
(especially when you look at how the URIs are created).
Anindita Banerjee wrote:
> Hi Ed,
>
> I changed the code to recursively traverse the model group, but I am
> still not able to get to the resolved complexType. In my particular
> case modelGroup.getParticles() returns an empty list.
>
> Thanks,
> -Anindita.
>
> XSDComplexTypeContent compContentType = complexType.getContentType();
>
> if (complexType.getContentType() instanceof XSDParticle ) {
>
> XSDModelGroup modelGrp =
> (XSDParticle)complexType.getContentType()).getTerm().
>
> resolveModelGroupDefinition(complexType.getName()).getModelG roup();
>
> XSDElementDeclaration xsElement = checkModelGroupForElement(modelGrp);
>
> ....
>
> XSDElementDeclaration checkModelGroupForElement(XSDModelGroup
> modelGroup) {
> List particles = modelGroup.getParticles();
>
> XSDElementDeclaration xsElement = null;
>
> for (Iterator iter = particles.iterator(); iter.hasNext();) {
> XSDTerm term = ((XSDParticle)iter.next()).getTerm();
> if (term instanceof XSDElementDeclaration) {
> return (XSDElementDeclaration)term;
> } else if (term instanceof XSDModelGroup) {
> xsElement = checkModelGroupForElement((XSDModelGroup)term);
> } else {
> System.out.println("wildcard group:" + term);
> }
> }
> return xsElement;
> }
>
>
|
|
|
Re: xs:redefine [message #63629 is a reply to message #63556] |
Thu, 22 September 2005 18:06 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Ed,
Thanks for offering to take a look at my use case. You can use the schemas
that I have attached at the beginning of the email thread.
modelGroup.getParticles() return an empty list.
Thanks a lot,
-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,
String elementName) {
if (complexType.getContentType() instanceof XSDParticle ) {
XSDModelGroup modelGrp =
((XSDParticle)complexType.getContentType()).getTerm().
resolveModelGroupDefinition(complexType.getName()).getModelG roup();
checkModelGroupForElement(modelGrp, elementName);
} else
System.out.println("complexType.getContentType(): " +
complexType.getContentType().getClass().getName());
}
XSDElementDeclaration checkModelGroupForElement(XSDModelGroup modelGroup,
String elementName) {
List particles = modelGroup.getParticles();
System.out.println("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) &&
((XSDElementDeclaration)term).getName().equals(elementName)) {
System.out.println("FOUND ELEMENT: " + elementName);
} else if (term instanceof XSDModelGroup) {
xsElement = checkModelGroupForElement((XSDModelGroup)term,
elementName);
} else
System.out.println("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, "AccidentDateTime");
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
|
|
Re: xs:redefine [message #63651 is a reply to message #63629] |
Thu, 22 September 2005 20:52 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
This is a multi-part message in MIME format.
--------------010900060703020100020900
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Anindita,
I changed this and things appear to be much better.
XSDModelGroup modelGrp =
*(XSDModelGroup)*((XSDParticle)complexType.getContentType()) .getTerm();*//.
//
resolveModelGroupDefinition(complexType.getName()).getModelG roup();*
I'm not quite sure that that code was trying to do, but there are no
named model groups in this schema so the above could only result in a
"placeholder" model group definition being returned, i.e., one whose
getContainer() is null because it's not really in any schema.
Anindita Banerjee wrote:
> Ed,
>
> Thanks for offering to take a look at my use case. You can use the
> schemas that I have attached at the beginning of the email thread.
> modelGroup.getParticles() return an empty list.
>
> Thanks a lot,
> -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,
> String elementName) {
> if (complexType.getContentType() instanceof XSDParticle ) {
> XSDModelGroup modelGrp =
> ((XSDParticle)complexType.getContentType()).getTerm().
>
> resolveModelGroupDefinition(complexType.getName()).getModelG roup();
> checkModelGroupForElement(modelGrp, elementName);
> } else
> System.out.println("complexType.getContentType(): " +
> complexType.getContentType().getClass().getName());
> }
>
> XSDElementDeclaration checkModelGroupForElement(XSDModelGroup
> modelGroup, String elementName) {
> List particles = modelGroup.getParticles();
> System.out.println("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) &&
> ((XSDElementDeclaration)term).getName().equals(elementName)) {
> System.out.println("FOUND ELEMENT: " + elementName);
> } else if (term instanceof XSDModelGroup) {
> xsElement = checkModelGroupForElement((XSDModelGroup)term,
> elementName);
> } else
> System.out.println("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, "AccidentDateTime");
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
--------------010900060703020100020900
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Anindita,<br>
<br>
I changed this and things appear to be much better.<br>
<br>
|
|
|
Re: xs:redefine [message #63673 is a reply to message #63651] |
Thu, 22 September 2005 22:57 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Ed,
It worked!! I was trying to resolve the ModelGroup and that was resulting
in an empty particle list.
Thanks once again for all your help,
-Anindita.
|
|
|
Re: xs:redefine [message #596405 is a reply to message #63283] |
Thu, 15 September 2005 10:13 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
Anindita,
This question is slightly different.
XSDComplexTypeDefinition.getContentType returns either the particle or
the simple type representing the content type. In the case of a
particle, you can walk the XSDParticle.getTerm to get at the root
XSDModelGroup and then you can walk the XSDModelGroup.getParticles to
recursively visit the children. The term of a particle can be either an
XSDElementDeclaration, an XSDModelGroup, or an XSDWildcard. This content
type particle tree includes the all content inherited from based types.
Anindita Banerjee wrote:
> Hi,
>
> How can I resolve a redefined ComplexType so that it includes the
> elements from redefined and original schema? The main schema attached
> below points to the 2nd schema which redefines the 3rd schema. The
> XSDComplexTypeDefintion corresponding to �ClaimType� points to the 2rd
> schema. The content of the CompleType is instanceof XSDRedefine and I
> can call redefine.getResolvedSchema() or
> redefine.getIncorporatedSchema() to get the 3rd schema. What api can I
> use to get the contents of �ClaimType
> � so that it includes the elements from schema 2 and schema 3.
>
> Thanks in advance,
> -Anindita.
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:include schemaLocation="ClaimType.xsd"/>
> <xsd:element name="Claim" type="ClaimType"/>
> </xsd:schema>
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:redefine schemaLocation="../../../bom/Claim/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>
>
> <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>
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: xs:redefine [message #596430 is a reply to message #63283] |
Thu, 15 September 2005 23:36 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Hi Ed,
I tried out the following code as per your suggestion but it doesn't work.
Am I missing something?
Thanks,
-Anindita.
/* complexType is "ClaimType" which has been redefined */
XSDComplexTypeContent compContentType = complexType.getContentType();
if (complexType.getContentType() instanceof XSDParticle ) {
XSDModelGroupDefinition modelGrp =
((XSDParticle)complexType.getContentType()).getTerm().resolv eModelGroupDefinition(complexType.getName());
List particles = modelGrp.getModelGroup().getParticles();
for (Iterator modelIter = particles.iterator();
modelIter.hasNext();) {
XSDParticleContent partContent =
((XSDParticle)modelIter.next()).getContent();
if (partContent instanceof XSDElementDeclaration) {
XSDElementDeclaration xsElement =
(XSDElementDeclaration)partContent;
System.out.println("===> " + xsElement.getName());
}
}
}
|
|
|
Re: xs:redefine [message #596435 is a reply to message #63423] |
Fri, 16 September 2005 10:01 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
Anindita,
I noticed you did ((XSDParticle)modelIter.next()).getContent() not
getTerm() for the second level particle. You are also not walking the
content model recursively and in this example you will definitely hit
another model group at the second level of particles.
Anindita Banerjee wrote:
> Hi Ed,
> I tried out the following code as per your suggestion but it doesn't
> work. Am I missing something?
>
> Thanks,
> -Anindita.
>
> /* complexType is "ClaimType" which has been redefined */
> XSDComplexTypeContent compContentType = complexType.getContentType();
>
> if (complexType.getContentType() instanceof XSDParticle ) {
> XSDModelGroupDefinition modelGrp =
> ((XSDParticle)complexType.getContentType()).getTerm().resolv eModelGroupDefinition(complexType.getName());
>
> List particles = modelGrp.getModelGroup().getParticles();
>
> for (Iterator modelIter = particles.iterator();
> modelIter.hasNext();) {
> XSDParticleContent partContent =
> ((XSDParticle)modelIter.next()).getContent();
> if (partContent instanceof XSDElementDeclaration) {
> XSDElementDeclaration xsElement =
> (XSDElementDeclaration)partContent;
> System.out.println("===> " + xsElement.getName());
> }
> }
> }
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: xs:redefine [message #596461 is a reply to message #63445] |
Wed, 21 September 2005 23:14 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Hi Ed,
I changed the code to recursively traverse the model group, but I am still
not able to get to the resolved complexType. In my particular case
modelGroup.getParticles() returns an empty list.
Thanks,
-Anindita.
XSDComplexTypeContent compContentType = complexType.getContentType();
if (complexType.getContentType() instanceof XSDParticle ) {
XSDModelGroup modelGrp =
(XSDParticle)complexType.getContentType()).getTerm().
resolveModelGroupDefinition(complexType.getName()).getModelG roup();
XSDElementDeclaration xsElement = checkModelGroupForElement(modelGrp);
.....
XSDElementDeclaration checkModelGroupForElement(XSDModelGroup modelGroup) {
List particles = modelGroup.getParticles();
XSDElementDeclaration xsElement = null;
for (Iterator iter = particles.iterator(); iter.hasNext();) {
XSDTerm term = ((XSDParticle)iter.next()).getTerm();
if (term instanceof XSDElementDeclaration) {
return (XSDElementDeclaration)term;
} else if (term instanceof XSDModelGroup) {
xsElement = checkModelGroupForElement((XSDModelGroup)term);
} else {
System.out.println("wildcard group:" + term);
}
}
return xsElement;
}
|
|
|
Re: xs:redefine [message #596467 is a reply to message #63535] |
Wed, 21 September 2005 23:59 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
Anindita,
If you can demonstrate the problem with a reproducible test case, I can
most efficiently help. I've loaded the schemas and they all appear to
work, but I don't know the context in which you are trying to do your
processing. An all too common mistake is to load the schema with a
relative URI causing relative schemaLocation URIs to fail to resolve.
Modifying org.eclipse.xsd.example to turn it into a test case is pretty
easy and often people find that problem goes away when they do that
(especially when you look at how the URIs are created).
Anindita Banerjee wrote:
> Hi Ed,
>
> I changed the code to recursively traverse the model group, but I am
> still not able to get to the resolved complexType. In my particular
> case modelGroup.getParticles() returns an empty list.
>
> Thanks,
> -Anindita.
>
> XSDComplexTypeContent compContentType = complexType.getContentType();
>
> if (complexType.getContentType() instanceof XSDParticle ) {
>
> XSDModelGroup modelGrp =
> (XSDParticle)complexType.getContentType()).getTerm().
>
> resolveModelGroupDefinition(complexType.getName()).getModelG roup();
>
> XSDElementDeclaration xsElement = checkModelGroupForElement(modelGrp);
>
> ....
>
> XSDElementDeclaration checkModelGroupForElement(XSDModelGroup
> modelGroup) {
> List particles = modelGroup.getParticles();
>
> XSDElementDeclaration xsElement = null;
>
> for (Iterator iter = particles.iterator(); iter.hasNext();) {
> XSDTerm term = ((XSDParticle)iter.next()).getTerm();
> if (term instanceof XSDElementDeclaration) {
> return (XSDElementDeclaration)term;
> } else if (term instanceof XSDModelGroup) {
> xsElement = checkModelGroupForElement((XSDModelGroup)term);
> } else {
> System.out.println("wildcard group:" + term);
> }
> }
> return xsElement;
> }
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: xs:redefine [message #596494 is a reply to message #63556] |
Thu, 22 September 2005 18:06 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Ed,
Thanks for offering to take a look at my use case. You can use the schemas
that I have attached at the beginning of the email thread.
modelGroup.getParticles() return an empty list.
Thanks a lot,
-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,
String elementName) {
if (complexType.getContentType() instanceof XSDParticle ) {
XSDModelGroup modelGrp =
((XSDParticle)complexType.getContentType()).getTerm().
resolveModelGroupDefinition(complexType.getName()).getModelG roup();
checkModelGroupForElement(modelGrp, elementName);
} else
System.out.println("complexType.getContentType(): " +
complexType.getContentType().getClass().getName());
}
XSDElementDeclaration checkModelGroupForElement(XSDModelGroup modelGroup,
String elementName) {
List particles = modelGroup.getParticles();
System.out.println("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) &&
((XSDElementDeclaration)term).getName().equals(elementName)) {
System.out.println("FOUND ELEMENT: " + elementName);
} else if (term instanceof XSDModelGroup) {
xsElement = checkModelGroupForElement((XSDModelGroup)term,
elementName);
} else
System.out.println("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, "AccidentDateTime");
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
|
|
Re: xs:redefine [message #596502 is a reply to message #63629] |
Thu, 22 September 2005 20:52 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------010900060703020100020900
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Anindita,
I changed this and things appear to be much better.
XSDModelGroup modelGrp =
*(XSDModelGroup)*((XSDParticle)complexType.getContentType()) .getTerm();*//.
//
resolveModelGroupDefinition(complexType.getName()).getModelG roup();*
I'm not quite sure that that code was trying to do, but there are no
named model groups in this schema so the above could only result in a
"placeholder" model group definition being returned, i.e., one whose
getContainer() is null because it's not really in any schema.
Anindita Banerjee wrote:
> Ed,
>
> Thanks for offering to take a look at my use case. You can use the
> schemas that I have attached at the beginning of the email thread.
> modelGroup.getParticles() return an empty list.
>
> Thanks a lot,
> -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,
> String elementName) {
> if (complexType.getContentType() instanceof XSDParticle ) {
> XSDModelGroup modelGrp =
> ((XSDParticle)complexType.getContentType()).getTerm().
>
> resolveModelGroupDefinition(complexType.getName()).getModelG roup();
> checkModelGroupForElement(modelGrp, elementName);
> } else
> System.out.println("complexType.getContentType(): " +
> complexType.getContentType().getClass().getName());
> }
>
> XSDElementDeclaration checkModelGroupForElement(XSDModelGroup
> modelGroup, String elementName) {
> List particles = modelGroup.getParticles();
> System.out.println("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) &&
> ((XSDElementDeclaration)term).getName().equals(elementName)) {
> System.out.println("FOUND ELEMENT: " + elementName);
> } else if (term instanceof XSDModelGroup) {
> xsElement = checkModelGroupForElement((XSDModelGroup)term,
> elementName);
> } else
> System.out.println("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, "AccidentDateTime");
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
--------------010900060703020100020900
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Anindita,<br>
<br>
I changed this and things appear to be much better.<br>
<br>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: xs:redefine [message #596508 is a reply to message #63651] |
Thu, 22 September 2005 22:57 |
Eclipse User |
|
|
|
Originally posted by: abanerjee.vitria.com
Ed,
It worked!! I was trying to resolve the ModelGroup and that was resulting
in an empty particle list.
Thanks once again for all your help,
-Anindita.
|
|
|
Powered by
FUDForum. Page generated in 0.03874 seconds