0

My IDL looks like:

interface TransactionResource {
    void prepare() raises (NotPreparedException);
    void commit() raises(TransactionException);
    void rollback() raises(TransactionException);
};
interface ManageDemand : TransactionResource {
    string createDemand(in string demand);
};

interface ManageAccount : TransactionResource {
    string createDemand(in string demand);
};

I create the ManageDemand distributed object on Server , I make it persistent, and it's reachable through the CORBALOC address.

On my client I have:

Object obj = orb.string_to_object(url.toString());
TransactionResource transactionResource = null;
if (obj._is_a("IDL:transaction/ManageDemand:1.0")){
    transactionResource = ManageDemandHelper.narrow(obj);
} else {
    transactionResource = ManageAccountHelper.narrow(obj);
}

When I try to test if the transactionResource object (distributed reference) is an instance of ManageDemand, the result is true.

But if I invoke Transaction object, defined like this:

interface Transaction {
    ProxyStream addResource(in TransactionResource resource);
}

And I pass in parameter the transactionResource distributed reference, in this method when I test if this resource is an instance of ManageDemand, the result is false.

What I have to do, to recognize that this transactionResource is instance of ManageDemand on the addResource method?

Saad Lamarti
  • 300
  • 1
  • 5
  • 15
  • I know how the method. This not respond my question – Saad Lamarti Dec 19 '13 at 16:26
  • Perhaps you should explain your question better. – Hot Licks Dec 19 '13 at 16:47
  • My question is how can I recognize that the transactionResource is instance of ManageDemand, when I pass it on addResource method (For Transaction object) ? Now when I test the instanceOf the result is false, And I have to detect that this transactionResource is instance of ManageDemand – Saad Lamarti Dec 19 '13 at 16:51
  • If `instanceof ManageDemand` is false then the object is not a Java ManageDemand object. (At least not one loaded by the same class loader as the current method -- you can get some class loader oddities with some of the "fancier" execution environments.) – Hot Licks Dec 19 '13 at 16:57
  • (I have no idea what `obj._is_a("IDL:transaction/ManageDemand:1.0")` is doing -- it's not standard Java stuff.) – Hot Licks Dec 19 '13 at 16:59
  • I think you code is doing something wrong in `ManageDemand transactionResource = null;`. The code: `ManageAccountHelper.narrow()` returns a ManageAccount not a ManageDemand. – Makah Dec 19 '13 at 17:37
  • If the instanceof didn't work, I think you can use obj._is_a() – Makah Dec 19 '13 at 17:38

1 Answers1

0

I don't know how you test if the transactionResource object(TransactionResource resource) is an instance of ManageDemand, in the 'addResource' method of your Transaction Servant implementation.
I guess maybe, you test it just like below:

if(resource instanceof ManageDemand ) {
  System.out.println("Yes, ManageDemand");
} else {
  System.out.println("No, ManageDemand");
}

If yes, then you wont' get the correct answer, since the 'resource' object obtained from the client is "_TransactionResourceStub" class, therefore, you can't use the 'instanceof' method to test.
However, you still can use the '_is_a' method to test it ,like below:

if (resource._is_a("IDL:transaction/ManageAccount:1.0")){
    System.out.println("Yes");
} else {
    System.out.println("No");
}

Then, you'll get the correct answer.

jawee
  • 271
  • 2
  • 11