Ejemplo n.º 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()
Ejemplo n.º 2
0
  /**
   * ************************************************************************ * * Method: performSet
   * * Input: CMIRequest theRequest - tokenized LMSSetValue() request * DMErrorManager dmErroMgr -
   * Error Manager * Output: none * * Description: This method takes the necessary steps to process
   * * an LMSSetValue() request *
   * *************************************************************************
   */
  public void performSet(CMIRequest theRequest, DMErrorManager dmErrorMgr) {
    if (true) {
      System.out.println("CMIObjectives::performSet()");
    }

    // The next token must be an array.  If not throw
    // an exception for this request.
    int index = -1;

    // 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 next token is an array index.  For
    // a LMSSetValue() this is true
    try {
      // Try to convert the token to the index
      Integer tmpInt = new Integer(token);
      index = tmpInt.intValue();

      // Get the Objective Data at position of the index
      CMIObjectiveData tmpObj = (CMIObjectiveData) objectives.elementAt(index);

      // An objective existed at the given index.
      // Invoke the performSet() on the Objective Data
      tmpObj.performSet(theRequest, dmErrorMgr);

      // replace the old ObjectiveData with the newly set Objective
      // Data.
      objectives.set(index, tmpObj);
    } catch (NumberFormatException nfe) {
      if (theRequest.isAKeywordRequest() == true) {
        dmErrorMgr.recKeyWordError(token);
      } else {
        if (true) {
          // Invalid parameter passed to LMSSetValue()
          System.out.println("Error - Data Model Element not implemented");
          System.out.println(
              "Invalid data model element: "
                  + theRequest.getRequest()
                  + " passed to LMSSetValue()");
        }

        // Notify error manager
        dmErrorMgr.recNotImplementedError(theRequest);
      }
    } catch (ArrayIndexOutOfBoundsException e) {
      if (true) {
        System.out.println("First time setting the Objective Data");
      }

      if (index <= objectives.size()) {
        // A new Objective Data.
        CMIObjectiveData objData = new CMIObjectiveData();

        // Invoke performSet() on the new Objective Data
        objData.performSet(theRequest, dmErrorMgr);

        // Place the Objective data into the vector at the
        // index position
        objectives.add(index, objData);
      } else {
        dmErrorMgr.SetCurrentErrorCode("201");
      }
    }

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

    return;
  } // end of performSet