KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > beans > XMLEncoder

java.beans
Class XMLEncoder

java.lang.Object
  extended by java.beans.Encoder
      extended by java.beans.XMLEncoder
See Also:
Top Examples, Source Code, XMLDecoder, ObjectOutputStream

public void close()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1386]_
By Anonymous on 2005/04/11 13:29:34  Rate
this an bean context api

public void flush()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object getOwner()
See Also:
setOwner(java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setOwner(Object owner)
See Also:
getOwner()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void writeExpression(Expression oldExp)
See Also:
PersistenceDelegate.initialize(java.lang.Class, java.lang.Object, java.lang.Object, java.beans.Encoder), Encoder
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void writeObject(Object o)
See Also:
XMLDecoder.readObject(), Encoder
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[558]Example of a custom bean and the use of XMLEncoder/XMLDecoder to serialize/deserialize
By Anonymous on 2003/12/09 08:32:27  Rate
import java.beans.*; 
 import java.io.*; 
 import javax.swing.JFrame; 
  
  
 /** Example of a custom bean and the use of XMLEncoder/XMLDecoder to 
  * serialize/deserialize. 
  * 
  * To Write: java MyBean w mybean.xml 
  * To Read: java MyBean r mybean.xml */
 
  
  
 public class MyBean  {  
  
  
   public MyBean (  )   {  
     _Name = "Paul Blankenbaker"; 
     _Age = 39; 
    }  
  
  
   public int getAge (  )   {  
     return _Age; 
    }  
  
  
   public void setAge ( int age )   {  
     _Age = age; 
    }  
  
  
   public String getName (  )   {  
     return _Name; 
    }  
  
  
   public void setName ( String name )   {  
     _Name = name; 
    }  
  
  
   public String toString (  )   {  
     return _Name+"  ( "+_Age+' ) '; 
    }  
  
  
  
   public static void main ( String [  ]  args )   {  
     if  ( args.length != 2 )   {  
       System.err.println ( "Usage: java MyBean r|w FILE\n" ) ; 
       System.exit ( 1 ) ; 
      }  
  
  
     String fn = args [ 1 ] ; 
     try  {  
       if  ( args [ 0 ] .equals ( "w" )  )   {  
   XMLEncoder e =  
     new XMLEncoder ( new BufferedOutputStream ( new FileOutputStream ( fn )  )  ) ; 
        
   MyBean o = new MyBean (  ) ; 
   o.setName ( "Megan" ) ; 
   o.setAge ( 38 ) ; 
   e.writeObject ( o ) ; 
  
  
   e.close (  ) ; 
        }  else  {  
   XMLDecoder e =  
     new XMLDecoder ( new BufferedInputStream ( new FileInputStream ( fn )  )  ) ; 
        
   Object o = e.readObject (  ) ; 
   e.close (  ) ; 
  
  
   System.out.println ( o ) ; 
        }  
      }  catch  ( Throwable t )   {  
       t.printStackTrace (  ) ; 
      }  
    }  
    
  
  
   private String _Name; 
   private int _Age; 
  }  
  
  
 


public void writeStatement(Statement oldStm)
See Also:
PersistenceDelegate.initialize(java.lang.Class, java.lang.Object, java.lang.Object, java.beans.Encoder), Encoder
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public XMLEncoder(OutputStream out)
See Also:
XMLDecoder.XMLDecoder(InputStream)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags