Win a copy of Head First Android this week in the Android forum!

Pavan Upadhya

Greenhorn
+ Follow
since Dec 12, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pavan Upadhya

Hi,

I am using JAXB1.0 RI libraries and I am seeing a strange issue. Here is what I see

I have this simple XSD

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="0"/>
<xs:element name="Age" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


I used xjc compiler (which is compliant with JAXB 1.0 version) to generate Java code and it generated bunch of java files. Here is the content of MANIFEST.MF file inside xjc jar file

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.4.1_02-b06 (Sun Microsystems Inc.)
Specification-Title: Java Architecture for XML Binding
Specification-Version: 1.0
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: JAXB Reference Implementation
Implementation-Version: 1.0.4
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: com.sun


In my client code I have a class which implements ValidationEventHandler to ignore unknown elements.



Everything works fine as long as I try to unmarshall an xml which has valid tags according to the xsd. But when I try to unmarshall an xml which has an unknown tag (shown below), I expected the handleEvent method in my validation handler to get called only for that particular tag which is unknown. But I am seeing handle Event being called for all the tags which follows the unknown tag.

Here is the XML input which contains one invalid tag (Junk)

<Person>
<Junk>123</Junk>
<Name>A</Name>
<Age>12</Age>
</Person>


Here is the sample client code



Here is the output

[severity=ERROR,message=Unexpected element {}:Junk,locator=[node=null,object=null,url=file:/c:/test.xml,line=2,col=8,offset=-1]]
[severity=ERROR,message=Unexpected element {}:Name,locator=[node=null,object=null,url=file:/c:/test.xml,line=3,col=8,offset=-1]]
[severity=ERROR,message=Unexpected element {}:Age,locator=[node=null,object=null,url=file:/c:/test.xml,line=4,col=7,offset=-1]]


I was expecting Unexpected element only for <Junk> tag, but I got the error for other 2 tags as well.

One interesting observation is, if I modify the XSD to remove minOccurs Indicator as shown below

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="Name"/>
<xs:element name="Age"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

and I regenerate the java files and pass in the same XML which contains invalid tag <Junk> and when I unmarshall the same xml, I see the handleEvent method in my handler is being called only for the unknown tag <Junk>

[severity=ERROR,message=Unexpected element {}:Junk,locator=[node=null,object=null,url=file:/c:/test.xml,line=2,col=8,offset=-1]]

When I use xjc JAXB2.0 compliant compiler, I do not see this behavior. Irrespective of the minOccurs Indicator being present or not, unmarshalling works and handleEvent method gets called only for the unknown tag.

Is this a known issue in JAXB1.0 RI or am I missing something here?
Oops! sorry for the typo. Actually I meant enum constants.
Thanks Punit, Now I recollect all enums are public, final and static.
Hi,

I have a class which as one of the static member of type enum. Below is the code


The output of the code is WINTER. But the question I have is, by default all non-initialized static members will be initialized to null. So I was expecting a NULL Pointer Exception while printing s.WINTER. Could some one explain why s is not initialized to null in this case.

Thanks,
Pavan
Thanks all for the reply. Looks like I need to do some more homework on inner classes now.
12 years ago

Originally posted by Christophe Verre:
Check the SCJP FAQ.



Thanks Crhistophe. That helps.
Hi,

I am planning to take up SCJP certification. Could any one help me understand the how different is latest SCJP for SE6.0 compared to SCJP for SE5.0. Also which is the best book to read for this.

Thanks,
pavan bg
Hi,

I am trying to declare a static variable in a inner class as shown below
class Test1
{
class Test2
{
static int i;
}
}

and get following error when I compile the class

Test1.java:5: inner classes cannot have static declarations
static int i;
^
1 error

Could any one explain, why can't there be a static variable or a static method inside a inner class.

Thanks,
pavanbg
12 years ago