CORBA application fails to compile
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   tomash_spring
Posted On:   Saturday, August 16, 2008 04:33 AM

Hi all, i have the following CORBA application which fails to compile Server side app: -------------------------------------------------------c package mh2000.IDLstock.server; import mh2000.IDLstock.common.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import java.util.*; import mh2000.IDLstock.common.*; class StockServant extends _StockServerInterfaceImplBase { String stockNames[] = { "NY - Dow Jones", "HK - Hang Sang", "TA - Habursa", "London - FTSE", "Frankfurt - DKS", "Tokio - NK" }; float stockValues[]   More>>

Hi all,
i have the following CORBA application which fails to compile

Server side app:
-------------------------------------------------------c
package mh2000.IDLstock.server;
import mh2000.IDLstock.common.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.util.*;
import mh2000.IDLstock.common.*;
class StockServant extends _StockServerInterfaceImplBase
{
String stockNames[] =
{ "NY - Dow Jones", "HK - Hang Sang", "TA - Habursa",
"London - FTSE", "Frankfurt - DKS", "Tokio - NK"
};

float stockValues[] = { 34.5f, 22f, 45.6f, 112f, 77.4f, 17f};
Hashtable stockTable = new Hashtable();

public StockServant()
{
for(int i=0; i
stockTable.put(stockNames[i], new Stock(stockNames[i], stockValues[i]));
}

public String getBestStockName()
{
return "London - FTSE";
}

public StockInterface getUpdate(String stockName)
{
return (Stock)stockTable.get(stockName);
}

public StockInterface getAll()
{
return stockTable;
}

}

public class StockServer
{
public static void main(String args[])
{
try {
// create and initialize the ORB
ORB orb = ORB.init(args, null);

// create servant and register it with the ORB
StockServant stockServerRef = new StockServant();
orb.connect(stockServerRef);

// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);

// bind the Object Reference in Naming
NameComponent nc = new NameComponent("StockServerInterface", "");
NameComponent path[] = {nc};
ncRef.rebind(path, stockServerRef);

// wait for invocations from clients
java.lang.Object sync = new java.lang.Object();
synchronized (sync)
{
sync.wait();
}

}
catch (Exception e) {
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
}
}

which fails with the following error:
javac StockServer.java

StockServer.java:36: incompatible types
found : java.util.Hashtable
required: mh2000.IDLstock.common.StockInterface
return stockTable;
^
Note: StockServer.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

Client side app:
package mh2000.IDLstock.client;

import mh2000.IDLstock.common.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import java.util.*;

public class StockClient
{
Hashtable stockTable;

public void main(String args[])
{
try {
// create and initialize the ORB
ORB orb = ORB.init(args, null);

// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);

// resolve the Object Reference in Naming
NameComponent nc = new NameComponent("StockServerInterface", "");
NameComponent path[] = {nc};
StockServerInterface stockServerRef = StockServerInterfaceHelper.narrow(ncRef.resolve(path));

// call the Stock server object and print results
String stockName = stockServerRef.getBestStockName();
System.out.println("Got the best Stock from server:");
System.out.println(stockName);

StockInterface s = stockServerRef.getUpdate(stockName);
System.out.println("Got stock update:");
System.out.println(s.getName() + ":" + s.getValue());

stockTable = stockServerRef.getAll();
}
catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}

which fails with the following error:
javac StockClient.java

StockServer.java:36: incompatible types
found : java.util.Hashtable
required: mh2000.IDLstock.common.StockInterface
return stockTable;
^
Note: StockServer.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

here is my stock.java class file:
package mh2000.IDLstock.common;

public class Stock extends _StockInterfaceImplBase
implements java.io.Serializable
{
String symbol;
float current;

public Stock(String s, float c)
{
symbol = s;
current = c;
}

public String getName() { return symbol;}
public float getValue() { return current;}
}

and my stock.idl file:
module mh2000
{
module IDLstock
{
module common
{
interface StockInterface
{
string getName();
float getValue();
};

interface StockServerInterface
{
string getBestStockName();
StockInterface getUpdate(in string stockName);
StockInterface getAll();
};
};
};
};

as you can see the idl file contains the getAll method which i
implemented the getAll method in the server side and made the call to the method on the client side

just for notice the application works fine without the getAll method included

appreciate every help i can get here!!!! :)

   <<Less
About | Sitemap | Contact