Example #1
0
  /**
   * Write the variable's declaration in a C-style syntax. This function is used to create textual
   * representation of the Data Descriptor Structure (DDS). See <em>The DODS User Manual</em> for
   * information about this structure.
   *
   * @param os The <code>PrintWriter</code> on which to print the declaration.
   * @param space Each line of the declaration will begin with the characters in this string.
   *     Usually used for leading spaces.
   * @param print_semi a boolean value indicating whether to print a semicolon at the end of the
   *     declaration.
   * @param constrained a boolean value indicating whether to print the declartion dependent on the
   *     projection information. <b>This is only used by Server side code.</b>
   * @see DDS
   */
  public void printDecl(PrintWriter os, String space, boolean print_semi, boolean constrained) {
    if (constrained && !Project) return;

    // BEWARE! Since printDecl()is (multiple) overloaded in BaseType
    // and all of the different signatures of printDecl() in BaseType
    // lead to one signature, we must be careful to override that
    // SAME signature here. That way all calls to printDecl() for
    // this object lead to this implementation.

    // Also, since printDecl()is (multiple) overloaded in BaseType
    // and all of the different signatures of printDecl() in BaseType
    // lead to the signature we are overriding here, we MUST call
    // the printDecl with the SAME signature THROUGH the super class
    // reference (assuming we want the super class functionality). If
    // we do otherwise, we will create an infinte call loop. OOPS!

    super.printDecl(os, space, print_semi, constrained);
  }
Example #2
0
  private static void test_dds() {
    System.out.println("DDS test:");

    DataDDS table = new DataDDS(new ServerVersion(2, 16));
    table.setName("test_table");

    // add variables to it
    DUInt32 myUInt = new DUInt32("myUInt");
    myUInt.setValue(42);
    table.addVariable(myUInt);

    // note that arrays and lists take their name from the addVariable method
    DArray myArray = new DArray();
    myArray.addVariable(new DByte("myArray"));
    myArray.appendDim(10, "dummy");
    myArray.setLength(10);
    BytePrimitiveVector bpv = (BytePrimitiveVector) myArray.getPrimitiveVector();
    for (int i = 0; i < 10; i++) bpv.setValue(i, (byte) (i * 10));
    table.addVariable(myArray);

    DList myList = new DList();
    myList.addVariable(new DURL("myList"));
    myList.setLength(10);
    BaseTypePrimitiveVector btpv = (BaseTypePrimitiveVector) myList.getPrimitiveVector();
    for (int i = 0; i < 10; i++) {
      DURL testURL = new DURL();
      testURL.setValue("http://" + i);
      btpv.setValue(i, testURL);
    }
    table.addVariable(myList);

    DStructure myStructure = new DStructure("myStructure");
    DFloat64 structFloat = new DFloat64("structFloat");
    structFloat.setValue(42.0);
    myStructure.addVariable(structFloat);
    DString structString = new DString("structString");
    structString.setValue("test value");
    myStructure.addVariable(structString);
    table.addVariable(myStructure);

    DGrid myGrid = new DGrid("myGrid");
    DArray gridArray = (DArray) myArray.clone();
    gridArray.setName("gridArray");
    myGrid.addVariable(gridArray, DGrid.ARRAY);
    DArray gridMap = new DArray();
    gridMap.addVariable(new DInt32("gridMap"));
    gridMap.appendDim(10, "dummy");
    gridMap.setLength(10);
    Int32PrimitiveVector ipv = (Int32PrimitiveVector) gridMap.getPrimitiveVector();
    for (int i = 0; i < 10; i++) ipv.setValue(i, i * 10);
    myGrid.addVariable(gridMap, DGrid.MAPS);
    table.addVariable(myGrid);

    // this is the one case where two DODS variables can have the same name:
    // each row should have the same exact variables (name doesn't matter)
    DSequence mySequence = new DSequence("mySequence");
    mySequence.addVariable(new DInt32("seqInt32"));
    mySequence.addVariable(new DString("seqString"));
    Vector seqRow = new Vector(); // a row of the sequence
    DInt32 seqVar1 = new DInt32("seqInt32");
    seqVar1.setValue(1);
    seqRow.addElement(seqVar1);
    DString seqVar2 = new DString("seqString");
    seqVar2.setValue("string");
    seqRow.addElement(seqVar2);
    mySequence.addRow(seqRow);
    seqRow = new Vector(); // add a second row
    seqVar1 = new DInt32("seqInt32");
    seqVar1.setValue(3);
    seqRow.addElement(seqVar1);
    seqVar2 = new DString("seqString");
    seqVar2.setValue("another string");
    seqRow.addElement(seqVar2);
    mySequence.addRow(seqRow);
    table.addVariable(mySequence);

    try {
      table.checkSemantics();
      System.out.println("DDS passed semantic check");
    } catch (BadSemanticsException e) {
      System.out.println("DDS failed semantic check:\n" + e);
    }

    try {
      table.checkSemantics(true);
      System.out.println("DDS passed full semantic check");
    } catch (BadSemanticsException e) {
      System.out.println("DDS failed full semantic check:\n" + e);
    }

    // print the declarations
    System.out.println("declarations:");
    table.print(System.out);

    // print the data
    System.out.println("\nData:");
    table.printVal(System.out);
    System.out.println();

    // and read it programmatically
    try {
      int testValue1 = ((DUInt32) table.getVariable("myUInt")).getValue();
      System.out.println("myUInt = " + testValue1);
      byte testValue2 =
          ((BytePrimitiveVector) ((DArray) table.getVariable("myArray")).getPrimitiveVector())
              .getValue(5);
      System.out.println("myArray[5] = " + testValue2);
      String testValue3 =
          ((DString)
                  ((BaseTypePrimitiveVector)
                          ((DList) table.getVariable("myList")).getPrimitiveVector())
                      .getValue(5))
              .getValue();
      System.out.println("myList[5] = " + testValue3);
      double testValue4 =
          ((DFloat64) ((DStructure) table.getVariable("myStructure")).getVariable("structFloat"))
              .getValue();
      System.out.println("myStructure.structFloat = " + testValue4);
      int testValue5 =
          ((Int32PrimitiveVector)
                  ((DArray) ((DGrid) table.getVariable("myGrid")).getVariable("gridMap"))
                      .getPrimitiveVector())
              .getValue(5);
      System.out.println("myGrid.gridMap[5] = " + testValue5);
      String testValue7 =
          ((DString) ((DSequence) table.getVariable("mySequence")).getVariable(0, "seqString"))
              .getValue();
      System.out.println("mySequence[0].seqString = " + testValue7);
    } catch (NoSuchVariableException e) {
      System.out.println("Error getting variable:\n" + e);
    }
    System.out.println();

    DataDDS table2 = (DataDDS) table.clone(); // test Cloneable interface
    try {
      table2.checkSemantics();
      System.out.println("DDS passed semantic check");
    } catch (BadSemanticsException e) {
      System.out.println("DDS failed semantic check:\n" + e);
    }

    try {
      table2.checkSemantics(true);
      System.out.println("DDS passed full semantic check");
    } catch (BadSemanticsException e) {
      System.out.println("DDS failed full semantic check:\n" + e);
    }

    // print the declarations and data
    System.out.println("clone declarations:");
    table2.print(System.out);
    System.out.println("\nData:");
    table2.printVal(System.out);
    System.out.println();

    // add some values to the original table
    DInt32 myNewInt = new DInt32("myNewInt");
    myNewInt.setValue(420);
    table.addVariable(myNewInt);

    // verify that they aren't in the cloned table
    try {
      DInt32 testInt = (DInt32) table2.getVariable("myNewInt");
      System.out.println("Error: value from table in table2");
    } catch (NoSuchVariableException e) {
      System.out.println("Variable cloning looks good");
    }
  }
Example #3
0
 /**
  * Prints the value of the variable, with its declaration. This function is primarily intended for
  * debugging DODS applications and text-based clients such as geturl.
  *
  * <h2>Important Note</h2>
  *
  * This method overrides the BaseType method of the same name and type signature and it
  * significantly changes the behavior for all versions of <code>printVal()</code> for this type:
  * <b><i> All the various versions of printVal() will only print a value, or a value with
  * declaration, if the variable is in the projection.</i></b> <br>
  * <br>
  * In other words, if a call to <code>isProject()</code> for a particular variable returns <code>
  * true</code> then <code>printVal()</code> will print a value (or a declaration and a value).
  * <br>
  * <br>
  * If <code>isProject()</code> for a particular variable returns <code>false</code> then <code>
  * printVal()</code> is basically a No-Op. <br>
  * <br>
  *
  * @param os the <code>PrintWriter</code> on which to print the value.
  * @param space this value is passed to the <code>printDecl</code> method, and controls the
  *     leading spaces of the output.
  * @param print_decl_p a boolean value controlling whether the variable declaration is printed as
  *     well as the value.
  * @see BaseType#printVal(PrintWriter, String, boolean)
  * @see ServerMethods#isProject()
  */
 public void printVal(PrintWriter os, String space, boolean print_decl_p) {
   if (!Project) return;
   super.printVal(os, space, print_decl_p);
 }