Changing labels in a JFace TreeViewer on node expansion/collapse - swt

I have a TreeViewer where some nodes represent folders, so I wanted to show the icon of an open folder when the node is expanded and a closed folder when it is collapsed. Sounds easy, I just need to add a tree listener (the code is in Scala, but Java equivalent should be easy to imagine):
val tree = new TreeViewer(contents)
tree.addTreeListener(folderIconFixingListener)
private def folderIconFixingListener = new ITreeViewerListener {
def treeCollapsed(event: TreeExpansionEvent) {
tree.update(event.getElement, null)
}
def treeExpanded(event: TreeExpansionEvent) {
tree.update(event.getElement, null)
}
}
Unfortunately, this gives an exception:
Ignored reentrant call while viewer is busy. This is only logged once per viewer instance, but similar calls will still be ignored.
java.lang.RuntimeException
at org.eclipse.jface.viewers.ColumnViewer.checkBusy(ColumnViewer.java:763)
at org.eclipse.jface.viewers.ColumnViewer.update(ColumnViewer.java:552)
at scsadmin.NodesTreeScreen$$anon$1.treeExpanded(NodesTreeScreen.scala:64)
at org.eclipse.jface.viewers.AbstractTreeViewer$3.run(AbstractTreeViewer.java:1101)
at org.eclipse.jface.util.SafeRunnable$1.run(SafeRunnable.java:128)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.AbstractTreeViewer.fireTreeExpanded(AbstractTreeViewer.java:1099)
at org.eclipse.jface.viewers.AbstractTreeViewer.handleTreeExpand(AbstractTreeViewer.java:1444)
at org.eclipse.jface.viewers.TreeViewer.handleTreeExpand(TreeViewer.java:937)
at org.eclipse.jface.viewers.AbstractTreeViewer$4.treeExpanded(AbstractTreeViewer.java:1453)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Tree.gtk_test_expand_row(Unknown Source)
at org.eclipse.swt.widgets.Widget.windowProc(Unknown Source)
at org.eclipse.swt.widgets.Display.windowProc(Unknown Source)
at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(Unknown Source)
at org.eclipse.swt.widgets.Display.eventProc(Unknown Source)
at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at scsadmin.BootStrapper$.main(BootStrapper.scala:64)
at scsadmin.BootStrapper.main(BootStrapper.scala)
How can I fix this?

You might try to put your code in your listener into a asyncExec, to postpone its execution a bit:
display.asyncExec(new Runnable(){
public void run(){
tree.update(.);
}
});

The solution I eventually went with was to use a TreeListener on the Tree control itself instead, which worked fine.

Related

Gwt Material Design: MaterialSlider not working in classic dev mode

Here is the exception that gets displayed on the Browser.
java.lang.reflect.InvocationTargetException at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:423) at
com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at
com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:530)
at
com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:368)
at java.lang.Thread.run(Unknown Source) Caused by:
com.google.gwt.core.client.JavaScriptException: (null)
#gwt.material.design.jquery.client.api.JQuery::$(Lcom/google/gwt/dom/client/Element;)([JavaScript
object(8)]): null at
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:252)
at
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:121)
at
com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:573)
at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:293)
at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at gwt.material.design.jquery.client.api.JQuery.$(JQuery.java) at
gwt.material.design.jquery.client.api.JQuery.$(JQuery.java:167) at
gwt.material.design.client.base.MaterialWidget.$this(MaterialWidget.java:157)
at
com.mdesign.vadiraj.client.MaterialDesignWithCarousel.onModuleLoad(MaterialDesignWithCarousel.java:32)
... 9 more
Here is the exception from Eclipse console.
14:34:14.799 [ERROR] [materialdesignwithcarousel] Unable to load
module entry point class
com.mdesign.vadiraj.client.MaterialDesignWithCarousel (see associated
exception for details)
com.google.gwt.core.client.JavaScriptException: (null)
#gwt.material.design.jquery.client.api.JQuery::$(Lcom/google/gwt/dom/client/Element;)([JavaScript
object(8)]): null
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:252)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:121)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:573)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:293)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at gwt.material.design.jquery.client.api.JQuery.$(JQuery.java)
at gwt.material.design.jquery.client.api.JQuery.$(JQuery.java:167)
at gwt.material.design.client.base.MaterialWidget.$this(MaterialWidget.java:157)
at com.mdesign.vadiraj.client.MaterialDesignWithCarousel.onModuleLoad(MaterialDesignWithCarousel.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:423)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:530)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:368)
at java.lang.Thread.run(Unknown Source)
This is my project setup - Java 1.8 | GWT 2.8.1 | Classic dev-mode
inherits name="gwt.material.design.jquery.JQuery"
inherits name='gwt.material.design.GwtMaterialWithJQuery'
inherits name="gwt.material.design.GwtMaterialDesignBasic"
Attaching the code snippet from the Entrypoint class
public void onModuleLoad() {
MaterialSlider slider = new MaterialSlider();
RootPanel.get().add(slider);
slider.add(new Label("safrfsdhhdf"));
slider.add(new Button("I am a button"));
slider.add(new TextArea());
slider.add(new MaterialSwitch(true));
}
GWT Material Design uses JsInterop which doesn't work in legacy dev mode (nobody should continue to use legacy dev mode these days anyway, it's been deprecated for years)

install4j service start exception

I created an new application iteration using install4j v5.1.15.
The application starts a windows service after installation which has couple of steps to try and hit few URLs to get the updates or make sure some other configuration is available.
All I am getting is this below exception after installation is complete(used debugger mode). Is there any way I can configure the installer to give out more information(either point out which URL it is accessing), I have made sure that the all URLs added as present in the .install4j file are available.
What else can I try?
[INFO] com.install4j.runtime.beans.screens.BannerFormScreen [ID 1202]: Show screen
[INFO] com.install4j.runtime.beans.actions.control.RunScriptAction [ID 1203]: Execute action
Property script: I4jScript_Internal_97
Property rollbackSupported: false
Property rollbackScript: null
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at I4jScript_Internal_97$1.execute(I4jScript_Internal_97.java:68)
at com.install4j.runtime.installer.ContextImpl.runElevatedInt(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.runElevated(Unknown Source)
at I4jScript_Internal_97.eval(I4jScript_Internal_97.java:34)
at I4jScript_Internal_97.evaluate(I4jScript_Internal_97.java:99)
at com.install4j.runtime.installer.helper.Script.evaluate(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source)
at com.install4j.runtime.beans.actions.control.RunScriptAction.execute(Unknown Source)
at com.install4j.runtime.beans.actions.SystemInstallOrUninstallAction.install(Unknown Source)
at com.install4j.runtime.installer.InstallerContextImpl$2.fetchValue(Unknown Source)
at com.install4j.runtime.installer.helper.comm.actions.FetchObjectAction.execute(Unknown Source)
at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeActionDirect(Unknown Source)
at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeActionInt(Unknown Source)
at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeActionChecked(Unknown Source)
at com.install4j.runtime.installer.helper.comm.HelperCommunication.fetchObjectChecked(Unknown Source)
at com.install4j.runtime.installer.InstallerContextImpl.performActionIntStatic(Unknown Source)
at com.install4j.runtime.installer.InstallerContextImpl.performActionInt(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.performAction(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.executeActions(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.handleCommand(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.start(Unknown Source)
at com.install4j.runtime.installer.Installer.runInProcess(Unknown Source)
at com.install4j.runtime.installer.Installer.main(Unknown Source)
Edit-1:
#Ingo Kegel
Adding the script that I believe is failing:
//Get the "Click Finish to start..." label and update the text once the application is starting.
Screen otherScreen = context.getScreenById("1202");
FormEnvironment otherFormEnvironment = ((FormPanelContainer)otherScreen).getFormEnvironment();
FormComponent finishLabel = otherFormEnvironment.getFormComponentById("1207");
((JLabel)finishLabel.getConfigurationObject()).setText(context.getMessage("Please.Be.Patient.While.Application.Name.Is.Starting"));
//Start spinning the progress bar
context.getProgressInterface().setIndeterminateProgress(true);
//Get a handle on the port the user chose
final Long port = (Long)context.getVariable("user.specified.port");
//It's necessary to run this task elevated, otherwise install4j can have permissions issues and throw exceptions.
//See: http://blog.ej-technologies.com/2012/06/migrating-to-install4j-51.html
Boolean result = (Boolean)context.runElevated(new RemoteCallable()
{
public Serializable execute()
{
int numRetries = 50;
int retries = 0;
java.net.URL url = null;
try
{
url = new java.net.URL("http", "localhost", port.intValue(), "");
}
catch (java.net.MalformedURLException mue)
{
//If something goes wrong, return false.
return false;
}
while(retries < numRetries)
{
try
{
Thread.sleep(5000);
}
catch(InterruptedException ie)
{
return false;
}
try
{
java.net.HttpURLConnection connection = (java.net.HttpURLConnection)url.openConnection();
int responseCode = connection.getResponseCode();
if (responseCode == java.net.HttpURLConnection.HTTP_OK)
{
return true;
}
else
{
retries++;
}
}
catch (Throwable t)
{
t.printStackTrace();
retries++;
}
}
//We did not successfully find an application running on the port.
return false;
}
}, true);
context.getProgressInterface().setIndeterminateProgress(false);
return result;
Providing an update as the root cause was found to be unrelated to the install4j tool.
The jar I was using for packaging the installable was invalid. We had recently updated the maven plugin versions. The newer version changed the way our jar was packaged, which did not allow the service to start post the installation.
I am still receiving the same error as listed in the initial post, not sure of the source (I am ignoring that one for now).

while adding tab, i am getting this exception, how can i solve this?

public void addTab(String text, Widget widget) {
TabItem item = new TabItem();
item.setText(text);
item.setClosable(true);
//item.add((Widget) new Dashboard());
tabPanel.add(item);
tabPanel.setSelection(item);
}
While Executing i am getting this exception,
how can i solve this problem in gxt. i am trying to add tab, but it gives this exception
com.google.gwt.event.shared.UmbrellaException: Exception caught: null
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
at com.sencha.gxt.widget.core.client.Component.fireEvent(Component.java:293)
at com.sencha.gxt.widget.core.client.button.IconButton.onClick(IconButton.java:215)
at com.sencha.gxt.widget.core.client.button.IconButton.onBrowserEvent(IconButton.java:196)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)

how to display a JFrame from an applet?

I have this class called PollFrame that extends JFrame in a file called PollFrame.java . PollFrame contains a form. I have an applet, which has a button in it. When the button is clicked, I want the PollFrame to be displayed. I set the ActionPerformed as:
Pollframe poll = new PollFrame(); // This initializes the form
poll.setVisible(true);
However, when I click the button, I get the following error :
Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkExit(Unknown Source)
at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
at com.org.pollFrame.initComponents(pollFrame.java:54)
at com.org.pollFrame.<init>(pollFrame.java:11)
at com.org.EmployeeApplet.requestRoomActionPerformed(EmployeeApplet.java:216)
at com.org.EmployeeApplet.access$300(EmployeeApplet.java:7)
at com.org.EmployeeApplet$4.actionPerformed(EmployeeApplet.java:71)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I am guessing fromt he above error that calling another class file from an applet is prohibited. Is there any way I can display the PollFrame from the applet?
It seems like you're calling setDefaultCloseOperation() on your JFrame, which raises the security exception
You can definitively call another class from an applet but some operations are restricted, eg. you can't open local files, open connections to other machines...
I have this class called PollFrame that extends JFrame in a file called PollFrame.java . PollFrame contains a form. I have an applet, which has a button in it. When the button is clicked, I want the PollFrame to be displayed.
This is a one liner:
applet.showDocument("PollFrame.jnlp", "_blank");
The frame launched by PollFrame.jnlp will be able to call any default close operation it likes while still sand-boxed, since it will have a separate VM. To be 'always on top' it will need to be trusted (and then fight it out with all the other apps. that aim to be always on top).

How can I use JAXB from an unsigned applet (without signing it)?

I would like to marshall Java objects into XML and vice-versa from within an Unsigned Applet and I can't change any of the security permission/policy files, or sign the application.
I seem to get a Security exception, because JAXB is attempting to access fields or constructors that it can't in the applet sandbox.
The browser is running JRE 1.6.0_17
I'm also open to solutions based on some other XML (or JSON) library but have tried the following and pretty much run into a similar problem;
- XStream
- Gson
Given (something like) the following object:
#XmlType
#XmlRootElement
public class SimpleObject {
public String sampleText;
public SimpleObject() {
}
public String getSampleText() {
return sampleText;
}
public void setSampleText(String sampleText) {
this.sampleText = sampleText;
}
}
And the following simple JAXB code:
public void actionPerformed(ActionEvent e) {
try {
JAXBContext jc = JAXBContext.newInstance(SimpleObject.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
SimpleObject object = new SimpleObject();
object.setSampleText("Hello");
marshaller.marshal(object, System.out);
}
catch (JAXBException e1) {
throw new RuntimeException(e1);
}
}
I get the following exception:
Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkMemberAccess(Unknown Source)
at java.lang.Class.checkMemberAccess(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator.hasDefaultConstructor(Unknown Source)
at com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator.hasDefaultConstructor(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ClassInfoImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeClassInfoImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createClassInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createClassInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getClassInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getClassInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at nz.co.zeal.maker.application.actions.build.JAXBTestAction.actionPerformed(JAXBTestAction.java:24)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I never did quite figure this one out. What I did instead was to grab a fairly simple JSON library called Flexjson. It also threw a similar security exception but the library was simple enough that I was able to switch-off the library code that causes the exception in an Applet with a boolean flag.
I also tried to find a solution with JAXB without any success.
I switched to Axis2 (1.5.4) with ADB binding, but it also tried accessing system properties which failed with security manager checks.
In the end, I got a workable solution together by using AspectJ and using an aspect that rewrites System.getProperty() calls to return null when they fail. Since all the properties Axis2 needed were non-critical anyway this worked. I also needed to apply an aspect over org.apache.axiom.util.stax.dialect.StAXDialectDetector.getRootUrlForResource() to always return null since it tried to make a ClassLoader.getSystemClassLoader() call which also failed under a security manager. Again this seemed like a non-critical call. Got AspectJ to rewrite the Axis2 classes at build-time and it ran as an unsigned applet.
It's a really messy solution, but at least it worked.
I couldn't get the same AspectJ hack working with JAXB because JAXB requires direct access to the private fields of classes which doesn't fly under a security manager if JAXB is bundled with the applet (which we need to do if AspectJ is used to rewrite classes).
This may solve your problem. I know it solved mine :)
public void actionPerformed(ActionEvent e) {
try {
JAXBContext jc = AccessController.doPrivileged(new PrivilegedExceptionAction<JAXBContext>() {
public JAXBContext run() throws JAXBException {
// needs to run here otherwise throws AccessControlException
return JAXBContext.newInstance(SimpleObject.class);
}
});
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
SimpleObject object = new SimpleObject();
object.setSampleText("Hello");
marshaller.marshal(object, System.out);
}
catch (JAXBException e1) {
throw new RuntimeException(e1);
}
} catch (PrivilegedActionException e2) {
throw new RuntimeException(e2);
}
}
Hope it helps