Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Deteriming if an ElementDeclaration is a Simple or Complex Type
Deteriming if an ElementDeclaration is a Simple or Complex Type [message #53049] Wed, 22 September 2004 22:11 Go to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)

My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();

and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #53075 is a reply to message #53049] Thu, 23 September 2004 11:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------010702050801040500000809
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

You've definitely cross a few wire here, and I've added comments below
where I think they crossed. ;-)

It's best to think of it like this. The methods getSimpleType and
getComplexType apply to either a simple type or a complex type. When
applied to a simple type, getSimpleType return "this", and
getComplexType return null. When applied to a complex type,
getSimpleType returns the content type, if it's simple, and
getComplexType returns the content type, if it's complex, i.e., a particle.


Gary J wrote:

>Hi,
>
>This is probably an obvious one. Given object of type XSDElementDeclaration
>I want to easily determine if it is a Simple or Complex Type.
>
>Here's what I'm doing:
>
>// get the element Type definition
>XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();
>
>// Get the Complex Content type if it is Complex
>XSDParticle particle = typeDef.getComplexType();
>
>// If not null, element must be complex
>if(particle != null)
> // This is a Complex Element
>
>
>Reading the JavaDocs it appears I could also do this:
>
>XSDSimpleTypeDefinition type = typeDef.getSimpleType();
>
>The javadocs state this will return the SimpleTypeDefinition if the type is
>simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
>readin that wrong?)
>
>
You omitted the qualification that it will return the content type of
the complex type *only if* it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.

>My question is:
>
>Since both SimpleTypeDefinition and XSDParticle implement the
>XSDComplexTypeContent interface couldn't I simply do this:
>
>XSDComplexTypeContent type = typeDef.getSimpleType();
>
>
>
You could write this, but since typeDefinition.getSimpleType() returns
an XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.

>and then check it type is an instance of either SimpleTypeDefinition or
>XSDParticle to determine if it is simple or complex?
>
>Sorry if this sounds a bit obvious but this is one I've been chewing over
>for a while and never got the relationships quite straight in my head.
>
>Thanks
>
>
>
>
>
>
>
>


--------------010702050801040500000809
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
You've definitely cross a few wire here, and I've added comments below
where I think they crossed. ;-)<br>
<br>
It's best to think of it like this.&nbsp; The methods getSimpleType and
getComplexType apply to either a simple type or a complex type.&nbsp; When
applied to a simple type, getSimpleType return "this", and
getComplexType return null.&nbsp; When applied to a complex type,
getSimpleType returns the content type, if it's simple, and
getComplexType returns the content type, if it's complex, i.e., a
particle.<br>
<br>
<br>
Gary J wrote:
<blockquote cite="midcist1h$c0v$1@eclipse.org" type="cite">
<pre wrap="">Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)
</pre>
</blockquote>
You omitted the qualification that it will return the content type of
the complex type <b>only if</b> it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.<br>
<blockquote cite="midcist1h$c0v$1@eclipse.org" type="cite">
<pre wrap="">
My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();

</pre>
</blockquote>
You could write this, but since typeDefinition.getSimpleType() returns
an XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.<br>
<blockquote cite="midcist1h$c0v$1@eclipse.org" type="cite">
<pre wrap="">and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks






</pre>
</blockquote>
<br>
</body>
</html>

--------------010702050801040500000809--
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #53180 is a reply to message #53075] Thu, 23 September 2004 22:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

Thanks Ed,

I suspected as much when I tried to implement the code. :)

Once thing that's been confusing me, probably due to my ignorance. Let me
know where I go right off the road here:

I'm looking at a ModelGroup in the debugger. The modelGroup contains
several Complex Elements and one Simple Element. Looking at getContents()
the EList is composed entirely of Particles.

I also remember that when I create a Element with a Simple Type it is
encapsulated in a particle. like this:

XSDParticle particle = factory.createXSDParticle();
XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();

itemElement.setName(name);
itemElement.setTypeDefinition(type);
particle.setContent(itemElement);
particle.setMinOccurs(minOccurs);
particle.setMaxOccurs(maxOccurs)

So it seems that all elements are Particles, they just differ in being
either Simple or Complext Type. Is that correct?

Now going back to when I scanned the abstract model to collect all of the
XSDElementDeclaration does this mean I would just call getContainer() to get
the particle for each element regardless if it is a Simple or Complex type?

----------------------------------------------


"Ed Merks" <merks@ca.ibm.com> wrote in message
news:ciuc5h$k7d$1@eclipse.org...
Gary,

You've definitely cross a few wire here, and I've added comments below where
I think they crossed. ;-)

It's best to think of it like this. The methods getSimpleType and
getComplexType apply to either a simple type or a complex type. When
applied to a simple type, getSimpleType return "this", and getComplexType
return null. When applied to a complex type, getSimpleType returns the
content type, if it's simple, and getComplexType returns the content type,
if it's complex, i.e., a particle.


Gary J wrote:
Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)

You omitted the qualification that it will return the content type of the
complex type only if it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.

My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();


You could write this, but since typeDefinition.getSimpleType() returns an
XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.

and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #53205 is a reply to message #53180] Fri, 24 September 2004 11:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------000409000206010506030307
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

My comments are inline below.

Gary J wrote:

>Thanks Ed,
>
>I suspected as much when I tried to implement the code. :)
>
>Once thing that's been confusing me, probably due to my ignorance. Let me
>know where I go right off the road here:
>
>I'm looking at a ModelGroup in the debugger. The modelGroup contains
>several Complex Elements and one Simple Element. Looking at getContents()
>the EList is composed entirely of Particles.
>
>I also remember that when I create a Element with a Simple Type it is
>encapsulated in a particle. like this:
>
> XSDParticle particle = factory.createXSDParticle();
> XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();
>
> itemElement.setName(name);
> itemElement.setTypeDefinition(type);
> particle.setContent(itemElement);
> particle.setMinOccurs(minOccurs);
> particle.setMaxOccurs(maxOccurs)
>
>So it seems that all elements are Particles, they just differ in being
>either Simple or Complext Type. Is that correct?
>
>
>
I wouldn't word it like this since an element and a particle are two
different kinds of objects and an element is not a particle. Probably
you make this statement because any <xsd:element> appearing in a content
model will produce both an XSDParticle and an XSDElementDeclaration,
where the particle contains the element. It's important to note that
this comment does *not *apply for a global element declaration, e.g.,
one contained directly by a <schema>, which maps only to an
XSDElementDeclaration .

>Now going back to when I scanned the abstract model to collect all of the
>XSDElementDeclaration does this mean I would just call getContainer() to get
>the particle for each element regardless if it is a Simple or Complex type?
>
>
>
The container for an XSDElementDeclaration will either be null, an
XSDSchema, or an XSDParticle, regardless of the type of the element or
whether that type is simple or complex.

>----------------------------------------------
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:ciuc5h$k7d$1@eclipse.org...
>Gary,
>
>You've definitely cross a few wire here, and I've added comments below where
>I think they crossed. ;-)
>
>It's best to think of it like this. The methods getSimpleType and
>getComplexType apply to either a simple type or a complex type. When
>applied to a simple type, getSimpleType return "this", and getComplexType
>return null. When applied to a complex type, getSimpleType returns the
>content type, if it's simple, and getComplexType returns the content type,
>if it's complex, i.e., a particle.
>
>
>Gary J wrote:
>Hi,
>
>This is probably an obvious one. Given object of type XSDElementDeclaration
>I want to easily determine if it is a Simple or Complex Type.
>
>Here's what I'm doing:
>
>// get the element Type definition
>XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();
>
>// Get the Complex Content type if it is Complex
>XSDParticle particle = typeDef.getComplexType();
>
>// If not null, element must be complex
>if(particle != null)
> // This is a Complex Element
>
>
>Reading the JavaDocs it appears I could also do this:
>
>XSDSimpleTypeDefinition type = typeDef.getSimpleType();
>
>The javadocs state this will return the SimpleTypeDefinition if the type is
>simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
>readin that wrong?)
>
>You omitted the qualification that it will return the content type of the
>complex type only if it's simple, i.e., only if it is an
>XSDSimpleTypeDefinition.
>
>My question is:
>
>Since both SimpleTypeDefinition and XSDParticle implement the
>XSDComplexTypeContent interface couldn't I simply do this:
>
>XSDComplexTypeContent type = typeDef.getSimpleType();
>
>
>You could write this, but since typeDefinition.getSimpleType() returns an
>XSDSimpleTypeDefinition it can't ever be the case that it will be an
>XSDParticle.
>
>and then check it type is an instance of either SimpleTypeDefinition or
>XSDParticle to determine if it is simple or complex?
>
>Sorry if this sounds a bit obvious but this is one I've been chewing over
>for a while and never got the relationships quite straight in my head.
>
>Thanks
>
>
>
>
>
>
>
>
>
>
>


--------------000409000206010506030307
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
My comments are inline below.<br>
<br>
Gary J wrote:<br>
<blockquote cite="midcivjie$3l0$1@eclipse.org" type="cite">
<pre wrap="">Thanks Ed,

I suspected as much when I tried to implement the code. :)

Once thing that's been confusing me, probably due to my ignorance. Let me
know where I go right off the road here:

I'm looking at a ModelGroup in the debugger. The modelGroup contains
several Complex Elements and one Simple Element. Looking at getContents()
the EList is composed entirely of Particles.

I also remember that when I create a Element with a Simple Type it is
encapsulated in a particle. like this:

XSDParticle particle = factory.createXSDParticle();
XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();

itemElement.setName(name);
itemElement.setTypeDefinition(type);
particle.setContent(itemElement);
particle.setMinOccurs(minOccurs);
particle.setMaxOccurs(maxOccurs)

So it seems that all elements are Particles, they just differ in being
either Simple or Complext Type. Is that correct?

</pre>
</blockquote>
I wouldn't word it like this since an element and a particle are two
different kinds of objects and an element is not a particle.&nbsp; Probably
you make this statement because any &lt;xsd:element&gt; appearing in a
content model will produce both an XSDParticle and an
XSDElementDeclaration, where the particle contains the element.&nbsp; It's
important to note that this comment does <b>not </b>apply for a
global element declaration, e.g., one contained directly by a
&lt;schema&gt;, which maps only to an XSDElementDeclaration .<br>
<blockquote cite="midcivjie$3l0$1@eclipse.org" type="cite">
<pre wrap="">Now going back to when I scanned the abstract model to collect all of the
XSDElementDeclaration does this mean I would just call getContainer() to get
the particle for each element regardless if it is a Simple or Complex type?

</pre>
</blockquote>
The container for an XSDElementDeclaration will either be null, an
XSDSchema, or an XSDParticle, regardless of the type of the element or
whether that type is simple or complex.<br>
<blockquote cite="midcivjie$3l0$1@eclipse.org" type="cite">
<pre wrap="">----------------------------------------------


"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:ciuc5h$k7d$1@eclipse.org">news:ciuc5h$k7d$1@eclipse.org</a>...
Gary,

You've definitely cross a few wire here, and I've added comments below where
I think they crossed. ;-)

It's best to think of it like this. The methods getSimpleType and
getComplexType apply to either a simple type or a complex type. When
applied to a simple type, getSimpleType return "this", and getComplexType
return null. When applied to a complex type, getSimpleType returns the
content type, if it's simple, and getComplexType returns the content type,
if it's complex, i.e., a particle.


Gary J wrote:
Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)

You omitted the qualification that it will return the content type of the
complex type only if it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.

My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();


You could write this, but since typeDefinition.getSimpleType() returns an
XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.

and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks









</pre>
</blockquote>
<br>
</body>
</html>

--------------000409000206010506030307--
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #53258 is a reply to message #53205] Fri, 24 September 2004 23:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gj.puredge.com

Thanks for your patience.

"The container for an XSDElementDeclaration will either be null, an
XSDSchema, or an XSDParticle"

Under what circumstances will it be null?

Sorry to be so dense :~

Thanks



"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cj0vom$6bu$1@eclipse.org...
Gary,

My comments are inline below.

Gary J wrote:

Thanks Ed,

I suspected as much when I tried to implement the code. :)

Once thing that's been confusing me, probably due to my ignorance. Let me
know where I go right off the road here:

I'm looking at a ModelGroup in the debugger. The modelGroup contains
several Complex Elements and one Simple Element. Looking at getContents()
the EList is composed entirely of Particles.

I also remember that when I create a Element with a Simple Type it is
encapsulated in a particle. like this:

XSDParticle particle = factory.createXSDParticle();
XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();

itemElement.setName(name);
itemElement.setTypeDefinition(type);
particle.setContent(itemElement);
particle.setMinOccurs(minOccurs);
particle.setMaxOccurs(maxOccurs)

So it seems that all elements are Particles, they just differ in being
either Simple or Complext Type. Is that correct?


I wouldn't word it like this since an element and a particle are two
different kinds of objects and an element is not a particle. Probably you
make this statement because any <xsd:element> appearing in a content model
will produce both an XSDParticle and an XSDElementDeclaration, where the
particle contains the element. It's important to note that this comment
does not apply for a global element declaration, e.g., one contained
directly by a <schema>, which maps only to an XSDElementDeclaration .

Now going back to when I scanned the abstract model to collect all of the
XSDElementDeclaration does this mean I would just call getContainer() to get
the particle for each element regardless if it is a Simple or Complex type?


The container for an XSDElementDeclaration will either be null, an
XSDSchema, or an XSDParticle, regardless of the type of the element or
whether that type is simple or complex.

----------------------------------------------


"Ed Merks" <merks@ca.ibm.com> wrote in message
news:ciuc5h$k7d$1@eclipse.org...
Gary,

You've definitely cross a few wire here, and I've added comments below where
I think they crossed. ;-)

It's best to think of it like this. The methods getSimpleType and
getComplexType apply to either a simple type or a complex type. When
applied to a simple type, getSimpleType return "this", and getComplexType
return null. When applied to a complex type, getSimpleType returns the
content type, if it's simple, and getComplexType returns the content type,
if it's complex, i.e., a particle.


Gary J wrote:
Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)

You omitted the qualification that it will return the content type of the
complex type only if it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.

My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();


You could write this, but since typeDefinition.getSimpleType() returns an
XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.

and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #53342 is a reply to message #53258] Mon, 27 September 2004 11:49 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Gary,

It will be null if you haven't attached it anywhere.


Gary J wrote:

>Thanks for your patience.
>
>"The container for an XSDElementDeclaration will either be null, an
>XSDSchema, or an XSDParticle"
>
>Under what circumstances will it be null?
>
>Sorry to be so dense :~
>
>Thanks
>
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cj0vom$6bu$1@eclipse.org...
>Gary,
>
>My comments are inline below.
>
>Gary J wrote:
>
>Thanks Ed,
>
>I suspected as much when I tried to implement the code. :)
>
>Once thing that's been confusing me, probably due to my ignorance. Let me
>know where I go right off the road here:
>
>I'm looking at a ModelGroup in the debugger. The modelGroup contains
>several Complex Elements and one Simple Element. Looking at getContents()
>the EList is composed entirely of Particles.
>
>I also remember that when I create a Element with a Simple Type it is
>encapsulated in a particle. like this:
>
> XSDParticle particle = factory.createXSDParticle();
> XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();
>
> itemElement.setName(name);
> itemElement.setTypeDefinition(type);
> particle.setContent(itemElement);
> particle.setMinOccurs(minOccurs);
> particle.setMaxOccurs(maxOccurs)
>
>So it seems that all elements are Particles, they just differ in being
>either Simple or Complext Type. Is that correct?
>
>
>I wouldn't word it like this since an element and a particle are two
>different kinds of objects and an element is not a particle. Probably you
>make this statement because any <xsd:element> appearing in a content model
>will produce both an XSDParticle and an XSDElementDeclaration, where the
>particle contains the element. It's important to note that this comment
>does not apply for a global element declaration, e.g., one contained
>directly by a <schema>, which maps only to an XSDElementDeclaration .
>
>Now going back to when I scanned the abstract model to collect all of the
>XSDElementDeclaration does this mean I would just call getContainer() to get
>the particle for each element regardless if it is a Simple or Complex type?
>
>
>The container for an XSDElementDeclaration will either be null, an
>XSDSchema, or an XSDParticle, regardless of the type of the element or
>whether that type is simple or complex.
>
>----------------------------------------------
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:ciuc5h$k7d$1@eclipse.org...
>Gary,
>
>You've definitely cross a few wire here, and I've added comments below where
>I think they crossed. ;-)
>
>It's best to think of it like this. The methods getSimpleType and
>getComplexType apply to either a simple type or a complex type. When
>applied to a simple type, getSimpleType return "this", and getComplexType
>return null. When applied to a complex type, getSimpleType returns the
>content type, if it's simple, and getComplexType returns the content type,
>if it's complex, i.e., a particle.
>
>
>Gary J wrote:
>Hi,
>
>This is probably an obvious one. Given object of type XSDElementDeclaration
>I want to easily determine if it is a Simple or Complex Type.
>
>Here's what I'm doing:
>
>// get the element Type definition
>XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();
>
>// Get the Complex Content type if it is Complex
>XSDParticle particle = typeDef.getComplexType();
>
>// If not null, element must be complex
>if(particle != null)
> // This is a Complex Element
>
>
>Reading the JavaDocs it appears I could also do this:
>
>XSDSimpleTypeDefinition type = typeDef.getSimpleType();
>
>The javadocs state this will return the SimpleTypeDefinition if the type is
>simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
>readin that wrong?)
>
>You omitted the qualification that it will return the content type of the
>complex type only if it's simple, i.e., only if it is an
>XSDSimpleTypeDefinition.
>
>My question is:
>
>Since both SimpleTypeDefinition and XSDParticle implement the
>XSDComplexTypeContent interface couldn't I simply do this:
>
>XSDComplexTypeContent type = typeDef.getSimpleType();
>
>
>You could write this, but since typeDefinition.getSimpleType() returns an
>XSDSimpleTypeDefinition it can't ever be the case that it will be an
>XSDParticle.
>
>and then check it type is an instance of either SimpleTypeDefinition or
>XSDParticle to determine if it is simple or complex?
>
>Sorry if this sounds a bit obvious but this is one I've been chewing over
>for a while and never got the relationships quite straight in my head.
>
>Thanks
>
>
>
>
>
>
>
>
>
>
>
>
>
>
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #591633 is a reply to message #53049] Thu, 23 September 2004 11:35 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010702050801040500000809
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

You've definitely cross a few wire here, and I've added comments below
where I think they crossed. ;-)

It's best to think of it like this. The methods getSimpleType and
getComplexType apply to either a simple type or a complex type. When
applied to a simple type, getSimpleType return "this", and
getComplexType return null. When applied to a complex type,
getSimpleType returns the content type, if it's simple, and
getComplexType returns the content type, if it's complex, i.e., a particle.


Gary J wrote:

>Hi,
>
>This is probably an obvious one. Given object of type XSDElementDeclaration
>I want to easily determine if it is a Simple or Complex Type.
>
>Here's what I'm doing:
>
>// get the element Type definition
>XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();
>
>// Get the Complex Content type if it is Complex
>XSDParticle particle = typeDef.getComplexType();
>
>// If not null, element must be complex
>if(particle != null)
> // This is a Complex Element
>
>
>Reading the JavaDocs it appears I could also do this:
>
>XSDSimpleTypeDefinition type = typeDef.getSimpleType();
>
>The javadocs state this will return the SimpleTypeDefinition if the type is
>simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
>readin that wrong?)
>
>
You omitted the qualification that it will return the content type of
the complex type *only if* it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.

>My question is:
>
>Since both SimpleTypeDefinition and XSDParticle implement the
>XSDComplexTypeContent interface couldn't I simply do this:
>
>XSDComplexTypeContent type = typeDef.getSimpleType();
>
>
>
You could write this, but since typeDefinition.getSimpleType() returns
an XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.

>and then check it type is an instance of either SimpleTypeDefinition or
>XSDParticle to determine if it is simple or complex?
>
>Sorry if this sounds a bit obvious but this is one I've been chewing over
>for a while and never got the relationships quite straight in my head.
>
>Thanks
>
>
>
>
>
>
>
>


--------------010702050801040500000809
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
You've definitely cross a few wire here, and I've added comments below
where I think they crossed. ;-)<br>
<br>
It's best to think of it like this.&nbsp; The methods getSimpleType and
getComplexType apply to either a simple type or a complex type.&nbsp; When
applied to a simple type, getSimpleType return "this", and
getComplexType return null.&nbsp; When applied to a complex type,
getSimpleType returns the content type, if it's simple, and
getComplexType returns the content type, if it's complex, i.e., a
particle.<br>
<br>
<br>
Gary J wrote:
<blockquote cite="midcist1h$c0v$1@eclipse.org" type="cite">
<pre wrap="">Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)
</pre>
</blockquote>
You omitted the qualification that it will return the content type of
the complex type <b>only if</b> it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.<br>
<blockquote cite="midcist1h$c0v$1@eclipse.org" type="cite">
<pre wrap="">
My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();

</pre>
</blockquote>
You could write this, but since typeDefinition.getSimpleType() returns
an XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.<br>
<blockquote cite="midcist1h$c0v$1@eclipse.org" type="cite">
<pre wrap="">and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks






</pre>
</blockquote>
<br>
</body>
</html>

--------------010702050801040500000809--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #591671 is a reply to message #53075] Thu, 23 September 2004 22:47 Go to previous message
Gary J is currently offline Gary JFriend
Messages: 61
Registered: July 2009
Member
Thanks Ed,

I suspected as much when I tried to implement the code. :)

Once thing that's been confusing me, probably due to my ignorance. Let me
know where I go right off the road here:

I'm looking at a ModelGroup in the debugger. The modelGroup contains
several Complex Elements and one Simple Element. Looking at getContents()
the EList is composed entirely of Particles.

I also remember that when I create a Element with a Simple Type it is
encapsulated in a particle. like this:

XSDParticle particle = factory.createXSDParticle();
XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();

itemElement.setName(name);
itemElement.setTypeDefinition(type);
particle.setContent(itemElement);
particle.setMinOccurs(minOccurs);
particle.setMaxOccurs(maxOccurs)

So it seems that all elements are Particles, they just differ in being
either Simple or Complext Type. Is that correct?

Now going back to when I scanned the abstract model to collect all of the
XSDElementDeclaration does this mean I would just call getContainer() to get
the particle for each element regardless if it is a Simple or Complex type?

----------------------------------------------


"Ed Merks" <merks@ca.ibm.com> wrote in message
news:ciuc5h$k7d$1@eclipse.org...
Gary,

You've definitely cross a few wire here, and I've added comments below where
I think they crossed. ;-)

It's best to think of it like this. The methods getSimpleType and
getComplexType apply to either a simple type or a complex type. When
applied to a simple type, getSimpleType return "this", and getComplexType
return null. When applied to a complex type, getSimpleType returns the
content type, if it's simple, and getComplexType returns the content type,
if it's complex, i.e., a particle.


Gary J wrote:
Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)

You omitted the qualification that it will return the content type of the
complex type only if it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.

My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();


You could write this, but since typeDefinition.getSimpleType() returns an
XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.

and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #591681 is a reply to message #53180] Fri, 24 September 2004 11:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000409000206010506030307
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

My comments are inline below.

Gary J wrote:

>Thanks Ed,
>
>I suspected as much when I tried to implement the code. :)
>
>Once thing that's been confusing me, probably due to my ignorance. Let me
>know where I go right off the road here:
>
>I'm looking at a ModelGroup in the debugger. The modelGroup contains
>several Complex Elements and one Simple Element. Looking at getContents()
>the EList is composed entirely of Particles.
>
>I also remember that when I create a Element with a Simple Type it is
>encapsulated in a particle. like this:
>
> XSDParticle particle = factory.createXSDParticle();
> XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();
>
> itemElement.setName(name);
> itemElement.setTypeDefinition(type);
> particle.setContent(itemElement);
> particle.setMinOccurs(minOccurs);
> particle.setMaxOccurs(maxOccurs)
>
>So it seems that all elements are Particles, they just differ in being
>either Simple or Complext Type. Is that correct?
>
>
>
I wouldn't word it like this since an element and a particle are two
different kinds of objects and an element is not a particle. Probably
you make this statement because any <xsd:element> appearing in a content
model will produce both an XSDParticle and an XSDElementDeclaration,
where the particle contains the element. It's important to note that
this comment does *not *apply for a global element declaration, e.g.,
one contained directly by a <schema>, which maps only to an
XSDElementDeclaration .

>Now going back to when I scanned the abstract model to collect all of the
>XSDElementDeclaration does this mean I would just call getContainer() to get
>the particle for each element regardless if it is a Simple or Complex type?
>
>
>
The container for an XSDElementDeclaration will either be null, an
XSDSchema, or an XSDParticle, regardless of the type of the element or
whether that type is simple or complex.

>----------------------------------------------
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:ciuc5h$k7d$1@eclipse.org...
>Gary,
>
>You've definitely cross a few wire here, and I've added comments below where
>I think they crossed. ;-)
>
>It's best to think of it like this. The methods getSimpleType and
>getComplexType apply to either a simple type or a complex type. When
>applied to a simple type, getSimpleType return "this", and getComplexType
>return null. When applied to a complex type, getSimpleType returns the
>content type, if it's simple, and getComplexType returns the content type,
>if it's complex, i.e., a particle.
>
>
>Gary J wrote:
>Hi,
>
>This is probably an obvious one. Given object of type XSDElementDeclaration
>I want to easily determine if it is a Simple or Complex Type.
>
>Here's what I'm doing:
>
>// get the element Type definition
>XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();
>
>// Get the Complex Content type if it is Complex
>XSDParticle particle = typeDef.getComplexType();
>
>// If not null, element must be complex
>if(particle != null)
> // This is a Complex Element
>
>
>Reading the JavaDocs it appears I could also do this:
>
>XSDSimpleTypeDefinition type = typeDef.getSimpleType();
>
>The javadocs state this will return the SimpleTypeDefinition if the type is
>simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
>readin that wrong?)
>
>You omitted the qualification that it will return the content type of the
>complex type only if it's simple, i.e., only if it is an
>XSDSimpleTypeDefinition.
>
>My question is:
>
>Since both SimpleTypeDefinition and XSDParticle implement the
>XSDComplexTypeContent interface couldn't I simply do this:
>
>XSDComplexTypeContent type = typeDef.getSimpleType();
>
>
>You could write this, but since typeDefinition.getSimpleType() returns an
>XSDSimpleTypeDefinition it can't ever be the case that it will be an
>XSDParticle.
>
>and then check it type is an instance of either SimpleTypeDefinition or
>XSDParticle to determine if it is simple or complex?
>
>Sorry if this sounds a bit obvious but this is one I've been chewing over
>for a while and never got the relationships quite straight in my head.
>
>Thanks
>
>
>
>
>
>
>
>
>
>
>


--------------000409000206010506030307
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
My comments are inline below.<br>
<br>
Gary J wrote:<br>
<blockquote cite="midcivjie$3l0$1@eclipse.org" type="cite">
<pre wrap="">Thanks Ed,

I suspected as much when I tried to implement the code. :)

Once thing that's been confusing me, probably due to my ignorance. Let me
know where I go right off the road here:

I'm looking at a ModelGroup in the debugger. The modelGroup contains
several Complex Elements and one Simple Element. Looking at getContents()
the EList is composed entirely of Particles.

I also remember that when I create a Element with a Simple Type it is
encapsulated in a particle. like this:

XSDParticle particle = factory.createXSDParticle();
XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();

itemElement.setName(name);
itemElement.setTypeDefinition(type);
particle.setContent(itemElement);
particle.setMinOccurs(minOccurs);
particle.setMaxOccurs(maxOccurs)

So it seems that all elements are Particles, they just differ in being
either Simple or Complext Type. Is that correct?

</pre>
</blockquote>
I wouldn't word it like this since an element and a particle are two
different kinds of objects and an element is not a particle.&nbsp; Probably
you make this statement because any &lt;xsd:element&gt; appearing in a
content model will produce both an XSDParticle and an
XSDElementDeclaration, where the particle contains the element.&nbsp; It's
important to note that this comment does <b>not </b>apply for a
global element declaration, e.g., one contained directly by a
&lt;schema&gt;, which maps only to an XSDElementDeclaration .<br>
<blockquote cite="midcivjie$3l0$1@eclipse.org" type="cite">
<pre wrap="">Now going back to when I scanned the abstract model to collect all of the
XSDElementDeclaration does this mean I would just call getContainer() to get
the particle for each element regardless if it is a Simple or Complex type?

</pre>
</blockquote>
The container for an XSDElementDeclaration will either be null, an
XSDSchema, or an XSDParticle, regardless of the type of the element or
whether that type is simple or complex.<br>
<blockquote cite="midcivjie$3l0$1@eclipse.org" type="cite">
<pre wrap="">----------------------------------------------


"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:ciuc5h$k7d$1@eclipse.org">news:ciuc5h$k7d$1@eclipse.org</a>...
Gary,

You've definitely cross a few wire here, and I've added comments below where
I think they crossed. ;-)

It's best to think of it like this. The methods getSimpleType and
getComplexType apply to either a simple type or a complex type. When
applied to a simple type, getSimpleType return "this", and getComplexType
return null. When applied to a complex type, getSimpleType returns the
content type, if it's simple, and getComplexType returns the content type,
if it's complex, i.e., a particle.


Gary J wrote:
Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)

You omitted the qualification that it will return the content type of the
complex type only if it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.

My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();


You could write this, but since typeDefinition.getSimpleType() returns an
XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.

and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks









</pre>
</blockquote>
<br>
</body>
</html>

--------------000409000206010506030307--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #591699 is a reply to message #53205] Fri, 24 September 2004 23:56 Go to previous message
Gary J is currently offline Gary JFriend
Messages: 61
Registered: July 2009
Member
Thanks for your patience.

"The container for an XSDElementDeclaration will either be null, an
XSDSchema, or an XSDParticle"

Under what circumstances will it be null?

Sorry to be so dense :~

Thanks



"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cj0vom$6bu$1@eclipse.org...
Gary,

My comments are inline below.

Gary J wrote:

Thanks Ed,

I suspected as much when I tried to implement the code. :)

Once thing that's been confusing me, probably due to my ignorance. Let me
know where I go right off the road here:

I'm looking at a ModelGroup in the debugger. The modelGroup contains
several Complex Elements and one Simple Element. Looking at getContents()
the EList is composed entirely of Particles.

I also remember that when I create a Element with a Simple Type it is
encapsulated in a particle. like this:

XSDParticle particle = factory.createXSDParticle();
XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();

itemElement.setName(name);
itemElement.setTypeDefinition(type);
particle.setContent(itemElement);
particle.setMinOccurs(minOccurs);
particle.setMaxOccurs(maxOccurs)

So it seems that all elements are Particles, they just differ in being
either Simple or Complext Type. Is that correct?


I wouldn't word it like this since an element and a particle are two
different kinds of objects and an element is not a particle. Probably you
make this statement because any <xsd:element> appearing in a content model
will produce both an XSDParticle and an XSDElementDeclaration, where the
particle contains the element. It's important to note that this comment
does not apply for a global element declaration, e.g., one contained
directly by a <schema>, which maps only to an XSDElementDeclaration .

Now going back to when I scanned the abstract model to collect all of the
XSDElementDeclaration does this mean I would just call getContainer() to get
the particle for each element regardless if it is a Simple or Complex type?


The container for an XSDElementDeclaration will either be null, an
XSDSchema, or an XSDParticle, regardless of the type of the element or
whether that type is simple or complex.

----------------------------------------------


"Ed Merks" <merks@ca.ibm.com> wrote in message
news:ciuc5h$k7d$1@eclipse.org...
Gary,

You've definitely cross a few wire here, and I've added comments below where
I think they crossed. ;-)

It's best to think of it like this. The methods getSimpleType and
getComplexType apply to either a simple type or a complex type. When
applied to a simple type, getSimpleType return "this", and getComplexType
return null. When applied to a complex type, getSimpleType returns the
content type, if it's simple, and getComplexType returns the content type,
if it's complex, i.e., a particle.


Gary J wrote:
Hi,

This is probably an obvious one. Given object of type XSDElementDeclaration
I want to easily determine if it is a Simple or Complex Type.

Here's what I'm doing:

// get the element Type definition
XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();

// Get the Complex Content type if it is Complex
XSDParticle particle = typeDef.getComplexType();

// If not null, element must be complex
if(particle != null)
// This is a Complex Element


Reading the JavaDocs it appears I could also do this:

XSDSimpleTypeDefinition type = typeDef.getSimpleType();

The javadocs state this will return the SimpleTypeDefinition if the type is
simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
readin that wrong?)

You omitted the qualification that it will return the content type of the
complex type only if it's simple, i.e., only if it is an
XSDSimpleTypeDefinition.

My question is:

Since both SimpleTypeDefinition and XSDParticle implement the
XSDComplexTypeContent interface couldn't I simply do this:

XSDComplexTypeContent type = typeDef.getSimpleType();


You could write this, but since typeDefinition.getSimpleType() returns an
XSDSimpleTypeDefinition it can't ever be the case that it will be an
XSDParticle.

and then check it type is an instance of either SimpleTypeDefinition or
XSDParticle to determine if it is simple or complex?

Sorry if this sounds a bit obvious but this is one I've been chewing over
for a while and never got the relationships quite straight in my head.

Thanks
Re: Deteriming if an ElementDeclaration is a Simple or Complex Type [message #591725 is a reply to message #53258] Mon, 27 September 2004 11:49 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Gary,

It will be null if you haven't attached it anywhere.


Gary J wrote:

>Thanks for your patience.
>
>"The container for an XSDElementDeclaration will either be null, an
>XSDSchema, or an XSDParticle"
>
>Under what circumstances will it be null?
>
>Sorry to be so dense :~
>
>Thanks
>
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cj0vom$6bu$1@eclipse.org...
>Gary,
>
>My comments are inline below.
>
>Gary J wrote:
>
>Thanks Ed,
>
>I suspected as much when I tried to implement the code. :)
>
>Once thing that's been confusing me, probably due to my ignorance. Let me
>know where I go right off the road here:
>
>I'm looking at a ModelGroup in the debugger. The modelGroup contains
>several Complex Elements and one Simple Element. Looking at getContents()
>the EList is composed entirely of Particles.
>
>I also remember that when I create a Element with a Simple Type it is
>encapsulated in a particle. like this:
>
> XSDParticle particle = factory.createXSDParticle();
> XSDElementDeclaration itemElement = factory.createXSDElementDeclaration();
>
> itemElement.setName(name);
> itemElement.setTypeDefinition(type);
> particle.setContent(itemElement);
> particle.setMinOccurs(minOccurs);
> particle.setMaxOccurs(maxOccurs)
>
>So it seems that all elements are Particles, they just differ in being
>either Simple or Complext Type. Is that correct?
>
>
>I wouldn't word it like this since an element and a particle are two
>different kinds of objects and an element is not a particle. Probably you
>make this statement because any <xsd:element> appearing in a content model
>will produce both an XSDParticle and an XSDElementDeclaration, where the
>particle contains the element. It's important to note that this comment
>does not apply for a global element declaration, e.g., one contained
>directly by a <schema>, which maps only to an XSDElementDeclaration .
>
>Now going back to when I scanned the abstract model to collect all of the
>XSDElementDeclaration does this mean I would just call getContainer() to get
>the particle for each element regardless if it is a Simple or Complex type?
>
>
>The container for an XSDElementDeclaration will either be null, an
>XSDSchema, or an XSDParticle, regardless of the type of the element or
>whether that type is simple or complex.
>
>----------------------------------------------
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:ciuc5h$k7d$1@eclipse.org...
>Gary,
>
>You've definitely cross a few wire here, and I've added comments below where
>I think they crossed. ;-)
>
>It's best to think of it like this. The methods getSimpleType and
>getComplexType apply to either a simple type or a complex type. When
>applied to a simple type, getSimpleType return "this", and getComplexType
>return null. When applied to a complex type, getSimpleType returns the
>content type, if it's simple, and getComplexType returns the content type,
>if it's complex, i.e., a particle.
>
>
>Gary J wrote:
>Hi,
>
>This is probably an obvious one. Given object of type XSDElementDeclaration
>I want to easily determine if it is a Simple or Complex Type.
>
>Here's what I'm doing:
>
>// get the element Type definition
>XSDTypeDefinition typeDef = xsdElement.getTypeDefinition();
>
>// Get the Complex Content type if it is Complex
>XSDParticle particle = typeDef.getComplexType();
>
>// If not null, element must be complex
>if(particle != null)
> // This is a Complex Element
>
>
>Reading the JavaDocs it appears I could also do this:
>
>XSDSimpleTypeDefinition type = typeDef.getSimpleType();
>
>The javadocs state this will return the SimpleTypeDefinition if the type is
>simple, otherwise it will return the XSDComplexTypeContent. (Maybe I'm
>readin that wrong?)
>
>You omitted the qualification that it will return the content type of the
>complex type only if it's simple, i.e., only if it is an
>XSDSimpleTypeDefinition.
>
>My question is:
>
>Since both SimpleTypeDefinition and XSDParticle implement the
>XSDComplexTypeContent interface couldn't I simply do this:
>
>XSDComplexTypeContent type = typeDef.getSimpleType();
>
>
>You could write this, but since typeDefinition.getSimpleType() returns an
>XSDSimpleTypeDefinition it can't ever be the case that it will be an
>XSDParticle.
>
>and then check it type is an instance of either SimpleTypeDefinition or
>XSDParticle to determine if it is simple or complex?
>
>Sorry if this sounds a bit obvious but this is one I've been chewing over
>for a while and never got the relationships quite straight in my head.
>
>Thanks
>
>
>
>
>
>
>
>
>
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to get resolvedModelGroupDefinition()?
Next Topic:Delete an Element
Goto Forum:
  


Current Time: Sat Apr 20 03:48:55 GMT 2024

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

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

Back to the top