| XMLPropertyDescriptor.java |
001 package com.javaworld.JavaBeans.XMLBeans;
002
003
004 import java.beans.*;
005 import java.lang.reflect.*;
006
007 public class XMLPropertyDescriptor extends PropertyDescriptor {
008
009 protected boolean _bVisible = true;
010 protected Method _domReadMethod = null;
011 protected Method _domWriteMethod = null;
012
013 // Set just the property name and the bean class
014 public XMLPropertyDescriptor(String propertyName, Class beanClass) throws IntrospectionException, NoSuchMethodException {
015 super(propertyName, beanClass);
016
017 _domReadMethod = null;
018
019 String domGetterName = "get" + Util.capitalize(propertyName) + "AsDOM";
020 try {
021 _domReadMethod = beanClass.getMethod(domGetterName, new Class[] {org.w3c.dom.Document.class});
022 } catch (NoSuchMethodException ex) {
023 // Ignore
024 }
025
026 _domWriteMethod = null;
027
028 String domSetterName = "set" + Util.capitalize(propertyName) + "AsDOM";
029 try {
030 _domWriteMethod = beanClass.getMethod(domSetterName, new Class[] {org.w3c.dom.Node.class});
031 } catch (NoSuchMethodException ex) {
032 // Ignore
033 }
034
035 }
036 // Set the property name and the class, plus the names
037 // of the setter and getter (which set/get property by
038 // value) and the domSetter and domGetter (which get/set
039 // property from a DOM Element object.
040 // Throws NoSuchMethodException if a nonexistent method of beanClass
041 // is specified.
042
043 public XMLPropertyDescriptor(String propertyName, Class beanClass, String getterName,
044 String setterName, String domGetterName, String domSetterName)
045 throws IntrospectionException, NoSuchMethodException {
046
047 super(propertyName, beanClass, getterName, setterName);
048
049 _domReadMethod = beanClass.getMethod(domGetterName,
050 new Class[] { org.w3c.dom.Document.class });
051
052 _domWriteMethod = beanClass.getMethod(domSetterName,
053 new Class[] { org.w3c.dom.Node.class });
054 }
055 // Set the property name, plus the Method objects
056 // for the setter and getter (which set/get property by
057 // value) and the domSetter and domGetter (which get/set
058 // property from a DOM Element object.
059 public XMLPropertyDescriptor(String propertyName, Method getter, Method setter,
060 Method domGetter, Method domSetter) throws IntrospectionException {
061 super(propertyName, getter, setter);
062
063 // Initialize setter and getter methods
064 _domReadMethod = domGetter;
065 _domWriteMethod = domSetter;
066 }
067 // Ask for read/write methods from DOM
068 public Method getDOMReadMethod() {
069 return _domReadMethod;
070 }
071 public Method getDOMWriteMethod() {
072 return _domWriteMethod;
073 }
074 public boolean isVisible() {
075 return _bVisible;
076 }
077 // Internal use only
078 protected void setDOMReadMethod(Method domReadMethod_) {
079 _domReadMethod = domReadMethod_;
080 }
081 protected void setDOMWriteMethod(Method domWriteMethod_) {
082 _domWriteMethod = domWriteMethod_;
083 }
084 public void setVisible(boolean bVisible_) {
085 _bVisible = bVisible_;
086 }
087 }