CORBA Integration

Creating an extension with CORBA

The full source code for this example can be found in the ExCORBA example in the XMLFoundation

CORBA implementations can be done in Java or C++.  This framework supports either and for many situations both within the same application.  CORBA breaks down the language barrier allowing Java applications to easily, and natively deal with C++ objects.  This example details the creation of C++ CORBA objects – The Java implementation is nearly identical further blurring the lines between Java/C++ within the same project.

The C++ CORBA implementation will bridge into J2EE Application servers everywhere, it will work for any ORB but a few of the most popular ones have been tested, and the makefiles are included.

Borland/Enterprise Studio      Visibroker

IONA/iPortal Enterprise           Orbix

BEA/Weblogic Enterprise            ObjectBroker (with or w/o Tuxedo)

The big picture:

This example extends the ORB to provide native XML accessors.  The application is based around 1 very simple object type.  It has a unique integer we call a CustomerID and a string we call a CustomerName.  Each customer may contain 0 to n references to another object of the same type as it’s self, a MyCORBAObject.  This would model something like a list of Customers that were referred by ‘this’ customer.

The IDL looks like this:

module ExCORBA
{
interface MyCORBAObject
{
void getXMLState(out string s);
void setXMLState(in string s);
void setState(in string s, in long l);
void addSubObject(in string s, in long l);
void delSubObjects();
MyCORBAObject getSubObjectIOR(in long l);
void dumpState(out string s);
};
};

The client application manipulates the object model  through 12 operations where

every even operation is just a getXMLState() to see what’s going on in the server.

The client obtains an initial IOR from a server serialized IOR upon server startup.

1. Assign some state in a native CORBA call

This is a typical CORBA data assignment operation.  Two values are set in the object.

The code looks like this on the client:

           CustObject1->setState(“Root”,777);

and simply assigns the two members on the server.

2. View the state of the object in XML

This uses the XML accessor to return the state of the object.

The code looks like this on the client:

CORBA::String_var s;
CustObject1->getXMLState(s);

and looks like this on the server:

void ExCORBAImpl::getXMLState( CORBA::String_out s)
{
const char *p = ToXML();
s = CORBA::string_dup(p);
}

and the result is this:

<MyCORBAImpl>
<CustomerID>777</CustomerID>
<CustomerName>Root</CustomerName>
< /MyCORBAImpl>

The tag names are configured by the object like this:

void ExCORBAImpl::MapXMLTagsToMembers() {
MapMember(&_nCustID, “CustomerID”);
MapMember(&_strCustName, “CustomerName”, &gGenericStrHandler);
MapMember(&m_lstCMyImplObjs, “MyCORBAImpl”, &gGListHandler,0);

}

3. Update the state of the object through XML

Step 1 used a typical object accessor to assign the state.  Step 3 accomplishes the same through XML.

On the client:

CustObject1->setXMLState(“<MyCorbaImpl><CustomerName>SuperUser</CustomerName></MyCorbaImpl>”);

On the Server:

void ExCORBAImpl::setXMLState( const char* pzXML ) 

{
FromXML( pzXML );

}

4. View the modified object state in XML

This is the exact same code client and server as Step 2.  We’re calling getXMLState() again.

and the result is:

<MyCORBAImpl>
<CustomerID>777</CustomerID>
<CustomerName>SuperUser</CustomerName>
< /MyCORBAImpl>

5. Add CORBA Sub-Objects through XML 

Step 5 is a lot like step 3 where we updated the name “root” to “SuperUser” through an XML assignment.  This time we’ll add an object reference.

the client code looks like this:

CustObject1->setXMLState(
“<MyCorbaImpl>”
“<MyCorbaImpl>”
“<CustomerID>123</CustomerID>”
“<CustomerName>Al Gore</CustomerName>”
“</MyCorbaImpl>”
“<MyCorbaImpl>”
“<CustomerID>456</CustomerID>”
“<CustomerName>George Bush Jr.</CustomerName>”
“</MyCorbaImpl>”
“</MyCorbaImpl>”);

The server code is the same as step 3.

6. (like 4 & 2) now view the object’s XML state 

the result is:

<MyCORBAImpl>
<CustomerID>777</CustomerID>
<CustomerName>SuperUser</CustomerName>
<MyCORBAImpl>
<CustomerID>123</CustomerID>
<CustomerName>Al Gore</CustomerName>
</MyCORBAImpl>
<MyCORBAImpl>
<CustomerID>456</CustomerID>
<CustomerName>George Bush Jr.</CustomerName>
</MyCORBAImpl>
< /MyCORBAImpl>

7. Get a CORBA object reference for object instance 456

On the client the code looks like this:

ExCORBA::MyCORBAObject_var CustObject2;
CustObject2 = CustObject1->getSubObjectIOR(456);

and on the server we walk the list of objects and return the first one that matches the supplied CustomerID like this:

you may choose to use template calls and remove the type casting:

ExCORBA::MyCORBAObject_ptr ExCORBAImpl::getSubObjectIOR(CORBA::Long CustomerID)

{
GListIterator it(&m_lstCMyImplObjs);
while(it())
{
XMLObject *pO = (XMLObject *)it++;
ExCORBAImpl*pIO = (ExCORBAImpl*)pO->GetInterfaceObject();
if (pIO->GetCustomerID() == CustomerID)
{
return pIO->_this();
break;
}
}
return 0;
}

8. Exactly like steps (2, 4 & 6) except we are using the Object ref returned by step 7.

the result is:

<MyCORBAImpl>
<CustomerID>456</CustomerID>
<CustomerName>George Bush Jr.</CustomerName>
< /MyCORBAImpl>

9. Add a Sub-Object without using XML
In the same way we used a traditional member assignment in step 1, we can create a new object reference to demonstrate the two models working together.  On the client:

CustObject1->addSubObject(“Michelangelo”,1475);

and on the server the code looks like this:

void ExCORBAImpl::addSubObject( const char* s, CORBA::Long l )

{
ExCORBAImpl *p = new ExCORBAImpl;
p->_nCustID = l;
p->_strCustName = s;
m_lstCMyImplObjs.AddLast((XMLObject *)p);
}

10. Get an object reference to the object created in step 9 and print it’s state in XML.

client code:

CustObject2 = CustObject1->getSubObjectIOR(1475); // exactly like step 7
CustObject2->getXMLState(s); // like steps (2, 4, 6, and 8) using the new reference.

and the result is:

<MyCORBAImpl>
<CustomerID>1475</CustomerID>
<CustomerName>Michelangelo</CustomerName>
< /MyCORBAImpl>

11. Deleting Sub objects.

All objects, no matter how they were created, are destroyed the same.

on the client:

CustObject1->delSubObjects();

on the server:

void ExCORBAImpl::delSubObjects() IT_THROW_DECL((CORBA::SystemException))
{
GListIterator it(&m_lstCMyImplObjs);
while(it())
{
XMLObject *pO = (XMLObject *)it++;
pO->DecRef();
}
m_lstCMyImplObjs.RemoveAll();
}

This the CORBA Implementation/Interface and XMLObject are all one in the same.  This cleans up the whole mess.

12.  To see that step 11 worked, view the XML state like we did in 2,4,6,8, & 10

The results are:

<MyCORBAImpl>
<CustomerID>777</CustomerID>
<CustomerName>SuperUser</CustomerName>
< /MyCORBAImpl>

The complete source and makefiles are located in the Examples/c++/ExCORBA directory.

 © 2015 United Business Technologies, Inc. All Rights Reserved.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s