Source Code Cross Referenced for AbstractStrategizedTransfer.java in  » GIS » udig-1.1 » net » refractions » udig » ui » 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 » GIS » udig 1.1 » net.refractions.udig.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package net.refractions.udig.ui;
004:
005:        import java.util.Arrays;
006:        import java.util.Collections;
007:        import java.util.HashSet;
008:        import java.util.Set;
009:
010:        import net.refractions.udig.internal.ui.TransferStrategy;
011:        import net.refractions.udig.internal.ui.UDIGTransfer;
012:        import net.refractions.udig.internal.ui.UiPlugin;
013:
014:        import org.eclipse.swt.dnd.ByteArrayTransfer;
015:        import org.eclipse.swt.dnd.TransferData;
016:
017:        /**
018:         * This class provides the framework for a transfer to have different behaviours depending on the 
019:         * strategy that is set.
020:         * <p> 
021:         * For example:
022:         * </p><p>
023:         * A GeometryTextTransfer can encode the geometry as a GML string or a WKT string (as created by JTS WKTWriter).
024:         * The GeometryTextTransfer class subclasses AbstractStrategizedTransfer and only needs to provide the current
025:         * strategy and the set of possible strategies.  The AbstractStrategizedTransfer will first try to use the current strategy for 
026:         * encoding the geometry then all the rest if the current strategy fails.  
027:         * Similarly for decoding an input(nativeToJava) the current strategy will be tried first then the rest of the
028:         * known strategies will be used until an object is obtained.
029:         * </p>
030:         * 
031:         * @see net.refractions.udig.internal.ui.TransferStrategy
032:         * @author jeichar
033:         */
034:        public abstract class AbstractStrategizedTransfer extends
035:                ByteArrayTransfer implements  UDIGTransfer {
036:
037:            final Set<TransferStrategy> knownStrategies = Collections
038:                    .synchronizedSet(new HashSet<TransferStrategy>());
039:
040:            public AbstractStrategizedTransfer() {
041:                knownStrategies.addAll(Arrays.asList(getAllStrategies()));
042:            }
043:
044:            @Override
045:            public void javaToNative(Object object, TransferData transferData) {
046:                try {
047:                    getCurrentStrategy().javaToNative(object, transferData);
048:                    return;
049:                } catch (Throwable e) {
050:                    UiPlugin.log("Error encoding " + object, e); //$NON-NLS-1$
051:                }
052:                for (TransferStrategy strategy : knownStrategies) {
053:                    if (strategy == getCurrentStrategy())
054:                        continue;
055:                    try {
056:                        strategy.javaToNative(object, transferData);
057:                        return;
058:                    } catch (Throwable e) {
059:                        UiPlugin.log("Error encoding " + object, e); //$NON-NLS-1$
060:                        continue;
061:                    }
062:                }
063:                throw new RuntimeException(
064:                        "No strategies were capable of encoding " + object); //$NON-NLS-1$
065:            }
066:
067:            @Override
068:            public Object nativeToJava(TransferData transferData) {
069:                try {
070:                    return getCurrentStrategy().nativeToJava(transferData);
071:                } catch (Throwable e) {
072:                    UiPlugin
073:                            .trace(getClass(), "Error decoding transferData", e); //$NON-NLS-1$
074:                }
075:                for (TransferStrategy strategy : knownStrategies) {
076:                    if (strategy == getCurrentStrategy())
077:                        continue;
078:                    try {
079:                        Object value = strategy.nativeToJava(transferData);
080:                        if (value != null)
081:                            return value;
082:                    } catch (Throwable e) {
083:                        UiPlugin.log("Error decoding transferData", e); //$NON-NLS-1$
084:                        continue;
085:                    }
086:                }
087:                throw new RuntimeException(
088:                        "No strategies were capable of decoding transfer data"); //$NON-NLS-1$
089:            }
090:
091:            /**
092:             * Returns the current strategy as indicated by the pereferences
093:             *
094:             * @return the current strategy as indicated by the pereferences
095:             */
096:            public TransferStrategy getCurrentStrategy() {
097:                String indicator = UiPlugin.getDefault().getPreferenceStore()
098:                        .getString(getClass().getName());
099:                if (indicator == null || indicator.length() == 0)
100:                    return getDefaultStrategy();
101:                try {
102:                    return getAllStrategies()[Integer.valueOf(indicator)];
103:                } catch (Exception e) {
104:                    return getDefaultStrategy();
105:                }
106:            }
107:
108:            /**
109:             * Returns the default strategy that is used to encode the java objects.
110:             * 
111:             * @return the strategy to use for encoding the java object.
112:             */
113:            public abstract TransferStrategy getDefaultStrategy();
114:
115:            /**
116:             * This method is only called once during construction to get the list of strategies known by
117:             * the implementation.  
118:             * 
119:             * @return
120:             */
121:            public abstract TransferStrategy[] getAllStrategies();
122:
123:            /**
124:             * Returns the names for the strategies returned by {@link #getAllStrategies()}.  The ith name
125:             * must correspond to the ith strategy.
126:             *
127:             * @return the names for the strategies returned by {@link #getAllStrategies()}
128:             */
129:            public abstract String[] getStrategyNames();
130:
131:            /**
132:             * Returns true if the transfer can transfer to and from the object.
133:             *
134:             * @return true if the transfer can transfer to and from the object.
135:             */
136:            public abstract boolean validate(Object object);
137:
138:            /**
139:             * Adds a new strategy the list of known strategies.
140:             */
141:            public void addStrategy(TransferStrategy newStrategy) {
142:                knownStrategies.add(newStrategy);
143:            }
144:
145:            /**
146:             * Returns a name for the Transfer.
147:             *
148:             * @return name for the Transfer
149:             */
150:            public abstract String getTransferName();
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.