|
|
Re: To make it clear.Re: test [message #70074 is a reply to message #70031] |
Thu, 19 October 2006 10:27 |
Eclipse User |
|
|
|
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 #70133 is a reply to message #70114] |
Thu, 19 October 2006 17:27 |
Eclipse User |
|
|
|
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 #70231 is a reply to message #70133] |
Thu, 19 October 2006 20:48 |
donghua deng 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 #70270 is a reply to message #70231] |
Thu, 19 October 2006 21:00 |
Eclipse User |
|
|
|
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 #70406 is a reply to message #70326] |
Fri, 20 October 2006 10:17 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 #70460 is a reply to message #70440] |
Fri, 20 October 2006 17:32 |
Eclipse User |
|
|
|
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 #598869 is a reply to message #70031] |
Thu, 19 October 2006 10:27 |
Ed Merks Messages: 33217 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 #598889 is a reply to message #70114] |
Thu, 19 October 2006 17:27 |
Ed Merks Messages: 33217 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 #598930 is a reply to message #70133] |
Thu, 19 October 2006 20:48 |
donghua deng 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 #598941 is a reply to message #70231] |
Thu, 19 October 2006 21:00 |
Ed Merks Messages: 33217 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 #598995 is a reply to message #70326] |
Fri, 20 October 2006 10:17 |
Ed Merks Messages: 33217 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 |
Ed Merks Messages: 33217 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/
|
|
|
|
|
|