Commit e534a517 authored by Rodrigo Carneiro Henrique's avatar Rodrigo Carneiro Henrique
Browse files

Inclusão da versão Java do demo Hello.


git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/trunk@85684 ae0415b3-e90b-0410-900d-d0be9363c56b
parent f559076b
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding=".classpath|.project|HelloWorld_Leandro/|HelloWorld_NovoSCS/|lib/" kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/scs.jar"/>
<classpathentry kind="lib" path="lib/openbus.jar"/>
<classpathentry kind="lib" path="lib/openbusidl.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>HelloWorld</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
package demo.hello;
import java.util.Properties;
import openbus.AccessControlServiceWrapper;
import openbus.ORBWrapper;
import openbus.Registry;
import openbus.RegistryServiceWrapper;
import openbus.common.exception.OpenBusException;
import openbusidl.rs.Property;
import openbusidl.rs.ServiceOffer;
import org.omg.CORBA.Object;
import scs.core.IComponent;
import demoidl.hello.IHello;
import demoidl.hello.IHelloHelper;
public class HelloClient {
public static void main(String[] args) throws OpenBusException {
String userLogin = "tester";
String userPassword = "tester";
Properties props = new Properties();
props.setProperty("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
props.setProperty("org.omg.CORBA.ORBSingletonClass",
"org.jacorb.orb.ORBSingleton");
ORBWrapper orb = new ORBWrapper(props);
Registry.getInstance().setORBWrapper(orb);
AccessControlServiceWrapper acs =
new AccessControlServiceWrapper(orb, "localhost", 2089);
Registry.getInstance().setACS(acs);
assert (acs.loginByPassword(userLogin, userPassword));
RegistryServiceWrapper registryService = acs.getRegistryService();
assert (registryService != null);
Property property =
new Property("component_id", new String[] { "HelloComponent:1" });
ServiceOffer[] servicesOffers =
registryService.find(new Property[] { property });
assert (servicesOffers.length == 1);
ServiceOffer serviceOffer = servicesOffers[0];
IComponent component = serviceOffer.member;
Object helloObject = component.getFacetByName("hello");
IHello hello = IHelloHelper.narrow(helloObject);
hello.sayHello();
assert (acs.logout());
System.out.println("Finalizando...");
}
}
package demo.hello;
import java.util.ArrayList;
import org.omg.CORBA.Object;
import org.omg.CORBA.UserException;
import org.omg.PortableServer.POA;
import scs.core.ComponentId;
import scs.core.FacetDescription;
import scs.core.servant.IComponentServant;
public class HelloComponentImpl extends IComponentServant {
private POA poa;
private Object helloObject;
public HelloComponentImpl(POA poa) throws UserException {
this.poa = poa;
HelloImpl helloImpl = new HelloImpl();
helloObject = this.poa.servant_to_reference(helloImpl);
}
@Override
protected ComponentId createComponentId() {
return new ComponentId("HelloComponent", 1);
}
@Override
protected ArrayList<FacetDescription> createFacets() {
FacetDescription facetDescription =
new FacetDescription("hello", "IDL:demoidl/hello/IHello:1.0", helloObject);
ArrayList<FacetDescription> facetDescriptions =
new ArrayList<FacetDescription>();
facetDescriptions.add(facetDescription);
return facetDescriptions;
}
@Override
protected boolean doShutdown() {
return true;
}
@Override
protected boolean doStartup() {
return true;
}
}
package demo.hello;
import demoidl.hello.IHelloPOA;
public final class HelloImpl extends IHelloPOA {
@Override
public void sayHello() {
System.out.println("Hello !!!");
}
}
package demo.hello;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateKey;
import java.util.Properties;
import openbus.AccessControlServiceWrapper;
import openbus.ORBWrapper;
import openbus.Registry;
import openbus.RegistryServiceWrapper;
import openbus.common.CryptoUtils;
import openbus.common.exception.OpenBusException;
import openbusidl.rs.Property;
import openbusidl.rs.ServiceOffer;
import org.omg.CORBA.UserException;
import org.omg.PortableServer.POA;
import scs.core.IComponent;
import scs.core.IComponentHelper;
public class HelloServer {
public static void main(String[] args) throws OpenBusException,
GeneralSecurityException, IOException, UserException {
RSAPrivateKey privateKey = CryptoUtils.readPrivateKey("HelloService.key");
X509Certificate acsCertificate = CryptoUtils
.readCertificate("AccessControlService.crt");
Properties props = new Properties();
props.setProperty("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
props.setProperty("org.omg.CORBA.ORBSingletonClass",
"org.jacorb.orb.ORBSingleton");
ORBWrapper orb = new ORBWrapper(props);
Registry.getInstance().setORBWrapper(orb);
AccessControlServiceWrapper acs = new AccessControlServiceWrapper(orb,
"localhost", 2089);
Registry.getInstance().setACS(acs);
assert (acs.loginByCertificate("HelloService", privateKey, acsCertificate));
POA rootPOA = orb.getRootPOA();
HelloComponentImpl helloComponentImpl = new HelloComponentImpl(rootPOA);
org.omg.CORBA.Object obj = rootPOA.servant_to_reference(helloComponentImpl);
IComponent component = IComponentHelper.narrow(obj);
component.startup();
ServiceOffer serviceOffer = new ServiceOffer(new Property[0], component);
RegistryServiceWrapper registryService = acs.getRegistryService();
assert (registryService != null);
registryService.register(serviceOffer);
orb.run();
assert (acs.logout());
System.out.println("Finalizando...");
}
}
package demoidl.hello;
/**
* Generated from IDL interface "IHello".
*
* @author JacORB IDL compiler V 2.3.0, 17-Feb-2007
* @version generated at Nov 13, 2008 6:53:42 PM
*/
public interface IHello
extends IHelloOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity
{
}
package demoidl.hello;
/**
* Generated from IDL interface "IHello".
*
* @author JacORB IDL compiler V 2.3.0, 17-Feb-2007
* @version generated at Nov 13, 2008 6:53:42 PM
*/
public final class IHelloHelper
{
public static void insert (final org.omg.CORBA.Any any, final demoidl.hello.IHello s)
{
any.insert_Object(s);
}
public static demoidl.hello.IHello extract(final org.omg.CORBA.Any any)
{
return narrow(any.extract_Object()) ;
}
public static org.omg.CORBA.TypeCode type()
{
return org.omg.CORBA.ORB.init().create_interface_tc("IDL:demoidl/hello/IHello:1.0", "IHello");
}
public static String id()
{
return "IDL:demoidl/hello/IHello:1.0";
}
public static IHello read(final org.omg.CORBA.portable.InputStream in)
{
return narrow(in.read_Object(demoidl.hello._IHelloStub.class));
}
public static void write(final org.omg.CORBA.portable.OutputStream _out, final demoidl.hello.IHello s)
{
_out.write_Object(s);
}
public static demoidl.hello.IHello narrow(final org.omg.CORBA.Object obj)
{
if (obj == null)
{
return null;
}
else if (obj instanceof demoidl.hello.IHello)
{
return (demoidl.hello.IHello)obj;
}
else if (obj._is_a("IDL:demoidl/hello/IHello:1.0"))
{
demoidl.hello._IHelloStub stub;
stub = new demoidl.hello._IHelloStub();
stub._set_delegate(((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate());
return stub;
}
else
{
throw new org.omg.CORBA.BAD_PARAM("Narrow failed");
}
}
public static demoidl.hello.IHello unchecked_narrow(final org.omg.CORBA.Object obj)
{
if (obj == null)
{
return null;
}
else if (obj instanceof demoidl.hello.IHello)
{
return (demoidl.hello.IHello)obj;
}
else
{
demoidl.hello._IHelloStub stub;
stub = new demoidl.hello._IHelloStub();
stub._set_delegate(((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate());
return stub;
}
}
}
package demoidl.hello;
/**
* Generated from IDL interface "IHello".
*
* @author JacORB IDL compiler V 2.3.0, 17-Feb-2007
* @version generated at Nov 13, 2008 6:53:42 PM
*/
public final class IHelloHolder implements org.omg.CORBA.portable.Streamable{
public IHello value;
public IHelloHolder()
{
}
public IHelloHolder (final IHello initial)
{
value = initial;
}
public org.omg.CORBA.TypeCode _type()
{
return IHelloHelper.type();
}
public void _read (final org.omg.CORBA.portable.InputStream in)
{
value = IHelloHelper.read (in);
}
public void _write (final org.omg.CORBA.portable.OutputStream _out)
{
IHelloHelper.write (_out,value);
}
}
package demoidl.hello;
/**
* Generated from IDL interface "IHello".
*
* @author JacORB IDL compiler V 2.3.0, 17-Feb-2007
* @version generated at Nov 13, 2008 6:53:42 PM
*/
public interface IHelloOperations
{
/* constants */
/* operations */
void sayHello();
}
package demoidl.hello;
/**
* Generated from IDL interface "IHello".
*
* @author JacORB IDL compiler V 2.3.0, 17-Feb-2007
* @version generated at Nov 13, 2008 6:53:42 PM
*/
public abstract class IHelloPOA
extends org.omg.PortableServer.Servant
implements org.omg.CORBA.portable.InvokeHandler, demoidl.hello.IHelloOperations
{
static private final java.util.Hashtable m_opsHash = new java.util.Hashtable();
static
{
m_opsHash.put ( "sayHello", new java.lang.Integer(0));
}
private String[] ids = {"IDL:demoidl/hello/IHello:1.0"};
public demoidl.hello.IHello _this()
{
return demoidl.hello.IHelloHelper.narrow(_this_object());
}
public demoidl.hello.IHello _this(org.omg.CORBA.ORB orb)
{
return demoidl.hello.IHelloHelper.narrow(_this_object(orb));
}
public org.omg.CORBA.portable.OutputStream _invoke(String method, org.omg.CORBA.portable.InputStream _input, org.omg.CORBA.portable.ResponseHandler handler)
throws org.omg.CORBA.SystemException
{
org.omg.CORBA.portable.OutputStream _out = null;
// do something
// quick lookup of operation
java.lang.Integer opsIndex = (java.lang.Integer)m_opsHash.get ( method );
if ( null == opsIndex )
throw new org.omg.CORBA.BAD_OPERATION(method + " not found");
switch ( opsIndex.intValue() )
{
case 0: // sayHello
{
_out = handler.createReply();
sayHello();
break;
}
}
return _out;
}
public String[] _all_interfaces(org.omg.PortableServer.POA poa, byte[] obj_id)
{
return ids;
}
}
package demoidl.hello;
import org.omg.PortableServer.POA;
/**
* Generated from IDL interface "IHello".
*
* @author JacORB IDL compiler V 2.3.0, 17-Feb-2007
* @version generated at Nov 13, 2008 6:53:42 PM
*/
public class IHelloPOATie
extends IHelloPOA
{
private IHelloOperations _delegate;
private POA _poa;
public IHelloPOATie(IHelloOperations delegate)
{
_delegate = delegate;
}
public IHelloPOATie(IHelloOperations delegate, POA poa)
{
_delegate = delegate;
_poa = poa;
}
public demoidl.hello.IHello _this()
{
return demoidl.hello.IHelloHelper.narrow(_this_object());
}
public demoidl.hello.IHello _this(org.omg.CORBA.ORB orb)
{
return demoidl.hello.IHelloHelper.narrow(_this_object(orb));
}
public IHelloOperations _delegate()
{
return _delegate;
}
public void _delegate(IHelloOperations delegate)
{
_delegate = delegate;
}
public POA _default_POA()
{
if (_poa != null)
{
return _poa;
}
return super._default_POA();
}
public void sayHello()
{
_delegate.sayHello();
}
}
package demoidl.hello;
/**
* Generated from IDL interface "IHello".
*
* @author JacORB IDL compiler V 2.3.0, 17-Feb-2007
* @version generated at Nov 13, 2008 6:53:42 PM
*/
public class _IHelloStub
extends org.omg.CORBA.portable.ObjectImpl
implements demoidl.hello.IHello
{
private String[] ids = {"IDL:demoidl/hello/IHello:1.0"};
public String[] _ids()
{
return ids;
}
public final static java.lang.Class _opsClass = demoidl.hello.IHelloOperations.class;
public void sayHello()
{
while(true)
{
if(! this._is_local())
{
org.omg.CORBA.portable.InputStream _is = null;
try
{
org.omg.CORBA.portable.OutputStream _os = _request( "sayHello", true);
_is = _invoke(_os);
return;
}
catch( org.omg.CORBA.portable.RemarshalException _rx ){}
catch( org.omg.CORBA.portable.ApplicationException _ax )
{
String _id = _ax.getId();
throw new RuntimeException("Unexpected exception " + _id );
}
finally
{
this._releaseReply(_is);
}
}
else
{
org.omg.CORBA.portable.ServantObject _so = _servant_preinvoke( "sayHello", _opsClass );
if( _so == null )
throw new org.omg.CORBA.UNKNOWN("local invocations not supported!");
IHelloOperations _localServant = (IHelloOperations)_so.servant;
try
{
_localServant.sayHello();
}
finally
{
_servant_postinvoke(_so);
}
return;
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment