Java源码示例:opendap.dap.DDS

示例1
private static void doit(String urlName) throws IOException, DAP2Exception {
  System.out.println("DODSV read =" + urlName);
  try (DConnect2 dodsConnection = new DConnect2(urlName, true)) {

    // get the DDS
    DDS dds = dodsConnection.getDDS();
    dds.print(System.out);
    DodsV root = DodsV.parseDDS(dds);

    // get the DAS
    DAS das = dodsConnection.getDAS();
    das.print(System.out);
    root.parseDAS(das);

    // show the dodsV tree
    root.show(System.out, "");
  }
}
 
示例2
@Test
public void testCollectFromDDS_TwoVariables() throws DAP2Exception, ParseException {
    // preparation
    final String[] variableNames = {"Chlorophyll", "Total_suspended_matter"};
    final DDS dds = createDDSWithTwoVariables();

    // execution
    variableCollector.collectDAPVariables(dds);

    // verification
    assertExpectedVariableNamesInList(variableNames, variableCollector.getVariables());
    final Set<DAPVariable> dapVariables = variableCollector.getVariables();
    assertEquals(2, dapVariables.size());
    assertTrue(containsDAPVariableAsExpected(variableNames[0], "Grid", "Float32", dapVariables));
    assertTrue(containsDAPVariableAsExpected(variableNames[1], "Grid", "Float32", dapVariables));
}
 
示例3
@Test
public void testMultipleCollectionOfTheSameDDS() throws DAP2Exception, ParseException {
    //preparation
    final String[] variableNames = new String[]{"Chlorophyll", "Total_suspended_matter", "Yellow_substance", "l2_flags", "X", "Y"};
    final DDS dds = createDDSWithTwoVariables();
    final DDS dds2 = createDDSWithMultipleVariables();

    //execution
    variableCollector.collectDAPVariables(dds);
    variableCollector.collectDAPVariables(dds2);

    //verification
    assertExpectedVariableNamesInList(variableNames, variableCollector.getVariables());
    final Set<DAPVariable> dapVariables = variableCollector.getVariables();
    assertEquals(6, dapVariables.size());
    assertTrue(containsDAPVariableAsExpected(variableNames[0], "Grid", "Float32", dapVariables));
    assertTrue(containsDAPVariableAsExpected(variableNames[1], "Grid", "Float32", dapVariables));
    assertTrue(containsDAPVariableAsExpected(variableNames[2], "Grid", "Float32", dapVariables));
    assertTrue(containsDAPVariableAsExpected(variableNames[3], "Grid", "Int32", dapVariables));
    assertTrue(containsDAPVariableAsExpected(variableNames[4], "Array", "Int32", dapVariables));
    assertTrue(containsDAPVariableAsExpected(variableNames[5], "Array", "Int32", dapVariables));
}
 
示例4
private DDS createDDSWithTwoVariables() throws DAP2Exception, ParseException {
    DDS dds = new DDS();
    String ddsString =
            "Dataset {\n" +
                    "    Grid {\n" +
                    "        Array:\n" +
                    "            Float32 Chlorophyll[Y = 849][X = 1121];\n" +
                    "        Maps:\n" +
                    "            Int32 Y[Y = 849];\n" +
                    "            Int32 X[X = 1121];\n" +
                    "    } Chlorophyll;\n" +
                    "    Grid {\n" +
                    "      Array:\n" +
                    "        Float32 Total_suspended_matter[Y = 849][X = 1121];\n" +
                    "      Maps:\n" +
                    "        Int32 Y[Y = 849];\n" +
                    "        Int32 X[X = 1121];\n" +
                    "    } Total_suspended_matter;\n" +
                    "} MER_RR__2PNKOF20120113_101320_000001493110_00324_51631_6150.N1.nc;";
    dds.parse(new ByteArrayInputStream(ddsString.getBytes()));
    return dds;
}
 
示例5
@Test
public void testThatAVariableCanBeExtractedFromADDSWithOneVariable() throws DAP2Exception, ParseException {
    DDS dds = createDDSWithOneVariable();

    final DAPVariable[] dapVariables = new VariableExtractor().extractVariables(dds);

    assertEquals(1, dapVariables.length);
    assertEquals("Chlorophyll", dapVariables[0].getName());
    assertEquals("Grid", dapVariables[0].getType());
    assertEquals("Float32", dapVariables[0].getDataType());
    assertEquals(2, dapVariables[0].getNumDimensions());
    final DArrayDimension[] dimensions = dapVariables[0].getDimensions();
    assertEquals("Y", dimensions[0].getEncodedName());
    assertEquals(849, dimensions[0].getSize());
    assertEquals("X", dimensions[1].getEncodedName());
    assertEquals(1121, dimensions[1].getSize());
}
 
示例6
/**
 * ************************************************************************
 * Gets a DDS for the specified data set and builds it using the class
 * factory in the package <b>opendap.servlet.www</b>.
 * <p/>
 * Currently this method uses a deprecated API to perform a translation
 * of DDS types. This is a known problem, and as soon as an alternate
 * way of achieving this result is identified we will implement it.
 * (Your comments appreciated!)
 *
 * @param dataSet A <code>String</code> containing the data set name.
 *        3 * @return A DDS object built using the www interface class factory.
 * @see opendap.dap.DDS
 * @see opendap.servlet.www.wwwFactory
 */
public DDS getWebFormDDS(String dataSet, ServerDDS sDDS) // changed jc
    throws DAP2Exception, ParseException {

  // Get the DDS we need, using the getDDS method
  // for this particular server
  // ServerDDS sDDS = dServ.getDDS(dataSet);

  // Make a special print writer to catch the ServerDDS's
  // persistent representation in a String.
  StringWriter ddsSW = new StringWriter();
  sDDS.print(new PrintWriter(ddsSW));

  // Now use that string to make an input stream to
  // pass to our new DDS for parsing.

  // Since parser expects/requires InputStream,
  // we must adapt utf16 string to at least utf-8

  ByteArrayInputStream bai = null;
  try {
    bai = new ByteArrayInputStream(ddsSW.toString().getBytes(CDM.UTF8));
  } catch (UnsupportedEncodingException uee) {
    throw new DAP2Exception("UTF-8 encoding not supported");
  }

  // Make a new DDS parser using the web form (www interface) class factory
  wwwFactory wfactory = new wwwFactory();
  DDS wwwDDS = new DDS(dataSet, wfactory);
  wwwDDS.setURL(dataSet);
  wwwDDS.parse(bai);
  return (wwwDDS);


}
 
示例7
/**
 * ************************************************************************
 * Gets a DDS for the specified data set and builds it using the class
 * factory in the package <b>opendap.servlet.www</b>.
 * <p/>
 * Currently this method uses a deprecated API to perform a translation
 * of DDS types. This is a known problem, and as soon as an alternate
 * way of achieving this result is identified we will implement it.
 * (Your comments appreciated!)
 *
 * @param dataSet A <code>String</code> containing the data set name.
 *        3 * @return A DDS object built using the www interface class factory.
 * @see opendap.dap.DDS
 * @see opendap.servlet.www.wwwFactory
 */
public DDS getWebFormDDS(String dataSet, ServerDDS sDDS) // changed jc
    throws DAP2Exception, ParseException {

  // Get the DDS we need, using the getDDS method
  // for this particular server
  // ServerDDS sDDS = dServ.getDDS(dataSet);

  // Make a new DDS using the web form (www interface) class factory
  wwwFactory wfactory = new wwwFactory();
  DDS wwwDDS = new DDS(dataSet, wfactory);
  wwwDDS.setURL(dataSet);

  // Make a special print writer to catch the ServerDDS's
  // persistent representation in a String.
  StringWriter ddsSW = new StringWriter();
  sDDS.print(new PrintWriter(ddsSW));

  // Now use that string to make an input stream to
  // pass to our new DDS for parsing.

  // Since parser expects/requires InputStream,
  // we must adapt utf16 string to at least utf-8

  ByteArrayInputStream bai = null;
  try {
    bai = new ByteArrayInputStream(ddsSW.toString().getBytes("UTF-8"));
  } catch (UnsupportedEncodingException uee) {
    throw new DAP2Exception("UTF-8 encoding not supported");
  }
  wwwDDS.parse(bai);

  return (wwwDDS);


}
 
示例8
public DAPVariable[] extractVariables(DDS dds) {
    final Enumeration ddsVariables = dds.getVariables();
    final List<DAPVariable> dapVariables = new ArrayList<DAPVariable>();
    while (ddsVariables.hasMoreElements()) {
        final BaseType ddsVariable = (BaseType) ddsVariables.nextElement();
        DAPVariable dapVariable = convertToDAPVariable(ddsVariable);
        dapVariables.add(dapVariable);
    }
    return dapVariables.toArray(new DAPVariable[dapVariables.size()]);
}
 
示例9
@Test
public void testCollectFromDDS_ThreeVariables() throws DAP2Exception, ParseException {
    //preparation
    final String[] variableNames = {"Baum", "Haus", "Eimer"};
    final DDS dds = getDDS(variableNames);

    //execution
    variableCollector.collectDAPVariables(dds);

    //verification
    assertExpectedVariableNamesInList(variableNames, variableCollector.getVariables());
}
 
示例10
private DDS getDDS(String[] variableNames) throws DAP2Exception, ParseException {
    final DDS dds = new DDS();
    final String ddsString = getDDSString(variableNames);
    final ByteArrayInputStream inputStream = new ByteArrayInputStream(ddsString.getBytes());
    dds.parse(inputStream);
    return dds;
}
 
示例11
private DDS createDDSWithMultipleVariables() throws DAP2Exception, ParseException {
    DDS dds = new DDS();
    String ddsString = "Dataset {\n" +
            "    Grid {\n" +
            "      Array:\n" +
            "        Float32 Chlorophyll[Y = 849][X = 1121];\n" +
            "      Maps:\n" +
            "        Int32 Y[Y = 849];\n" +
            "        Int32 X[X = 1121];\n" +
            "    } Chlorophyll;\n" +
            "    Grid {\n" +
            "      Array:\n" +
            "        Float32 Total_suspended_matter[Y = 849][X = 1121];\n" +
            "      Maps:\n" +
            "        Int32 Y[Y = 849];\n" +
            "        Int32 X[X = 1121];\n" +
            "    } Total_suspended_matter;\n" +
            "    Grid {\n" +
            "      Array:\n" +
            "        Float32 Yellow_substance[Y = 849][X = 1121];\n" +
            "      Maps:\n" +
            "        Int32 Y[Y = 849];\n" +
            "        Int32 X[X = 1121];\n" +
            "    } Yellow_substance;\n" +
            "    Grid {\n" +
            "      Array:\n" +
            "        Int32 l2_flags[Y = 849][X = 1121];\n" +
            "      Maps:\n" +
            "        Int32 Y[Y = 849];\n" +
            "        Int32 X[X = 1121];\n" +
            "    } l2_flags;\n" +
            "    Int32 X[X = 1121];\n" +
            "    Int32 Y[Y = 849];\n" +
            "} MER_RR__2PNKOF20120113_101320_000001493110_00324_51631_6150.N1.nc;";
    dds.parse(new ByteArrayInputStream(ddsString.getBytes()));
    return dds;
}
 
示例12
@Test
public void testThatByteVariableCanBeRead() throws DAP2Exception, ParseException {
    DDS dds = createDDSWithByteVariable();

    final DAPVariable[] dapVariables = new VariableExtractor().extractVariables(dds);

    assertEquals(1, dapVariables.length);
    assertEquals("metadata", dapVariables[0].getName());
    assertEquals("atomic", dapVariables[0].getType());
    assertEquals("Byte", dapVariables[0].getDataType());
    assertEquals(0, dapVariables[0].getNumDimensions());
}
 
示例13
@Test
public void testThatFloatVariableCanBeRead() throws DAP2Exception, ParseException {
    DDS dds = createDDSWithFloatVariable();

    final DAPVariable[] dapVariables = new VariableExtractor().extractVariables(dds);

    assertEquals(1, dapVariables.length);
    assertEquals("metadata", dapVariables[0].getName());
    assertEquals("atomic", dapVariables[0].getType());
    assertEquals("Float32", dapVariables[0].getDataType());
    assertEquals(0, dapVariables[0].getNumDimensions());
}
 
示例14
@Test
public void testThatMultipleVariablesCanBeExtractedFromADDSWithMultipleVariables() throws DAP2Exception, ParseException {
    DDS dds = createDDSWithMultipleVariables();

    final DAPVariable[] dapVariables = new VariableExtractor().extractVariables(dds);

    assertEquals(6, dapVariables.length);
    assertEquals("Chlorophyll", dapVariables[0].getName());
    assertEquals("Total_suspended_matter", dapVariables[1].getName());
    assertEquals("Yellow_substance", dapVariables[2].getName());
    assertEquals("l2_flags", dapVariables[3].getName());
    assertEquals("X", dapVariables[4].getName());
    assertEquals("Y", dapVariables[5].getName());
}
 
示例15
private DDS createDDSWithByteVariable() throws DAP2Exception, ParseException {
    DDS dds = new DDS();
    String ddsString = "Dataset {\n" +
            "    Byte metadata;\n" +
            "} coastcolour%2ftasmania24948_0001%2enc;";
    dds.parse(new ByteArrayInputStream(ddsString.getBytes()));
    return dds;
}
 
示例16
private DDS createDDSWithFloatVariable() throws DAP2Exception, ParseException {
    DDS dds = new DDS();
    String ddsString = "Dataset {\n" +
            "    Float32 metadata;\n" +
            "} coastcolour%2ftasmania24948_0001%2enc;";
    dds.parse(new ByteArrayInputStream(ddsString.getBytes()));
    return dds;
}
 
示例17
private DDS createDDSWithOneVariable() throws DAP2Exception, ParseException {
    DDS dds = new DDS();
    String ddsString =
            "Dataset {\n" +
                    "    Grid {\n" +
                    "        Array:\n" +
                    "            Float32 Chlorophyll[Y = 849][X = 1121];\n" +
                    "        Maps:\n" +
                    "            Int32 Y[Y = 849];\n" +
                    "            Int32 X[X = 1121];\n" +
                    "    } Chlorophyll;\n" +
                    "} MER_RR__2PNKOF20120113_101320_000001493110_00324_51631_6150.N1.nc;";
    dds.parse(new ByteArrayInputStream(ddsString.getBytes()));
    return dds;
}
 
示例18
private DDS createDDSWithMultipleVariables() throws DAP2Exception, ParseException {
    DDS dds = new DDS();
    String ddsString = "Dataset {\n" +
            "    Grid {\n" +
            "      Array:\n" +
            "        Float32 Chlorophyll[Y = 849][X = 1121];\n" +
            "      Maps:\n" +
            "        Int32 Y[Y = 849];\n" +
            "        Int32 X[X = 1121];\n" +
            "    } Chlorophyll;\n" +
            "    Grid {\n" +
            "      Array:\n" +
            "        Float32 Total_suspended_matter[Y = 849][X = 1121];\n" +
            "      Maps:\n" +
            "        Int32 Y[Y = 849];\n" +
            "        Int32 X[X = 1121];\n" +
            "    } Total_suspended_matter;\n" +
            "    Grid {\n" +
            "      Array:\n" +
            "        Float32 Yellow_substance[Y = 849][X = 1121];\n" +
            "      Maps:\n" +
            "        Int32 Y[Y = 849];\n" +
            "        Int32 X[X = 1121];\n" +
            "    } Yellow_substance;\n" +
            "    Grid {\n" +
            "      Array:\n" +
            "        Int32 l2_flags[Y = 849][X = 1121];\n" +
            "      Maps:\n" +
            "        Int32 Y[Y = 849];\n" +
            "        Int32 X[X = 1121];\n" +
            "    } l2_flags;\n" +
            "    Int32 X[X = 1121];\n" +
            "    Int32 Y[Y = 849];\n" +
            "} MER_RR__2PNKOF20120113_101320_000001493110_00324_51631_6150.N1.nc;";
    dds.parse(new ByteArrayInputStream(ddsString.getBytes()));
    return dds;
}
 
示例19
void dotest(String test) throws Exception {
  boolean constrained = false;
  this.test = test;
  this.testname = test;
  this.ce = "";
  // see if we are using constraints
  constrained = (test.indexOf(';') >= 0);
  if (constrained) {
    String[] pieces = test.split(";");
    this.testname = pieces[0];
    this.testno = pieces[1];
    this.ce = pieces[2];
    try {
      Integer.decode(this.testno);
    } catch (NumberFormatException nfe) {
      System.err.printf("Illegal constrained test testno: %s\n", test);
      return;
    }
  }

  if (constrained) {
    testdataname = "ce." + testname + "." + testno;
    url = currentTestSet.url + "/" + testname;
  } else {
    testdataname = testname;
    url = currentTestSet.url + "/" + testname;

  }
  if (verbose)
    System.out.println("*** Testing: " + testdataname);
  if (verbose)
    System.out.println("*** URL: " + url);


  if (!constrained)
    testpart(TestPart.DAS, ce);
  testpart(TestPart.DDS, ce);
  if (constrained)
    testpart(TestPart.DATADDS, ce);
  if (!pass)
    Assert.assertTrue(testname, pass);
}
 
示例20
public DAPVariable[] extractVariables(OpendapLeaf leaf) {
    DDS dds = getDDS(leaf.getDdsUri());
    return extractVariables(dds);
}
 
示例21
public DAPVariable[] collectDAPVariables(DDS dds) {
    final DAPVariable[] dapVariables = variableExtractor.extractVariables(dds);
    storeDAPVariables(dapVariables);
    return dapVariables;
}