Esempio n. 1
0
  /**
   * Create the given ViewManager
   *
   * @param viewDescriptor Identifies the VM
   * @param properties Property string to pass
   * @return The new one
   */
  public ViewManager createViewManager(ViewDescriptor viewDescriptor, String properties) {
    synchronized (viewManagers) {
      try {
        ViewManager viewManager = null;
        if (viewDescriptor == null) {
          viewDescriptor = new ViewDescriptor();
        }
        if (viewDescriptor.getClassNames().size() > 0) {
          Class viewManagerClass = Misc.findClass((String) viewDescriptor.getClassNames().get(0));
          Constructor ctor =
              Misc.findConstructor(
                  viewManagerClass,
                  new Class[] {IntegratedDataViewer.class, ViewDescriptor.class, String.class});

          if (ctor == null) {
            throw new IllegalArgumentException(
                "cannot create ViewManager:" + viewManagerClass.getName());
          }

          viewManager =
              (ViewManager) ctor.newInstance(new Object[] {getIdv(), viewDescriptor, properties});
        } else {
          viewManager = new MapViewManager(getIdv(), viewDescriptor, properties);
        }

        addViewManager(viewManager);
        return viewManager;
      } catch (Throwable e) {
        logException("In getViewManager", e);
        return null;
      }
    }
  }
  /**
   * _more_
   *
   * @param entry _more_
   * @param className _more_
   * @param properties _more_
   * @return _more_
   * @throws Exception _more_
   */
  private RecordFile doMakeRecordFile(Entry entry, String className, Hashtable properties)
      throws Exception {
    Class c = Misc.findClass(className);
    Constructor ctor = Misc.findConstructor(c, new Class[] {String.class, Hashtable.class});
    if (ctor != null) {
      return (RecordFile) ctor.newInstance(new Object[] {entry.getFile().toString(), properties});
    }
    ctor = Misc.findConstructor(c, new Class[] {String.class});

    if (ctor != null) {
      return (RecordFile) ctor.newInstance(new Object[] {entry.getResource().getPath()});
    }

    throw new IllegalArgumentException("Could not find constructor for " + className);
  }
Esempio n. 3
0
 /**
  * Make the default projections from the internal list of classes.
  *
  * @return list of default projections
  */
 public static List makeDefaultProjections() {
   List defaults = new ArrayList();
   List classNames = getDefaultProjections();
   for (int i = 0; i < classNames.size(); i++) {
     String className = (String) classNames.get(i);
     try {
       Class projClass = Misc.findClass(className);
       ProjectionImpl pi = (ProjectionImpl) projClass.newInstance();
       pi.setName("Default " + pi.getProjectionTypeLabel());
       defaults.add(pi);
     } catch (Exception ee) {
       System.err.println("Error creating default projection: " + className);
       ee.printStackTrace();
     }
   }
   return defaults;
 }
Esempio n. 4
0
    /**
     * Create a new ProjectionClass from the class
     *
     * @param pc projection class
     * @throws ClassNotFoundException couldn't find the class
     * @throws IntrospectionException problem with introspection
     */
    ProjectionClass(Class pc) throws ClassNotFoundException, IntrospectionException {
      projClass = pc;

      // eliminate common properties with "stop class" for getBeanInfo()
      Class stopClass;
      try {
        stopClass = Misc.findClass("ucar.unidata.geoloc.ProjectionImpl");
      } catch (Exception ee) {
        System.err.println("constructParamInput failed ");
        stopClass = null;
      }

      // analyze current projection class as a bean; may throw IntrospectionException
      BeanInfo info = java.beans.Introspector.getBeanInfo(projClass, stopClass);

      // find read/write methods
      PropertyDescriptor[] props = info.getPropertyDescriptors();
      if (debugBeans) {
        System.out.print("Bean Properties for class " + projClass);
        if ((props == null) || (props.length == 0)) {
          System.out.println("none");
          return;
        }
        System.out.println("");
      }
      for (int i = 0; i < props.length; i++) {
        PropertyDescriptor pd = props[i];
        Method reader = pd.getReadMethod();
        Method writer = pd.getWriteMethod();
        // only interesetd in read/write properties
        if ((reader == null) || (writer == null)) {
          continue;
        }
        // A hack to exclude some attributes
        if (pd.getName().equals("name") || pd.getName().equals("defaultMapArea")) {
          continue;
        }
        ProjectionParam p = new ProjectionParam(pd.getName(), reader, writer, pd.getPropertyType());
        paramList.add(p);

        if (debugBeans) {
          System.out.println("  -->" + p);
        }
      }

      // get an instance of this class so we can call toClassName()
      Projection project;
      if (null == (project = makeDefaultProjection())) {
        name = "none";
        return;
      }

      // invoke the toClassName method
      try {
        Method m = projClass.getMethod("getProjectionTypeLabel", VOIDCLASSARG);
        name = (String) m.invoke(project, VOIDOBJECTARG);
      } catch (NoSuchMethodException ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " does not have method getProjectionTypeLabel()");
        throw new ClassNotFoundException();
      } catch (SecurityException ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " got SecurityException on getProjectionTypeLabel()"
                + ee);
        throw new ClassNotFoundException();
      } catch (Exception ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " Exception when invoking getProjectionTypeLabel()"
                + ee);
        throw new ClassNotFoundException();
      }
    }
Esempio n. 5
0
 /**
  * Create a new ProjectionClass from the class name
  *
  * @param className full package name of class
  * @throws ClassNotFoundException couldn't find the class
  * @throws IntrospectionException problem with introspection
  */
 ProjectionClass(String className) throws ClassNotFoundException, IntrospectionException {
   this(Misc.findClass(className));
 }