Wildcard (*) imports are no longer supported in CWMS. The steps outlined in this tutorial will help you remove any wildcard imports and determine which specific imports are required in your scripts. These steps also correct any issues that may arise when developers move packages. Removing wildcard imports should improve the processing speed of your script, since the script is not being told to look for and add items that it will not use. 

Process

  1. From the Setup module in the CAVI, select Editor from the Scripts menu. The Script Editor dialog will open.

  2. Select the script of interest from the tree.
    Script Editor Dialog - Selecting a Script

  3. Comment out the wildcard import lines one at a time by placing a # at the start of the line. Commenting out one line at a time allows you to identify the class or class member that triggers the error (if the script fails to run). It is the package identified after the "from" keyword in the import statement you commented out. However, the ultimate objective is to remove ALL lines with wildcard imports.
    Script Editor Dialog - Wildcard Import Line Commented Out 

  4. Click the Save/Run button in the Script Editor to see if the script fails.
    1. If it does not fail, then the import line you commented out was unnecessary and can be deleted from the script. Go back to Step 3 and repeat the process for the next wildcard import.
    2. If the script fails, make note of the error message and the line number that causes the script to fail. Continue on with Step 5.
      Script Failed Warning

  5. The error message should tell you that something is not defined. In this example, the "MessageBox" is undefined. Use this information to search the JavaDocs that are supplied with CWMS/HEC-RTS to find the class that is needed on the import line.

    The JavaDocs provide the most authoritative information regarding the CWMS Java API. In addition, the Script Editors in CWMS, CWMS-Vue, HEC-DSSVue, and HEC-ResSim include a tree structure that lists the major packages in the CWMS Java API that might be useful in your scripts.

  6. Open a file browser, locate the CWMS installation folder, then browse to the CAVI/JavaDocs folder.

  7. Open the index.html file. This will launch your default web browser and display the index of the CWMS JavaDocs.

  8. Select the INDEX option at the top of the main viewing window.
    JavaDocs Index

  9. From the JavaDocs index, use ctrl+f to access the Find function. Enter the name of the object or method that is undefined (the information you learned in Step 5, for this example the "MessageBox" will highlight).
    Results of the Search Function within JavaDocs

  10. Scroll through the results and determine which class is being used in your script, as there may be multiple results with the same name from your search. If the search highlights a result in the list of classes, start there. In this example the "MessageBox" was listed in Step 5 as undefined in the script, and it was displayed in a Java Class. 
    Class MessageBox - JavaDocs Example

  11. Uncomment the import * line in your script and replace the * with the name of the class you identified in Step 10.
    Script Editor Dialog - Import Class Example

  12. Click Save/Run to see if the script runs successfully.
    1. Some items have the potential to be denoted in multiple classes, but one of them should align with one of the wildcard imports in your script. If it happens to fall within multiple ones, use trial and error until the script runs.
    2. It is also possible multiple classes will need to be imported per package. To do this, place a comma after the first import then a space, then the name of the second import.
      1.  For example, assume that the class "HecDss" was used by this script in addition to "MessageBox" (both of which are a class of hec.script), the user could write the import as:
        from hec.script import MessageBox, HecDss
        CODE
        This would import both classes from the hec.script package.

  13. If the script runs successfully, return to Step 3 and repeat the process until all wildcard imports have been replaced.