users@jaxb.java.net

Problem with using JAXB from applet

From: Hyun Shin <hshin_at_FSC-USA.COM>
Date: Mon, 17 Mar 2003 12:34:24 -0700

Hi,

I am trying to use JAXB from applet but I am getting AccessControlException during unmarshal. The following are stack trace of Exception and the test programs I used (which is modified from SampleApp1 in users guide in order to run in the applet). Of course the same program has no problem if it is invoked as an application. Of course, I haven't had such problem using early access version.

Any clue?
Regards,
-Hyun

Stack trace ---

Starting ...

java.security.AccessControlException: access denied (java.util.PropertyPermission entityExpansionLimit read)

 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.checkPropertyAccess(Unknown Source)

 at java.lang.System.getProperty(Unknown Source)

 at java.lang.Integer.getInteger(Unknown Source)

 at java.lang.Integer.getInteger(Unknown Source)

 at org.apache.xerces.impl.XMLEntityManager.reset(XMLEntityManager.java:1077)

 at org.apache.xerces.parsers.BasicParserConfiguration.reset(BasicParserConfiguration.java:544)

 at org.apache.xerces.parsers.DTDConfiguration.reset(DTDConfiguration.java:630)

 at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:502)

 at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:585)

 at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)

 at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1142)

 at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:130)

 at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:139)

 at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:186)

 at Main.<init>(Main.java:82)

 at Test.start(Test.java:43)

 at sun.applet.AppletPanel.run(Unknown Source)

 at java.lang.Thread.run(Unknown Source)





Main.java ---
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

// import java content classes generated by binding compiler
import primer.po.*;

/*
 * $Id: Main.java,v 1.3.4.1 2003/02/03 16:23:21 ryans Exp $
 *
 * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the proprietary information of Sun Microsystems, Inc.
 * Use is subject to license terms.
 *
 */

public class Main {

        static String postr = "<?xml version=\"1.0\"?> <purchaseOrder orderDate=\"1999-10-20\"><shipTo country=\"US\"><name>Alice Smith</name><street>123 Maple Street</street> <city>Cambridge</city> <state>MA</state> <zip>12345</zip> </shipTo> <billTo country=\"US\"> <name>Robert Smith</name> <street>8 Oak Avenue</street> <city>Cambridge</city> <state>MA</state> <zip>12345</zip> </billTo> <items> <item partNum=\"242-NO\" > <productName>Nosferatu - Special Edition (1929)</productName> <quantity>5</quantity> <USPrice>19.99</USPrice> </item> <item partNum=\"242-MU\" > <productName>The Mummy (1959)</productName> <quantity>3</quantity> <USPrice>19.98</USPrice> </item> <item partNum=\"242-GZ\" > <productName>Godzilla and Mothra: Battle for Earth/Godzilla vs. King Ghidora</productName> <quantity>3</quantity> <USPrice>27.95</USPrice> </item> </items> </purchaseOrder>";

    // This sample application demonstrates how to unmarshal an instance
    // document into a Java content tree and access data contained within it.

        Main()
        {
        try {
            // create a JAXBContext capable of handling classes generated into
            // the primer.po package
            JAXBContext jc = JAXBContext.newInstance( "primer.po" );

            // create an Unmarshaller
            Unmarshaller u = jc.createUnmarshaller();

            // unmarshal a po instance document into a tree of Java content
            // objects composed of classes from the primer.po package.
            PurchaseOrder po =
                (PurchaseOrder)u.unmarshal(new ByteArrayInputStream(
                                        postr.getBytes("UTF-8")));

            // examine some of the content in the PurchaseOrder
            System.out.println( "Ship the following items to: " );

            // display the shipping address
            USAddress address = po.getShipTo();
            displayAddress( address );

            // display the items
            Items items = po.getItems();
            displayItems( items );

        } catch( JAXBException je ) {
            je.printStackTrace();
        } catch( IOException ioe ) {
            ioe.printStackTrace();
        }
    }

    public static void displayAddress( USAddress address ) {
        // display the address
        System.out.println( "\t" + address.getName() );
        System.out.println( "\t" + address.getStreet() );
        System.out.println( "\t" + address.getCity() +
                            ", " + address.getState() +
                            " " + address.getZip() );
        System.out.println( "\t" + address.getCountry() + "\n");
    }

    public static void displayItems( Items items ) {
        // the items object contains a List of primer.po.ItemType objects
        List itemTypeList = items.getItem();


        // iterate over List
        for( Iterator iter = itemTypeList.iterator(); iter.hasNext(); ) {
            Items.ItemType item = (Items.ItemType)iter.next();
            System.out.println( "\t" + item.getQuantity() +
                                " copies of \"" + item.getProductName() +
                                "\"" );
        }
    }
}

Test.java --

import java.io.*;
import java.net.*;
import java.applet.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.accessibility.*;

public class Test extends JApplet {

        public static URL codeBase = null;
        JFrame root;

        public Test()
        {
        }

        public void init()
        {
                codeBase = this.getCodeBase();
                root = new JFrame("Test Frame");
                root.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                                destroy();
                        }
                } );
        }

        public void destroy()
        {
                if (root != null)
                        root.dispose();
                setVisible(false);
        }

        public void start()
        {
                System.out.println("Starting ...");
                new Main();
                System.out.println("Starting done ...");
        }

        public void stop()
        {
                System.out.println("Stopping ...");
                destroy();
        }

        void destroyApplet()
        {
                destroy();
        }

        public static void main(String args[]) {
                new Main();
        }
}