ServantLocator.java 1.93 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.omg.PortableServer._ServantLocatorLocalBase
 */
package com.adobe.CORBA.impl;

import java.util.HashMap;
import java.util.Map;
import org.omg.PortableServer.ForwardRequest;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.Servant;
import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
import org.omg.PortableServer._ServantLocatorLocalBase;

class ServantLocator
extends _ServantLocatorLocalBase {
    private Map<Integer, Servant> servantMap = new HashMap<Integer, Servant>();
    private int currentKey = 0;

    ServantLocator() {
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public Servant preinvoke(byte[] oid, POA adapter, String operation, CookieHolder cookie) throws ForwardRequest {
        ServantLocator servantLocator = this;
        synchronized (servantLocator) {
            return this.servantMap.get(ServantLocator.byteArray2int(oid));
        }
    }

    public void postinvoke(byte[] oid, POA adapter, String operation, Object cookie, Servant servant) {
    }

    public synchronized byte[] activate_object(Servant servant) {
        ++this.currentKey;
        byte[] key = ServantLocator.int2byteArray(this.currentKey);
        this.servantMap.put(this.currentKey, servant);
        return key;
    }

    public synchronized void deactivate_object(byte[] objectKey) {
        this.servantMap.remove(ServantLocator.byteArray2int(objectKey));
    }

    private static byte[] int2byteArray(int i) {
        byte[] a = new byte[8];
        for (int j = 0; j < 4; ++j) {
            a[j] = (byte)(i % 256);
            i >>>= 8;
        }
        return a;
    }

    private static int byteArray2int(byte[] a) {
        int i = 0;
        for (int j = 3; j >= 0; --j) {
            int b = a[j];
            i = (i << 8) + (b >= 0 ? b : 256 + b);
        }
        return i;
    }
}