Thread: [Ejtools-cvs] CVS: libraries/xmlweb/src/main/net/sourceforge/ejtools/xml/editors XmlBooleanEditor.ja
Brought to you by:
letiemble
From: Laurent E. <let...@us...> - 2002-04-20 11:42:24
|
Update of /cvsroot/ejtools/libraries/xmlweb/src/main/net/sourceforge/ejtools/xml/editors In directory usw-pr-cvs1:/tmp/cvs-serv28761 Added Files: XmlBooleanEditor.java XmlIntegerEditor.java XmlLongEditor.java XmlObjectNameEditor.java XmlPropertyEditor.java XmlPropertyEditorManager.java XmlPropertyEditorSupport.java XmlStringEditor.java Log Message: Initial Import --- NEW FILE: XmlBooleanEditor.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.xml.editors; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public class XmlBooleanEditor extends XmlPropertyEditorSupport { /** Constructor */ public XmlBooleanEditor() { super(); this.renderer.setType(Boolean.TYPE.getName()); } } --- NEW FILE: XmlIntegerEditor.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.xml.editors; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public class XmlIntegerEditor extends XmlPropertyEditorSupport { /** Constructor */ public XmlIntegerEditor() { super(); this.renderer.setType(Integer.TYPE.getName()); } } --- NEW FILE: XmlLongEditor.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.xml.editors; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public class XmlLongEditor extends XmlPropertyEditorSupport { /** Constructor */ public XmlLongEditor() { super(); this.renderer.setType(Long.TYPE.getName()); } } --- NEW FILE: XmlObjectNameEditor.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.xml.editors; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public class XmlObjectNameEditor extends XmlPropertyEditorSupport { /** Constructor */ public XmlObjectNameEditor() { super(); this.renderer.setType(javax.management.ObjectName.class.getName()); } } --- NEW FILE: XmlPropertyEditor.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.xml.editors; import net.sourceforge.ejtools.xml.XmlComponent; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public interface XmlPropertyEditor { /** * Setter for the value attribute * * @param value The new value */ public void setValue(Object value); /** * Setter for the asText attribute * * @param text The new value */ public void setAsText(String text); /** * Getter for the asText attribute * * @return The value */ public String getAsText(); /** * Getter for the tags attribute * * @return The value */ public String[] getTags(); /** * Description of the Method * * @return Description of the Returned Value */ public boolean supportsCustomRenderer(); /** * Getter for the customRenderer attribute * * @return The value */ public XmlComponent getCustomRenderer(); } --- NEW FILE: XmlPropertyEditorManager.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.xml.editors; import java.util.Hashtable; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public class XmlPropertyEditorManager { private static String searchPath[] = {"com.etiemble.xml.editors"}; private static Hashtable registry; /** * Setter for the editorSearchPath attribute * * @param path The new value */ public static synchronized void setEditorSearchPath(String path[]) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPropertiesAccess(); } if (path == null) { path = new String[0]; } searchPath = path; } /** * Getter for the editorSearchPath attribute * * @return The value */ public static synchronized String[] getEditorSearchPath() { // Return a copy of the searchPath. String result[] = new String[searchPath.length]; for (int i = 0; i < searchPath.length; i++) { result[i] = searchPath[i]; } return result; } /** * Description of the Method * * @param targetType Description of Parameter * @param xmlEditorClass Description of Parameter */ public static void registerXmlEditor(Class targetType, Class xmlEditorClass) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPropertiesAccess(); } initialize(); if (xmlEditorClass == null) { registry.remove(targetType); } else { registry.put(targetType, xmlEditorClass); } } /** * Description of the Method * * @param targetType Description of Parameter * @return Description of the Returned Value */ public static synchronized XmlPropertyEditor findXmlEditor(Class targetType) { initialize(); Class xmlEditorClass = (Class) registry.get(targetType); if (xmlEditorClass != null) { try { Object o = xmlEditorClass.newInstance(); return (XmlPropertyEditor) o; } catch (Exception ex) { System.err.println("Couldn't instantiate type editor \"" + xmlEditorClass.getName() + "\" : " + ex); } } // We couldn't find a suitable Editor. return null; } /** * Description of the Method * * @param targetType Description of Parameter * @param name Description of Parameter */ private static synchronized void load(Class targetType, String name) { String xmlEditorName = name; for (int i = 0; i < searchPath.length; i++) { try { xmlEditorName = searchPath[i] + "." + name; Class cls = Class.forName(xmlEditorName); registry.put(targetType, cls); return; } catch (Exception ex) { // Drop through and try next package. } } // This shouldn't happen. System.err.println("load of " + xmlEditorName + " failed"); } /** Description of the Method */ private static synchronized void initialize() { if (registry != null) { return; } registry = new java.util.Hashtable(); load(Integer.TYPE, "XmlIntegerEditor"); load(Long.TYPE, "XmlLongEditor"); load(Boolean.TYPE, "XmlBooleanEditor"); load(java.lang.String.class, "XmlStringEditor"); load(javax.management.ObjectName.class, "XmlObjectNameEditor"); } } --- NEW FILE: XmlPropertyEditorSupport.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.xml.editors; import net.sourceforge.ejtools.xml.XmlComponent; import net.sourceforge.ejtools.xml.XmlEditor; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public class XmlPropertyEditorSupport implements XmlPropertyEditor { /** Description of the Field */ protected XmlEditor renderer = new XmlEditor(); /** Description of the Field */ protected Object value = null; /** Constructor for use by derived PropertyEditor classes. */ public XmlPropertyEditorSupport() { } /** * Setter for the value attribute * * @param value The new value for value attribute */ public void setValue(Object value) { this.value = value; renderer.setText("" + this.value); } /** * Setter for the asText attribute * * @param value The new value */ public void setAsText(String value) { if (value instanceof String) { setValue(value); renderer.setText(value); return; } throw new java.lang.IllegalArgumentException(value); } /** * Getter for the asText attribute * * @return The value of asText attribute */ public String getAsText() { if (value instanceof String) { return (String) value; } return ("" + value); } /** * Getter for the tags attribute * * @return The value of tags attribute */ public String[] getTags() { return null; } /** * Getter for the customRenderer attribute * * @return The value */ public XmlComponent getCustomRenderer() { return renderer; } /** * Description of the Method * * @return Description of the Returned Value */ public boolean supportsCustomRenderer() { return true; } } --- NEW FILE: XmlStringEditor.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.xml.editors; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public class XmlStringEditor extends XmlPropertyEditorSupport { /** Constructor */ public XmlStringEditor() { super(); this.renderer.setType(java.lang.String.class.getName()); } } |