Response to mr.CEHJ's response to my previous question on serializing problem...

Hello sir,
 The JCO contains JCO.Client as its static inner class.I have wrriten the code...as..below..as

import com.sap.mw.jco.*;

import java.io.*;



public class AdapterJCOClient extends JCO implements Serializable
{
        JCO.Client client;


          AdapterJCOClient(String client,String user,String pass,String lang,String host,String system)

          {
                    super();

                this.client= super.createClient(client,user,pass,lang,host,system);

          }


}

would the JCO.Client  be serialized.
The constructor code where I am using this class(AdapterJCOClient) is as follows.....


public class AdapterManagedConnection
    implements ManagedConnection, Serializable
{
    public AdapterLocalTransaction theAdapterLocalTransaction;
    public ConnectionEvent theConnectionEvent;
    public ConnectionEventListener theConnectionEventListener;
    public AdapterJCOConnectionMetaData theAdapterJCOConnectionMetadata;
    public AdapterConnectionEventListener theAdapterConnectionEventListener;
    public AdapterManagedConnectionMetaData theAdapterManagedConnectionMetaData;
    PrintWriter logWriter;
    String sUser;
    String sPass;
    String sLang;
    String sSystem;
    String sHost;
    String sClnt;
    com.sap.mw.jco.JCO.Client adConnection;

    public AdapterManagedConnection(AdapterManagedConnectionFactory adaptermanagedconnectionfactory, PasswordCredential passwordcredential)
    {
        sUser = "";
        sPass = "";
        sLang = "";
        sSystem = "";
        sHost = "";
        sClnt = "";
        System.out.println("1");
        sUser = passwordcredential.getUserName();
        System.out.println("2");
        sPass = new String(passwordcredential.getPassword());
        System.out.println("3");
        sLang = adaptermanagedconnectionfactory.getLanguage();
        System.out.println("4");
        sSystem = adaptermanagedconnectionfactory.getSystem();
        System.out.println("5");
        sHost = adaptermanagedconnectionfactory.getHost();
        System.out.println("7");
        sClnt = adaptermanagedconnectionfactory.getClient();
        System.out.println("8");
        try
        {
            System.out.println("ac 1");
            AdapterJCOClient ac = new AdapterJCOClient();//sClnt, sUser, sPass, sLang, sHost, sSystem);
            System.out.println("ac 2");
            adConnection = ac.client;
            System.out.println("9");
            adConnection.connect();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }

    public PrintWriter getLogWriter()
        throws ResourceException
    {
        return logWriter;
    }

    public ManagedConnectionMetaData getMetaData()
        throws ResourceException
    {
        return (ManagedConnectionMetaData)new AdapterManagedConnectionMetaData(this);
    }

    public com.sap.mw.jco.JCO.Client getAdconnection()
    {
        return adConnection;
    }

    public Object getConnection(Subject subject, ConnectionRequestInfo connectionrequestinfo)
        throws ResourceException
    {
        AdapterJCOConnection adapterjcoconnection = null;
        sUser = adConnection.getUser();
        Set set = subject.getPrivateCredentials();
        PasswordCredential apasswordcredential[] = (PasswordCredential[])set.toArray();
        for(int i = 0; i < apasswordcredential.length; i++)
        {
            String s = apasswordcredential[i].getUserName();
            if(s.equals(sUser))
                adapterjcoconnection = new AdapterJCOConnection(this);
            else
                adapterjcoconnection = null;
        }

        return adapterjcoconnection;
    }

    public void destroy()
        throws ResourceException
    {
        JCO.releaseClient(adConnection);
    }

    public void cleanup()
        throws ResourceException
    {
        adConnection.disconnect();
    }

    public void associateConnection(Object obj)
        throws ResourceException
    {
        ((com.sap.mw.jco.JCO.Client)obj).disconnect();
    }

    public void removeConnectionEventListener(ConnectionEventListener connectioneventlistener)
    {
        theConnectionEventListener = connectioneventlistener;
    }

    public void setLogWriter(PrintWriter printwriter)
    {
        logWriter = printwriter;
    }

    public void addConnectionEventListener(ConnectionEventListener connectioneventlistener)
    {
        theConnectionEventListener = connectioneventlistener;
    }

    public XAResource getXAResource()
        throws ResourceException
    {
        return null;
    }

    public LocalTransaction getLocalTransaction()
        throws ResourceException
    {
        return null;
    }

    public void closeAdapterJCOConnection()
    {
        ConnectionEvent connectionevent = new ConnectionEvent(this, 1);
        theConnectionEventListener.connectionClosed(connectionevent);
    }
}

 I tried but the weblogic server does'nt deploy the rar file.There is an exception at runtime
Kindly resolve this for mee...
Regards
Anuradha
anuchoudhryAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CEHJConnect With a Mentor Commented:
Although I haven't got a firm grip on what your situation is, I made the following as a general example, which you can possibly adapt:

import java.io.*;

/**
 * For a given inner class X, that needs to be serialized,
 * but is not itself serializable, show that its data can be
 * serialized by creating a subclass Y that can be serialized.
 *
 * @author     CEHJ
 * @created    12 July 2002
 */
public class MakeSerializable {
     X user;


     /**
      * The main program for the MakeSerializable class
      *
      * @param  args  Not used
      */
     public static void main(String[] args) {
          MakeSerializable ms = new MakeSerializable();
      /**
       * Although we call for a class X, the member variable 'user'
          * actually contains a reference to subclass Y, so it can
          * be serialized.
          */
     
          ms.user = ms.makeUser("", "nixon", "watergate", "", "", "");          
          ms.serialize(ms.user);
     }


     
     public X makeUser(String client, String user, String pass, String lang, String host, String system) {
          // Note that we actually return an instance of subclass Y here
          return new Y(client, user, pass, lang, host, system);
     }


     /**
      * This is where we need to serialize X,
      * which is unserializable.
      *
      * @param  user  Description of Parameter
      */
     public void serialize(X x) {
          try {
               ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("x.ser"));
               out.writeObject(user);
               out.close();
          } catch (IOException e) {
               e.printStackTrace();
          }
     }


     /**
      * In this case, X represents a client
      * connection, but the general pattern
      * holds true for any other X.
      *
      * @author     protean
      * @created    12 July 2002
      */
     static class X {
          String client;
          String user;
          String pass;
          String lang;
          String host;
          String system;

          public X(String client, String user, String pass, String lang, String host, String system) {
               this.client = client;
               this.user = user;
               this.pass = pass;
               this.lang = lang;
               this.host = host;
               this.system = system;
          }

     }


     /**
      * Extends the unserializable X to allow
      * an 'instanceof' X to be serialized.
      *
      * @author     CEHJ
      * @created    12 July 2002
      */
     static class Y extends X implements Serializable {
          // The following member won't be serialized as it's marked transient
          transient String doNotCopy = "This won't be serialized";
          String copyUser;
          String copyPass;


  /**
      * In this case, Y represents a client
      * connection, but the general pattern
      * holds true for any other Y.
      *
      * @author     protean
      * @created    12 July 2002
      */
     
          public Y(String client, String user, String pass, String lang, String host, String system) {
               super(client, user, pass, lang, host, system);
               copyUser = this.user;
               copyPass = this.pass;
          }
     }
}

0
 
CEHJCommented:
>>I tried but the weblogic server does'nt deploy the rar file.'managing exception...' at runtime....

I don't really understand the above I'm afraid.

Can you post the constructor source code for the below?:

JCOClient(String client,String user,String pass,String lang,String host,String system){ ? }


Can you also give the code where you create an instance of AdapterJCOClient?
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to CEHJ

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.