Source Code Cross Referenced for RADConnectionPropertyEditor.java in  » IDE-Netbeans » form » org » netbeans » modules » form » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » form » org.netbeans.modules.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.form;
043:
044:        import java.awt.*;
045:        import java.beans.*;
046:
047:        import org.openide.explorer.propertysheet.*;
048:        import org.openide.explorer.propertysheet.editors.*;
049:
050:        /**
051:         * RADConnectionPropertyEditor is a special property editor that can set
052:         * properties (of any type) indirectly - e.g. as a property of some bean
053:         * or as the result of a method call or as a code entered by the user, etc.
054:         * Only the source code is generated for such property (usually) so it
055:         * doesn't take effect until runtime.
056:         *
057:         * @author Ian Formanek
058:         */
059:
060:        public class RADConnectionPropertyEditor implements  PropertyEditor,
061:                FormAwareEditor, XMLPropertyEditor, NamedPropertyEditor {
062:            public enum Type {
063:                FormConnection, CustomCode
064:            }
065:
066:            private Type editorType;
067:
068:            protected PropertyChangeSupport support = new PropertyChangeSupport(
069:                    this );
070:            private Class propertyType;
071:            private FormModel formModel = null;
072:            private FormProperty property;
073:            private RADConnectionDesignValue designValue = null;
074:            private Object realValue = null;
075:
076:            /**
077:             * Creates a new RADConnectionPropertyEditor
078:             * 
079:             * @param propertyType type of the property.
080:             */
081:            public RADConnectionPropertyEditor(Class propertyType) {
082:                this .propertyType = propertyType;
083:                this .editorType = Type.FormConnection;
084:            }
085:
086:            public RADConnectionPropertyEditor(Class propertyType,
087:                    Type editorType) {
088:                this .propertyType = propertyType;
089:                this .editorType = editorType;
090:            }
091:
092:            public Type getEditorType() {
093:                return editorType;
094:            }
095:
096:            /** If a property editor or customizer implements the FormAwareEditor
097:             * interface, this method is called immediately after the PropertyEditor
098:             * instance is created or the Customizer is obtained from getCustomizer().
099:             * 
100:             * @param model  The FormModel representing data of opened form.
101:             * @param prop property.
102:             */
103:            public void setContext(FormModel model, FormProperty prop) {
104:                formModel = model;
105:                property = prop;
106:            }
107:
108:            // FormAwareEditor implementation
109:            public void updateFormVersionLevel() {
110:            }
111:
112:            // -----------------------------------------------------------------------------
113:            // PropertyEditor implementation
114:
115:            public Object getValue() {
116:
117:                return designValue != null ? designValue : realValue;
118:            }
119:
120:            public void setValue(Object value) {
121:                if (value instanceof  RADConnectionDesignValue) {
122:                    designValue = (RADConnectionDesignValue) value;
123:                    editorType = designValue.getType() == RADConnectionDesignValue.TYPE_CODE ? Type.CustomCode
124:                            : Type.FormConnection;
125:                    if (editorType == Type.CustomCode) {
126:                        String code = designValue.getCode();
127:                        if ((code == null) || (code.trim().length() == 0)) {
128:                            // Issue 101617
129:                            setValue(property.getDefaultValue());
130:                        }
131:                    }
132:                } else {
133:                    designValue = null;
134:                    realValue = value;
135:                }
136:                support.firePropertyChange("", null, null); // NOI18N
137:            }
138:
139:            public void setAsText(String string) {
140:            }
141:
142:            public String getAsText() {
143:                return null;
144:            }
145:
146:            public String[] getTags() {
147:                return null;
148:            }
149:
150:            public boolean isPaintable() {
151:                return true;
152:            }
153:
154:            public void paintValue(Graphics g, Rectangle rectangle) {
155:                FontMetrics fm = g.getFontMetrics();
156:                g.drawString(getValueString(), rectangle.x, rectangle.y
157:                        + (rectangle.height - fm.getHeight()) / 2
158:                        + fm.getAscent());
159:            }
160:
161:            public boolean supportsCustomEditor() {
162:                return true;
163:            }
164:
165:            public java.awt.Component getCustomEditor() {
166:                if (editorType == Type.FormConnection) {
167:                    ConnectionCustomEditor cust = new ConnectionCustomEditor(
168:                            this , formModel, propertyType);
169:                    cust.setValue(designValue);
170:                    return cust;
171:                } else {
172:                    CodeCustomEditor cust = new CodeCustomEditor(this ,
173:                            formModel, property);
174:                    cust.setValue(designValue);
175:                    return cust;
176:                }
177:            }
178:
179:            public String getJavaInitializationString() {
180:                if (designValue != null) {
181:                    if (designValue.needsInit)
182:                        designValue.initialize();
183:
184:                    if (designValue.type == RADConnectionDesignValue.TYPE_VALUE) {
185:                        if ("java.lang.String"
186:                                .equals(designValue.requiredTypeName)) // NOI18N
187:                            return "\"" + designValue.value + "\""; // NOI18N
188:                        else if ("long".equals(designValue.requiredTypeName)) // NOI18N
189:                            return designValue.value + "L"; // NOI18N
190:                        else if ("float".equals(designValue.requiredTypeName)) // NOI18N
191:                            return designValue.value + "F"; // NOI18N
192:                        else if ("double".equals(designValue.requiredTypeName)) // NOI18N
193:                            return designValue.value + "D"; // NOI18N
194:                        else if ("char".equals(designValue.requiredTypeName)) // NOI18N
195:                            return "\'" + designValue.value + "\'"; // NOI18N
196:                        else
197:                            return designValue.value;
198:                    } else if (designValue.type == RADConnectionDesignValue.TYPE_CODE)
199:                        return designValue.userCode;
200:                    else {
201:                        if (designValue.radComponent == null
202:                                || designValue.radComponent.getCodeExpression() == null)
203:                            return null; // invalid component (probably deleted)
204:
205:                        if (designValue.type == RADConnectionDesignValue.TYPE_PROPERTY) {
206:                            PropertyDescriptor pd = designValue.getProperty();
207:                            if (pd == null)
208:                                return null; // failed to initialize => do not generate code
209:                            else {
210:                                if (designValue.radComponent == formModel
211:                                        .getTopRADComponent()) {
212:                                    return pd.getReadMethod().getName() + "()"; // [FUTURE: Handle indexed properties] // NOI18N
213:                                } else {
214:                                    return designValue.radComponent.getName()
215:                                            + "."
216:                                            + pd.getReadMethod().getName()
217:                                            + "()"; // [FUTURE: Handle indexed properties] // NOI18N
218:                                }
219:                            }
220:                        } else if (designValue.type == RADConnectionDesignValue.TYPE_METHOD) {
221:                            if (designValue.radComponent == formModel
222:                                    .getTopRADComponent()) {
223:                                return designValue.methodName + "()"; // NOI18N
224:                            } else {
225:                                return designValue.radComponent.getName() + "."
226:                                        + designValue.methodName + "()"; // NOI18N
227:                            }
228:                        } else if (designValue.type == RADConnectionDesignValue.TYPE_BEAN) {
229:                            if (designValue.radComponent == formModel
230:                                    .getTopRADComponent()) {
231:                                return "this"; // NOI18N
232:                            } else {
233:                                return designValue.radComponent.getName();
234:                            }
235:                        }
236:                    }
237:                }
238:                return null;
239:            }
240:
241:            public void addPropertyChangeListener(
242:                    PropertyChangeListener propertyChangeListener) {
243:                support.addPropertyChangeListener(propertyChangeListener);
244:            }
245:
246:            public void removePropertyChangeListener(
247:                    PropertyChangeListener propertyChangeListener) {
248:                support.removePropertyChangeListener(propertyChangeListener);
249:            }
250:
251:            // ------------------------------------------
252:            // NamedPropertyEditor implementation
253:
254:            /** @return display name of the property editor */
255:            public String getDisplayName() {
256:                return FormUtils
257:                        .getBundleString(editorType == Type.FormConnection ? "CTL_FormConnection_DisplayName"
258:                                : "CTL_CustomCode_DisplayName"); // NOI18N
259:            }
260:
261:            // ------------------------------------------
262:            private String getValueString() {
263:                String str;
264:                if (designValue != null) {
265:                    str = designValue.getName();
266:                } else if (realValue != null) {
267:                    if (realValue instanceof  Number
268:                            || realValue instanceof  Boolean
269:                            || realValue instanceof  String
270:                            || realValue instanceof  Character)
271:                        str = realValue.toString();
272:                    else
273:                        str = realValue.getClass().isArray() ? "["
274:                                + FormUtils.getBundleString("CTL_ArrayOf")
275:                                + " " // NOI18N
276:                                + realValue.getClass().getComponentType()
277:                                        .getName() + "]" // NOI18N
278:                                : "["
279:                                        + org.openide.util.Utilities
280:                                                .getShortClassName(realValue
281:                                                        .getClass()) + "]"; // NOI18N
282:                } else
283:                    str = "null"; // NOI18N
284:
285:                return str;
286:            }
287:
288:            // ------------------------------------------
289:            // implementation class for FormDesignValue
290:
291:            public static class RADConnectionDesignValue implements 
292:                    FormDesignValue { //, java.io.Serializable {
293:                public final static int TYPE_PROPERTY = 0;
294:                public final static int TYPE_METHOD = 1;
295:                public final static int TYPE_CODE = 2;
296:                public final static int TYPE_VALUE = 3;
297:                public final static int TYPE_BEAN = 4;
298:
299:                /** Determines the type of connection design value */
300:                int type;
301:
302:                private transient RADComponent radComponent = null; // used if type = TYPE_PROPERTY or TYPE_METHOD or TYPE_BEAN
303:                String radComponentName = null; // used if type = TYPE_PROPERTY or TYPE_METHOD
304:
305:                private transient MethodDescriptor method = null; // used if type = TYPE_METHOD
306:                String methodName = null; // used if type = TYPE_METHOD
307:                private transient PropertyDescriptor property = null; // used if type = TYPE_PROPERTY
308:                String propertyName = null; // used if type = TYPE_PROPERTY
309:                String userCode = null; // used if type = TYPE_CODE
310:                String value = null; // used if type = TYPE_VALUE
311:                String requiredTypeName = null; // used if type = TYPE_VALUE
312:
313:                transient private boolean needsInit = false; // used for deserialization init if type = TYPE_PROPERTY or TYPE_METHOD or TYPE_BEAN
314:                transient private FormModel formModel; // used for deserialization init if type = TYPE_PROPERTY or TYPE_METHOD or TYPE_BEAN
315:
316:                static final long serialVersionUID = 147134837271021412L;
317:
318:                RADConnectionDesignValue(RADComponent comp) {
319:                    radComponent = comp;
320:                    radComponentName = radComponent.getName();
321:                    type = TYPE_BEAN;
322:                }
323:
324:                RADConnectionDesignValue(RADComponent comp, MethodDescriptor md) {
325:                    radComponent = comp;
326:                    radComponentName = radComponent.getName();
327:                    method = md;
328:                    methodName = md.getName();
329:                    type = TYPE_METHOD;
330:                }
331:
332:                RADConnectionDesignValue(RADComponent comp,
333:                        PropertyDescriptor pd) {
334:                    radComponent = comp;
335:                    radComponentName = radComponent.getName();
336:                    property = pd;
337:                    propertyName = pd.getName();
338:                    type = TYPE_PROPERTY;
339:                }
340:
341:                RADConnectionDesignValue(String reqTypeName, String valueText) {
342:                    this .requiredTypeName = reqTypeName;
343:                    this .value = valueText;
344:                    type = TYPE_VALUE;
345:                }
346:
347:                private RADConnectionDesignValue(String compName,
348:                        int valueType, String name, FormModel manager) {
349:                    radComponentName = compName;
350:                    formModel = manager;
351:                    if (valueType == TYPE_PROPERTY) {
352:                        needsInit = true;
353:                        type = TYPE_PROPERTY;
354:                        propertyName = name;
355:                    } else if (valueType == TYPE_METHOD) {
356:                        needsInit = true;
357:                        type = TYPE_METHOD;
358:                        methodName = name;
359:                    } else if (valueType == TYPE_BEAN) {
360:                        needsInit = true;
361:                        type = TYPE_BEAN;
362:                    } else
363:                        throw new IllegalArgumentException();
364:                }
365:
366:                public RADConnectionDesignValue(Class requiredType,
367:                        String valueText) {
368:                    this .requiredTypeName = requiredType.getName();
369:                    this .value = valueText;
370:                    type = TYPE_VALUE;
371:                }
372:
373:                public RADConnectionDesignValue(String userCode) {
374:                    this .userCode = userCode;
375:                    type = TYPE_CODE;
376:                }
377:
378:                public FormDesignValue copy(FormProperty formProperty) {
379:                    switch (type) {
380:                    case TYPE_CODE:
381:                        return new RADConnectionDesignValue(userCode);
382:                    case TYPE_VALUE:
383:                        return new RADConnectionDesignValue(requiredTypeName,
384:                                value);
385:                    }
386:                    return null;
387:                }
388:
389:                String getName() {
390:                    if (needsInit)
391:                        initialize();
392:
393:                    if (type == TYPE_VALUE)
394:                        return FormUtils.getFormattedBundleString(
395:                                "FMT_VALUE_CONN", // NOI18N
396:                                new Object[] { value });
397:                    else if (type == TYPE_CODE)
398:                        return FormUtils.getBundleString("CTL_CODE_CONN"); // NOI18N
399:                    else {
400:                        if (radComponent == null
401:                                || radComponent.getCodeExpression() == null)
402:                            return FormUtils
403:                                    .getBundleString("CTL_CONNECTION_INVALID"); // NOI18N
404:
405:                        if (radComponent == null)
406:                            return null;
407:
408:                        if (type == TYPE_PROPERTY)
409:                            return FormUtils.getFormattedBundleString(
410:                                    "FMT_PROPERTY_CONN", // NOI18N
411:                                    new Object[] { radComponent.getName(),
412:                                            propertyName });
413:                        else if (type == TYPE_METHOD)
414:                            return FormUtils.getFormattedBundleString(
415:                                    "FMT_METHOD_CONN", // NOI18N
416:                                    new Object[] { radComponent.getName(),
417:                                            methodName });
418:                        else if (type == TYPE_BEAN)
419:                            return FormUtils.getFormattedBundleString(
420:                                    "FMT_BEAN_CONN", // NOI18N
421:                                    new Object[] { radComponent.getName() });
422:                    }
423:
424:                    throw new IllegalStateException();
425:                }
426:
427:                public PropertyDescriptor getProperty() {
428:                    if (needsInit) {
429:                        if (!initialize())
430:                            return null;
431:                    }
432:                    return property;
433:                }
434:
435:                public MethodDescriptor getMethod() {
436:                    if (needsInit) {
437:                        if (!initialize())
438:                            return null;
439:                    }
440:                    return method;
441:                }
442:
443:                public String getCode() {
444:                    if (needsInit) {
445:                        if (!initialize())
446:                            return null;
447:                    }
448:                    return userCode;
449:                }
450:
451:                public String getValue() {
452:                    if (needsInit) {
453:                        if (!initialize())
454:                            return null;
455:                    }
456:                    return value;
457:                }
458:
459:                public RADComponent getRADComponent() {
460:                    if (needsInit) {
461:                        if (!initialize())
462:                            return null;
463:                    }
464:                    return radComponent;
465:                }
466:
467:                private boolean initialize() {
468:                    boolean retVal = false;
469:                    radComponent = formModel.findRADComponent(radComponentName);
470:                    if (radComponent != null) {
471:                        if (type == TYPE_BEAN) { // bean
472:                            retVal = true;
473:                        } else if (type == TYPE_PROPERTY) { // property
474:                            PropertyDescriptor[] componentsProps = radComponent
475:                                    .getBeanInfo().getPropertyDescriptors();
476:                            for (int i = 0; i < componentsProps.length; i++) {
477:                                if (componentsProps[i].getName().equals(
478:                                        propertyName)) {
479:                                    property = componentsProps[i];
480:                                    retVal = true;
481:                                    break;
482:                                }
483:                            } // if the property of given name cannot be found => ignore
484:                        } else { // method
485:                            MethodDescriptor[] componentMethods = radComponent
486:                                    .getBeanInfo().getMethodDescriptors();
487:                            for (int i = 0; i < componentMethods.length; i++) {
488:                                if (componentMethods[i].getName().equals(
489:                                        methodName)) {
490:                                    method = componentMethods[i];
491:                                    retVal = true;
492:                                    break;
493:                                }
494:                            } // if the property of given name cannot be found => ignore
495:                        }
496:                    } // if the component cannot be found, simply ignore it
497:                    if (retVal)
498:                        needsInit = false;
499:                    return retVal;
500:                }
501:
502:                /** Provides a value which should be used during design-time
503:                 * as the real property value on the bean instance.
504:                 * E.g. the ResourceBundle String would provide the real value
505:                 * of the String from the resource bundle, so that the design-time
506:                 * representation reflects the real code being generated.
507:                 *
508:                 * @return the real property value to be used during design-time
509:                 */
510:                public Object getDesignValue() { //RADComponent radComponent) {
511:                    /*      if (needsInit) {
512:                            if (!initialize()) {
513:                            return IGNORED_VALUE; // failed to initialize
514:                            }
515:                            } */
516:                    switch (type) {
517:                    case TYPE_PROPERTY:
518:                        try {
519:                            return getProperty().getReadMethod().invoke(
520:                                    getRADComponent().getBeanInstance(),
521:                                    new Object[0]);
522:                        } catch (Exception e) {
523:                            // in case of failure do not provide the value during design time
524:                            return FormDesignValue.IGNORED_VALUE;
525:                        }
526:                    case TYPE_METHOD:
527:                        try {
528:                            return getMethod().getMethod().invoke(
529:                                    getRADComponent().getBeanInstance(),
530:                                    new Object[0]);
531:                        } catch (Exception e) {
532:                            // in case of failure do not provide the value during design time
533:                            return FormDesignValue.IGNORED_VALUE;
534:                        }
535:                    case TYPE_VALUE:
536:                        return parseValue(requiredTypeName, value);
537:                    case TYPE_BEAN:
538:                        RADComponent comp = getRADComponent();
539:                        return (comp == null) ? FormDesignValue.IGNORED_VALUE
540:                                : comp.getBeanInstance();
541:                    case TYPE_CODE:
542:                        return FormDesignValue.IGNORED_VALUE;
543:                    default:
544:                        return FormDesignValue.IGNORED_VALUE;
545:                    }
546:                }
547:
548:                public Object getDesignValue(Object target) {
549:                    return null;
550:                    // Return null because RADConnectionValue is not related to the
551:                    // bean on which this value is set (target). The related (source)
552:                    // bean is another component, represented by 'radComponent' field.
553:                    // That's why there is the getValueForBean method.
554:                }
555:
556:                /**
557:                 * Returns represented value for specific bean instance. E.g. if this
558:                 * represents a "text" property, it tries to invoke getText() on the
559:                 * bean. The bean should be of the same type as the bean of the
560:                 * 'radComponent' field.
561:                 * @param target explicitly provided bean instance to get value from
562:                 * @return represented value obtained from given target bean
563:                 */
564:                public Object getValueForBean(Object target) {
565:                    if (target != null) {
566:                        switch (type) {
567:                        case TYPE_PROPERTY:
568:                            try {
569:                                return getProperty().getReadMethod().invoke(
570:                                        target, new Object[0]);
571:                            } catch (Exception e) {
572:                            }
573:                            break;
574:                        case TYPE_METHOD:
575:                            try {
576:                                return getMethod().getMethod().invoke(target,
577:                                        new Object[0]);
578:                            } catch (Exception e) {
579:                            }
580:                            break;
581:                        case TYPE_BEAN:
582:                            return target;
583:                        }
584:                    }
585:                    return null;
586:                }
587:
588:                public String getDescription() {
589:                    return getName();
590:                }
591:
592:                /**
593:                 * Returns type of this connection design value.
594:                 * 
595:                 * @return type of this connection design value.
596:                 */
597:                public int getType() {
598:                    return type;
599:                }
600:            } // end of inner class
601:
602:            private static Object parseValue(String typeName, String value) {
603:                try {
604:                    if ("java.lang.String".equals(typeName)) { // NOI18N
605:                        return value;
606:                    } else if ("int".equals(typeName)) { // NOI18N
607:                        return Integer.valueOf(value);
608:                    } else if ("short".equals(typeName)) { // NOI18N
609:                        return Short.valueOf(value);
610:                    } else if ("long".equals(typeName)) { // NOI18N
611:                        return Long.valueOf(value);
612:                    } else if ("byte".equals(typeName)) { // NOI18N
613:                        return Byte.valueOf(value);
614:                    } else if ("float".equals(typeName)) { // NOI18N
615:                        return Float.valueOf(value);
616:                    } else if ("double".equals(typeName)) { // NOI18N
617:                        return Double.valueOf(value);
618:                    } else if ("boolean".equals(typeName)) { // NOI18N
619:                        return Boolean.valueOf(value);
620:                    } else if ("char".equals(typeName)) { // NOI18N
621:                        if (value.length() > 0)
622:                            return new Character(value.charAt(0));
623:                    }
624:                    return FormDesignValue.IGNORED_VALUE;
625:                } catch (Exception e) {
626:                    // some problem => use ignored value
627:                    return FormDesignValue.IGNORED_VALUE;
628:                }
629:            }
630:
631:            //--------------------------------------------------------------------------
632:            // XMLPropertyEditor implementation
633:
634:            public static final String XML_CONNECTION = "Connection"; // NOI18N
635:
636:            public static final String ATTR_TYPE = "type"; // NOI18N
637:            public static final String ATTR_COMPONENT = "component"; // NOI18N
638:            public static final String ATTR_NAME = "name"; // NOI18N
639:            public static final String ATTR_CODE = "code"; // NOI18N
640:            public static final String ATTR_VALUE = "value"; // NOI18N
641:            public static final String ATTR_REQUIRED_TYPE = "valueType"; // NOI18N
642:
643:            public static final String VALUE_VALUE = "value"; // NOI18N
644:            public static final String VALUE_PROPERTY = "property"; // NOI18N
645:            public static final String VALUE_METHOD = "method"; // NOI18N
646:            public static final String VALUE_BEAN = "bean"; // NOI18N
647:            public static final String VALUE_CODE = "code"; // NOI18N
648:
649:            /** Called to load property value from specified XML subtree. If succesfully loaded,
650:             * the value should be available via the getValue method.
651:             * An IOException should be thrown when the value cannot be restored from the specified XML element
652:             * 
653:             * @param element the XML DOM element representing a subtree of XML from which the value should be loaded
654:             * @throws java.io.IOException thrown when the value cannot be restored from the specified XML element
655:             */
656:            public void readFromXML(org.w3c.dom.Node element)
657:                    throws java.io.IOException {
658:                if (!XML_CONNECTION.equals(element.getNodeName())) {
659:                    throw new java.io.IOException();
660:                }
661:                org.w3c.dom.NamedNodeMap attributes = element.getAttributes();
662:                try {
663:                    String typeString = attributes.getNamedItem(ATTR_TYPE)
664:                            .getNodeValue();
665:                    if (VALUE_VALUE.equals(typeString)) {
666:                        String value = attributes.getNamedItem(ATTR_VALUE)
667:                                .getNodeValue();
668:                        String valueType = attributes.getNamedItem(
669:                                ATTR_REQUIRED_TYPE).getNodeValue();
670:                        setValue(new RADConnectionDesignValue(valueType, value));
671:
672:                    } else if (VALUE_PROPERTY.equals(typeString)) {
673:                        String component = attributes.getNamedItem(
674:                                ATTR_COMPONENT).getNodeValue();
675:                        String name = attributes.getNamedItem(ATTR_NAME)
676:                                .getNodeValue();
677:                        setValue(new RADConnectionDesignValue(component,
678:                                RADConnectionDesignValue.TYPE_PROPERTY, name,
679:                                formModel)); //rcomponent.getFormModel()));
680:
681:                    } else if (VALUE_METHOD.equals(typeString)) {
682:                        String component = attributes.getNamedItem(
683:                                ATTR_COMPONENT).getNodeValue();
684:                        String name = attributes.getNamedItem(ATTR_NAME)
685:                                .getNodeValue();
686:                        setValue(new RADConnectionDesignValue(component,
687:                                RADConnectionDesignValue.TYPE_METHOD, name,
688:                                formModel)); //rcomponent.getFormModel()));
689:
690:                    } else if (VALUE_BEAN.equals(typeString)) {
691:                        String component = attributes.getNamedItem(
692:                                ATTR_COMPONENT).getNodeValue();
693:                        setValue(new RADConnectionDesignValue(component,
694:                                RADConnectionDesignValue.TYPE_BEAN, null,
695:                                formModel)); //rcomponent.getFormModel()));
696:
697:                    } else {
698:                        String code = attributes.getNamedItem(ATTR_CODE)
699:                                .getNodeValue();
700:                        setValue(new RADConnectionDesignValue(code));
701:                    }
702:                } catch (NullPointerException e) {
703:                    java.io.IOException ioex = new java.io.IOException();
704:                    ioex.initCause(e);
705:                    throw ioex;
706:                }
707:            }
708:
709:            /** Called to store current property value into XML subtree. The property
710:             * value should be set using the setValue method prior to calling this method.
711:             * @param doc The XML document to store the XML in - should be used for creating nodes only
712:             * @return the XML DOM element representing a subtree of XML from which the
713:             * value should be loaded
714:             */
715:
716:            public org.w3c.dom.Node storeToXML(org.w3c.dom.Document doc) {
717:                if (designValue == null)
718:                    return null;
719:
720:                String componentName = designValue.radComponent != null ? designValue.radComponent
721:                        .getName()
722:                        : designValue.radComponentName;
723:
724:                if (componentName == null && designValue.radComponent != null)
725:                    return null; // invalid component (probably deleted)
726:
727:                org.w3c.dom.Element el = doc.createElement(XML_CONNECTION);
728:                String typeString;
729:                switch (designValue.type) {
730:                case RADConnectionDesignValue.TYPE_VALUE:
731:                    typeString = VALUE_VALUE;
732:                    break;
733:                case RADConnectionDesignValue.TYPE_PROPERTY:
734:                    typeString = VALUE_PROPERTY;
735:                    break;
736:                case RADConnectionDesignValue.TYPE_METHOD:
737:                    typeString = VALUE_METHOD;
738:                    break;
739:                case RADConnectionDesignValue.TYPE_BEAN:
740:                    typeString = VALUE_BEAN;
741:                    break;
742:                case RADConnectionDesignValue.TYPE_CODE:
743:                default:
744:                    typeString = VALUE_CODE;
745:                    break;
746:                }
747:                el.setAttribute(ATTR_TYPE, typeString);
748:                switch (designValue.type) {
749:                case RADConnectionDesignValue.TYPE_VALUE:
750:                    el.setAttribute(ATTR_VALUE, designValue.value);
751:                    el.setAttribute(ATTR_REQUIRED_TYPE,
752:                            designValue.requiredTypeName);
753:                    break;
754:                case RADConnectionDesignValue.TYPE_PROPERTY:
755:                    el.setAttribute(ATTR_COMPONENT, componentName);
756:                    el.setAttribute(ATTR_NAME, designValue.propertyName);
757:                    break;
758:                case RADConnectionDesignValue.TYPE_METHOD:
759:                    el.setAttribute(ATTR_COMPONENT, componentName);
760:                    el.setAttribute(ATTR_NAME, designValue.methodName);
761:                    break;
762:                case RADConnectionDesignValue.TYPE_BEAN:
763:                    el.setAttribute(ATTR_COMPONENT, componentName);
764:                    break;
765:                case RADConnectionDesignValue.TYPE_CODE:
766:                    el.setAttribute(ATTR_CODE, designValue.userCode);
767:                    break;
768:                }
769:
770:                return el;
771:            }
772:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.