Skip to main content

java has no "com.sun.xml.internal.stream.events.XMLEventAllocatorImpl"?

8 replies [Last post]
minka99
Offline
Joined: 2008-03-27
Points: 0

This must be something dumb I'm doing, please be nice.

When i develop on the eclipse platform, this gives me no problem:

inputFactory.setEventAllocator(new XMLEventAllocatorImpl());

This is exactly what the java 1.6 Web Services tutorial shows in a code example.

Eclipse adds this import for the above:
import com.sun.xml.internal.stream.events.XMLEventAllocatorImpl;

I am using (in Eclipse) jdk_1.6.0_03

I build the production jar outside of Eclipse (it's smaller), using
java and javac:
java "1.6.0_03"
javac 1.6.0_03

But when I 'javac' my test case outside of Eclipse, I get:

package com.sun.xml.internal.stream.events does not exist
import com.sun.xml.internal.stream.events.XMLEventAllocatorImpl;

cannot find symbol
symbol : class XMLEventAllocatorImpl
location: class ValidRdrHandler.beelucid.plugin.Xml.XmlReader
inputFactory.setEventAllocator(new XMLEventAllocatorImpl());

???

Thanks!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rongji
Offline
Joined: 2008-09-17
Points: 0

It seems that the com.sun.xml.internal.stream.event package is no longer existed in JDK1.6. your problem can be solved by downloading a sjsxp.jar file for the lib, the XMLEventAllocatorImpl class is included.

minka99
Offline
Joined: 2008-03-27
Points: 0

oh, just to be clear...

I tried not setting the EventAllocator, hoping that in that case the default would be used (and hoping, in other words, that the facility of setting it was only for custom allocators) but that won't work for me, because the allocator is null always in that case, and I do need an allocator. thx.

joehw
Offline
Joined: 2004-12-15
Points: 0

I'm not familiar with Eclipse, and what it's using for the StAX. The setEventAllocator method on javax.xml.stream.XMLInputFactory is meant to be used to set a user defined event allocator for events If the tutorial tells you to use the allocator impl in the jdk, and you get a null value when you don't supply one, that seems to me that it didn't have its own alloator impl. Can you point me to the tutorial or post the sample here?

Generally, it's not a good idea to refer to internal classes in the JDK because implementation can change. However, in this case, that particular class, a class in the JAXP parckage, does exist in the JDK.

minka99
Offline
Joined: 2008-03-27
Points: 0

Tutorial link:
http://java.sun.com/webservices/docs/1.6/tutorial/doc/index.html
Specific example link:
http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP6.html#wp107699

The tutorial isn't available for download anymore, I'm reading from the online text.

This is chapter 3, CursorApproachEventObject.java, and
this is cut and pasted from the tutorial:

Instantiating an XMLEventAllocator

The first step is to create a new XMLInputFactory and instantiate an XMLEventAllocator:

XMLInputFactory xmlif = XMLInputFactory.newInstance();
System.out.println("FACTORY: " + xmlif);
xmlif.setEventAllocator(new XMLEventAllocatorImpl()); // THIS IS IT
allocator = xmlif.getEventAllocator();
XMLStreamReader xmlr = xmlif.createXMLStreamReader(filename,
new FileInputStream(filename));

joehw
Offline
Joined: 2004-12-15
Points: 0

I see that now. It seemed to me that the sample was intended to demonstrate how to get event out of a stream reader. It appears to be a convenient way to construct events than using the EventFactory. However, just as you've found out, it creates dependency on specific implementation, which is unwanted, and against the principle behind the JAXP API. So I think it's ok if the sample meant to show users how to plugin a custom event allocator, but it's not a good idea for general usage in my opinion.

It seems to me it might be useful to add a general XMLEvent creating method to the EventFactory. It does look like it would be useful in this use case than those currently provided by the EventFactory. There has been some suggestions on improving the StAX API. Maybe it's time for the BEA folks to start working on 2.0 :)

So back to your issue, the problem appears to that the package has been changed when the StAX implementation was integrated into the JDK. The package name in JDK is:
com.sun.xml.internal.stream.events

Again, I think it would be better if you could avoid referencing the implementation class. Without a tool as convenient as the allocator, it would have to be done using the Event Factory, or switch to even reader if possible -- see the other thread you posted.

Joe

minka99
Offline
Joined: 2008-03-27
Points: 0

I figured out my issue with not being able to find this class. My bad. It was a
config install difference caused by building jars both inside and outside eclipse.

I do hope being able to create events from the stream reader doesn't go away!
I think there are a variety of uses for this.

thanks!

jasonray76
Offline
Joined: 2008-04-22
Points: 0

What did you do to resolve this?

minka99
Offline
Joined: 2008-03-27
Points: 0

I had multiple java versions on my system and was inadvertently picking up 1.4 in
my class path.