Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Error when setting "xsi:schemaLocation" attribute
Error when setting "xsi:schemaLocation" attribute [message #49998] Wed, 17 September 2008 16:58 Go to next message
Roshan S. is currently offline Roshan S.
Messages: 125
Registered: July 2009
Senior Member
Hi, I'm trying to load an xml configuration file and add some attributes.
Here is the code:

<c:load url="spring-context.xml" var="springContext"/>
<c:set select="$springContext/*" name="xmlns:ehcache">
http://www.springmodules.org/schema/ehcache</c:set>
<c:set select="$springContext/*" name="xsi:schemaLocation">
http://www.springframework.org/schema/beans</c:set>

For some reason I get a java.lang.ClassCastException: java.lang.String
exception on the second <c:set for the "xsi:schemaLocation". My only
theory is that the attribute already exists even though I have not put it
in my spring-context.xml and it causes an error.
I'm also almost positive it has something to do with this particular
attribute "xsi:schemaLocation" because if I change the attr name to
something like "xsi:schemaLocations" then it works.

Anyone have a reason for this error or know a way to get around it?

Thanks,
Roshan
Re: Error when setting "xsi:schemaLocation" attribute [message #50028 is a reply to message #49998] Thu, 18 September 2008 09:05 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Roshan:

I don't think that will work. There are several limitations at work:

First, while the JET xpath engine understands the concept of namespace
prefixes, there are no tags defined to map a prefix to an NS URI, so JET
Xpath expressions will never match an expression like:
$springContext/*/@xmlns:ehcache. Because of this, the engine is a little
lax on processing unqualified attributes, $springContext/*/@ehcache would
have chance of returning a result.

Second, the c:set tag is not recognizing a namespace prefix in 'name', and
doing something appropriate. The <c:set> tag attempts to do the following:
1) figure out what kind of object $springContext/* is, and if it can handle
the setting of an attribute calls xmlns:ehcache. None of the in-the-box
'inspector' implementations correctly handle a namespace prefix.
2) if #1 fails, then the XPath engine starts the value in a map associated
with the selected object. But, again, I don't think the namespace prefix
will be correctly han

I have seen the 'load-a-document-and-modify-it' pattern in a number of JET
transformations. So I feel that getting the XPath engine, inspectors and tag
libraries to support this better is important. But, of course, that's not
going to happen quickly. So, here are some workaround suggestions:

1) From you example, it looks like you're trying to move to the DTD-based
spring context to the XML Schema based context. If your goal is to get this
to save to disk properly, how about using a template instead...

<c:load url="spring-context.xml" var="oldSpringContext"/>
<ws:file tempate="templates/new-spring-context.xml.jet" path="..."/>

where templates/new-spring-context.xml.jet is:

------------- Start: templates/new-spring-context.xml.jet is: ----------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5 .xsd">

<%-- copy old <bean/> definitions here --%>
<c:iterate select="$oldSpringContext/beans/bean" var="bean">
<c:dump select="$bean"/>
</c:iterate>
</beans>
------------- End: templates/new-spring-context.xml.jet is: ----------

In this case, c:dump is pretty good at maintaining the original XML below
the <bean> tags.

2) Do the modifications in a custom tag which gets directly at the
underlying model implementation. Now, <c:load> default is to use the
org.eclipse.emf.ecore.xml.type package to represent an XML document - this
API is not for mere mortals. With JET 0.9, you can get <c:load> to use the
XML DOM by specifiying:

<c:load url="spring-context.xml" var="springContext"
loader="org.eclipse.jet.xml"/>

The 'var' then points to the org.w3c.dom.Document object. So, your custom
tag could be something like:

<custom:addNS document="$springContext" prefix="xsi"
uri="http://www.w3.org/2001/XMLSchema-instance"
schemaLocation=" http://www.springframework.org/schema/beans/spring-beans-2.5 .xsd"/>

The tag implementation would do all the appropriate work directly against
the Document object.

My guess is that the second approach will be much more work for you, and it
will end up discovering more wholes in JETs support for modifying in-memory
models.

Paul
Re: Error when setting "xsi:schemaLocation" attribute [message #50498 is a reply to message #50028] Wed, 24 September 2008 08:54 Go to previous messageGo to next message
justin Mising name is currently offline justin Mising name
Messages: 28
Registered: July 2009
Junior Member
Hi Paul,

Iam trying to append bean tags to existing spring config.xml.
I have followed the approach of c:load to load xml file and then have
xml.jet where <c:dump> is there to read it.
I am getting error when loading spring.xml file on running JET
transformation:
templates/main.jet(45,2): <c:load url="./templates/spring-context.xml"
var="oldSpringContext">
Error: Unable to load: ./templates/spring-context.xml
Feature 'id' not found.
(platform:/resource/testWebtemplates/templates/spring-contex t.xml, 11, 68)
Feature 'id' not found.

----- spring-context.xml file content is below ---
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0 .xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="create" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
--------
It is failing on line :<tx:advice id="txAdvice"
transaction-manager="transactionManager">

When i remove the attributes -' id="txAdvice"
transaction-manager="transactionManager"',then the xml gets loaded.

I tried this with jet 0.8 as well as JET 0.9.

As we need to load existing xml,how to do this with JET.
Pls let me know at the earliest possible as i need to complete this POC.

Thanks,
Justin.
Re: Error when setting "xsi:schemaLocation" attribute [message #50689 is a reply to message #50498] Thu, 25 September 2008 10:48 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Justin:

I think you can blame this one on EMF, which JET uses, by default, for
loading XML documents. Under the covers, EMF loads the XML schemas
referenced, generates EPackages, etc... and the tries to parse the document
and create a bunch of EObjects. I'm still looking at the EMF code, but the
attribute id on tx:advice is not defined in the tx namespace, but the
default namespace. I'm guessing that in constructing is on-the-fly ecore
packages, it is missing out on the schema-location information, and thus the
definition of id. I'll continue to look into this...

But, to move you forward...

With JET 0.9.0, XML documents can be loaded directly with the XML DOM.
Currently , this is not the default (although I'm seriously thinking about
this for the future).

To make it happen, do:

<c:load url="./templates/spring-context.xml"
var="oldSpringContext"
loader="org.eclipse.jet.xml" />

I have tested that this does, indeed load and dumpyour document.

A few caveats: I've discovered that XPath expressions such as:

$oldSpringContext/beans/advice

or

$oldSpringContext/beans/tx:advice

do not work. With EMF-based XML parsing, the XPath engine was matching
'advice' to tx:advice. But, with the XML DOM, the first expression returns
no result, and the second complains that the namespace tx is underfined. As
a workaround, you can do:

/beans/*[namespace-uri() = 'http://www.springframework.org/schema/tx' and
local-name()='advice']/@transaction-manager

Although, I must admit, this is gross. You could mitigate this by defining a
variable:

<c:setVariable var="txNS" select="
'http://www.springframework.org/schema/tx' "/>

and using the expression:

/beans/*[namespace-uri() = $txNS and
local-name()='advice']/@transaction-manager

Paul

"justin " <justin_prabhu@yahoo.com> wrote in message
news:6a8b7f95606ded07adf18752ca870cf4$1@www.eclipse.org...
> Hi Paul,
>
> Iam trying to append bean tags to existing spring config.xml.
> I have followed the approach of c:load to load xml file and then have
> xml.jet where <c:dump> is there to read it.
> I am getting error when loading spring.xml file on running JET
> transformation:
> templates/main.jet(45,2): <c:load url="./templates/spring-context.xml"
> var="oldSpringContext">
> Error: Unable to load: ./templates/spring-context.xml
> Feature 'id' not found.
> (platform:/resource/testWebtemplates/templates/spring-contex t.xml, 11, 68)
> Feature 'id' not found.
> ----- spring-context.xml file content is below ---
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:aop="http://www.springframework.org/schema/aop"
> xmlns:tx="http://www.springframework.org/schema/tx"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0 .xsd
> http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
> http://www.springframework.org/schema/aop
> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
>
> <tx:advice id="txAdvice" transaction-manager="transactionManager">
> <tx:attributes>
> <tx:method name="create" propagation="REQUIRED" />
> </tx:attributes>
> </tx:advice>
> --------
> It is failing on line :<tx:advice id="txAdvice"
> transaction-manager="transactionManager">
>
> When i remove the attributes -' id="txAdvice"
> transaction-manager="transactionManager"',then the xml gets loaded.
>
> I tried this with jet 0.8 as well as JET 0.9.
>
> As we need to load existing xml,how to do this with JET. Pls let me know
> at the earliest possible as i need to complete this POC.
>
> Thanks,
> Justin.
>
>
Re: Error when setting "xsi:schemaLocation" attribute [message #51559 is a reply to message #50689] Fri, 03 October 2008 08:03 Go to previous messageGo to next message
justin Mising name is currently offline justin Mising name
Messages: 28
Registered: July 2009
Junior Member
Hi Paul,
Thanks for your reply.
I had implemented code as per your suggestions.
When I ran the transformation, I could not find tx ,aop parts of the input
file in the output.

The code snippet I used in main.jet and
spring-context-withxmlloader.xml.jet is below:
Main.jet:
<c:load
url=" credentials/credentials-business-service/src/main/resources/ serviceContext.xml "
urlContext="workspace" var="oldSpringContext"
loader="org.eclipse.jet.xml" />

<c:load url="./springInput.xml" var="springInput" />


<%-- Iterate over all the artifacts in the input xml file --%>
<c:iterate select="$artifact/artifact" var="currentArtifact" >

<c:setVariable var="java.project" select="$currentArtifact/project/@name
"/>
</c:iterate>
<ws:project name="{$java.project}">

<%--Create or merge the spring context file--%>
<ws:file
template=" src/main/templates/springTemplates/spring-context-withxmlloa der.xml.jet "
path=" credentials-business-service/src/main/resources/serviceConte xt.xml "/>

</ws:project>


spring-context-withxmlloader.xml.jet:
<c:setVariable var="txNS" select="
'http://www.springframework.org/schema/tx' "/>

<c:iterate select="$oldSpringContext/beans/*[namespace-uri() = $txNS and
local-name()='advice']/@transaction-manager" var="tx">
<c:dump select="$tx"/>
</c:iterate>
<c:iterate select="$oldSpringContext/beans/config" var="aop">

<c:dump select="$aop"/>
</c:iterate>



tx part of The input file being read is shown below:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0 .xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="store*" propagation="REQUIRED" />
<tx:method name="remove" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>

Normally,’@XX’ tag is used to fetch the value of XPath expression. The tag
to be used is given as ‘@transaction-manager’ in <c:iterate
select="$oldSpringContext/beans/*[namespace-uri() = $txNS and
local-name()='advice']/@transaction-manager" var="tx">
How does '@transaction-manager' work here?
Am I using it rightly .Am I missing something?
Pls let me know at the earliest possible as the POC end date is nearing.

Also,one strange thing i noticed is:
When I have the spring-context.xml file as below:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5 .xsd

http://www.springmodules.org/schema/ehcache classpath:springmodules-ehcache.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="store*" propagation="REQUIRED" />
<tx:method name="remove" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
and JET uses default emf loader,
the JET loads properly.
I donot know how this works .However, this ehcache does not seem to be
standard solution as one may not require ehcache in certain scenarios.

Regards,
Justin.
Re: Error when setting "xsi:schemaLocation" attribute [message #51602 is a reply to message #51559] Fri, 03 October 2008 12:43 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Justin:

I have just release the first build on the next JET maintenance release
(0.9.2). In the build, there are changes to eliminate the need to do
namespace testing on DOM documents. The build is available here:

http://www.eclipse.org/modeling/m2t/downloads/?showAll=1& ;hlbuild=M200810010919&project=jet#M200810010919

Give it a try. In the meantime, I'll try to have a look at your code in
detail.

Paul

"justin " <justin_prabhu@yahoo.com> wrote in message
news:4b0f21950ef31f76fc51bb0f2443f362$1@www.eclipse.org...
> Hi Paul,
> Thanks for your reply.
> I had implemented code as per your suggestions.
> When I ran the transformation, I could not find tx ,aop parts of the input
> file in the output.
>
> The code snippet I used in main.jet and
> spring-context-withxmlloader.xml.jet is below:
> Main.jet:
> <c:load
> url=" credentials/credentials-business-service/src/main/resources/ serviceContext.xml "
> urlContext="workspace" var="oldSpringContext"
> loader="org.eclipse.jet.xml" />
>
> <c:load url="./springInput.xml" var="springInput" />
>
>
> <%-- Iterate over all the artifacts in the input xml file --%>
> <c:iterate select="$artifact/artifact" var="currentArtifact" >
>
> <c:setVariable var="java.project" select="$currentArtifact/project/@name
> "/> </c:iterate> <ws:project name="{$java.project}">
>
> <%--Create or merge the spring context file--%>
> <ws:file
> template=" src/main/templates/springTemplates/spring-context-withxmlloa der.xml.jet "
> path=" credentials-business-service/src/main/resources/serviceConte xt.xml "/>
>
> </ws:project>
>
>
> spring-context-withxmlloader.xml.jet:
> <c:setVariable var="txNS" select="
> 'http://www.springframework.org/schema/tx' "/>
>
> <c:iterate select="$oldSpringContext/beans/*[namespace-uri() = $txNS and
> local-name()='advice']/@transaction-manager" var="tx">
> <c:dump select="$tx"/>
> </c:iterate> <c:iterate select="$oldSpringContext/beans/config" var="aop">
>
> <c:dump select="$aop"/>
> </c:iterate>
>
>
>
> tx part of The input file being read is shown below:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:aop="http://www.springframework.org/schema/aop"
> xmlns:tx="http://www.springframework.org/schema/tx"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0 .xsd
> http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
> http://www.springframework.org/schema/aop
> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
>
> <tx:advice id="txAdvice" transaction-manager="transactionManager">
> <tx:attributes>
> <tx:method name="create*" propagation="REQUIRED" />
> <tx:method name="update*" propagation="REQUIRED" />
> <tx:method name="store*" propagation="REQUIRED" />
> <tx:method name="remove" propagation="REQUIRED" />
> <tx:method name="delete*" propagation="REQUIRED" />
> <tx:method name="*" propagation="REQUIRED" read-only="true" />
> </tx:attributes>
> </tx:advice>
>
> Normally,
Re: Error when setting "xsi:schemaLocation" attribute [message #51622 is a reply to message #51602] Mon, 06 October 2008 07:56 Go to previous message
justin Mising name is currently offline justin Mising name
Messages: 28
Registered: July 2009
Junior Member
Thanks Paul.
JET seems to work properly now when loading with jet 0.9.2.
Regards,
Justin.
Previous Topic:<c:userRegion> vs. <java:jmerge>
Next Topic:JET tag to Check if file exists
Goto Forum:
  


Current Time: Sat Apr 19 02:57:38 EDT 2014

Powered by FUDForum. Page generated in 0.02582 seconds