GeoTessJavaExamples  2.0
ExtendedModel.java
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
4 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5 //- retains certain rights in this software.
6 //-
7 //- BSD Open Source License.
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- * Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //- * Redistributions in binary form must reproduce the above copyright
16 //- notice, this list of conditions and the following disclaimer in the
17 //- documentation and/or other materials provided with the distribution.
18 //- * Neither the name of Sandia National Laboratories nor the names of its
19 //- contributors may be used to endorse or promote products derived from
20 //- this software without specific prior written permission.
21 //-
22 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //- POSSIBILITY OF SUCH DAMAGE.
33 //-
34 //- ****************************************************************************
35 
36 package gov.sandia.geotess.examples;
37 
38 import gov.sandia.geotess.GeoTessModel;
39 
40 import java.io.File;
41 
42 public class ExtendedModel
43 {
44 
45  /**
46  * An example of how to implement an extension of a GeoTessModel.
47  * The definition of the extended model is contained in file
48  * GeoTessModelExtended.java. This method instantiates
49  * an instance of the model and queries it for the extra data.
50  *
51  * @param args must supply one argument: the path to the GeoTessModels directory.
52  */
53  public static void main(String[] args)
54  {
55  try
56  {
57  if (args.length == 0)
58  throw new Exception(
59  "\nMust specify a single command line argument specifying " +
60  "the path to the GeoTessModels diretory\n");
61 
62  File baseModelFile = new File(new File(args[0]), "crust20.geotess");
63 
64  System.out.println("Example that illustrates how to use GeoTessModelExtended that " +
65  "extends a regular GeoTessModel base class.");
66  System.out.println();
67 
68  // load a regular GeoTessModel. This is not the extended model.
69  GeoTessModel baseModel = new GeoTessModel(baseModelFile);
70 
71  // construct an instance of a GeoTessModelExtended that
72  // has MetaData, Grid and Profile information copied from
73  // the base class. The extra data accessible only from the
74  // derived class is initialized in the constructor to
75  // "extraData initialized in GeoTessModelExtended.initializeData()".
76  GeoTessModelExtended extModel = new GeoTessModelExtended(baseModel);
77 
78  // Note that instead of using a copy constructor to instantiate a
79  // new GeoTessModelExtended object, we could have used one of the
80  // methods that demonstrated in populateModel2D or populateModel3D.
81 
82  // in this trivial example, the extended model implements a single
83  // string called 'extraData'. It is initialized to 'default value'
84  // in the GeoTessModelExtended constructor. A getter() and setter()
85  // are implemented to allow applications to retrieve and modify the
86  // value. Likely, real classes that extend GeoTessModel
87  // would involve more complicated structures.
88 
89  // print the extraData to the screen. This is the default value
90  // assigned by the GeoTessModelExtended constructor.
91  System.out.println(extModel.getExtraData());
92 
93  // change the extraData to a new string.
94  extModel.setExtraData("modified value");
95 
96  // retrieve the modified value of extraData.
97  System.out.println(extModel.getExtraData());
98 
99  System.out.println("\nDone.");
100  }
101  catch (Exception ex)
102  {
103  ex.printStackTrace();
104  }
105 
106  }
107 
108 }
gov.sandia.geotess.examples.ExtendedModel
Definition: ExtendedModel.java:43
gov.sandia.geotess.examples.GeoTessModelExtended.getExtraData
String getExtraData()
Getter.
Definition: GeoTessModelExtended.java:319
gov
gov.sandia.geotess
gov.sandia.geotess.examples.ExtendedModel.main
static void main(String[] args)
An example of how to implement an extension of a GeoTessModel.
Definition: ExtendedModel.java:53
gov.sandia.geotess.examples.GeoTessModelExtended.setExtraData
void setExtraData(String extraData)
Setter.
Definition: GeoTessModelExtended.java:328
gov.sandia.geotess.examples.GeoTessModelExtended
This class is an example of a class that extends GeoTessModel.
Definition: GeoTessModelExtended.java:80
gov.sandia