コード例 #1
0
ファイル: ReflectionUtils.java プロジェクト: windy1/foduru
 /**
  * Sets the {@link PrimaryKey} field of the specified {@link Resource} instance.
  *
  * @param resource to set primary key of
  * @param value to set primary key to
  * @throws ResourceException
  */
 public static void setPrimaryKey(Resource resource, Object value) throws ResourceException {
   try {
     getPrimaryKeyField(resource.getClass()).set(resource, value);
   } catch (IllegalAccessException e) {
     throw new ResourceException(e);
   }
 }
コード例 #2
0
ファイル: ReflectionUtils.java プロジェクト: windy1/foduru
 /**
  * Returns the {@link PrimaryKey} of the specified {@link Resource} instance.
  *
  * @param resource to get pk of
  * @return primary key
  * @throws ResourceException
  */
 public static Object getPrimaryKey(Resource resource) throws ResourceException {
   try {
     return getPrimaryKeyField(resource.getClass()).get(resource);
   } catch (IllegalAccessException e) {
     throw new ResourceException(e);
   }
 }
コード例 #3
0
ファイル: ResourceManager.java プロジェクト: abhean/jooprtype
  /**
   * @param _sResource
   * @return
   */
  public <T extends Resource> T getResourceRef(final Class<T> type, final String path) {
    T resource = null;

    Resource genericResource = resources.get(path);

    if (genericResource != null) {
      if (type.isInstance(genericResource)) {
        resource = type.cast(genericResource);
      } else {
        System.err.println(
            "Resource '"
                + path
                + ":"
                + genericResource.getClass().toString()
                + "' is not of type '"
                + type.getName());
      }
    } else {
      resource = loadResource(type, path);

      if (resource != null) {
        resources.put(path, resource);
      }
    }

    if (resource != null) {
      addResourceRef(resource);
    }

    return resource;
  }
コード例 #4
0
  /**
   * Returns list of mapped files, that should be transformed. Files can by specified via attributes
   * (srcFile, srcDir) or resources (FileSet, FileList, DirSet, etc). Mapped file represents input
   * and output file for transformation.
   *
   * @return list of mapped files
   */
  public List<MappedFile> getMappedFiles() {
    mappedFiles.clear();

    // one src file
    if (getSrcFile() != null) {
      addMappedFile(getSrcFile());
    }

    if (getSrcDir() != null) {
      addMappedFile(getSrcDir());
    }

    Iterator element = resources.iterator();
    while (element.hasNext()) {
      ResourceCollection rc = (ResourceCollection) element.next();
      if (rc instanceof FileSet && rc.isFilesystemOnly()) {
        FileSet fs = (FileSet) rc;
        File fromDir = fs.getDir(getProject());

        DirectoryScanner ds;
        try {
          ds = fs.getDirectoryScanner(getProject());
        } catch (BuildException ex) {
          log("Could not scan directory " + fromDir, ex, Project.MSG_ERR);
          continue;
        }

        for (String f : ds.getIncludedFiles()) {
          addMappedFile(new File(fromDir + System.getProperty("file.separator") + f), fromDir);
        }
      } else {
        if (!rc.isFilesystemOnly()) {
          log("Only filesystem resources are supported", Project.MSG_WARN);
          continue;
        }
        Iterator rcIt = rc.iterator();
        while (rcIt.hasNext()) {
          Resource r = (Resource) rcIt.next();
          if (!r.isExists()) {
            log("Could not find resource " + r.toLongString(), Project.MSG_VERBOSE);
            continue;
          }

          if (r instanceof FileResource) {
            FileResource fr = (FileResource) r;
            addMappedFile(fr.getFile(), fr.getBaseDir());
          } else {
            log(
                "Only file resources are supported (" + r.getClass().getSimpleName() + " found)",
                Project.MSG_WARN);
            continue;
          }
        }
      }
    }

    return mappedFiles;
  }
コード例 #5
0
ファイル: ReflectionUtils.java プロジェクト: windy1/foduru
 /**
  * Put's the specified {@link Resource}'s non-null fields into a map and returns the result.
  *
  * @param resource to build parameters map for
  * @return parameter map
  * @throws IllegalAccessException
  */
 public static Map<String, Object> getParameters(@NotNull Resource resource)
     throws IllegalAccessException {
   Class<?> clazz = resource.getClass();
   Field[] fields = clazz.getFields();
   Map<String, Object> params = new HashMap<>();
   for (Field field : fields) {
     Object value = field.get(resource);
     if (isResourceField(field) && value != null) params.put(field.getName(), value);
   }
   return params;
 }
コード例 #6
0
 @Override
 public boolean isAnalogousTo(Resource other) {
   return getClass() == other.getClass() && other.material.equals(this.material);
 }