001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013: package org.itsnat.core.event;
014:
015: /**
016: * Is used to command ItsNat to transport the specified node property of a client
017: * element and optionally synchronize it with the matched server element as an attribute.
018: *
019: * <p>After synchronization the server DOM element has the same attribute value
020: * as the client property counterpart. If the client property value is null
021: * the server element attribute will be removed too.</p>
022: *
023: * <p>With or without synchronization the property value can be obtained
024: * calling {@link org.itsnat.core.event.ItsNatEvent#getExtraParam(String)}</p>
025: *
026: * @see org.itsnat.core.ItsNatDocument#addEventListener(org.w3c.dom.events.EventTarget,String,org.w3c.dom.events.EventListener,boolean,int,ParamTransport[],String,long)
027: * @author Jose Maria Arranz Santamaria
028: */
029: public class NodePropertyTransport extends SingleParamTransport {
030: private String javaSetMethodName;
031: private Class type;
032: private String attName;
033:
034: /**
035: * Creates a new instance ready to transport the node property with the specified name
036: * and synchronize it at the server side as an attribute, the attribute name used is the same
037: * as the property name.
038: *
039: * @param name the property name.
040: */
041: public NodePropertyTransport(String name) {
042: this (name, name, true);
043: }
044:
045: /**
046: * Creates a new instance ready to transport the node property with the specified name
047: * and optionally synchronize it at the server side as an attribute, the attribute name used is the same
048: * as the property name.
049: *
050: *
051: * @param name the property name.
052: * @param sync if true the server is updated.
053: */
054: public NodePropertyTransport(String name, boolean sync) {
055: this (name, name, sync);
056: }
057:
058: /**
059: * Creates a new instance ready to transport the node property with the specified name
060: * and synchronize it at the server side as an attribute with the specified name.
061: *
062: * <p>Use this constructor when the property name differs from the attribute name.</p>
063: *
064: * @param name the property name.
065: * @param attName the attribute name.
066: */
067: public NodePropertyTransport(String name, String attName) {
068: this (name, attName, true);
069: }
070:
071: private NodePropertyTransport(String name, String attName,
072: boolean sync) {
073: // No hacemos público este constructor pues si se especifica el nombre del atributo
074: // como diferente a la propiedad es que queremos sincronizar seguro.
075: super (name, sync);
076:
077: this .attName = attName;
078:
079: this .type = null;
080:
081: this .javaSetMethodName = null;
082: }
083:
084: /**
085: * Creates a new instance ready to transport the node property with the specified name
086: * and synchronize it at the server side as an attribute. The synchronization is
087: * done using reflection calling the method set<i>Name</i>(<i>Class type</i>)
088: * of the target DOM element.
089: *
090: * <p>For instance: if specified name is "value" and specified type is String,
091: * the method called will be <code>setValue(String)</code></p>
092: *
093: * @param name the property name.
094: * @param type the class type of the property.
095: */
096: public NodePropertyTransport(String name, Class type) {
097: super (name, true);
098:
099: this .type = type;
100:
101: String javaMethodName = Character.toUpperCase(name.charAt(0))
102: + name.substring(1);
103: this .javaSetMethodName = "set" + javaMethodName;
104: this .attName = null;
105: }
106:
107: /**
108: * Creates a new instance ready to transport the node property with the specified name
109: * and synchronize it at the server side as an attribute. The synchronization is
110: * done using reflection calling the set method with the specified name
111: * of the target DOM element.
112: *
113: * <p>For instance: if specified method name is "setValue" and specified type is String,
114: * the method called will be <code>setValue(String)</code></p>
115: *
116: * @param name the property name.
117: * @param type the class type of the property.
118: */
119: public NodePropertyTransport(String name, Class type,
120: String javaSetMethodName) {
121: super (name, true);
122:
123: this .type = type;
124: this .javaSetMethodName = javaSetMethodName;
125: this .attName = null;
126: }
127:
128: /**
129: * Returns the attribute name.
130: *
131: * @return the attribute name or null if reflection is used to synchronize.
132: */
133: public String getAttrName() {
134: return attName;
135: }
136:
137: /**
138: * Returns the class type of the property value when using reflection to synchronize.
139: *
140: * @return the class type or null if reflection is not used to synchronize.
141: */
142: public Class getType() {
143: return type;
144: }
145:
146: /**
147: * Returns the method name used to synchronize using reflection.
148: *
149: * @return the method name or null if reflection is not used to synchronize.
150: */
151: public String getJavaSetMethodName() {
152: return javaSetMethodName;
153: }
154:
155: }
|