00001
00002
00003
00004
00005
00006
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 }