Пример #1
0
 /**
  * Find the class for the projection
  *
  * @param proj projection
  * @return corresponding ProjectionClass (or null if not found)
  */
 private ProjectionClass findProjectionClass(Projection proj) {
   Class want = proj.getClass();
   ComboBoxModel projClassList = projClassCB.getModel();
   for (int i = 0; i < projClassList.getSize(); i++) {
     ProjectionClass pc = (ProjectionClass) projClassList.getElementAt(i);
     if (want.equals(pc.projClass)) {
       return pc;
     }
   }
   return null;
 }
Пример #2
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;
 }
Пример #3
0
 /**
  * Return a String representation of the object
  *
  * @return a String representation of the object
  */
 public String toString() {
   return paramType.getName()
       + " "
       + name
       + " "
       + ((reader == null) ? "-" : "R")
       + ((writer == null) ? "-" : "W");
 }
Пример #4
0
 /**
  * Create the default projection for the default class
  *
  * @return a default projection
  */
 private ProjectionImpl makeDefaultProjection() {
   // the default constructor
   try {
     Constructor c = projClass.getConstructor(VOIDCLASSARG);
     return (ProjectionImpl) c.newInstance(VOIDOBJECTARG);
   } catch (Exception ee) {
     System.err.println(
         "ProjectionManager makeDefaultProjection failed to construct class " + projClass);
     System.err.println("   " + ee);
     return null;
   }
 }
Пример #5
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();
      }
    }