001    package org.hackystat.telemetry.analyzer.language.ast;
002    
003    /**
004     * A reference to telemetry chart definition by its name. This is used by 
005     * <code>TelemetryReportDefinition</code>.
006     * 
007     * @author (Cedric) Qin Zhang
008     */
009    public class ChartReference {
010      
011      /** The name of telemetry chart being referenced. */
012      private String name;
013      
014      /** 
015       * The parameters that need to be passed. Note that not all <code>Expression</code>
016       * objects are valid. Only <code>Variable</code> and <code>Constant</code> objects
017       * are legal.
018       */
019      private Expression[] parameters;
020    
021      /**
022       * Constructs this instance.
023       * 
024       * @param name The name of telemetry chart being referenced.
025       * @param parameters The parameters that need to be passed. 
026       *        Note that not all <code>Expression</code> objects are valid. 
027       *        Only <code>Variable</code> and <code>Constant</code> objects are legal.
028       *        Null is valid if no parameter needs to be passed.
029       */
030      public ChartReference(String name, Expression[] parameters) {
031        this.name = name;
032        this.parameters = parameters == null ? new Expression[0] : parameters;
033        
034        //validity check
035        for (int i = 0; i < this.parameters.length; i++) {
036          Expression exp = this.parameters[i];
037          if (! (exp instanceof Variable || exp instanceof Constant)) {
038            throw new RuntimeException("Only objects of Variable and Constant types are legal"
039                + " parameter types.");
040          }
041        }
042      }
043    
044      /**
045       * Gets the name of the referenced telemetry chart object.
046       * 
047       * @return The name.
048       */
049      public String getName() {
050        return this.name;
051      }
052    
053      /**
054       * Gets the parameters.
055       * 
056       * @return An array of <code>Variable</code> or <code>Constant</code> or both objects.
057       *         Null will never be returned. If there is no parameter, an empty array will be returned.
058       */
059      public Expression[] getParameters() {
060        return this.parameters;
061      }
062    }