Making an object serializable

Hey guys, im new at this so i dont know almost anything about serialization, so here's my problem:
Got an array of an object "Article" that i defined, wanna write it to a file but i get the "NotSerializableException",
here's my object's constructor:
Article (String n, int u, float p)
name = n;
amount = u;
price = p;
fmt = new DecimalFormat ("0.##");
by the way, all of the variables are private, i dont have any problem storing several articles in my array, i just get my exception at runtime here:
public static void save(Object obj, String nombrearch) throws IOException
ObjectOutputStream objstream = new ObjectOutputStream(new FileOutputStream(nombrearch));
objstream.writeObject(obj);
objstream.close();
apologizing for inconviniences, hope you can help me work this out

sanu018 wrote:
When ever u are writing to a stream all the objects that u r exporting should be serializable. Primitive types are as such non serializable so replace all those int with Integer type objects.Absolute total rubbish. Just pure bullshit.
If you don't have a clue what you're talking about then please don't offer "advice" on these forums.

Similar Messages

  • 2D objects Serialization problem

    Welcome!
    I'm making a net game using RMI and I have this problem.
    When I'm trying to join my client with the server an error occures:
    Error: error marshalling arguments; nested exception is:
         java.io.NotSerializableException: java.awt.geom.Ellipse2D$Double
    My client contains an Object extending a JPanel class. There are 2D object used to make the map, and that's why this error occures.
    It's a funny thing, cause I'm not sending a whole Object of my client, but only it's refference (using "this" in the join() method) so I dont know why does the 2D object need to be serialized and sent :|?
    Any way, my question is how to make 2D objects serializable!? I have jdk1.5.0_06 and as far as I remember they should be srializable in this version. Mabey I'm dooing something wrong!? Mabey it's nessesary to ad an appropreate code-line or import sth... i don't know
    please help me... I have little time to finish my project, and this thing is blocking my work.
    Big thanks to anybodey who will help.
    regards floW

    I'll tel u the whole story then, my problem is as follows:
    public class BounceThread{
       public static void main(String[] args)   {
          JFrame ramka = new BounceFrame();
             ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             ramka.setVisible(true);
    class BounceFrame extends JFrame{
    public BounceFrame()
          setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
          setTitle("MiniGolf v 1.0");
          panel = new BallPanel(); // this contains maps made with 2D objects
          panel.setBackground(Color.green);
          panel.setVisible(panel.czy_widać_panel());
          add(panel, BorderLayout.CENTER);
    // I add a menu bar, that starts a net game:
    JMenuBar pasekMenu = new JMenuBar();
              setJMenuBar(pasekMenu);
              JMenu menuGra = new JMenu("Game");
           // and so on... and finaly I add an option:
              menuGame_Nowa.add(new
                        AbstractAction("Net game")
                             public void actionPerformed(ActionEvent event)
                                  net_game(panel);
    // here i write my net_game method:
    public void net_game(BallPanel aPanel)
         //here, i make an Client object, and connect him with my server
         client = new mgClient(panel);
         client.join();
         // I give panel as a paramete, cause I cant think of another way of leting my server to uce it's (panels) methods
         // If I join only a name of my client, then how can I change the panel in my BounceFrame from the Clients method
         // "shouted" by the server!? It has to be a field in the client's object.
         // Is there any other way out!?
    // Class BouceFrame holds the panel as a field:
    private mgClient client;
    private BallPanel panel;
    //and so on...
    }and that's the real problem I'm facing here. Is there any solution!? I think, that making a Client's field out of my panel is the only way ot. And that means I need those 2D objects serialized... :(
    Please help if u can.
    Regards floW

  • Servlet and Object Serialization

    Hi,
    I am developing a routing server in Java
    2 Instances of the same server will be running in 2 different data centers.
    The servers have a Jetty server embedded with a Servlet inside.
    Server 1 will use a GET method to talk to the Server 2 -> Servlet which will write the state of an object back which will read by Server 1 and reconstruct the object back.
    Do you find any issues in Object Serialization/DeSerialization in the Servlet.
    What are the factors that I need to consider in this case?
    Regards,
    Jana

    Make sure that your servlet handles the transaction in the same thread that doPost() or doGet() is called in.
    I ended up porting some old ServerSocket based code to a servlet, and was handing off the request and response objects to a handler thread on the server side. I ended up with a ton of intermittent errors like this.
    Once I started handling the transactions in the same thread things worked heartbreakingly well.

  • Customizing Forte object serialization

    Forte supports serialization of arbitrary object graphs into streams.
    However, there do not seem to be any well documented ways to customize
    this serialization, e.g. by using a different encoding scheme. It would
    seem there must be some support in there somewhere. I suppose at the
    very least, one could parse a serialized object (once one decoded the
    Forte encoding scheme) and do the conversion from that. That seems
    suboptimal, though.
    Has anyone done this? Any thoughts on how it might be done?
    Regards,
    Coty
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/forte>

    JavaFunda wrote:
    Object serialization is the process of saving an object's state to a sequence of bytes. Does it saves only the instance variable or also the object methods(like getter and setter methods) ? Only the state--the instance variables. It doesn't save the class definition. That has to be available separately (via classloader) at deserilaization time. In other words, you cannot deserialize an instance of a class that is not on your classpath.
    Once we we write the object to outputstream or some text file, how does it get transmitted over network?The same way any other bytes get transmitted. You have a Socket. You get its OutputStream. You wrap that in an ObjectOutputStream. When you write to the ObjectOutputStream, that writes through to the Socket's OutputStream, which is responsible for putting the bytes on the wire.
    Does we write the java object to text file only duuring serialization?We write the objects to wherever the other end of the ObjectOutputStream is connected to. Just like any other I/O.

  • Runtime Object serialization

    Hi,
    Could someone explain the concept of Runtime Object Serialization with a simple example?
    Thanks

    import java.io.*;
    /* you NEED to make the class implement Serializable */
    class Client implements Serializable {
        private String name;
        private String address;
        public String getName() { return name; }
        public String getAddress() { return address; }
        public void setName(String name) { this.name = name; }
        public void setAddress(String address) { this.address = address; }
        public String toString() { return "name='" + name + "' and address= " + address + "'"; }
    public class Test17 {
        public static void main(String[] args)  throws Exception {
            ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream ("test.bin"));
            Client myClient = new Client();
            myClient.setName("Steve Jobs");
            myClient.setAddress("1 Infinite Loop; Cupertino, CA 95014");
            System.out.println (myClient);
            oos.writeObject (myClient);
            oos.close();
            ObjectInputStream ois = new ObjectInputStream (new FileInputStream ("test.bin"));
            Client yourClient = (Client) ois.readObject();
            System.out.println (yourClient);
    }Run the program above. It creates an object of the class "Client", serializes it into a file named "test.bin" and recreates the object reading it from the same file.
    Dumping the binary file you get this:
    0000    AC ED 00 05 73 72 00 06  43 6C 69 65 6E 74 F1 D7   ....sr..Client..
    0010    74 76 C4 64 FD 43 02 00  02 4C 00 07 61 64 64 72   tv.d.C...L..addr
    0020    65 73 73 74 00 12 4C 6A  61 76 61 2F 6C 61 6E 67   esst..Ljava/lang
    0030    2F 53 74 72 69 6E 67 3B  4C 00 04 6E 61 6D 65 71   /String;L..nameq
    0040    00 7E 00 01 78 70 74 00  24 31 20 49 6E 66 69 6E   .~..xpt.$1 Infin
    0050    69 74 65 20 4C 6F 6F 70  3B 20 43 75 70 65 72 74   ite Loop; Cupert
    0060    69 6E 6F 2C 20 43 41 20  39 35 30 31 34 74 00 0A   ino, CA 95014t..
    0070    53 74 65 76 65 20 4A 6F  62 73                     Steve JobsYou can see a lot of things in the serialization of the object Client - the name of the class is written, the names of the fields, the type (java/lang/String), and the values of the fields as UTF-8 encoded strings.

  • Object serializable?

    Hi,
    When writing a vector of my own objects out to a file, do the objects need to be serializable even though it is actually the vector I am outputting?
    Also, each of my objects in this vector have a field that is a vector of other objects...do I need to declare those objects serializable also?

    I think you still need to implement serializable on objects contained in the vector. I tried serializing a hashmap and my hashmap contained objects which needed to be serialized before the hashmap could be stored in a file.

  • SetAttribute() makes object serializable Recursively ?

              Hi everyone,
              could anyone answer me whether httpSession.setAttribute(key, very big object)
              makes the object serializable recursively.
              What I mean is, I am storing an object bigObject in http session using setAttribute().
              This bigObject contains several other objects which are not serialized.
              But I have read that setAttribute() makes the object serializable.
              So, does it mean that all the objects stored in bigObject also will be serialized
              thanks,
              jyothi
              

    But you can't serialize an Object that isn't Serializable somewhere in it's
              inheritance. A method can't make an Object Serializable.
              "jyothi" <[email protected]> wrote in message
              news:[email protected]...
              >
              > But i read clearly some where in bea online manual that use
              setAttribute() which
              > makes the object searializable. So I wonder whether this
              setAttribute() does
              > the searlization recursively ?
              >
              > thanks,
              > jyothi
              >
              > "justin" <[email protected]> wrote:
              > >
              > >Cluster requirement is that all objects placed in a session should be
              > >serializable.
              > >So your Big objects with small object which are not serializable is going
              > >to be
              > >a problem.
              > >
              > >"jyothi" <[email protected]> wrote:
              > >>
              > >>Hi everyone,
              > >>
              > >>could anyone answer me whether httpSession.setAttribute(key, very
              > >>big object)
              > >> makes the object serializable recursively.
              > >>
              > >>What I mean is, I am storing an object bigObject in http session using
              > >> setAttribute().
              > >> This bigObject contains several other objects which are not serialized.
              > >>
              > >>But I have read that setAttribute() makes the object serializable.
              > >>
              > >>So, does it mean that all the objects stored in bigObject also will
              > >>be serialized
              > >>?
              > >>
              > >>thanks,
              > >>jyothi
              > >
              >
              

  • Object serialization failure during OutOfMemory error (EOFException)

    Hello all,
    We are seeing a very strange situation when writing a serializable object to a flat file, specifically during an OutOfMemory condition. Our application saves the state of an object if an error occurs, and retries at a later point by reviving the object from its serialized form. We recently encountered a series of EOFExcetions when trying to reload the serialized object. Looking at the serialized data, we see that the file is indeed incomplete, and that it appears to be the serialized representation of the data contained within the object that is missing (the structure of the object appears to be stored in the serialized file, but not the runtime data).
    The code that produces and consumes these serialized objects is used in a variety of locations, and even in the case where these EOF errors occurred usually works as expected. The difference appears to be that the error condition which lead to the object serialization was in-fact an OutOfMemory error. That is, we had an OOM error elsewhere in our application, which caused our objects to be serialized to disk. During this serialization process we end up with corrupt (incomplete) serialization data.
    So.. the question is: Is it possible that the OutOfMemory situation causes the JVM to incorrectly serialize an object (without an error), and specifically to omit runtime data (variables) from the serialized form of the object?
    Thanks/

    jasonpolites wrote:
    So.. the question is: Is it possible that the OutOfMemory situation causes the JVM to incorrectly serialize an object (without an error), and specifically to omit runtime data (variables) from the serialized form of the object?you're sure that the serialization process completed without an error? how do you know the the OOME did not cause the serialization to fail (because the serialization process itself will require more memory, hence if it is happening while the system is near the memory peak, it is likely to fail as well)? generally, when a jvm starts throwing OOME's all bets are off. failures in random places can easily cause the whole internal state of a system to become invalid.

  • Object serialization EOFException

    Essentially what I want to do is write to an object to a file. The program can terminate and then when I start the program again, it will read the object from the file and restore the program's original state before it was terminated.
    I get an EOFException with this code
    //insert code that gets input which will be stored in a hashtable
    //save Hashtable in "data.dat" using ObjectOutputStream
    //program terminates
    //program is re-ran again and checks for existing file
    File f = new File("data.dat");
    if(f.exists()){
           ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
           Object obj = ois.readObject(); //EOF exception occurs here
    }I know the above code works if I write the Hashtable and then read it back immediately without terminating in between. Am I missing something? Can object serialization be used in such a way that I can restore a program's original state before it was terminated?

    Sorry, I led you to believe that the actual class itself was going to be written to a file. I meant to say that the Hashtable in the class should be written to a file and then later on when I start the program again, it will restore the Hashtable to it's original state.
    My writing coding is something like this:
    Hashtable accounts = new Hashtable();
    //do stuff to the hashtable
    FileOutputStream fos = new FileOutputStream("data.dat");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(accounts);
    //Program can be terminated from this point
    //there is no further oos.writeObject() if it wasn't terminated
    //immediately after the above writeObject() call
    //Program is ran again and at startup it checks for existing file
    File f = new File("data.dat");
    if(f.exists()){
    ObjectInputStream ois = new ObjectInputStream(new FileInpuStream(f));
    Object obj = obj.readObject(); //EOFException occurs here
    }Again those lines work perfectly fine if I do not terminate the program and I force it to check for an existing file. If I terminate, it's almost as if the program thinks there's nothing in "data.dat" eventhough it's obvious by my code that I did write something to "data.dat".

  • Need algrithim for constantly making new objects

    How would I go about making an object and then remake the same object again but with a different name.
    here is the problem:
    for(int i=0;i<23;i++){
    //But i want the second time to run around and create a Printer object
    //named something else not printer.
    Printer printer = new Printer();
    any help would be appreciated

    Well I my case I'm trying to get different names. So I guess the easist thing I can do is to make an array. But then it brings me to this question,
    This is my class:
    import java.awt.*;
    public class Printer {
         public void init(){
         public void paint(Graphics g,String string,int x,int y){
              g.drawString(string,x,y);
    }if I wanted to make an array out of it like so:
    Printer[] print = new Printer[xAmount];It says nullPointerException when I try to access the class's function by doing this:
    print[0].paint(g,"test",2,3);What can I put in print[0] to make it not null? I mean you can put numbers and letters. (
    Message was edited by:
    jkhoa
    Message was edited by:
    jkhoa

  • Object Serialization and IO Error

    Hi,
    I am trying to serialize 3 hashtable objects, with serializable keys and elements, on to disk. Here is a snippet of the code disk management code:
         public void loadData(StoreManager s_man) {
              // read from disk
              Hashtable o = (Hashtable)readObjects();
              Hashtable c = (Hashtable)readClasses();
              Hashtable i = (Hashtable)readIndex();
              //Hashtable e = (Hashtable)readEnv();
              Integer id = (Integer)readEnv();
              // set the store manager objects
              s_man.setObjects(o);
              s_man.setClasses(c);
              s_man.setIndex(i);
              Env.setCurrentID(id);
    Here is what the readObject method looks like:
         * Deserialize disk data and return Object data.
         public synchronized Object readObjects() {
              if (!objectdatafile.exists())
                   return null;
              Object o = new Object();
              try {
                   FileInputStream istream = new FileInputStream(objectdatafile);
                   ObjectInputStream pack = new ObjectInputStream(istream);
                   o = pack.readObject();
                   istream.close();
              catch (Exception e) {
                   e.printStackTrace();
    Occasionally, when starting the program (i.e. when it initially reads all data from disk), I am getting the following exceptions:
    java.io.EOFException
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2426)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1238)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:325)
    at java.util.Hashtable.readObject(Hashtable.java:799)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:42)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:28)
    at java.lang.reflect.Method.invoke(Method.java:327)
    at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:812
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1736)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
    639)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1267)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:325)
    at DiskManager.readObjects(DiskManager.java:165)
    at DiskManager.loadData(DiskManager.java:42)
    at LoadDataAction.run(LoadDataAction.java:30)
    at java.lang.Thread.run(Thread.java:539)
    java.lang.ClassCastException: java.lang.Object
    at DiskManager.loadData(DiskManager.java:42)
    at LoadDataAction.run(LoadDataAction.java:30)
    at java.lang.Thread.run(Thread.java:539)
    I would like to repeat that I am not getting this error everytime, but about once every two runs. Please share your feelings about possible errors I am making or if there is an inherent bug with serialization of hashtables.
    Thanks

    the java.io.EOFException looks like you did not properly close the stream on writing. to me this seems like there is an error in the writing code rather than the reading code. although there are some things you can improve...
    robert

  • How Would One Go About Making an Object Rotate to Face in Direction of Mouse?

    I'm just a teenager who happens to have Flash as part of CS4 Production Premium, which I got as a gift.  I don't have any training or previous experience in Flash, and have only just in the past few month been looking into what ActionScript is.  I've just been fiddling with Flash in my spare time, just as something to do, and am working on making very basic computer games.  Currently I am trying to make a very basic top-down shooter computer game.  I've gotten it to where I can move the player (a circle with an arrow on the edge) in eight directions using the standard FPS movement keys (W,A,S,D) and make it move faster for a limited time by holding down the SHIFT key. 
    But now I've come to a standstill.  I am trying to make the player rotate in the direction of the mouse cursor (made to look like crosshairs) so that the player can move in any of the eight directions and aim in any direction at the same time.  I've searched the Internet for hours on end, looking for anything that might help, but not a single Web page section relates to this kind of thing.  So now I'm giving up on searching for a help article, and am making one instead.  Is there anyone that's successfully done this kind of thing before?  Or at least someone who actually knows how to properly use ActionScript 3.0 and can figure it out themselves, then tell me what they did?   (In the meantime, I've made it so that the player rotates and faces in the direction he is traveling in.)
    I've attatched all the code that I've typed to make the game work, so that anyone can look at it and tell me if I'm doing something wrong already.  I've only been learning ActionScript by figuring it out on my own as I go (watched a few videos I have on a disc too), and in the case of this game, I've just been making is up as I go, so to all of you people who actually know this stuff pretty well, this code is probably going to look nasty.

    I pasted it to the bottom of my code on the main timeline (correcting it for my use), but I get this message in the Compiler Errors window:
    Warning: 1090: Migration issue: The onMouseMove event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0.  You must first register this handler for the event using addEventListener ( 'mouseMove', callback_handler).
    So what do I do about that?  (again, I'm just a beginner, so I don't know what any of this means)
    (attached is a snapshot of the various objects refered to in the code.  also the original code is attached to the original post.  in case these help at all.)

  • Object Serialization(Materialization and Dematerialization)

    I've encountered some issues with mapping my objects to an RDBMS and am hoping for some advice.
    I've tried various O/R mapping frameworks like Castor(too complex and too slow for my liking), JRF(nice but very repetitive and difficult to extend) and then some, but have yet to find one which I'm comfortable with building an application on.
    Instead, I've chosen to do it the low-tech way, with each domain class, say Book for instance, having a Broker class which knows how to communicate with the chosen form of persistence. So, since I chose an RDBMS, Book class has a BookRelationalBroker class which knows how to materialize and dematerialize Book objects to and from a RDBMS. If so required, I can plug in a BookXMLBroker which knows how to serialize the object in the form of an xml data file.
    I've also implemented a primitive object caching system which (when enabled), caches objects requested so we only have to materialize it from the db once.
    Here are 2 issues I have with my system:
    It is amazingly tedious (not to mention inefficient) to recreate the entire object from the database. This is even more so because I've implemented the Event Notification pattern, such that when say a book is deleted, the members who have reserved it are notified. The whole point of the Event Notification mechanism is so that the object being watched does not need to know of the objects which need to be notified on a state change. However, I've found it necessary to re-attach all the listeners on an object when it is materialized from the DB, defeating the purpose of the pattern.
    Complex object relationships are mapped poorly and recursive materialization leads to slow response times. If a Group object has a Vector of Members and other Groups, then whenever a Group object is materialized, all its constituent Members and Group objects also need to be materialized. (I understand O/R frameworks solve this through lazy instantiation)
    I studied the Jive2 architecture and found that they approached this problem by accessing the DB directly for any complex object relationships. In other words, the Group object does not actually contain a Vector of Members and Groups. Instead, it has a method called say getMembers() which proceeds to retrieve the necessary data from the DB and then materialize these objects.
    I'm not too excited about this approach for 2 reasons:
    How object-oriented is this approach? Seems more like database-oriented programming to me.
    Every call to retrieve Members necessitates a call to the DB. The data isn't cached with the Group object because the Group object does not actually contain the necessary reference to the Members and Groups.
    Can anyone shed some light on this topic?

    How object-oriented is this approach? Seems more like database-oriented programming to me. There is a reason people still use Relational databases rather than OO DBs. First, is that the vast majority of data in the real world maps easily to a relational model, consequently there is no advantage to a OO model. Second, either because of this or simply because OO models are not computationally simple, OO databases tend to be slower than relational DBs.
    It sounds like you are trying to implement a OO DB model using a relational database. So you basically end up with two problems. The DB is not optimized for OO models, and you have to find a way to map it in the OO model itself. And this is slow and messy.
    To solve the slowness problem you could, just like EJB servers, cache the data in memory. Lot of work but if you want to do it then have fun.
    The second way is to give up. Realize that your data model is not inherently OO'd and just implement it efficiently as a relational model. Then provide an interface that loads it into the OO model. And where needed add pass through logic to allow the database itself to do things it is really good at - like queries.

  • Script for making an object the artboard size.

    I am looking for some help on trying to make an object the exact size of the artboard.  This is something I do on a daily basis for several different reasons and it would be very helpful if this can happen automatically for whatever size the artboard may be.  As I understand it the only way is with a script but I have no experience with making illustrator scripts, im definately no programmer.  I have set up quickkeys in the past to copy from the artboard inputs when you are on the artboard tool but these round to the nearest .01 and this is not accurate enough for what I am working with.  Also if I do this with multiple pages open illustrator is very slow to respond to the artboard tool.  If anyone has any idea where to start or has seen other such scripts I would greatly appreciate it.  Thank you.
    Below is a script that I saw on here that I believe may contain what I need but now knowing programming I have no idea where to start on editing.  All I need is the part where an object is placed on the artboard that is the exact same size as the artboard.  If anyone can advise on editing I would greatly apprecaite it.
    #target illustrator
    function main() {
         if (app.documents.length == 0) {
              alert('Open a document before running this script');
              return; // Stop script here no doc open…
         } else {
              var docRef = app.activeDocument;
              with (docRef) {
                   if (selection.length == 0) {
                        alert('No items are selected…');
                        return; // Stop script here with no selection…
                   if (selection.length > 1) {
                        alert('Too many items are selected…');
                        return; // Stop script here with selection Array…
                   } else {                   
                        var selVB = selection[0].visibleBounds;
                        var rectTop = selVB[1] + 36;
                        var rectLeft = selVB[0] - 36;
                        var rectWidth = (selVB[2] - selVB[0]) + 72;
                        var rectHeight = (selVB[1] - selVB[3]) + 72;              
                        selection[0].parent.name = 'CC';
                        selection[0].filled = false;
                        selection[0].stroked = true;
                        var ccColor = cmykColor(0, 100, 0, 0);              
                        var ccCol = spots.add()
                        ccCol.name = 'CC';
                        ccCol.color = ccColor;
                        ccCol.tint = 100;
                        ccCol.colorType = ColorModel.SPOT;
                        var cc = new SpotColor();
                        cc.spot = ccCol;                   
                        selection[0].strokeColor = cc;
                        selection[0].strokeWidth = 1;                   
                        var tcLayer = layers.add();
                        tcLayer.name = 'TC';
                        var padBox = pathItems.rectangle(rectTop, rectLeft, rectWidth, rectHeight, false);
                        padBox.stroked = false;
                        padBox.filled = true;
                        var tcColor = cmykColor(0, 100, 90, 0);         
                        var tcCol = spots.add()
                        tcCol.name = 'TC';
                        tcCol.color = tcColor;
                        tcCol.tint = 100;
                        tcCol.colorType = ColorModel.SPOT;
                        var tc = new SpotColor();
                        tc.spot = tcCol;
                        padBox.fillColor = tc;    
                        padBox.move(docRef, ElementPlacement.PLACEATEND);
                        artboards[0].artboardRect = (padBox.visibleBounds);
                        redraw();
                        rectWidth = (rectWidth-72)/72;
                        rectWidth = roundToDP(rectWidth,1);
                        rectHeight = (rectHeight-72)/72;
                        rectHeight = roundToDP(rectHeight,1);
                        var textString = rectWidth + ' x ' + rectHeight;
                        prompt('Copy Me', textString);
    main();
    function roundToDP(nbr, dP) {
         dpNbr = Math.round(nbr*Math.pow(10,dP))/Math.pow(10,dP);
         return dpNbr;
    function cmykColor(c, m, y, k) {
         var newCMYK = new CMYKColor();
         newCMYK.cyan = c;
         newCMYK.magenta = m;
         newCMYK.yellow = y;
         newCMYK.black = k;
         return newCMYK;

    Thanks to CarlosCanto for the original script, it was very a very helpful starting point to optimize one of our workflows. We customized it a bit to maintain the aspect ratio (just takes the greater of the width / height and scales proportionally to the artboard size), and also center up the object in the middle of the artboard once scaling is complete. I hope it is helpful to someone:
    #target Illustrator
    //  script.name = fitObjectToArtboardBounds.jsx;
    //  script.description = resizes selected object to fit exactly to Active Artboard Bounds;
    //  script.required = select ONE object before running; CS4 & CS5 Only.
    //  script.parent = carlos canto // 01/25/12;
    //  script.elegant = false;
    var idoc = app.activeDocument;
    selec = idoc.selection;
    if (selec.length==1)
            // get document bounds
            var docw = idoc.width;
            var doch = idoc.height;
            var activeAB = idoc.artboards[idoc.artboards.getActiveArtboardIndex()]; // get active AB
            docLeft = activeAB.artboardRect[0];
            docTop = activeAB.artboardRect[1];
            // get selection bounds
            var sel = idoc.selection[0];
            var selVB = sel.visibleBounds;
            var selVw = selVB[2]-selVB[0];
            var selVh = selVB[1]-selVB[3];
            var selGB = sel.geometricBounds;
            var selGw = selGB[2]-selGB[0];
            var selGh = selGB[1]-selGB[3];
            // get the difference between Visible & Geometric Bounds
            var deltaX = selVw-selGw;
            var deltaY = selVh-selGh;
            if (sel.width > sel.height) {
                var newWidth = docw-deltaX;
                var ratio = sel.width / newWidth;
                sel.width = newWidth; // width is Geometric width, so we need to make it smaller...to accomodate the visible portion.
                sel.height = sel.height * ratio;
            } else {
                var newHeight = doch-deltaY;
                var ratio = sel.height / newHeight;
                sel.height = newHeight;
                sel.width = sel.width / ratio;
            sel.top = (doch / 2) - (sel.height / 2);
            sel.left = (docw / 2) - (sel.width / 2);
        else
                alert("select ONE object before running");

  • Bussiness object serialization problem

    Hi, I have a little problem with serialization, when I want to create xml from Business object. Example:
    MyBoObject obj = new MyBoObject ();
    obj.atr1 = "aaa";
    obj.atr2 = "bbb";
    String xml = DynamicXml.createXmlTextFor(object : obj, topLevelTag : "something");
    display(xml);
    And displayed result is:
    <something>
    <atr2>bbb</atr2>
    </something>
    atr1 is attribute, which is inherited from db table.
    atr2 is atribute, which I created (it is not inherited from db table)
    Whole problem is, that it only serialize atr2 - from some reason it completely ignores atr1 and his value.
    Like I can't serialize attributes, which are inherited from db table.
    But when I created new attribute atr2 in my Business Object (which is not inherited from db table), everything work ok. Where's the problem? I read docs, but found nothing...
    Edited by: user12189610 on Nov 9, 2009 2:42 AM
    Edited by: user12189610 on Nov 9, 2009 2:46 AM

    If you need a simple project that duplicates this problem for customer support, here's where I put one: http://www.4shared.com/file/181611971/d21e9444/_2__DynamicXMLBug.html.
    Have them import the project, start Studio's Engine, login as "test" and start the Workspace. Create a work item instance and then run the work item when it reaches the "Test" activity. When you run the logic, you'll see this displayed:
    <?xml version="1.0" encoding="UTF-8"?>
    <poHeir xmlns="http://bea.com/albpm/DynamicXml/version/2.0">
        <nameForPO>Dan</nameForPO>
    </poHeir>They should note that only the "nameForPO" tag is created by the DynamicXml.createXmlTextFor() method. "nameForPO" is an attribute I manually added to the XML Heir BPM Object. The attributes of the inherited heir (e.g. "poHeir.orderDate" and "poHeir.billTo") are not included as tags in the generated XML even though these attributes have been set in the logic.

Maybe you are looking for