ObjectRegistry.java

00001 /* 
00002 ** Author(s): Miguel Calejo
00003 ** Contact:   interprolog@declarativa.com, http://www.declarativa.com
00004 ** Copyright (C) Declarativa, Portugal, 2000-2002
00005 ** Use and distribution, without any warranties, under the terms of the 
00006 ** GNU Library General Public License, readable in http://www.fsf.org/copyleft/lgpl.html
00007 */
00008 package com.declarativa.interprolog.util;
00009 import com.declarativa.interprolog.*;
00010 
00012 public class ObjectRegistry{
00013         private static final int MAXOBJECTS = 2000;
00014     private Object objectTable[] = new Object[MAXOBJECTS]; int nObjects=0;
00015 
00016         public Object getRealJavaObject(InvisibleObject o){
00017                 return getRealJavaObject(o.ID);
00018         }
00019         
00020         public Object getRealJavaObject(int ID){
00021                 if (ID<0 | ID>nObjects-1) 
00022                         throw new RuntimeException("Bad object ID in ObjectRegistry");
00023                 return objectTable[ID];
00024         }
00025         
00026         public int registerJavaObject(Object x){
00027                 int i = getObjectID(x);
00028                 if (i>=0) return i;
00029                 if (nObjects>=MAXOBJECTS) 
00030                         throw new IPException("Too many Java objects in ObjectRegistry");
00031                 if (x==null)
00032                         throw new IPException("Null object in ObjectRegistry");
00033                 objectTable[nObjects++] = x;
00034                 return nObjects-1;
00035         }
00036         
00037         private int getObjectID(Object x){
00038                 int i = 0;
00039                 while (i<nObjects)
00040                         if (objectTable[i]==x) return i;
00041                         else i++;
00042                 return -1;
00043         }
00044 }

Generated on Wed Jul 26 13:30:44 2006 for XSB by  doxygen 1.4.5