Class Interview

java.lang.Object
com.sun.interview.Interview
Direct Known Subclasses:
ConcurrencyInterview, EnvironmentInterview, ExcludeListInterview, InterviewParameters, InterviewSet, KeywordsInterview, KnownFailuresListInterview, ListQuestion.Body, PriorStatusInterview, TestsInterview, TimeoutFactorInterview

public class Interview extends Object
The base class for an interview: a series of questions, to be presented to the user via some tool such as an assistant or wizard. Interviews may be stand-alone, or designed to be part of other interviews.
  • Field Details

  • Constructor Details

    • Interview

      protected Interview(String tag)
      Create a top-level interview.
      Parameters:
      tag - A tag that will be used to qualify the tags of any questions in this interview, to help ensure uniqueness of those tags.
    • Interview

      protected Interview(Interview parent, String baseTag)
      Create an interview to be used as part of another interview.
      Parameters:
      parent - The parent interview of which this is a part.
      baseTag - A name that will be used to qualify the tags of any questions in this interview, to help ensure uniqueness of those tags. It will be combined with the parent's tag if that has been specified.
  • Method Details

    • isChecksumValid

      @Deprecated public static boolean isChecksumValid(Map<String,String> data, boolean okIfOmitted)
      Deprecated.
      As of version 4.4.1, checksums are no longer calculated or checked. True is always returned.
      Check if the checksum is valid for a set of responses. When responses are saved to a map, they are checksummed, so that they can be checked for validity when reloaded. This method verifies that a set of responses are acceptable for loading.
      Parameters:
      data - The set of responses to be checked.
      okIfOmitted - A boolean determining the response if there is no checksum available in the data
      Returns:
      Always true.
    • writeLocale

      protected static void writeLocale(Map<String,String> data)
      Writes information about current locale to the given map.
      This information is used later to properly restore locale-sensitive values, like numerics.
      Parameters:
      data - target map to write data to
      See Also:
    • readLocale

      protected static Locale readLocale(Map<?,?> data)
      Reads information about locale from the given map.
      Implementation looks for the string keyed by LOCALE and then tries to decode it to valid locale object.
      Parameters:
      data - map with interview values
      Returns:
      locale, decoded from value taken from map; or default (current) locale
      See Also:
    • getParent

      public Interview getParent()
      Get the parent interview for which this is a child.
      Returns:
      the parent interview, or null if no parent has been specified.
    • getTag

      public String getTag()
      Get a tag used to qualify the tags of questions in this interview.
      Returns:
      the title
    • getTitle

      public String getTitle()
      Get a descriptive title associated with this interview. If not specified, the system will try and locate the title in the interview's resource bundle, using the resource name title. of the interview.
      Returns:
      the title
      See Also:
    • setTitle

      protected void setTitle(String title)
      Set a descriptive title to be used to annotate this interview.
      Parameters:
      title - A short descriptive title.
      See Also:
    • getDefaultImage

      public URL getDefaultImage()
      Get a default image to be used for the questions of an interview. If no default has been set for this interview, the parent's default image (if any) is used instead.
      Returns:
      a URL for the default image to be used
      See Also:
    • setDefaultImage

      protected void setDefaultImage(URL u)
      Set a default image to be used for the questions of an interview.
      Parameters:
      u - A URL for the image
      See Also:
    • setResourceBundle

      protected void setResourceBundle(String name, File file)
      Set the base name of the resource bundle used to look up internationalized strings, such as the title and text of each question. If the name is treated as filename of file which is located in directory file. The default is the interview tag name if this is a root interview. If this is a child interview, there is no default resource bundle.
      Parameters:
      name - The name of the resource bundle used to look up internationalized strings.
      file - The directory to find name.
      Throws:
      MissingResourceException - if the resource bundle cannot be found.
      See Also:
    • getResourceBundle

      public ResourceBundle getResourceBundle()
      Get the resource bundle for this interview, used to look up internationalized strings, such as the title and text of each question. If the bundle has not been set explicitly, it defaults to the parent's resource bundle; the root interview has a default resource bundle based on the interview tag name.
      Returns:
      the resource bundle for this interview.
      See Also:
    • setResourceBundle

      protected void setResourceBundle(String name)
      Set the base name of the resource bundle used to look up internationalized strings, such as the title and text of each question. If the name starts with '/', it will be treated as an absolute resource name, and used "as is"; otherwise it will be treated as relative to the package in which the actual interview class is defined. The default is the interview tag name if this is a root interview. If this is a child interview, there is no default resource bundle.
      Parameters:
      name - The name of the resource bundle used to look up internationalized strings.
      Throws:
      MissingResourceException - if the resource bundle cannot be found.
      See Also:
    • setHelpSet

      protected void setHelpSet(String name, File file) throws Interview.Fault
      Set the name of the help set used to locate the "more info" for each question. The name should identify a resource containing a JavaHelp helpset file. If the name is treated as filename of file which is located in directory file. If help sets are specified for child interviews, they will automatically be added into the help set for the root interview.
      Parameters:
      name - The name of the help set containing the "more info" for each question.
      file - The directory to find help set.
      Throws:
      Interview.HelpNotFoundFault - if the help set could not be located
      Interview.BadHelpFault - if some problem occurred while opening the help set
      Interview.Fault
      See Also:
    • getHelpSet

      public Object getHelpSet()
      Get the help set used to locate the "more info" for each question. If the help set has not been set explicitly, it defaults to the parent's help set.
      Returns:
      the help set used to locate "more info" for questions in this interview.
      See Also:
    • setHelpSet

      protected void setHelpSet(String name) throws Interview.Fault
      Set the name of the help set used to locate the "more info" for each question. The name should identify a resource containing a JavaHelp helpset file. If the name starts with '/', it will be treated as an absolute resource name, and used "as is"; otherwise it will be treated as relative to the package in which the actual interview class is defined. If help sets are specified for child interviews, they will automatically be added into the help set for the root interview.
      Parameters:
      name - The name of the help set containing the "more info" for each question.
      Throws:
      Interview.HelpNotFoundFault - if the help set could not be located
      Interview.BadHelpFault - if some problem occurred while opening the help set
      Interview.Fault
      See Also:
    • setHelpSet

      protected void setHelpSet(Object hs)
      Set the help set used to locate the "more info" for each question. If help sets are specified for child interviews, they will automatically be added into the help set for the root interview.
      Parameters:
      hs - The help set containing the "more info" for each question in this interview.
      See Also:
    • isEdited

      public boolean isEdited()
      Determine if this interview as having been edited or not.
      Returns:
      true if this interview is marked as having been edited
    • setEdited

      public void setEdited(boolean edited)
      Mark this interview as having been edited or not.
      Parameters:
      edited - whether or not this interview is marked as edited
    • getFirstQuestion

      public Question getFirstQuestion()
      Get the first question of the interview.
      Returns:
      the first question of the interview
      See Also:
    • setFirstQuestion

      protected void setFirstQuestion(Question q)
      Set the first question for an interview. This may be called more than once, but only while the interview is being constructed. Once any method has been called that refers to the interview path, the initial question may not be changed.
      Parameters:
      q - The initial question
      Throws:
      IllegalStateException - if it is too late to change the initial question.
      See Also:
    • getInterview

      public Interview getInterview(String tag) throws Interview.Fault
      Get a sub-interview with a given tag name. All descendents are searched (i.e. all children, all their children, etc.)
      Parameters:
      tag - The tag of the interview to be found.
      Returns:
      the sub-interview with the specified name.
      Throws:
      Interview.Fault - if no interview is found with the given name.
    • isFirst

      public boolean isFirst(Question q)
      Determine if a question is the first question of the interview.
      Parameters:
      q - the question to check
      Returns:
      true if this is the first question.
    • isLast

      public boolean isLast(Question q)
      Determine if a question is the last question of the interview.
      Parameters:
      q - the question to check
      Returns:
      true if this is the last question.
    • hasNext

      public boolean hasNext(Question q)
      Determine if a question has a non-null successor.
      Parameters:
      q - the question to check
      Returns:
      true if this question has a non-null successor.
    • hasValidNext

      public boolean hasValidNext(Question q)
      Determine if a question has a successor which is neither null nor an ErrorQuestion.
      Parameters:
      q - the question to check
      Returns:
      true if this question has a successor which is neither null nor an ErrorQuestion
    • reset

      public void reset()
      Start (or restart) the interview. The current question is reset to the first question, and the current path is evaluated from there.
    • next

      public void next() throws Interview.Fault
      Advance to the next question in the interview. Questions that have been disabled will be skipped over.
      Throws:
      Interview.Fault - if there are no more questions
    • prev

      public void prev() throws Interview.Fault
      Back up to the previous question in the interview. Questions that have been disabled will be skipped over.
      Throws:
      Interview.Fault - if there is no previous question.
    • last

      public void last() throws Interview.Fault
      Advance to the last question in the interview. Questions that have been disabled will be skipped over.
      Throws:
      Interview.Fault - if there are no more questions
    • isStarted

      public boolean isStarted()
      Check if the interview has been started. An interview is considered to be at the beginning if there is only one question on the current path of a type that requires a response. This indirectly implies it must be the last question on the current path, and must only be preceded by information-only questions.
      Returns:
      true if the first answerable question is unanswered.
    • isFinishable

      public boolean isFinishable()
      Check if the interview has been completed. An interview is considered to have been completed if the final question on the current path is of type FinalQuestion.
      Returns:
      true if the interview has been completed.
    • isInterviewFinishable

      protected boolean isInterviewFinishable()
      Check if this subinterview has been completed. A subinterview is considered to have been completed if none of the questions from this subinterview on the current path return null as the result of getNext(). Note:compare this to isFinishable() which checks that the entire interview (of which this subinterview may be a part) is complete.
      Returns:
      true is this subinterview has been completed.
    • getCurrentQuestion

      public Question getCurrentQuestion()
      Get the current question in the interview.
      Returns:
      The current question.
      See Also:
    • setCurrentQuestion

      public void setCurrentQuestion(Question q) throws Interview.Fault
      Jump to a specific question in the interview. The question must be on the current path, but can be either before or after the current position at the time this is called.
      Parameters:
      q - The question which is to become the current question in the interview.
      Throws:
      Interview.Fault - if the question given is not on the current path.
      See Also:
    • getPath

      public Question[] getPath()
      Get the set of questions on the current path. The first question is determined by the interview; after that, each question in turn determines its successor. The path ends when a question indicates no successor (or erroneously returns a question that is already on the path, that would otherwise form a cycle). The special type of question, FinalQuestion, never returns a successor. Within a particular interview, a question may refer to a nested interview, before continuing within the original interview. Any such references to nested interviews are automatically expanded by this method, leaving just the complete set of basic questions on the path.
      Returns:
      an array containing the list of questions on the current path.
      See Also:
    • getPathToCurrent

      public Question[] getPathToCurrent()
      Get the set of questions on the current path up to and including the current question.
      Returns:
      an array containing the list of questions on the current path up to and including the current question
      See Also:
    • getRawPath

      public Question[] getRawPath(boolean includeFinals)
      Get the current set path of questions, including some things normally hidden. Hidden, disabled and final questions are included upon demand. The list of questions is flattened to only include questions, no representation of the interview structure is given.
      Parameters:
      includeFinals - Should FinalQuestions be included.
      Returns:
      The current active path of questions, based on the requested options. Returns null if no path information is available.
    • iteratePath

      public Iterator<Question> iteratePath(boolean flattenNestedInterviews)
      Get an iterator for the set of questions on the current path. The first question is determined by the interview; after that, each question in turn determines its successor. The path ends when a question indicates no successor (or erroneously returns a question that is already on the path, that would otherwise form a cycle). The special type of question, FinalQuestion, never returns a successor. Within a particular interview, a question may refer to a nested interview, before continuing within the original interview. Such nested interviews may optionally be expanded by this method, depending on the arguments.
      Parameters:
      flattenNestedInterviews - If true, any nested interviews will be expanded in place and returned via the iterator; otherwise, the the nested interview will be returned instead.
      Returns:
      an Iterator for the questions on the current path
      See Also:
    • iteratePathToCurrent

      public Iterator<Question> iteratePathToCurrent(boolean flattenNestedInterviews)
      Get an iterator for the set of questions on the current path up to and including the current question.
      Parameters:
      flattenNestedInterviews - If true, any nested interviews will be expanded in place and returned via the iterator; otherwise, the the nested interview will be returned instead.
      Returns:
      an Iterator for the questions on the current path up to and including the current question
      See Also:
    • verifyPathContains

      public void verifyPathContains(Question q) throws Interview.NotOnPathFault
      Verify that the current path contains a specified question, and throw an exception if it does not.
      Parameters:
      q - the question to be checked
      Throws:
      Interview.NotOnPathFault - if the current path does not contain the specified question.
    • pathContains

      public boolean pathContains(Question q)
      Check if the path contains a specific question.
      Parameters:
      q - The question for which to check.
      Returns:
      true if the question is found on the current path.
    • pathContains

      public boolean pathContains(Interview i)
      Check if the path contains questions from a specific interview.
      Parameters:
      i - The interview for which to check.
      Returns:
      true if the interview is found on the current path.
    • getQuestions

      public Set<Question> getQuestions()
      Get the complete set of questions in this interview and recursively, in all child interviews.
      Returns:
      a set of all questions in this and every child interview.
    • getAllQuestions

      public Map<String,Question> getAllQuestions()
      Get all questions in this interview and recursively, in all child interviews.
      Returns:
      a map containing all questions in this and every child interview.
    • isChecklistEmpty

      public boolean isChecklistEmpty()
      Check whether any questions on the current path have any associated checklist items.
      Returns:
      true if no questions have any corresponding checklist items, and false otherwise.
    • createChecklist

      public Checklist createChecklist()
      Create a checklist composed of all checklist items for questions on the current path.
      Returns:
      a checklist composed of all checklist items for questions on the current path.
      See Also:
    • createChecklistItem

      public Checklist.Item createChecklistItem(String sectionKey, String textKey)
      Create a checklist item based on entries in the interview's resource bundle.
      Parameters:
      sectionKey - A key to identify the section name within the interview's resource bundle
      textKey - A key to identify the checklist item text within the interview's resource bundle
      Returns:
      a Checklist.Item object composed from the appropriate entries in the interview's resource bundle
    • createChecklistItem

      public Checklist.Item createChecklistItem(String sectionKey, String textKey, Object textArg)
      Create a checklist item based on entries in the interview's resource bundle.
      Parameters:
      sectionKey - A key to identify the section name within the interview's resource bundle
      textKey - A key to identify the checklist item text within the interview's resource bundle
      textArg - a single argument to be formatted into the checklist item text
      Returns:
      a Checklist.Item object composed from the appropriate entries in the interview's resource bundle and the specified argument value
    • createChecklistItem

      public Checklist.Item createChecklistItem(String sectionKey, String textKey, Object... textArgs)
      Create a checklist item based on entries in the interview's resource bundle.
      Parameters:
      sectionKey - A key to identify the section name within the interview's resource bundle
      textKey - A key to identify the checklist item text within the interview's resource bundle
      textArgs - an array of arguments to be formatted into the checklist item text
      Returns:
      a Checklist.Item object composed from the appropriate entries in the interview's resource bundle and the specified argument values
    • removeMarkers

      public void removeMarkers(String name)
      Remove all the markers with a specified name.
      Parameters:
      name - The name of the markers to be removed
    • removeAllMarkers

      public void removeAllMarkers()
      Remove all the markers, whatever their name.
    • clearMarkedResponses

      public void clearMarkedResponses(String name)
      Clear the response to marked questions.
      Parameters:
      name - The name of the markers for the questions to be cleared.
    • callInterview

      protected Question callInterview(Interview i, Question q)
      Return a special type of question used to indicate that a sub-interview interview should be called before proceeding to the next question in this interview.
      Parameters:
      i - The nested interview to be called next
      q - The next question to be asked when the nested interview has completes with a final question.
      Returns:
      a pseudo-question that will call a nested interview before continuing with the specified follow-on question.
    • clear

      public void clear()
      Clear any responses to all the questions in this interview, and then recursively, in its child interviews.
    • load

      public void load(Map<String,String> data) throws Interview.Fault
      Load the state for questions from an archive map. The map will be passed to each question in this interview and in any child interviews, and each question should load its state, according to its tag. The data must normally contain a valid checksum, generated during save(java.util.Map<java.lang.String, java.lang.String>).
      Parameters:
      data - The archive map from which the state should be loaded.
      Throws:
      Interview.Fault - if the checksum is found to be incorrect.
    • load

      public void load(Map<String,String> data, boolean checkChecksum) throws Interview.Fault
      Load the state for questions from an archive map. The map will be passed to each question in this interview and in any child interviews, and each question should load its state, according to its tag. The data must normally contain a valid checksum, generated during save(java.util.Map<java.lang.String, java.lang.String>).
      Parameters:
      data - The archive map from which the state should be loaded.
      checkChecksum - If true, the checksum in the data will be checked.
      Throws:
      Interview.Fault - if the checksum is found to be incorrect.
    • save

      public void save(Map<String,String> data)
      Save the state for questions in an archive map. The map will be passed to each question in this interview and in any child interviews, and each question should save its state, according to its tag.
      Parameters:
      data - The archive in which the values should be saved.
    • export

      public void export(Map<String,String> data)
      Export values for questions on the current path, by calling Question.export(java.util.Map<java.lang.String, java.lang.String>) for each question returned by getPath(). It should be called on the root interview to export the values for all questions on the current path, or it can be called on a sub-interview to export just the values from the question in that sub-interview (and in turn, in any further sub-interviews for which there are questions on the path.) Unchecked exceptions that arise from each question's export method are treated according to the policy set by setExportIgnoreExceptionPolicy for the interview for which export was called. It may be convenient to ignore runtime exceptions during export, if exceptions may be thrown when the interview is incomplete. It may be preferred not to ignore any exceptions, if no exceptions are expected.
      Parameters:
      data - The map in which the values will be placed.
      See Also:
    • getExportIgnoreExceptionPolicy

      public int getExportIgnoreExceptionPolicy()
      Get a value representing the policy regarding how to treat exceptions that may arise during export.
      Returns:
      a value representing the policy regarding how to treat exceptions that may arise during export.
      See Also:
    • setExportIgnoreExceptionPolicy

      public void setExportIgnoreExceptionPolicy(int policy)
      Set the policy regarding how to treat exceptions that may arise during export. The default value is to ignore runtime exceptions.
      Parameters:
      policy - a value representing the policy regarding how to treat exceptions that may arise during export
      See Also:
    • addObserver

      public void addObserver(Interview.Observer o)
      Add an observer to monitor updates to the interview.
      Parameters:
      o - an observer to be notified as changes occur
    • removeObserver

      public void removeObserver(Interview.Observer o)
      Remove an observer previously registered to monitor updates to the interview.
      Parameters:
      o - the observer to be removed from the list taht are notified
    • containsObserver

      public boolean containsObserver(Interview.Observer o)
    • setBaseTag

      protected void setBaseTag(String newBaseTag)
      Change the base tag for this interview. This should not be done for most interviews, since the base tag is the basis for storing loading and storing values, and changing the base tag may lead to unexpected results. Changing the base tag will caused the tags in all statically nested interviews and questions to be updated as well. This method is primarily intended to be used when renaming dynamically allocated loop bodies in ListQuestion.
      Parameters:
      newBaseTag - the new value for the base tag.
    • getInterviewSemantics

      public int getInterviewSemantics()
      Determine which semantics are being used for interview and question behavior. This is important because new behavior in future versions can cause unanticipated code flow, resulting in incorrect behavior of existing code.
      Returns:
      The semantics that the interview is currently using.
      Since:
      3.2
      See Also:
    • setInterviewSemantics

      public void setInterviewSemantics(int value)
      This method is being used to toggle changes which are not backwards compatible with existing interviews. Changing this value after you first initialize the top-level interview object is not recommended or supported. This method should be called as soon as possible during construction. It is recommended that you select the most recent version possible when developing a new interview. As this interview ages and the harness libraries progress, the interview should remain locked at the current behavior. Each subsequent version works under the assumption that the behavior of all previous versions is also enabled, there is no way to select individual behaviors.

      The version numbers are effectively an indication of the harness version where the behavior was added (32 = 3.2, 50 = 5.0). Gaps in numbering would indicate that no incompatible behavior changes occurred.

      Select PRE_32 behavior to select behaviors prior to 3.2.

      In Version 32, the first versioned semantic change was introduced. Interviews will generally request SEMANTIC_PRE_32 for old semantics. This version has the behavioral changes:
      ChoiceQuestion
      If the value is reset to null, resulting in the value being "cleared", new behavior simply calls clear() to do this. Old behavior was to select either the last value or first possible choice (from the array of possible choices) THEN call updatePath() and setEdited().
      FileListQuestion
      During construction, clear() will be called before the default value is set, in older implementations it was not called.
      FileQuestion
      During construction, clear() will be called before the default value is set, in older implementations it was not called.

      In Version 43 changes to the way in which export() works were introduced. Earlier than this version, the list of questions to call export() upon with pre-generated as a flattened list of Questions (with all sub-interviews removed). In 43 and later, the structure is NOT flattened, but instead exporting will recurse into sub-interviews by calling its (the Interview) export(). Additionally, questions which are on the path but hidden will be exported. Note that being hidden is not the same at being disabled.

      In Version 50, FileListQuestion has significantly altered processing of filters. See the FileListQuestion.isValueValid() for an explanation.

      Parameters:
      value - Which semantics the interview should use.
      Since:
      3.2
      See Also:
    • storeProperty

      public String storeProperty(String key, String value)
      Store an "external" value into the configuration. This is a value not associated with any interview question and in a separate namespace than all the question keys.
      Parameters:
      key - The name of the key to store.
      value - The value associated with the given key. Null to remove the property from the current set of properties for this interview.
      Returns:
      The old value of this property, null if not previously set.
      See Also:
    • storeTemplateProperty

      public String storeTemplateProperty(String key, String value)
      Store a template value into the configuration.
      Parameters:
      key - The name of the key to store.
      value - The value associated with the given key.
      Returns:
      The old value of this property, null if not previously set.
    • storeTemplateProperties

      public void storeTemplateProperties(Map<String,String> props)
      Clear a previous template properties and store the new into the configuration.
      Parameters:
      props - The properties to store.
    • retrieveProperty

      public String retrieveProperty(String key)
      Retrieve a property from the collection of "external" values being stored in the configuration.
      Parameters:
      key - The key which identifies the property to retrieve.
      Returns:
      The value associated with the given key, or null if it is not found.
      See Also:
    • retrieveTemplateProperty

      public String retrieveTemplateProperty(String key)
      Retrieve a template property.
      Parameters:
      key - The key which identifies the property to retrieve.
      Returns:
      The value associated with the given key, or null if it is not found.
    • retrieveTemplateKeys

      public Set<String> retrieveTemplateKeys()
    • getPropertyKeys

      public Set<String> getPropertyKeys()
      Retrieve set of keys for the "external" values being stored in the configuration.
      Returns:
      The set of keys currently available. Null if there are none. All values in the Set are Strings.
      See Also:
    • getExternalProperties

      public Map<String,String> getExternalProperties()
      Get a (shallow) copy of the current "external" values.
      Returns:
      The copy of the properties, null if there are none.
      See Also:
    • propagateTemplateForAll

      public void propagateTemplateForAll()
    • isRoot

      public boolean isRoot()
      Determine if this is the root interview.
      Returns:
      True if this is the root interview.
    • getRoot

      public Interview getRoot()
      Get the root interview object for an interview series. Some parts of the data are associated only with the root interview, such as tags, external values and the getRawPath(boolean) information.
    • updatePath

      public void updatePath()
      Update the current path, typically because a response to a question has changed.
    • updatePath

      public void updatePath(Question q)
      Update the current path, typically because a response to a question has changed.
      Parameters:
      q - The question that was changed.
    • getResourceString

      protected String getResourceString(String key)
      Get an entry from the 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
    • getResourceString

      protected String getResourceString(String key, boolean checkAncestorsFirst)
      Get an entry from the resource bundle. If checkAncestorsFirst is true, then 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. 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