CS 696 Emerging Technologies: Distributed Objects |
---|
public static void registerEditor(Class targetType, Class editorClass)
public static void setEditorSearchPath(String path[])
package beanExamples; import java.beans.*; import java.io.Serializable; public class SchoolReporter implements TimeAdvancedListener, Serializable { School name = new School( School.SDSU); int count = 0; public void setName( School newName) { School oldName = name; name = newName; //Just to show that property change System.out.println( "Old: " + oldName + " New: " + name ); } public School getName() { return name; } public void timeAdvanced( TimeAdvancedEvent timeEvent ) { report(); } public void report() { System.out.println( "Report number: " + (count++) + " from " + name ); } }
package beanExamples; import java.beans.*; import java.io.Serializable; public class School implements Serializable { public static final int SDSU = 1; public static final int USD = 2; public static final int UCSD = 3; private int aSchool; public School( int id ) { aSchool = id; } public int getType() { return aSchool; } public String getName() { switch ( aSchool ) { case 1: return "SDSU"; case 2: return "USD"; case 3: return "UCSD"; default: return "Not Known"; } } }
package beanExamples; import java.beans.*; public class SchoolEditor extends PropertyEditorSupport { public String[] getTags() { return new String[] { "SDSU", "USD", "UCSD" }; } public void setAsText( String input ) { if ( input.equals( "SDSU" ) ) setValue( new School( School.SDSU )); else if ( input.equals( "USD" ) ) setValue( new School( School.USD )); else if ( input.equals( "UCSD" ) ) setValue( new School( School.UCSD )); else throw new IllegalArgumentException( input ); } public String getJavaInitializationString() { School value = (School) getValue(); int type = value.getType(); switch ( type ) { default: case 1: return "new School( School.SDSU )"; case 2: return "new School( School.USD )"; case 3: return "new School( School.UCSD )"; } } }
package beanExamples; import java.beans.*; import java.io.Serializable; public class SchoolReporter implements TimeAdvancedListener, Serializable { String name = "SDSU"; int count = 0; public void setName( String newName) { String oldName = name; name = newName; System.out.println( "New name: " + name + " old " + oldName ); } public String getName() { return name; } public void timeAdvanced( TimeAdvancedEvent timeEvent ) { report(); } public void report() { System.out.println( "Report number: " + (count++) + " from " + name ); } }
package beanExamples; import java.beans.*; public class SchoolEditor extends PropertyEditorSupport { public String[] getTags() { return new String[] { "SDSU", "USD", "UCSD" }; } public void setAsText( String input ) { setValue( input ); } public String getJavaInitializationString() { String school = (String) getValue(); if (school.equals( "SDSU" )) return "SDSU"; else if (school.equals( "UCSD" )) return "UCSD"; else return "USD"; } }
package beanExamples; import java.beans.*; public class SchoolReporterBeanInfo extends SimpleBeanInfo { public PropertyDescriptor[] getPropertyDescriptors() { try { PropertyDescriptor nameProperty = new PropertyDescriptor( "name", SchoolReporter.class ); nameProperty.setDisplayName( "Reporter's School"); nameProperty.setPropertyEditorClass( SchoolEditor.class ); nameProperty.setShortDescription( "This is the name of your reporter"); PropertyDescriptor[] allProperties = { nameProperty }; return allProperties; } catch ( IntrospectionException error ) { return super.getPropertyDescriptors(); } } }
public static Object instantiate(ClassLoader cls, String beanName) throws IOException, ClassNotFoundException