コード例 #1
0
  /**
   * ************************************************************************* * * Method:
   * performGet * Input: CMIRequest theRequest - tokenized LMSGetValue() request * DMErrorManager
   * dmErrorMgr - Error manager * * Output: String - the value portion of the element for the
   * LMSGetValue() * * Description: This method takes the necessary steps to process * an
   * LMSGetValue() request *
   * *************************************************************************
   */
  public String performGet(CMIRequest theRequest, DMErrorManager dmErrorMgr) {
    if (true) {
      System.out.println("CMIObjectives::performGet()");
    }

    // Resultant value to return
    String result = new String("");

    // Check to make sure this is a valid LMSGetValue() request
    if (isValidObjRequest(theRequest) == true) {
      // Get the next token off of the request
      String token = theRequest.getNextToken();

      if (true) {
        System.out.println("Token being processed: " + token);
      }

      // Check to see if the Request has more tokens to process
      if (theRequest.hasMoreTokensToProcess()) {
        // Token has to be an array index
        try {
          // Convert the string integer to a number
          Integer tmpInt = new Integer(token);
          int indexOfArr = tmpInt.intValue();

          try {
            // Get the Objective Data that is positioned at the input index
            CMIObjectiveData objData = (CMIObjectiveData) objectives.elementAt(indexOfArr);

            // Invoke the performGet on the Objective Data returned.
            result = objData.performGet(theRequest, dmErrorMgr);
          } catch (ArrayIndexOutOfBoundsException e) {
            if (true) {
              System.out.println("Element does not exist at the given index");
              System.out.println("Index: " + indexOfArr);
            }

            // if element has not been initialized, return Invalid
            // Argument Error
            dmErrorMgr.SetCurrentErrorCode("201");
          }
        } catch (NumberFormatException nfe) {
          if (true) {
            // Invalid parameter passed to LMSGetValue()
            System.out.println("Error - Data Model Element not implemented");
            System.out.println(
                "Invalid data model element: "
                    + theRequest.getRequest()
                    + " passed to LMSGetValue()");
            System.out.println("Array index required");
          }

          // Notify error manager
          dmErrorMgr.SetCurrentErrorCode("401");
        }
      } else {
        // No more tokens to process

        // Check to see if the request is for the children of Core Data
        if (theRequest.isAChildrenRequest()) {
          // Set result to the string of children
          result = getChildren();
        } else if (theRequest.isACountRequest()) {
          int count = 0;

          count = objectives.size();

          System.out.println("Count: " + count);

          Integer tmpInt = new Integer(count);
          result = tmpInt.toString();
        } else {
          if (true) {
            System.out.println("Error - Data Model Element not implemented");
            System.out.println("Invalid request: " + theRequest.getRequest());
          }

          dmErrorMgr.recNotImplementedError(theRequest);
        }
      }
    } else {
      if (true) {
        // Error - Data Model Element not implemented
        System.out.println("Error - Data Model Element not implemented");
        System.out.println("Invalid request: " + theRequest.getRequest());
      }

      dmErrorMgr.SetCurrentErrorCode("401");
    }

    // Done processing.  Let CMIRequest object know the processing
    // of the LMSGetValue() is done.
    theRequest.done();

    if (true) {
      System.out.println("Returning from CMIObjectives::performGet()");
      System.out.println("Value returned: " + result);
    }

    return result;
  } // end of performGet()