Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-07-11
3
Medium Priority
?
229 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:anuchoudhry
  • 2
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 7145929
>>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
 
LVL 86

Accepted Solution

by:
CEHJ earned 80 total points
ID: 7148451
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
 
LVL 35

Expert Comment

by:girionis
ID: 8917208
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question