Exemplo n.º 1
0
  /**
   * Get the ModelParameter Struct for a given parameter name based on a given data model.
   *
   * @param model
   * @param paramName
   * @return
   */
  public static ModelParameter getModelParameter(Model model, String paramName) {
    /** Get the parameter's parent object in the data model */
    ModelObject modelObject = getObjectByParamName(model, paramName);
    if (modelObject == null) {
      log.error("Unable to find parent object for parameter " + paramName);
      return null;
    }

    /** Short Parameter name within the object */
    String paramShortName = paramName.substring(paramName.lastIndexOf(".") + 1, paramName.length());
    /*
    log.debug("paramName " + paramName +
            ": modelObjectName " + modelObject.getName() + ", parameterShortName " + paramShortName);
    */

    /** lookup the parameter within the parent object */
    for (ModelParameter modelParameter : modelObject.getParameterArray()) {
      if (paramShortName.equals(modelParameter.getName())) {
        return modelParameter;
      }
    }
    log.error(
        "Unable to find parameter "
            + paramShortName
            + " within object "
            + modelObject.getName()
            + "!");
    return null;
  }
Exemplo n.º 2
0
  /**
   * Find Model Object by Name
   *
   * @param objName
   * @return
   */
  public static ModelObject getObjectByObjName(Model model, String objName) {
    for (ModelObject object : model.getObjectArray()) {
      if (object.getName().equals(objName)) {
        return object;
      }
    }

    return null;
  }
Exemplo n.º 3
0
  /**
   * When learning the data model from the CPEs via the "GetParameterNames" RPC method, the
   * "GetParameterNamesResponse" message will only contain the parameter names and a boolean
   * "writable" attribute.
   *
   * <p>We will have to compare the parameter names against the standard TR-09 model, and figure out
   * the diffs.
   *
   * <p>For the objects/parameters that are defined in TR-098, we copy all the object/parameter's
   * attribute over from TR-098.
   *
   * <p>For the objects/parameters that are not defined in TR-098, we leave them wide open for now.
   */
  public static Model getModelByGetParameterNamesResponse(
      GetParameterNamesResponseDocument.GetParameterNamesResponse getParameterNamesResponse) {
    // Start with an empty model
    Model model = Model.Factory.newInstance();

    // Go through the response
    ParameterInfoList paramList = getParameterNamesResponse.getParameterList();
    log.info("Found " + paramList.sizeOfParameterInfoStructArray() + " parameters in the response");
    for (ParameterInfoStruct paramInfo : paramList.getParameterInfoStructArray()) {
      /** Extract parameter name/writable from ParameterInfoStruct */
      String name = paramInfo.getName();
      int writable =
          paramInfo.getWritable() ? ReadWriteAccess.INT_READ_WRITE : ReadWriteAccess.INT_READ_ONLY;

      /** Is it an Object (partial path) or a Parameter? */
      if (name.charAt(name.length() - 1) == '.') {
        /**
         * Partial Path ends with a '.' which indicates an Object
         *
         * <p>Have TR-098 model already defined this object?
         */
        ModelObject tr098ModelObject = getTR098ModelObjectByName(name);
        if (tr098ModelObject != null) {
          /** Yes, this object is defined in TR-098. Copy the object over. */
          model.setObjectArray(model.sizeOfObjectArray(), tr098ModelObject);
        } else {
          /**
           * No, this object is not defined in TR-098.
           *
           * <p>Create a new object:
           */
          ModelObject object = model.addNewObject();
          object.setName(name);
          object.setAccess(ReadWriteAccess.Enum.forInt(writable));
          /** TODO: How do we figure out other attributes of this vendor specific parameter? */
          log.info("Created a new vendor specific data model object " + name);
        }
      } else {
        /**
         * This is a full path which indicates a parameter.
         *
         * <p>Do we already have a parent object for it?
         */
        ModelObject parentObj = getObjectByParamName(model, name);
        if (parentObj == null) {
          log.error("Unable to find parent object for parameter " + name);
        } else {
          /**
           * Found the parent object.
           *
           * <p>Have TR-098 already defined this parameter?
           */
          ModelParameter tr098ModelParameter = getTR098ModelParameterByName(name);
          if (tr098ModelParameter != null) {
            // Copy the TR-098 parameter to the new data model
            model.setParameterArray(model.sizeOfParameterArray(), tr098ModelParameter);
          } else {
            // Create a new vendor specific parameter
            ModelParameter newParam = model.addNewParameter();
            newParam.setName(paramInfo.getName());
            newParam.setAccess(ReadWriteAccess.Enum.forInt(writable));

            /** TODO: How do we figure out other attributes of this vendor specific parameter? */
            log.info("Created a new vendor specific data model parameter " + name);
          }
        }
      }
    }

    return model;
  }