home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / allaire / util / template / Function.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  2.9 KB  |  116 lines

  1. package allaire.util.template;
  2.  
  3. import allaire.util.Assert;
  4. import allaire.util.TypeConversionException;
  5. import allaire.util.TypelessValue;
  6. import netscape.util.Vector;
  7.  
  8. public abstract class Function {
  9.    FunctionInfo m_functionInfo;
  10.    public static final int ARG_NONE = -1;
  11.    public static final int ARG_ANY = 0;
  12.    public static final int ARG_STRING = 1;
  13.    public static final int ARG_NUMBER = 2;
  14.    public static final int ARG_POSITIVE = 3;
  15.    public static final int ARG_POSITIVE_NZ = 4;
  16.  
  17.    public TypelessValue doIt(Vector var1) throws FunctionCallException {
  18.       return new TypelessValue("");
  19.    }
  20.  
  21.    protected boolean checkArgument(TypelessValue var1, int var2) {
  22.       boolean var3;
  23.       try {
  24.          switch (var2) {
  25.             case -1:
  26.                Assert.fail("Internal: mismatched argument type info");
  27.             case 0:
  28.             case 1:
  29.                break;
  30.             case 2:
  31.                var1.asReal();
  32.                break;
  33.             case 3:
  34.                double var7 = var1.asReal();
  35.                if (var7 < (double)0.0F) {
  36.                   throw new TypeConversionException("");
  37.                }
  38.                break;
  39.             case 4:
  40.                double var4 = var1.asReal();
  41.                if (var4 <= (double)0.0F) {
  42.                   throw new TypeConversionException("");
  43.                }
  44.                break;
  45.             default:
  46.                Assert.fail("Internal: unknown argument type");
  47.          }
  48.  
  49.          var3 = true;
  50.       } catch (TypeConversionException var6) {
  51.          var3 = false;
  52.       }
  53.  
  54.       return var3;
  55.    }
  56.  
  57.    protected String getArgumentAsString(Vector var1, int var2) {
  58.       TypelessValue var3 = (TypelessValue)var1.elementAt(var2);
  59.       return var3.asString();
  60.    }
  61.  
  62.    private void checkArguments(Vector var1) throws FunctionCallException {
  63.       int var2 = var1.count();
  64.       if (var2 < this.m_functionInfo.m_nNumRequired) {
  65.          throw new FunctionCallException(151, var2 + " arguments were passed " + "to function '" + this.m_functionInfo.m_strName + "' (" + this.m_functionInfo.m_nNumRequired + " arguments are required).");
  66.       } else if (!this.m_functionInfo.m_bHasOptional && var2 > this.m_functionInfo.m_nNumRequired) {
  67.          throw new FunctionCallException(152, var2 + " arguments were passed " + "to function '" + this.m_functionInfo.m_strName + "' (" + this.m_functionInfo.m_nNumRequired + " arguments are required). ");
  68.       } else {
  69.          int var3 = Math.min(var2, 4);
  70.  
  71.          for(int var4 = 0; var4 < var3; ++var4) {
  72.             boolean var5 = this.checkArgument((TypelessValue)var1.elementAt(var4), this.m_functionInfo.m_enTypes[var4]);
  73.             if (!var5) {
  74.                throw new FunctionCallException(150, "Argument number " + String.valueOf(var4 + 1) + " of function " + this.m_functionInfo.m_strName + " is not of the correct type");
  75.             }
  76.          }
  77.  
  78.       }
  79.    }
  80.  
  81.    public Function(FunctionInfo var1) {
  82.       this.m_functionInfo = var1;
  83.    }
  84.  
  85.    protected boolean getArgumentAsBoolean(Vector var1, int var2) {
  86.       try {
  87.          TypelessValue var3 = (TypelessValue)var1.elementAt(var2);
  88.          return var3.asBoolean();
  89.       } catch (TypeConversionException var4) {
  90.          return false;
  91.       }
  92.    }
  93.  
  94.    TypelessValue call(TemplateRuntimeContext var1, Vector var2) throws FunctionCallException {
  95.       this.checkArguments(var2);
  96.       return this.doItWithContext(var1, var2);
  97.    }
  98.  
  99.    String getName() {
  100.       return this.m_functionInfo.m_strName;
  101.    }
  102.  
  103.    protected double getArgumentAsReal(Vector var1, int var2) {
  104.       try {
  105.          TypelessValue var3 = (TypelessValue)var1.elementAt(var2);
  106.          return var3.asReal();
  107.       } catch (TypeConversionException var4) {
  108.          return (double)0.0F;
  109.       }
  110.    }
  111.  
  112.    public TypelessValue doItWithContext(TemplateRuntimeContext var1, Vector var2) throws FunctionCallException {
  113.       return this.doIt(var2);
  114.    }
  115. }
  116.