コード例 #1
0
ファイル: SystemListener.java プロジェクト: njcharran/APDPlat
  public static void contextInitialized(ServletContextEvent sce) {
    contextPath = sce.getServletContext().getContextPath();
    log.info("启动【" + PropertyHolder.getProperty("app.name") + "】");
    log.info("Launch【" + PropertyHolder.getProperty("app.name") + "】", Locale.ENGLISH);
    log.info("应用上下文:" + contextPath);
    log.info("App context:" + contextPath, Locale.ENGLISH);
    ServletContext sc = sce.getServletContext();
    basePath = sc.getRealPath("/");
    if (!basePath.endsWith(File.separator)) {
      basePath = basePath + File.separator;
    }
    // 整个系统中的文件操作都以basePath为基础
    FileUtils.setBasePath(basePath);
    log.info("basePath:" + basePath);
    String userDir = System.getProperty("user.dir");
    log.info("user.dir:" + userDir);
    userDir = FileUtils.getAbsolutePath("/WEB-INF/classes/data/");
    System.setProperty("user.dir", userDir);
    log.info("将user.dir重新设置为:" + userDir);
    log.info("Reset user directory:" + userDir, Locale.ENGLISH);

    String encoding = System.getProperty("file.encoding");
    log.info("你的操作系统所用的编码file.encoding:" + encoding);
    log.info("Encoding of your OS is file.encoding:" + encoding, Locale.ENGLISH);

    // 为spring的配置做预处理
    prepareForSpring();
    // 注册模块
    registerModules();
    // 解析所有的dic.xml文件,并生成供客户端EXT JS调用的文件
    DictionaryGenerator.generateDic(basePath);

    if (runingMonitor) {
      log.info("记录服务器启动日志");
      log.info("Recording the server boot logging", Locale.ENGLISH);
      runingTime = new RuningTime();
      try {
        runingTime.setServerIP(InetAddress.getLocalHost().getHostAddress());
      } catch (UnknownHostException e) {
        log.error("记录服务器启动日志出错", e);
        log.error("Failed to record the server boot logging", e, Locale.ENGLISH);
      }
      runingTime.setAppName(contextPath);
      runingTime.setOsName(System.getProperty("os.name"));
      runingTime.setOsVersion(System.getProperty("os.version"));
      runingTime.setOsArch(System.getProperty("os.arch"));
      runingTime.setJvmName(System.getProperty("java.vm.name"));
      runingTime.setJvmVersion(System.getProperty("java.vm.version"));
      runingTime.setJvmVendor(System.getProperty("java.vm.vendor"));
      runingTime.setStartupTime(new Date());
    }
    if (memoryMonitor) {
      log.info("启动内存监视线程");
      log.info("Enable memory monitor thread", Locale.ENGLISH);
      int circle = PropertyHolder.getIntProperty("monitor.memory.circle");
      memoryMonitorThread = new MemoryMonitorThread(circle);
      memoryMonitorThread.start();
    }
    running = true;
  }
コード例 #2
0
 @Override
 public <T extends Annotation> T getAnnotationOnSetter(String name, Class<T> clz) {
   PropertyHolder pp = properties.get(name);
   if (pp == null) return null;
   Method method = pp.getWriteMethod();
   if (method == null) return null;
   return method.getAnnotation(clz);
 }
コード例 #3
0
 @Override
 public Class<?> getPropertyRawType(String fieldName) {
   PropertyHolder pp = properties.get(fieldName);
   if (pp == null)
     throw new NoSuchElementException(
         fieldName + " not found in bean " + this.obj.getClass().getName());
   return pp.getType();
 }
コード例 #4
0
ファイル: SystemListener.java プロジェクト: njcharran/APDPlat
 public static void prepareForSpring() {
   // 供spring扫描组件用
   String basePackage = PropertyHolder.getProperty("basePackages");
   String localBasePackage = PropertyHolder.getProperty("basePackages.local");
   if (localBasePackage != null && !"".equals(localBasePackage.trim())) {
     basePackage = basePackage + "," + localBasePackage;
   }
   System.setProperty("basePackage", basePackage);
 }
コード例 #5
0
 @Override
 public Collection<String> getRwPropertyNames() {
   ArrayList<String> list = new ArrayList<String>();
   for (PropertyHolder pp : properties.values()) {
     if (pp.getReadMethod() != null && pp.getWriteMethod() != null) {
       list.add(pp.getName());
     }
   }
   return list;
 }
コード例 #6
0
 public Class<?> getFieldType(String fieldName) {
   PropertyHolder pp = properties.get(fieldName);
   if (pp == null)
     throw new NullPointerException("Can not find PropertyHolder for field: " + fieldName);
   Method m = pp.getWriteMethod();
   if (m == null)
     throw new NullPointerException("Can not find WriterMethod for field: " + fieldName);
   Class<?>[] cs = m.getParameterTypes();
   return cs[0];
 }
コード例 #7
0
ファイル: SystemListener.java プロジェクト: njcharran/APDPlat
 private static void registerModules() {
   StringBuilder modules = new StringBuilder();
   try {
     Enumeration<URL> ps =
         Thread.currentThread()
             .getContextClassLoader()
             .getResources("META-INF/services/module.xml");
     while (ps.hasMoreElements()) {
       URL url = ps.nextElement();
       String file = url.getFile();
       if (file.contains(".jar!")) {
         int start = file.indexOf("WEB-INF/lib/");
         int end = file.indexOf("!/META-INF/services/module.xml");
         if (start == -1 || end == -1) {
           continue;
         }
         String jar = file.substring(start, end);
         modules.append(jar).append(",");
         log.info("注册模块:" + jar);
         log.info("Register module:" + jar, Locale.ENGLISH);
         extractWebFromModule(jar);
         extractDataFromModule(jar);
       } else {
         log.warn("在非jar包中找到META-INF/services/module.xml");
         log.warn("Find META-INF/services/module.xml in non-jar", Locale.ENGLISH);
       }
     }
   } catch (IOException e) {
     log.error("注册模块出错", e);
     log.error("Failed to register module", e, Locale.ENGLISH);
   }
   if (modules.length() > 0) {
     modules = modules.deleteCharAt(modules.length() - 1);
   }
   // 从配置文件中获取属性
   String scanJars = PropertyHolder.getProperty("scan.jars");
   log.info("注册模块前,scanJars: " + scanJars);
   log.info("Before register,scanJars: " + scanJars, Locale.ENGLISH);
   if (scanJars != null && !"".equals(scanJars.trim())) {
     scanJars = scanJars + "," + modules.toString();
   } else {
     scanJars = modules.toString();
   }
   // 设置到系统属性中
   // spring会把系统属性中的配置覆盖掉配置文件中的配置
   // <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
   System.setProperty("scan.jars", scanJars);
   // 设置回配置属性
   PropertyHolder.setProperty("scan.jars", scanJars);
   log.info("注册模块后,scanJars: " + scanJars);
   log.info("After register,scanJars: " + scanJars, Locale.ENGLISH);
 }
コード例 #8
0
 public Object getPropertyValue(String fieldName) {
   PropertyHolder pp = properties.get(fieldName);
   if (pp == null) throw new NullPointerException(fieldName + " is not exist!");
   Method m = pp.getReadMethod();
   if (m == null) throw new NullPointerException();
   try {
     return m.invoke(obj, new Object[] {});
   } catch (IllegalArgumentException e) {
     LogUtil.exception(e);
     return null;
   } catch (IllegalAccessException e) {
     LogUtil.exception(e);
     return null;
   } catch (InvocationTargetException e) {
     LogUtil.exception(e);
     return null;
   }
 }
コード例 #9
0
ファイル: SystemListener.java プロジェクト: njcharran/APDPlat
 static {
   memoryMonitor = PropertyHolder.getBooleanProperty("monitor.memory");
   if (memoryMonitor) {
     log.info("启用内存监视日志");
     log.info("Enable memory monitor log", Locale.ENGLISH);
   } else {
     log.info("禁用内存监视日志");
     log.info("Disable memory monitor log", Locale.ENGLISH);
   }
   runingMonitor = PropertyHolder.getBooleanProperty("monitor.runing");
   if (runingMonitor) {
     log.info("启用系统运行日志");
     log.info("Enable system log", Locale.ENGLISH);
   } else {
     log.info("禁用系统运行日志");
     log.info("Disable system log", Locale.ENGLISH);
   }
 }
コード例 #10
0
 public void setPropertyValue(String fieldName, Object newValue) {
   PropertyHolder pp = properties.get(fieldName);
   if (pp == null)
     throw new NullPointerException(
         "Can not find property '" + fieldName + "' in bean " + obj.getClass().getName());
   Method m = pp.getWriteMethod();
   if (m == null)
     throw new NullPointerException(
         "Can not find set method '" + fieldName + "' in bean " + obj.getClass().getName());
   try {
     m.invoke(obj, new Object[] {newValue});
   } catch (IllegalArgumentException e) {
     StringBuilder sb =
         new StringBuilder("IllegalArgumentException:")
             .append(e.getLocalizedMessage())
             .append('\n');
     sb.append(obj.getClass().getName())
         .append('\t')
         .append(fieldName)
         .append('\t')
         .append(newValue.getClass().getName());
     throw new IllegalArgumentException(sb.toString());
   } catch (IllegalAccessException e) {
     StringBuilder sb =
         new StringBuilder("IllegalAccessException:").append(e.getLocalizedMessage()).append('\n');
     sb.append(obj.getClass().getName())
         .append('\t')
         .append(fieldName)
         .append('\t')
         .append(newValue);
     throw new IllegalArgumentException(sb.toString());
   } catch (InvocationTargetException e) {
     StringBuilder sb =
         new StringBuilder("InvocationTargetException:")
             .append(e.getLocalizedMessage())
             .append('\n');
     sb.append(obj.getClass().getName())
         .append('\t')
         .append(fieldName)
         .append('\t')
         .append(newValue);
     throw new IllegalArgumentException(sb.toString());
   }
 }
コード例 #11
0
 public static void checkIfJoinColumn(
     Object columns, PropertyHolder holder, PropertyData property) {
   if (!(columns instanceof Ejb3JoinColumn[])) {
     throw new AnnotationException(
         "@Column cannot be used on an association property: "
             + holder.getEntityName()
             + "."
             + property.getPropertyName());
   }
 }
コード例 #12
0
ファイル: Fix.java プロジェクト: bee-path/BeePath2013_v2.0
  public JSONObject exportJSON(Context context) {

    PropertyHolder.init(context);

    JSONObject object = new JSONObject();
    try {
      object.put("userid", PropertyHolder.getUserId());
      object.put("tripid", this.tripid);
      object.put("lat", String.valueOf(this.lat));
      object.put("lon", String.valueOf(this.lng));
      object.put("alt", String.valueOf(this.alt));
      object.put("acc", String.valueOf(this.acc));
      object.put("provider", String.valueOf(this.prov));
      object.put("timestamp", String.valueOf(this.time));
      object.put("pow_bat", String.valueOf(this.pow));

    } catch (JSONException e) {
    }
    return object;
  }
コード例 #13
0
 public static Ejb3JoinColumn[] buildJoinColumnsWithDefaultColumnSuffix(
     JoinColumn[] anns,
     String mappedBy,
     Map<String, Join> joins,
     PropertyHolder propertyHolder,
     String propertyName,
     String suffixForDefaultColumnName,
     MetadataBuildingContext buildingContext) {
   JoinColumn[] actualColumns =
       propertyHolder.getOverriddenJoinColumn(
           StringHelper.qualify(propertyHolder.getPath(), propertyName));
   if (actualColumns == null) actualColumns = anns;
   if (actualColumns == null || actualColumns.length == 0) {
     return new Ejb3JoinColumn[] {
       buildJoinColumn(
           null,
           mappedBy,
           joins,
           propertyHolder,
           propertyName,
           suffixForDefaultColumnName,
           buildingContext)
     };
   } else {
     int size = actualColumns.length;
     Ejb3JoinColumn[] result = new Ejb3JoinColumn[size];
     for (int index = 0; index < size; index++) {
       result[index] =
           buildJoinColumn(
               actualColumns[index],
               mappedBy,
               joins,
               propertyHolder,
               propertyName,
               suffixForDefaultColumnName,
               buildingContext);
     }
     return result;
   }
 }
コード例 #14
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.splash);

    context = getApplicationContext();
    PropertyHolder.init(context);

    if (context.getPackageName().toLowerCase().contains("asmpro")) {
      PropertyHolder.setProVersion(true);
    }

    // 18 December 2013: end of data collection:
    if (PropertyHolder.getShareData()) {
      PropertyHolder.setShareData(false);
      buildEndResearchAnnouncement();
    } else {

      if (Util.trafficCop(this)) finish();
      // check if there was a database update that tried to
      // trigger a values update before any crash
      Util.needDatabaseUpdate = PropertyHolder.needDatabaseValueUpdate();

      // open and close database in order to trigger any updates
      ContentResolver cr = getContentResolver();
      Cursor c =
          cr.query(Util.getFixesUri(context), new String[] {Fixes.KEY_ROWID}, null, null, null);
      c.close();

      if (PropertyHolder.isServiceOn()) {
        Intent scheduler =
            new Intent(
                getResources().getString(R.string.internal_message_id) + Util.MESSAGE_SCHEDULE);
        context.sendBroadcast(scheduler);
      }

      if (PropertyHolder.getUploadOldFiles()) {
        Intent oldFileUploaderIntent = new Intent(SplashScreen.this, OldFileUploader.class);
        startService(oldFileUploaderIntent);
      }

      Intent intent = new Intent(SplashScreen.this, MapMyData.class);
      startActivity(intent);
      finish();
    }
  }
コード例 #15
0
ファイル: Consent.java プロジェクト: kffallon/CampusMapper
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.consent);
    context = getApplicationContext();
    PropertyHolder.init(context);

    TextView consent = (TextView) findViewById(R.id.consenttext);
    consent.setText(Html.fromHtml(getString(R.string.consent_text)));
    consent.setTextColor(Color.WHITE);
    consent.setTextSize(getResources().getDimension(R.dimen.textsize_normal));

    final Button consentButton = (Button) findViewById(R.id.consent_button);
    consentButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            Date now = new Date(System.currentTimeMillis());
            String consentTime = Util.userDate(now);
            PropertyHolder.setConsentTime(consentTime);
            PropertyHolder.setConsent(true);

            if (PropertyHolder.isRegistered()) {
              if (PropertyHolder.getUserId() != null) {
                ContentResolver ucr = getContentResolver();
                ucr.insert(
                    Util.getUploadQueueUri(context),
                    UploadContentValues.createUpload("CON", consentTime));
              }
              Intent i = new Intent(Consent.this, MapMyData.class);
              startActivity(i);
              finish();
              return;
            } else {

              Intent i = new Intent(Consent.this, Registration.class);
              // start the intent
              startActivity(i);
              finish();
              return;
            }
          }
        });

    final Button consentDeclineButton = (Button) findViewById(R.id.consent_decline_button);
    consentDeclineButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            if (PropertyHolder.getProVersion()) {

              PropertyHolder.setShareData(false);

              Intent i = new Intent(Consent.this, MapMyData.class);
              startActivity(i);
            }
            finish();
            return;
          }
        });
  }
コード例 #16
0
 public boolean isReadableProperty(String fieldName) {
   PropertyHolder pp = properties.get(fieldName);
   if (pp == null) return false;
   return pp.getReadMethod() != null;
 }
コード例 #17
0
 private boolean isSubPackagesEnabled(PropertyHolder propertyHolder) {
   return isTrue(propertyHolder.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES));
 }
コード例 #18
0
ファイル: Fix.java プロジェクト: bee-path/BeePath2013_v2.0
  public String makeFileName(Context context) {

    PropertyHolder.init(context);
    return PropertyHolder.getUserId() + "_" + this.tripid + "_" + Util.fileNameDate(this.time);
  }
コード例 #19
0
 public boolean isWritableProperty(String fieldName) {
   if (fieldName == null) return false;
   PropertyHolder pp = properties.get(fieldName);
   if (pp == null) return false;
   return pp.getWriteMethod() != null;
 }
コード例 #20
0
  // TODO refactor this code, there is a lot of duplication in this method
  public void doSecondPass(Map persistentClasses) throws MappingException {
    org.hibernate.mapping.OneToOne value =
        new org.hibernate.mapping.OneToOne(
            mappings, propertyHolder.getTable(), propertyHolder.getPersistentClass());
    final String propertyName = inferredData.getPropertyName();
    value.setPropertyName(propertyName);
    String referencedEntityName =
        ToOneBinder.getReferenceEntityName(inferredData, targetEntity, mappings);
    value.setReferencedEntityName(referencedEntityName);
    AnnotationBinder.defineFetchingStrategy(value, inferredData.getProperty());
    // value.setFetchMode( fetchMode );
    value.setCascadeDeleteEnabled(cascadeOnDelete);
    // value.setLazy( fetchMode != FetchMode.JOIN );

    if (!optional) value.setConstrained(true);
    value.setForeignKeyType(
        value.isConstrained()
            ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT
            : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
    PropertyBinder binder = new PropertyBinder();
    binder.setName(propertyName);
    binder.setValue(value);
    binder.setCascade(cascadeStrategy);
    binder.setAccessType(inferredData.getDefaultAccess());
    Property prop = binder.makeProperty();
    if (BinderHelper.isEmptyAnnotationValue(mappedBy)) {
      /*
       * we need to check if the columns are in the right order
       * if not, then we need to create a many to one and formula
       * but actually, since entities linked by a one to one need
       * to share the same composite id class, this cannot happen in hibernate
       */
      boolean rightOrder = true;

      if (rightOrder) {
        String path = StringHelper.qualify(propertyHolder.getPath(), propertyName);
        (new ToOneFkSecondPass(
                value,
                joinColumns,
                !optional, // cannot have nullabe and unique on certain DBs
                propertyHolder.getEntityOwnerClassName(),
                path,
                mappings))
            .doSecondPass(persistentClasses);
        // no column associated since its a one to one
        propertyHolder.addProperty(prop, inferredData.getDeclaringClass());
      } else {
        // this is a many to one with Formula

      }
    } else {
      PersistentClass otherSide =
          (PersistentClass) persistentClasses.get(value.getReferencedEntityName());
      Property otherSideProperty;
      try {
        if (otherSide == null) {
          throw new MappingException("Unable to find entity: " + value.getReferencedEntityName());
        }
        otherSideProperty = BinderHelper.findPropertyByName(otherSide, mappedBy);
      } catch (MappingException e) {
        throw new AnnotationException(
            "Unknown mappedBy in: "
                + StringHelper.qualify(ownerEntity, ownerProperty)
                + ", referenced property unknown: "
                + StringHelper.qualify(value.getReferencedEntityName(), mappedBy));
      }
      if (otherSideProperty == null) {
        throw new AnnotationException(
            "Unknown mappedBy in: "
                + StringHelper.qualify(ownerEntity, ownerProperty)
                + ", referenced property unknown: "
                + StringHelper.qualify(value.getReferencedEntityName(), mappedBy));
      }
      if (otherSideProperty.getValue() instanceof OneToOne) {
        propertyHolder.addProperty(prop, inferredData.getDeclaringClass());
      } else if (otherSideProperty.getValue() instanceof ManyToOne) {
        Iterator it = otherSide.getJoinIterator();
        Join otherSideJoin = null;
        while (it.hasNext()) {
          Join otherSideJoinValue = (Join) it.next();
          if (otherSideJoinValue.containsProperty(otherSideProperty)) {
            otherSideJoin = otherSideJoinValue;
            break;
          }
        }
        if (otherSideJoin != null) {
          // @OneToOne @JoinTable
          Join mappedByJoin =
              buildJoinFromMappedBySide(
                  (PersistentClass) persistentClasses.get(ownerEntity),
                  otherSideProperty,
                  otherSideJoin);
          ManyToOne manyToOne = new ManyToOne(mappings, mappedByJoin.getTable());
          // FIXME use ignore not found here
          manyToOne.setIgnoreNotFound(ignoreNotFound);
          manyToOne.setCascadeDeleteEnabled(value.isCascadeDeleteEnabled());
          manyToOne.setEmbedded(value.isEmbedded());
          manyToOne.setFetchMode(value.getFetchMode());
          manyToOne.setLazy(value.isLazy());
          manyToOne.setReferencedEntityName(value.getReferencedEntityName());
          manyToOne.setUnwrapProxy(value.isUnwrapProxy());
          prop.setValue(manyToOne);
          Iterator otherSideJoinKeyColumns = otherSideJoin.getKey().getColumnIterator();
          while (otherSideJoinKeyColumns.hasNext()) {
            Column column = (Column) otherSideJoinKeyColumns.next();
            Column copy = new Column();
            copy.setLength(column.getLength());
            copy.setScale(column.getScale());
            copy.setValue(manyToOne);
            copy.setName(column.getQuotedName());
            copy.setNullable(column.isNullable());
            copy.setPrecision(column.getPrecision());
            copy.setUnique(column.isUnique());
            copy.setSqlType(column.getSqlType());
            copy.setCheckConstraint(column.getCheckConstraint());
            copy.setComment(column.getComment());
            copy.setDefaultValue(column.getDefaultValue());
            manyToOne.addColumn(copy);
          }
          mappedByJoin.addProperty(prop);
        } else {
          propertyHolder.addProperty(prop, inferredData.getDeclaringClass());
        }

        value.setReferencedPropertyName(mappedBy);

        String propertyRef = value.getReferencedPropertyName();
        if (propertyRef != null) {
          mappings.addUniquePropertyReference(value.getReferencedEntityName(), propertyRef);
        }
      } else {
        throw new AnnotationException(
            "Referenced property not a (One|Many)ToOne: "
                + StringHelper.qualify(otherSide.getEntityName(), mappedBy)
                + " in mappedBy of "
                + StringHelper.qualify(ownerEntity, ownerProperty));
      }
    }
    ForeignKey fk = inferredData.getProperty().getAnnotation(ForeignKey.class);
    String fkName = fk != null ? fk.name() : "";
    if (!BinderHelper.isEmptyAnnotationValue(fkName)) value.setForeignKeyName(fkName);
  }