title image


Smiley XMLEncoder
Hallo!



Ich habe mich gerade in einen Faustkampf mit dem XMLEncoder eingelassen und die erste Runde scheint er gewonnen zu haben. Einfache Objekte zu schreiben ist kein Problem. Ich veruche jedoch JGraph (wers kennt: speziell den GraphLayoutCache) zu speichern.



Es ist doch richtig das ich für eine Klasse, die nicht Bean-konform ist, einen PersistenceDeligate erzeugen muss (ich benutze den DefaultPersistenceDelagate). Ich habe jedoch gedacht, dass wenn ein Parameterloser Konstruktor vorhanden ist ich dies nicht machen muss. Der GraphLayoutCache belehrt mich jedoch enies besseres indem er unten aufgeführte Exception veranlasst. Kann es an Objekte liegen die darin enthalten sind, z.B. Listen? (Speziell für Listen mache ich folgendes: enc.setPersistenceDelegate(ArrayList.class, enc.getPersistenceDelegate(List.class));). Habe mir das Tutorial von Sun mal durchglesen, aber scheinbar was net verstanden oder beachtet.



Hoffe mir kann jemand nen Tipp geben woran es liegen könnte.



Vielen Dank und viele Grüße, DaBoo



PS: da Code bekanntlich mehr sagt als 1000 Worte findet ihr die (recht kleine Methode) gaanz am Ende, versteckt hinter der Exception! :-)





java.lang.InstantiationException: Start$1

at java.lang.Class.newInstance0(Unknown Source)

at java.lang.Class.newInstance(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 sun.reflect.misc.Trampoline.invoke(Unknown Source)

at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at sun.reflect.misc.MethodUtil.invoke(Unknown Source)

at java.beans.Statement.invoke(Unknown Source)

at java.beans.Expression.getValue(Unknown Source)

at java.beans.Encoder.getValue(Unknown Source)

at java.beans.Encoder.get(Unknown Source)

at java.beans.PersistenceDelegate.writeObject(Unknown Source)

at java.beans.Encoder.writeObject(Unknown Source)

at java.beans.XMLEncoder.writeObject(Unknown Source)

at java.beans.Encoder.writeExpression(Unknown Source)

at java.beans.XMLEncoder.writeExpression(Unknown Source)

at java.beans.PersistenceDelegate.writeObject(Unknown Source)

at java.beans.Encoder.writeObject(Unknown Source)

at java.beans.XMLEncoder.writeObject(Unknown Source)

at java.beans.Encoder.writeObject1(Unknown Source)

at java.beans.Encoder.cloneStatement(Unknown Source)

at java.beans.Encoder.writeExpression(Unknown Source)

at java.beans.XMLEncoder.writeExpression(Unknown Source)

at java.beans.PersistenceDelegate.writeObject(Unknown Source)

at java.beans.Encoder.writeObject(Unknown Source)

at java.beans.XMLEncoder.writeObject(Unknown Source)

at java.beans.Encoder.writeObject1(Unknown Source)

at java.beans.Encoder.cloneStatement(Unknown Source)

at java.beans.Encoder.writeStatement(Unknown Source)

at java.beans.XMLEncoder.writeStatement(Unknown Source)

at java.beans.XMLEncoder.writeObject(Unknown Source)

at SaveAction.actionPerformed(SaveAction.java:74)

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

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)

java.lang.Exception: XMLEncoder: discarding statement XMLEncoder.writeObject(GraphLayoutCache);

at java.beans.XMLEncoder.writeStatement(Unknown Source)

at java.beans.XMLEncoder.writeObject(Unknown Source)

at SaveAction.actionPerformed(SaveAction.java:74)

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

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)

Caused by: java.lang.RuntimeException: failed to evaluate: =Class.new();

at java.beans.Encoder.getValue(Unknown Source)

at java.beans.Encoder.get(Unknown Source)

at java.beans.PersistenceDelegate.writeObject(Unknown Source)

at java.beans.Encoder.writeObject(Unknown Source)

at java.beans.XMLEncoder.writeObject(Unknown Source)

at java.beans.Encoder.writeExpression(Unknown Source)

at java.beans.XMLEncoder.writeExpression(Unknown Source)

at java.beans.PersistenceDelegate.writeObject(Unknown Source)

at java.beans.Encoder.writeObject(Unknown Source)

at java.beans.XMLEncoder.writeObject(Unknown Source)







at java.beans.Encoder.writeObject1(Unknown Source)

at java.beans.Encoder.cloneStatement(Unknown Source)

at java.beans.Encoder.writeExpression(Unknown Source)

at java.beans.XMLEncoder.writeExpression(Unknown Source)

at java.beans.PersistenceDelegate.writeObject(Unknown Source)

at java.beans.Encoder.writeObject(Unknown Source)

at java.beans.XMLEncoder.writeObject(Unknown Source)

at java.beans.Encoder.writeObject1(Unknown Source)

at java.beans.Encoder.cloneStatement(Unknown Source)

at java.beans.Encoder.writeStatement(Unknown Source)

... 27 more





Java Code









































01 public void actionPerformed(ActionEvent e) {

02     GraphLayoutCache glc = this.graph.getGraphLayoutCache();

03     DefaultGraphModel model = (DefaultGraphModel) this.graph.getModel();

04 

05     XMLEncoder enc = new XMLEncoder(System.out);

06     enc.setExceptionListener(new ExceptionListener() {

07 

08       public void exceptionThrown(Exception e) {

09         e.printStackTrace();

10         //JOptionPane.showMessageDialog(graph, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);

11       }

12 

13     });

14 

15     enc.setPersistenceDelegate(DefaultGraphModel.class, new DefaultPersistenceDelegate());

16     enc.setPersistenceDelegate(GraphLayoutCache.class, 

17       new DefaultPersistenceDelegate(new String[] {"model", "factory", "partial"}));

18     enc.setPersistenceDelegate(DefaultGraphCell.class, new DefaultPersistenceDelegate(

19         new String[] {"userObject"}));

20     enc.setPersistenceDelegate(DefaultEdge.class, new DefaultPersistenceDelegate(

21         new String[] {"userObject"}));

22     enc.setPersistenceDelegate(DefaultPort.class, new DefaultPersistenceDelegate(

23         new String[] {"userObject"}));

24     enc.setPersistenceDelegate(AbstractCellView.class, new DefaultPersistenceDelegate(

25         new String[] {"cell", "attribuets"}));

26     enc.setPersistenceDelegate(DefaultEdge.DefaultRouting.class, new PersistenceDelegate() {

27 

28       @Override

29       protected Expression instantiate(Object oldInstance, Encoder out) {

30         return new Expression(oldInstance, GraphConstants.class, "getROUTING_SIMPLE", null);

31       }

32       

33     });

34     enc.setPersistenceDelegate(DefaultEdge.LoopRouting.class, new PersistenceDelegate() {

35 

36       @Override

37       protected Expression instantiate(Object oldInstance, Encoder out) {

38         return new Expression(oldInstance, GraphConstants.class, "getROUTING_DEFAULT", null);

39       }

40       

41     });

42     enc.setPersistenceDelegate(ArrayList.class, enc.getPersistenceDelegate(List.class));

43     

44 //    enc.writeObject(model);

45     enc.writeObject(glc);

46     enc.close();

47   }

















Java2html























geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: