/** * Get the appropriate editor for the given property. * * @param prop Property to get editor for. * @return Editor to use, or null if none found. */ private PropertyEditor getEditorForProperty(PropertyDescriptor prop) { PropertyEditor retval = null; Class type = prop.getPropertyEditorClass(); if (type != null) { try { retval = (PropertyEditor) type.newInstance(); } catch (Exception ex) { ex.printStackTrace(); } } // Handle case where there is no special editor // associated with the property. In that case we ask the // PropertyEditor manager for the editor registered for the // given property type. if (retval == null) { Class t = prop.getPropertyType(); if (t != null) { retval = PropertyEditorManager.findEditor(t); } } // In the worse case we resort to the generic editor for Object types. if (retval == null) { retval = PropertyEditorManager.findEditor(Object.class); } return retval; }
/** * 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(); } }