Exemplo n.º 1
0
  public static Object getJavaObject(HttpServletRequest pRequest, String pFullClassName)
      throws Exception {
    HttpSession session = pRequest.getSession();
    CleanwiseUser appUser = (CleanwiseUser) session.getAttribute(Constants.APP_USER);
    StoreData storeD = appUser.getUserStore();
    AccountData accountD = appUser.getUserAccount();
    int storeId = 0;
    int accountId = 0;
    if (storeD != null) storeId = storeD.getBusEntity().getBusEntityId();
    if (accountD != null) accountId = accountD.getBusEntity().getBusEntityId();
    String key = storeId + "@" + accountId + "@" + pFullClassName;
    Object javaObj = session.getAttribute(key);
    if (javaObj == null) {
      ArrayList prefAL = new ArrayList();
      String path = "";
      PropertyData storePrefixPD = storeD.getPrefix();
      if (storePrefixPD != null) {
        path = Utility.strNN(storePrefixPD.getValue());
      }
      String accountDir = accountD.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.ACCOUNT_FOLDER);
      if (Utility.isSet(accountDir)) {
        path += "/" + accountDir;
      }
      path = path.replace('\\', '/').toLowerCase();
      String[] pathDirA = Utility.parseStringToArray(path, "/");
      String pathInc = null;
      for (int ii = 0; ii < pathDirA.length; ii++) {
        String ss = pathDirA[ii];
        if (Utility.isSet(ss)) {
          if (pathInc == null) {
            pathInc = "." + ss;
          } else {
            pathInc += "." + ss;
          }
          pathDirA[ii] = pathInc;
        } else {
          pathDirA[ii] = null;
        }
      }

      int ll = pFullClassName.lastIndexOf(".");
      String defaultPath = pFullClassName.substring(0, ll);
      String className = pFullClassName.substring(ll);
      Class clazz = null;
      for (int ii = pathDirA.length - 1; ii >= 0; ii--) {
        if (pathDirA[ii] != null) {
          String fullClassNameTest = defaultPath + pathDirA[ii] + className;
          try {
            clazz = Class.forName(fullClassNameTest);
            if (clazz != null) {
              break;
            }
          } catch (Exception exc) {
          }
        }
      }
      if (clazz == null) {
        clazz = Class.forName(pFullClassName);
      }
      if (clazz != null) {
        javaObj = clazz.newInstance();
        session.setAttribute(key, javaObj);
      }
    }
    return javaObj;
  }