Пример #1
0
 private Object getAnnotationValue(final Object object, final String methodName)
     throws SiminovException {
   try {
     return object.getClass().getMethod(methodName, null).invoke(object, null);
   } catch (Exception e) {
     Log.loge(
         getClass().getName(),
         "getAnnotationValue",
         "Exception caught while getting annotation value, CLASS-NAME: "
             + object.getClass().getName()
             + ", METHOD NAME: "
             + methodName
             + ", "
             + e.getMessage());
     throw new SiminovException(
         getClass().getName(),
         "getAnnotationValue",
         "Exception caught while getting annotation value, CLASS-NAME: "
             + object.getClass().getName()
             + ", METHOD NAME: "
             + methodName
             + ", "
             + e.getMessage());
   }
 }
Пример #2
0
  /**
   * Get database mapping object after parsing annotation based on class name provided.
   *
   * @param className Name Of Class.
   * @return Database Mapping Object.
   * @throws SiminovException If any exception occur while parsing annotations of class.
   */
  public DatabaseMappingDescriptor parseClass(final String className) throws SiminovException {

    Class<?> classObject = null;
    try {
      classObject = Class.forName(className);
    } catch (Exception exception) {
      Log.logd(
          AnnotationParser.class.getName(),
          "parseClass",
          "Exception caught while creating class object, CLASS-NAME: "
              + className
              + ", "
              + exception.getMessage());
      throw new SiminovException(
          AnnotationParser.class.getName(),
          "parseClass",
          "SiminovException caught while creating class object, CLASS-NAME: "
              + className
              + ", "
              + exception.getMessage());
    }

    try {
      return parseClass(classObject);
    } catch (SiminovException siminovException) {
      Log.logd(
          AnnotationParser.class.getName(),
          "parserClass",
          "SiminovException caught while parsing anootation defined within class, CLASS-NAME: "
              + className
              + ", "
              + siminovException.getMessage());
      throw new SiminovException(
          AnnotationParser.class.getName(),
          "parserClass",
          "SiminovException caught while parsing anootation defined within class, CLASS-NAME: "
              + className
              + ", "
              + siminovException.getMessage());
    }
  }
  private void doValidation() throws DeploymentException {

    /*
     * Validation for name field.
     */
    String name = libraryDescriptor.getName();
    if (name == null || name.length() <= 0) {
      Log.loge(
          getClass().getName(),
          "doValidation",
          "LIBRARY-NAME IS MANDATORY FIELD - LIBRARY-DESCRIPTOR: " + this.libraryName);
      throw new DeploymentException(
          getClass().getName(),
          "doValidation",
          "LIBRARY-NAME IS MANDATORY FIELD - LIBRARY-DESCRIPTOR: " + this.libraryName);
    }

    Iterator<String> databaseMappingPaths = libraryDescriptor.getDatabaseMappingPaths();
    while (databaseMappingPaths.hasNext()) {
      String databaseMappingPath = databaseMappingPaths.next();

      if (databaseMappingPath.endsWith(XML_FILE_EXTENSION)) {
        if (!databaseMappingPath.contains(SIMINOV_DESCRIPTOR_EXTENSION)) {
          Log.loge(
              getClass().getName(),
              "doValidation",
              "INVALID LIBRARY DATABASE MAPPING PATH FOUND, it should contain .core extension in path, PATH-DEFINED: "
                  + databaseMappingPath);
          throw new DeploymentException(
              getClass().getName(),
              "doValidation",
              "INVALID LIBRARY DATABASE MAPPING PATH FOUND, it should contain .core extension in path, PATH-DEFINED: "
                  + databaseMappingPath);
        }
      }
    }
  }
  public LibraryDescriptorParser(final String libraryName) {

    if (libraryName == null || libraryName.length() <= 0) {
      Log.loge(getClass().getName(), "Constructor", "Invalid Library Name Found.");
      throw new DeploymentException(
          getClass().getName(), "Constructor", "Invalid Library Name Found.");
    }

    this.libraryName = libraryName;

    Context context = resources.getApplicationContext();
    if (context == null) {
      Log.loge(getClass().getName(), "Constructor", "Invalid Application Context Found.");
      throw new DeploymentException(
          getClass().getName(), "Constructor", "Invalid Application Context Found.");
    }

    InputStream libraryDescriptorStream = null;
    libraryDescriptorStream =
        getClass()
            .getClassLoader()
            .getResourceAsStream(
                libraryName.replace(".", "/") + "/" + Constants.LIBRARY_DESCRIPTOR_FILE_NAME);

    if (libraryDescriptorStream == null) {
      Log.loge(
          getClass().getName(),
          "Constructor",
          "Invalid Library Descriptor Stream Found, LIBRARY-NAME: "
              + this.libraryName
              + ", PATH: "
              + libraryName.replace(".", "/")
              + "/"
              + Constants.LIBRARY_DESCRIPTOR_FILE_NAME);
      throw new DeploymentException(
          getClass().getName(),
          "Constructor",
          "Invalid Library Descriptor Stream Found, LIBRARY-NAME: "
              + this.libraryName
              + ", PATH: "
              + libraryName.replace(".", "/")
              + "/"
              + Constants.LIBRARY_DESCRIPTOR_FILE_NAME);
    }

    try {
      parseMessage(libraryDescriptorStream);
    } catch (Exception exception) {
      Log.loge(
          getClass().getName(),
          "Constructor",
          "Exception caught while parsing LIBRARY-DESCRIPTOR: "
              + this.libraryName
              + ", "
              + exception.getMessage());
      throw new DeploymentException(
          getClass().getName(),
          "Constructor",
          "Exception caught while parsing LIBRARY-DESCRIPTOR: "
              + this.libraryName
              + ", "
              + exception.getMessage());
    }

    doValidation();
  }