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
  /**
   * Get the parameter's XML Schema Type for a given parameter name (based on a given data model).
   *
   * @param model
   * @param paramName
   * @return
   */
  public static SchemaType getParamSchemaType(Model model, String paramName) {
    /** Get the ModelParameter Struct from the data model */
    ModelParameter modelParameter = getModelParameter(model, paramName);
    if (modelParameter == null) {
      log.debug(
          "Unable to find ModelParameter Struct for "
              + paramName
              + "in data model! Treat it as String for now.");
      return XmlString.type;
    }

    broadbandForumOrgCwmpDatamodel14.Syntax syntax = modelParameter.getSyntax();
    if (syntax == null) {
      log.error("Unable to get syntax for " + paramName + "!");
      return XmlString.type;
    }

    if (syntax.isSetString()) {
      return XmlString.type;
    } else if (syntax.isSetBoolean()) {
      return XmlBoolean.type;
    } else if (syntax.isSetInt()) {
      return XmlInt.type;
    } else if (syntax.isSetUnsignedInt()) {
      return XmlUnsignedInt.type;
    } else if (syntax.isSetUnsignedLong()) {
      return XmlUnsignedLong.type;
    } else if (syntax.isSetLong()) {
      return XmlLong.type;
    } else if (syntax.isSetBase64()) {
      return XmlBase64Binary.type;
    } else if (syntax.isSetHexBinary()) {
      return XmlHexBinary.type;
    } else if (syntax.isSetDateTime()) {
      return XmlDateTime.type;
    } else {
      if (syntax.getDataType() != null && syntax.getDataType().getRef() != null) {
        switch (syntax.getDataType().getRef()) {
          case "Alias":
          case "IPAddress":
            return XmlString.type;
        }
      }

      log.error("unknown type in syntax:\n" + syntax.xmlText());
      return XmlString.type;
    }
  }
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;
  }