Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » test
test [message #70012] Thu, 19 October 2006 00:45 Go to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
For some reason, I want to change an element (that refers to a global
element) to be a local element.

currentElem refers to a global element,
currentElem.getXSDParticleContainer() will get the XSDParticle for
"currentElem".

So first I want to clone this element (how can I change it to be local
element?) , and then replace the "currentElem" with the new cloned one.

How can I do this? Something like below won't work?

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
currentElem.cloneConcreteComponent(true, false);

currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);

Thanks a lot!!!
To make it clear.Re: test [message #70031 is a reply to message #70012] Thu, 19 October 2006 00:51 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Sorry. I guess I did not make it clear..

What I am trying to do is: I have an element e1 (within a particle "p1")
that refers to a global element e2, and then I want to make a copy of the
global element e2 and add the copy to be a local element of "p1".

The problem is I can clone this global element e2, but i cannot add it
into particle "p1". How can I replace the element e1 with the copy of e2?

I did sth like this:

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
currentElem.cloneConcreteComponent(true, false);

currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);

Thanks a lot for your instructions!!

-Mavis....
Re: To make it clear.Re: test [message #70074 is a reply to message #70031] Thu, 19 October 2006 10:27 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.
--------------090406060702060605050103
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Mavis,

It looks like you are replacing the currentElem with a clone of itself.
That's likely to produce exactly what you started with. If
currentElement is an element declaration reference (<xsd:element
ref="..."/>) then you'll want to clone the resolved element declaration:

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
currentElem.getResolvedElementDeclaration().cloneConcreteCom ponent(true,
false)


exquisitus wrote:
> Sorry. I guess I did not make it clear..
>
> What I am trying to do is: I have an element e1 (within a particle
> "p1") that refers to a global element e2, and then I want to make a
> copy of the global element e2 and add the copy to be a local element
> of "p1".
>
> The problem is I can clone this global element e2, but i cannot add it
> into particle "p1". How can I replace the element e1 with the copy of e2?
>
> I did sth like this:
>
> XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
> currentElem.cloneConcreteComponent(true, false);
>
> currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);
>
> Thanks a lot for your instructions!!
>
> -Mavis....
>


--------------090406060702060605050103
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">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Mavis,<br>
<br>
It looks like you are replacing the currentElem with a clone of
itself.
Re: To make it clear.Re: test [message #70114 is a reply to message #70074] Thu, 19 October 2006 17:10 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks a lot for your advice!

Even if I change to be the copy of the global element as you instructed, I
still get the following error message when trying to "set content" to
particle. So something is different between the original element and
cloned element? It seems that the "XSDContents" of cloned element is
"null"!

java.lang.NullPointerException
at
org.eclipse.xsd.impl.XSDSimpleTypeDefinitionImpl.createEleme nt(XSDSimpleTypeDefinitionImpl.java:604)
at
org.eclipse.xsd.impl.XSDElementDeclarationImpl.createElement (XSDElementDeclarationImpl.java:536)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1331)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.adoptContent(X SDConcreteComponentImpl.java:1395)
at
org.eclipse.xsd.impl.XSDParticleImpl.adoptContent(XSDParticl eImpl.java:682)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1203)
at
org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch (NotificationImpl.java:1029)
at
org.eclipse.xsd.impl.XSDParticleImpl.setContent(XSDParticleI mpl.java:323)
......

Any further instructions will be highly appreciated!

-Mavis
Re: To make it clear.Re: test [message #70133 is a reply to message #70114] Thu, 19 October 2006 17:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

If you send a working self-contained example that I can run to reproduce
the problem locally, I can have a look and can either fix your code or
find the underlying problem in XSD. This type of result only seems to
be possible if the particle you are updating isn't actually contained by
a schema, but in that case, it shouldn't be trying to create the
underlying DOM representation. So I don't understand the context in
which this problem is occurring...


exquisitus wrote:
> Thanks a lot for your advice!
> Even if I change to be the copy of the global element as you
> instructed, I still get the following error message when trying to
> "set content" to particle. So something is different between the
> original element and cloned element? It seems that the "XSDContents"
> of cloned element is "null"!
> java.lang.NullPointerException
> at
> org.eclipse.xsd.impl.XSDSimpleTypeDefinitionImpl.createEleme nt(XSDSimpleTypeDefinitionImpl.java:604)
>
> at
> org.eclipse.xsd.impl.XSDElementDeclarationImpl.createElement (XSDElementDeclarationImpl.java:536)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1331)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.adoptContent(X SDConcreteComponentImpl.java:1395)
>
> at
> org.eclipse.xsd.impl.XSDParticleImpl.adoptContent(XSDParticl eImpl.java:682)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1203)
>
> at
> org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch (NotificationImpl.java:1029)
>
> at
> org.eclipse.xsd.impl.XSDParticleImpl.setContent(XSDParticleI mpl.java:323)
> .....
>
> Any further instructions will be highly appreciated!
>
> -Mavis
>
Re: To make it clear.Re: test [message #70173 is a reply to message #70133] Thu, 19 October 2006 17:31 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks!! I got a meeting...
Later~~~ ;)
Re: To make it clear.Re: test [message #70231 is a reply to message #70133] Thu, 19 October 2006 20:48 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
This is a small piece of a project, it is just a simple method, and the
input is an XSDElementDeclaration: currentElem, which is a local element
refers to a global element. such as,

<xsd:element name="interfaces" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="interface" minOccurs="0"
maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>

<!-- currentElem -->
<xsd:element ref="ipaddress"/>
......

</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="ipaddress">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern

value=" ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\ d\d?) "/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>

The code is:

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)

currentElem.getResolvedElementDeclaration().cloneConcreteCom ponent(true,
false);

currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);

So first clone the decl of global element "ipaddress", and then replace
<xsd:element ref="ipaddress"/> with the new cloned one (make it to be a
local element? ).

while currentElem.getXSDParticleContainer() will return the particle of
currentElem.

And in debugging mode, I can see clonedXSDElem has been created and
"currentElem.getXSDParticleContainer()" can return the right XSDParticle.
I guess somehow when it runs "SetContent", some needed fireds are null?
Such as, why XSDContents are null but in currentElem it is actually not
null?

Thanks a lot for your instructions!

-Mavis
Re: To make it clear.Re: test [message #70251 is a reply to message #70231] Thu, 19 October 2006 20:58 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
In addition, I did the similar things to "type definition" and it worked
very well. I can clone a global type and then set it to be an anonymous
type of an element declaration. But why it does not work for element decl?
:-(

Thanks!!!

-Mavis..
Re: To make it clear.Re: test [message #70270 is a reply to message #70231] Thu, 19 October 2006 21:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

I'm absolutely swamped and have to deal often with dozens of newsgroup
questions per day, in addition to my other responsibilities, so I will
be able to help much more easily if you provide a runnable test case.
Perhaps modifying XSDMainExample.java to reproduce the problem there
would be quite easy. Otherwise, it might take me a significant amount
of time to get to this. With a runnable example, I can look at it
quickly tomorrow morning...


exquisitus wrote:
> This is a small piece of a project, it is just a simple method, and
> the input is an XSDElementDeclaration: currentElem, which is a local
> element refers to a global element. such as,
> <xsd:element name="interfaces" minOccurs="0" maxOccurs="1">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="interface" minOccurs="0"
> maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
>
> <!-- currentElem -->
> <xsd:element ref="ipaddress"/>
> ......
>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="ipaddress">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:pattern
>
> value=" ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\ d\d?) "/>
>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
>
> The code is:
> XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
>
> currentElem.getResolvedElementDeclaration().cloneConcreteCom ponent(true,
> false);
>
> currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);
> So first clone the decl of global element "ipaddress", and then
> replace <xsd:element ref="ipaddress"/> with the new cloned one (make
> it to be a local element? ).
> while currentElem.getXSDParticleContainer() will return the particle
> of currentElem.
>
> And in debugging mode, I can see clonedXSDElem has been created and
> "currentElem.getXSDParticleContainer()" can return the right
> XSDParticle. I guess somehow when it runs "SetContent", some needed
> fireds are null? Such as, why XSDContents are null but in currentElem
> it is actually not null?
> Thanks a lot for your instructions!
>
> -Mavis
>
Re: To make it clear.Re: test [message #70310 is a reply to message #70270] Thu, 19 October 2006 21:19 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks for your helps. I will create the example soon..
Re: To make it clear.Re: test [message #70326 is a reply to message #70133] Thu, 19 October 2006 23:02 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Sorry...I do not know how could I send you the testing code?

-Mavis
Re: To make it clear.Re: test [message #70406 is a reply to message #70326] Fri, 20 October 2006 10:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

It's possible to add attachments to your postings, but some news readers
seem to do a bad job of that. But I see you've figured out to send it
to me directly, so I will soon have a look.


exquisitus wrote:
> Sorry...I do not know how could I send you the testing code?
> -Mavis
>
Re: To make it clear.Re: test [message #70423 is a reply to message #70326] Fri, 20 October 2006 12:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

There is a bug in XSD that needs to be fixed. This case is handled
poorly because a particle and its child element declaration share the
same DOM node and the handling of the change of the particle's contents
causes the particle itself to be removed from the model resulting
ultimately in the null pointer exception you see. I have a patch for
that problem already, so please open a bugzilla defect and I'll commit
that. As a simple workaround, the following change to your code will
avoid this problem for the time being:

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)

currentElem.getResolvedElementDeclaration().cloneConcreteCom ponent(true,
false);

XSDParticle clonedXSDParticle =
(XSDParticle)xsdParticle.cloneConcreteComponent(false, false);
clonedXSDParticle.setContent(clonedXSDElem);
EcoreUtil.replace(xsdParticle, clonedXSDParticle);
// xsdParticle.setContent(clonedXSDElem);

I.e., clone the particle as well (shallowly) and then replace the
original particle with the new one.

exquisitus wrote:
> Sorry...I do not know how could I send you the testing code?
> -Mavis
>
Re: To make it clear.Re: test [message #70440 is a reply to message #70423] Fri, 20 October 2006 17:20 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thank you so much for your helps!
It works now! :-D

-Mavis
Re: To make it clear.Re: test [message #70460 is a reply to message #70440] Fri, 20 October 2006 17:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

You're welcome. Will you open a bugzilla so that your original approach
can be made to work?


exquisitus wrote:
> Thank you so much for your helps! It works now! :-D
>
> -Mavis
>
Re: To make it clear.Re: test [message #70477 is a reply to message #70460] Fri, 20 October 2006 21:09 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
I am not sure that I know how to use the bugzilla...I just filed a bug
161794...
Thanks a lot..So far I am fine with this work around way...

-Mavis
To make it clear.Re: test [message #598857 is a reply to message #70012] Thu, 19 October 2006 00:51 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Sorry. I guess I did not make it clear..

What I am trying to do is: I have an element e1 (within a particle "p1")
that refers to a global element e2, and then I want to make a copy of the
global element e2 and add the copy to be a local element of "p1".

The problem is I can clone this global element e2, but i cannot add it
into particle "p1". How can I replace the element e1 with the copy of e2?

I did sth like this:

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
currentElem.cloneConcreteComponent(true, false);

currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);

Thanks a lot for your instructions!!

-Mavis....
Re: To make it clear.Re: test [message #598869 is a reply to message #70031] Thu, 19 October 2006 10:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090406060702060605050103
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Mavis,

It looks like you are replacing the currentElem with a clone of itself.
That's likely to produce exactly what you started with. If
currentElement is an element declaration reference (<xsd:element
ref="..."/>) then you'll want to clone the resolved element declaration:

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
currentElem.getResolvedElementDeclaration().cloneConcreteCom ponent(true,
false)


exquisitus wrote:
> Sorry. I guess I did not make it clear..
>
> What I am trying to do is: I have an element e1 (within a particle
> "p1") that refers to a global element e2, and then I want to make a
> copy of the global element e2 and add the copy to be a local element
> of "p1".
>
> The problem is I can clone this global element e2, but i cannot add it
> into particle "p1". How can I replace the element e1 with the copy of e2?
>
> I did sth like this:
>
> XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
> currentElem.cloneConcreteComponent(true, false);
>
> currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);
>
> Thanks a lot for your instructions!!
>
> -Mavis....
>


--------------090406060702060605050103
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">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Mavis,<br>
<br>
It looks like you are replacing the currentElem with a clone of
itself.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: To make it clear.Re: test [message #598885 is a reply to message #70074] Thu, 19 October 2006 17:10 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks a lot for your advice!

Even if I change to be the copy of the global element as you instructed, I
still get the following error message when trying to "set content" to
particle. So something is different between the original element and
cloned element? It seems that the "XSDContents" of cloned element is
"null"!

java.lang.NullPointerException
at
org.eclipse.xsd.impl.XSDSimpleTypeDefinitionImpl.createEleme nt(XSDSimpleTypeDefinitionImpl.java:604)
at
org.eclipse.xsd.impl.XSDElementDeclarationImpl.createElement (XSDElementDeclarationImpl.java:536)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1331)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.adoptContent(X SDConcreteComponentImpl.java:1395)
at
org.eclipse.xsd.impl.XSDParticleImpl.adoptContent(XSDParticl eImpl.java:682)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1203)
at
org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch (NotificationImpl.java:1029)
at
org.eclipse.xsd.impl.XSDParticleImpl.setContent(XSDParticleI mpl.java:323)
......

Any further instructions will be highly appreciated!

-Mavis
Re: To make it clear.Re: test [message #598889 is a reply to message #70114] Thu, 19 October 2006 17:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Mavis,

If you send a working self-contained example that I can run to reproduce
the problem locally, I can have a look and can either fix your code or
find the underlying problem in XSD. This type of result only seems to
be possible if the particle you are updating isn't actually contained by
a schema, but in that case, it shouldn't be trying to create the
underlying DOM representation. So I don't understand the context in
which this problem is occurring...


exquisitus wrote:
> Thanks a lot for your advice!
> Even if I change to be the copy of the global element as you
> instructed, I still get the following error message when trying to
> "set content" to particle. So something is different between the
> original element and cloned element? It seems that the "XSDContents"
> of cloned element is "null"!
> java.lang.NullPointerException
> at
> org.eclipse.xsd.impl.XSDSimpleTypeDefinitionImpl.createEleme nt(XSDSimpleTypeDefinitionImpl.java:604)
>
> at
> org.eclipse.xsd.impl.XSDElementDeclarationImpl.createElement (XSDElementDeclarationImpl.java:536)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1331)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.adoptContent(X SDConcreteComponentImpl.java:1395)
>
> at
> org.eclipse.xsd.impl.XSDParticleImpl.adoptContent(XSDParticl eImpl.java:682)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1203)
>
> at
> org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch (NotificationImpl.java:1029)
>
> at
> org.eclipse.xsd.impl.XSDParticleImpl.setContent(XSDParticleI mpl.java:323)
> .....
>
> Any further instructions will be highly appreciated!
>
> -Mavis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: To make it clear.Re: test [message #598904 is a reply to message #70133] Thu, 19 October 2006 17:31 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks!! I got a meeting...
Later~~~ ;)
Re: To make it clear.Re: test [message #598930 is a reply to message #70133] Thu, 19 October 2006 20:48 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
This is a small piece of a project, it is just a simple method, and the
input is an XSDElementDeclaration: currentElem, which is a local element
refers to a global element. such as,

<xsd:element name="interfaces" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="interface" minOccurs="0"
maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>

<!-- currentElem -->
<xsd:element ref="ipaddress"/>
......

</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="ipaddress">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern

value=" ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\ d\d?) "/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>

The code is:

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)

currentElem.getResolvedElementDeclaration().cloneConcreteCom ponent(true,
false);

currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);

So first clone the decl of global element "ipaddress", and then replace
<xsd:element ref="ipaddress"/> with the new cloned one (make it to be a
local element? ).

while currentElem.getXSDParticleContainer() will return the particle of
currentElem.

And in debugging mode, I can see clonedXSDElem has been created and
"currentElem.getXSDParticleContainer()" can return the right XSDParticle.
I guess somehow when it runs "SetContent", some needed fireds are null?
Such as, why XSDContents are null but in currentElem it is actually not
null?

Thanks a lot for your instructions!

-Mavis
Re: To make it clear.Re: test [message #598936 is a reply to message #70231] Thu, 19 October 2006 20:58 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
In addition, I did the similar things to "type definition" and it worked
very well. I can clone a global type and then set it to be an anonymous
type of an element declaration. But why it does not work for element decl?
:-(

Thanks!!!

-Mavis..
Re: To make it clear.Re: test [message #598941 is a reply to message #70231] Thu, 19 October 2006 21:00 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Mavis,

I'm absolutely swamped and have to deal often with dozens of newsgroup
questions per day, in addition to my other responsibilities, so I will
be able to help much more easily if you provide a runnable test case.
Perhaps modifying XSDMainExample.java to reproduce the problem there
would be quite easy. Otherwise, it might take me a significant amount
of time to get to this. With a runnable example, I can look at it
quickly tomorrow morning...


exquisitus wrote:
> This is a small piece of a project, it is just a simple method, and
> the input is an XSDElementDeclaration: currentElem, which is a local
> element refers to a global element. such as,
> <xsd:element name="interfaces" minOccurs="0" maxOccurs="1">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="interface" minOccurs="0"
> maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
>
> <!-- currentElem -->
> <xsd:element ref="ipaddress"/>
> ......
>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="ipaddress">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:pattern
>
> value=" ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\ d\d?) "/>
>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
>
> The code is:
> XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)
>
> currentElem.getResolvedElementDeclaration().cloneConcreteCom ponent(true,
> false);
>
> currentElem.getXSDParticleContainer().setContent(clonedXSDEl em);
> So first clone the decl of global element "ipaddress", and then
> replace <xsd:element ref="ipaddress"/> with the new cloned one (make
> it to be a local element? ).
> while currentElem.getXSDParticleContainer() will return the particle
> of currentElem.
>
> And in debugging mode, I can see clonedXSDElem has been created and
> "currentElem.getXSDParticleContainer()" can return the right
> XSDParticle. I guess somehow when it runs "SetContent", some needed
> fireds are null? Such as, why XSDContents are null but in currentElem
> it is actually not null?
> Thanks a lot for your instructions!
>
> -Mavis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: To make it clear.Re: test [message #598956 is a reply to message #70270] Thu, 19 October 2006 21:19 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks for your helps. I will create the example soon..
Re: To make it clear.Re: test [message #598970 is a reply to message #70133] Thu, 19 October 2006 23:02 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Sorry...I do not know how could I send you the testing code?

-Mavis
Re: To make it clear.Re: test [message #598995 is a reply to message #70326] Fri, 20 October 2006 10:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Mavis,

It's possible to add attachments to your postings, but some news readers
seem to do a bad job of that. But I see you've figured out to send it
to me directly, so I will soon have a look.


exquisitus wrote:
> Sorry...I do not know how could I send you the testing code?
> -Mavis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: To make it clear.Re: test [message #599011 is a reply to message #70326] Fri, 20 October 2006 12:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Mavis,

There is a bug in XSD that needs to be fixed. This case is handled
poorly because a particle and its child element declaration share the
same DOM node and the handling of the change of the particle's contents
causes the particle itself to be removed from the model resulting
ultimately in the null pointer exception you see. I have a patch for
that problem already, so please open a bugzilla defect and I'll commit
that. As a simple workaround, the following change to your code will
avoid this problem for the time being:

XSDElementDeclaration clonedXSDElem = (XSDElementDeclaration)

currentElem.getResolvedElementDeclaration().cloneConcreteCom ponent(true,
false);

XSDParticle clonedXSDParticle =
(XSDParticle)xsdParticle.cloneConcreteComponent(false, false);
clonedXSDParticle.setContent(clonedXSDElem);
EcoreUtil.replace(xsdParticle, clonedXSDParticle);
// xsdParticle.setContent(clonedXSDElem);

I.e., clone the particle as well (shallowly) and then replace the
original particle with the new one.

exquisitus wrote:
> Sorry...I do not know how could I send you the testing code?
> -Mavis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: To make it clear.Re: test [message #599018 is a reply to message #70423] Fri, 20 October 2006 17:20 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thank you so much for your helps!
It works now! :-D

-Mavis
Re: To make it clear.Re: test [message #599028 is a reply to message #70440] Fri, 20 October 2006 17:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Mavis,

You're welcome. Will you open a bugzilla so that your original approach
can be made to work?


exquisitus wrote:
> Thank you so much for your helps! It works now! :-D
>
> -Mavis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: To make it clear.Re: test [message #599034 is a reply to message #70460] Fri, 20 October 2006 21:09 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
I am not sure that I know how to use the bugzilla...I just filed a bug
161794...
Thanks a lot..So far I am fine with this work around way...

-Mavis
Previous Topic:Copy a new local element into another schema
Next Topic:Copy a new local element into another schema
Goto Forum:
  


Current Time: Tue Apr 16 20:21:09 GMT 2024

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

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

Back to the top