Solved

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

Posted on 2002-07-11
3
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 20 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

631 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