FileDocCategorySizeDatePackage
IORAddrAnyInterceptor.javaAPI DocGlassfish v2 API8934Fri May 04 22:34:54 BST 2007com.sun.enterprise.iiop

IORAddrAnyInterceptor

public class IORAddrAnyInterceptor extends org.omg.CORBA.LocalObject implements org.omg.PortableInterceptor.IORInterceptor

Fields Summary
public static final String
baseMsg
private static Logger
_logger
private org.omg.IOP.Codec
codec
Constructors Summary
public IORAddrAnyInterceptor(org.omg.IOP.Codec c)
Creates a new instance of IORAddrAnyInterceptor

        codec = c;
    
Methods Summary
private voidaddAddressComponents(org.omg.PortableInterceptor.IORInfo iorInfo, java.util.ArrayList allInetAddress, int port)

        try {
            for (int i = 0; i < allInetAddress.size(); i++) {
                String address = ((InetAddress)allInetAddress.get(i)).getHostAddress();
                AlternateIIOPAddressComponent iiopAddress = 
                    new AlternateIIOPAddressComponent(address, intToShort(port));
                Any any = ORB.init().create_any();
                AlternateIIOPAddressComponentHelper.insert(any, iiopAddress);
                byte[] data = codec.encode_value(any);
                TaggedComponent taggedComponent =
                    new TaggedComponent( org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS.value,
					//AlternateIIOPAddressComponent.TAG_ALTERNATE_IIOP_ADDRESS_ID,
                            data);
                iorInfo.add_ior_component(taggedComponent);
            }
        } catch (Exception e) {
            _logger.log(Level.WARNING,"Exception in " + baseMsg, e);
        }
    
public voiddestroy()
Provides an opportunity to destroy this interceptor. The destroy method is called during ORB.destroy. When an application calls ORB.destroy, the ORB:
  1. waits for all requests in progress to complete
  2. calls the Interceptor.destroy operation for each interceptor
  3. completes destruction of the ORB
Method invocations from within Interceptor.destroy on object references for objects implemented on the ORB being destroyed result in undefined behavior. However, method invocations on objects implemented on an ORB other than the one being destroyed are permitted. (This means that the ORB being destroyed is still capable of acting as a client, but not as a server.)

    
public voidestablish_components(org.omg.PortableInterceptor.IORInfo iorInfo)
A server side ORB calls the establish_components operation on all registered IORInterceptor instances when it is assembling the list of components that will be included in the profile or profiles of an object reference. This operation is not necessarily called for each individual object reference. For example, the POA specifies policies at POA granularity and therefore, this operation might be called once per POA rather than once per object. In any case, establish_components is guaranteed to be called at least once for each distinct set of server policies.

An implementation of establish_components must not throw exceptions. If it does, the ORB shall ignore the exception and proceed to call the next IOR Interceptor's establish_components operation.

param
info The IORInfo instance used by the ORB service to query applicable policies and add components to be included in the generated IORs.

        try {
            IORInfoExt iorInfoExt = (IORInfoExt) iorInfo;
            int port = iorInfoExt.getServerPort(ORBSocketFactory.IIOP_CLEAR_TEXT);

            ArrayList allInetAddress = getAllInetAddresses();
            addAddressComponents(iorInfo, allInetAddress, port);
            com.sun.corba.ee.internal.corba.ORB orb = 
                    (com.sun.corba.ee.internal.corba.ORB)((IORInfoImpl)iorInfo).getORB();
            Object[] userPorts = orb.getUserSpecifiedListenPorts().toArray();
            if (userPorts.length > 0) {
                for (int i = 0; i < userPorts.length; i++) {
                    com.sun.corba.ee.internal.corba.ORB.UserSpecifiedListenPort p = 
                        ((com.sun.corba.ee.internal.corba.ORB.UserSpecifiedListenPort)userPorts[i]);
            //        if (p.getType().equals(ORBSocketFactory.IIOP_CLEAR_TEXT)) {
                        addAddressComponents(iorInfo, allInetAddress, p.getPort());
            //        }
                }
            }
        } catch (Exception e) {
            _logger.log(Level.WARNING,"Exception in " + baseMsg, e);
        }
    
private static java.util.ArrayListgetAllInetAddresses()
Get all the InetAddresses on the machine

        ArrayList result = new ArrayList();
        try {
            Enumeration e = NetworkInterface.getNetworkInterfaces();
            while (e.hasMoreElements()) {
                NetworkInterface ni = (NetworkInterface)e.nextElement();
                Enumeration ee = ni.getInetAddresses();
                while (ee.hasMoreElements()) {
                    InetAddress addr = (InetAddress)ee.nextElement();
                    result.add(addr);
                }
            }
        } catch (SocketException se) {
            _logger.log(Level.WARNING,"Exception getting all Network Interfaces",se);
            return result;
        }
        return result;
    
protected shortintToShort(int value)

	if (value > 32767)
	    return (short)(value - 65536) ;
	return (short)value ;
    
public java.lang.Stringname()
Returns the name of the interceptor.

Each Interceptor may have a name that may be used administratively to order the lists of Interceptors. Only one Interceptor of a given name can be registered with the ORB for each Interceptor type. An Interceptor may be anonymous, i.e., have an empty string as the name attribute. Any number of anonymous Interceptors may be registered with the ORB.

return
the name of the interceptor.

        return baseMsg;