Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.

747 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

13 Experts available now in Live!

Get 1:1 Help Now