Class Question

java.lang.Object
com.sun.interview.Question
Direct Known Subclasses:
ChoiceArrayQuestion, ChoiceQuestion, CompositeQuestion, FileListQuestion, FileQuestion, FloatQuestion, InetAddressQuestion, IntQuestion, ListQuestion, NullQuestion, StringListQuestion, StringQuestion, TreeQuestion

public abstract class Question extends Object
Questions are the primary constituent elements of interviews. They provide text and an optional graphic to be presented to the user, and they provide a place to store the user's response. Various subtypes are provided, according to the type of response they request and store. Questions are identified internally by a unique tag, which is used to identify the question in contexts such as resource bundles, dictionaries, and so on.
  • Field Details

    • key

      protected final String key
      A unique key to identify the resources for this question.
    • interview

      protected Interview interview
      The interview to which this question belongs.
    • tag

      protected String tag
      A unique tag to identify this question.
  • Constructor Details

    • Question

      protected Question(Interview interview, String baseTag)
      Create a question with a nominated tag.
      Parameters:
      interview - The interview containing this question.
      baseTag - A name to uniquely identify this question within its interview.
    • Question

      protected Question(Interview interview)
      Create a question with no identifying tag.
      Parameters:
      interview - The interview containing this question.
  • Method Details

    • getInterview

      public Interview getInterview()
      Return the interview of which this question is a part.
      Returns:
      the interview of which this question is a part
    • getKey

      public String getKey()
      Get the key for a question. The key is the class name of the parent interview followed by a period followed by the tag given to the constructor. It therefore reasonably identifies the question relative to the class of its parent interview. The key is normally used to identify resources such as the question text in a resource file or help information in a help set.
      Returns:
      the key for this question
      See Also:
    • getTag

      public String getTag()
      Get the tag for a question. The tag is the tag of the parent interview, followed by a dot, followed by the tag given to the constructor. It therefore reasonably identifies the question relative to the instance of its parent interview. The tag is normally used to identify instance-specific responses in a saved interview file.
      Returns:
      the tag for this question
      See Also:
    • getText

      public String getText()
      Get the text for this question. If not specified, the system will try and locate the text in the containing interviews resource bundle, using the resource name key.text.
      Returns:
      the text for this question
      See Also:
    • setText

      protected void setText(String text)
      Set the text for this question. The text can also be provided in the containing interview's resource bundle, using the resource name key.text.
      Parameters:
      text - the text for this question
      See Also:
    • getTextArgs

      protected Object[] getTextArgs()
      Get any arguments necessary to go with the question text. The text is formatted using the rules specified for MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition). By default, this method returns null. If the text for the question contains variable entries (using the '{' '}' notation), you should override this method to provide the corresponding values.
      Returns:
      An array of objects suitable for formatting in the text of the question.
    • getSummary

      public String getSummary()
      Set the summary text for this question.
      Returns:
      a short summary of the text for this question
      See Also:
    • setSummary

      protected void setSummary(String summary)
      Set the summary text for this question. The text can also be provided in the containing interview's resource bundle, using the resource name key.smry.
      Parameters:
      summary - a short summary of the text for this question
      See Also:
    • getImage

      public URL getImage()
      Get the graphic for this question. If setImage(java.lang.String) has been called to supply a specific image for this question, that will be the result here; otherwise, the value defaults first to a question-specific resource (tag.gif) and then to a default image for the interview.
      Returns:
      a URL for the question.
      See Also:
    • setImage

      public void setImage(String resource)
      Set the URL for a specific graphic for this question.
      Parameters:
      resource - The name of a resource containing the desired image.
      See Also:
    • setImage

      protected void setImage(URL u)
      Set the URL for a specific graphic for this question.
      Parameters:
      u - The URL of a resource containing the desired image.
      See Also:
    • getHelpID

      public Object getHelpID()
      Get the HelpID identifying the "more info" help for this question, or null if none.

      Normally, this method returns null and real work on JavaHelp HelpID is done by com.sun.interview.wizard.Help class, if wizard presents. Subclasses might override this method to return not null value, in this case returned value will be used. Returned object must be an instance of HelpID.

      Returns:
      the HelpID identifying the "more info" help for this question, or null if none.
    • setHelpID

      public void setHelpID(Object object)
      Set HelpID object associated with the Question.
      Parameters:
      object - Should be instance of HelpID
    • getChecklistItems

      public Checklist.Item[] getChecklistItems()
      Get any items which should be added to the interview's checklist.
      Returns:
      any items which should be added to the interview's checklist, or null if none.
      See Also:
    • addMarker

      public void addMarker(String name)
      Add a named marker to this question, if it has not already been added.
      Parameters:
      name - the name of the marker to be added.
      Throws:
      NullPointerException - if name is null
    • removeMarker

      public void removeMarker(String name)
      Remove a named marker to this question.
      Parameters:
      name - the name of the marker to be removed.
    • hasMarker

      public boolean hasMarker(String name)
      Check if a marker has been added to this question.
      Parameters:
      name - the name of the marker to be checked.
      Returns:
      true if the marker has been added to this question, and false otherwise.
    • isHidden

      public boolean isHidden()
      Determine if this question is currently "hidden". Hidden questions do not appear on the current path and so are skipped over by Interview.prev() and Interview.next(), etc. By default, questions are not hidden, and this method returns false. Override this method if you want to hide a question - note that the value of isEnabled() is currently tied to the value of this method. Developers who wish to independently play with hiding and enabling should override both methods.
      Returns:
      true if this question has been hidden.
      Since:
      4.3
      See Also:
    • isEnabled

      public boolean isEnabled()
      Determine if this question is currently enabled. Disabled questions do not appear on the current path and so are skipped over by Interview.prev() and Interview.next(), etc. By default, all questions are enabled, and this method returns true. Override this method if you want to hide a question. It can be convenient to determine whether or not a question should be disabled by using the values of earlier questions. Note: for backwards compatibility, the default implementation returns !isHidden().
      Returns:
      true if this question should appear on the current path, and false otherwise.
    • getNext

      protected abstract Question getNext()
      Get the next question to be asked.
      Returns:
      the next question to be asked
    • clear

      public abstract void clear()
      Clear any state for this question, setting the value to a question-specific default value. Most question types also provide a way to set the default value.
    • getStringValue

      public abstract String getStringValue()
      Get the response to this question as a string.
      Returns:
      a string representing the current response to this question, or null.
      See Also:
    • setValue

      public abstract void setValue(String s) throws Interview.Fault
      Set the response to this question to the value represented by a string-valued argument. Subtypes of Question will typically have type-specific methods to set the value as well.
      Parameters:
      s - A string containing a value value appropriate for the particular type of question whose value is being set.
      Throws:
      Interview.Fault - retained for compatibility; should not be thrown
      See Also:
    • isValueValid

      public abstract boolean isValueValid()
      Check if the question currently has a valid response.
      Returns:
      true if the question currently has a valid response, and false otherwise.
    • isValueAlwaysValid

      public abstract boolean isValueAlwaysValid()
      Check if the question always has a valid response. This may be true, for example, for a choice question with a default response.
      Returns:
      true if the question always has a valid response, and false otherwise.
    • load

      protected void load(Map<String,String> data)
      Loads any state for this question from the given map, using tag as the key. If the loaded value is not null then calls method setValue(String) passing the value.
      Parameters:
      data - The map from which to load the value for this question.
    • save

      protected abstract void save(Map<String,String> data)
      Save any state for this question in a dictionary, using the tag as the key.
      Parameters:
      data - The map in which to save the value for this question.
    • export

      protected void export(Map<String,String> data)
      Export any appropriate values to the dictionary, as part of Interview.export(java.util.Map<java.lang.String, java.lang.String>). The default is to do nothing. Note that only questions which are on the current path have their export method called. Questions do not appear on the current path if they are not accessible from any question on the path, or if they have been disabled.
      Parameters:
      data - The map in which to export any data for this question.
      See Also:
    • reload

      public void reload()
      This methods invokes save(Map), clear() and load(Map). These actions will lead to the default value (if set) will become the question value.
    • equals

      public boolean equals(Object other)
      Check if this question equals another. By default, two questions are equal if they have equal tags, and the string values are either both null or are equal.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getResourceString

      protected String getResourceString(String key)
      Get an entry from the interview's resource bundle. The parent and other ancestors bundles will be checked first before this interview's bundle, allowing the root interview a chance to override the default value provided by this interview.
      Parameters:
      key - the name of the entry to be returned
      Returns:
      the value of the resource, or null if not found
      See Also:
    • getResourceString

      protected String getResourceString(String key, boolean checkAncestorsFirst)
      Get an entry from the interview's resource bundle. If checkAncestorsFirst is true, then the parent and other ancestor interviews' bundles will be checked first before this interview's bundle, allowing the root interview a chance to override the default value provided by this interview. Otherwise, the parent bundles will only be checked if this bundle does not provide a value.
      Parameters:
      key - the name of the entry to be returned
      checkAncestorsFirst - whether to recursively call this method on the parent (if any) before checking this bundle, or only afterwards, if this bundle does not provide a value
      Returns:
      the value of the resource, or null if not found
      See Also: