Solved

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

Posted on 2002-07-11
3
223 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 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 96
Python Assistance 7 79
eclipse shortcuts 9 54
object oriented programming comparison 5 69
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

815 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now