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"); } }
public void process(InputStream is) throws DAP2Exception, ParseException { dds.parseXML(is, false); }
public void process(InputStream is) throws ParseException, DAP2Exception, IOException { dds.parse(is); dds.readData(is, statusUI); }
/** * ************************************************************************ Default handler for * OPeNDAP ascii requests. Returns OPeNDAP DAP2 data in comma delimited ascii columns for * ingestion into some not so OPeNDAP enabled application such as MS-Excel. Accepts constraint * expressions in exactly the same way as the regular OPeNDAP dataserver. * * @param request * @param response * @param dataSet * @throws opendap.dap.DAP2Exception * @throws ParseException */ public void sendASCII(HttpServletRequest request, HttpServletResponse response, String dataSet) throws DAP2Exception, ParseException { if (Debug.isSet("showResponse")) System.out.println( "Sending OPeNDAP ASCII Data For: " + dataSet + " CE: '" + request.getQueryString() + "'"); String requestURL, ce; DConnect2 url; DataDDS dds; if (request.getQueryString() == null) { ce = ""; } else { ce = "?" + request.getQueryString(); } int suffixIndex = request.getRequestURL().toString().lastIndexOf("."); requestURL = request.getRequestURL().substring(0, suffixIndex); if (Debug.isSet("showResponse")) { System.out.println("New Request URL Resource: '" + requestURL + "'"); System.out.println("New Request Constraint Expression: '" + ce + "'"); } try { if (_Debug) System.out.println("Making connection to .dods service..."); url = new DConnect2(requestURL, true); if (_Debug) System.out.println("Requesting data..."); dds = url.getData(ce, null, new asciiFactory()); if (_Debug) System.out.println(" ASC DDS: "); if (_Debug) dds.print(System.out); PrintWriter pw = new PrintWriter(response.getOutputStream()); PrintWriter pwDebug = new PrintWriter(System.out); if (dds != null) { dds.print(pw); pw.println("---------------------------------------------"); String s = ""; Enumeration e = dds.getVariables(); while (e.hasMoreElements()) { BaseType bt = (BaseType) e.nextElement(); if (_Debug) ((toASCII) bt).toASCII(pwDebug, true, null, true); // bt.toASCII(pw,addName,getNAme(),true); ((toASCII) bt).toASCII(pw, true, null, true); } } else { String betterURL = request.getRequestURL().substring(0, request.getRequestURL().lastIndexOf(".")) + ".dods?" + request.getQueryString(); pw.println("-- ASCII RESPONSE HANDLER PROBLEM --"); pw.println(""); pw.println("The ASCII response handler was unable to obtain requested data set."); pw.println(""); pw.println("Because this handler calls it's own OPeNDAP server to get the requested"); pw.println("data the source error is obscured."); pw.println(""); pw.println("To get a better idea of what is going wrong, try requesting the URL:"); pw.println(""); pw.println(" " + betterURL); pw.println(""); pw.println("And then look carefully at the returned document. Note that if you"); pw.println("are using a browser to access the URL the returned document will"); pw.println("more than likely be treated as a download and written to your"); pw.println("local disk. It should be a file with the extension \".dods\""); pw.println(""); pw.println("Locate it, open it with a text editor, and find your"); pw.println("way to happiness and inner peace."); pw.println(""); } // pw.println("</pre>"); pw.flush(); if (_Debug) pwDebug.flush(); } catch (FileNotFoundException fnfe) { System.out.println("OUCH! FileNotFoundException: " + fnfe.getMessage()); fnfe.printStackTrace(System.out); } catch (MalformedURLException mue) { System.out.println("OUCH! MalformedURLException: " + mue.getMessage()); mue.printStackTrace(System.out); } catch (IOException ioe) { System.out.println("OUCH! IOException: " + ioe.getMessage()); ioe.printStackTrace(System.out); } catch (Throwable t) { System.out.println("OUCH! Throwable: " + t.getMessage()); t.printStackTrace(System.out); } if (_Debug) System.out.println(" GetAsciiHandler done"); }