Source Code Cross Referenced for SystemFlavorMap.java in  » Apache-Harmony-Java-SE » java-package » java » awt » datatransfer » 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 » Apache Harmony Java SE » java package » java.awt.datatransfer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Michael Danilov, Pavel Dolgov
019:         * @version $Revision$
020:         */package java.awt.datatransfer;
021:
022:        import java.util.ArrayList;
023:        import java.util.Arrays;
024:        import java.util.HashMap;
025:        import java.util.Iterator;
026:        import java.util.LinkedList;
027:        import java.util.List;
028:        import java.util.Map;
029:
030:        import org.apache.harmony.awt.datatransfer.DTK;
031:
032:        public final class SystemFlavorMap implements  FlavorMap, FlavorTable {
033:
034:            private static final String SERIALIZED_PREFIX = "org.apache.harmony.awt.datatransfer:"; //$NON-NLS-1$
035:
036:            private final HashMap<DataFlavor, List<String>> flavor2Native = new HashMap<DataFlavor, List<String>>();
037:            private final HashMap<String, List<DataFlavor>> native2Flavor = new HashMap<String, List<DataFlavor>>();
038:
039:            public static boolean isJavaMIMEType(String str) {
040:                return ((str != null) && str.startsWith(SERIALIZED_PREFIX));
041:            }
042:
043:            public static String encodeJavaMIMEType(String mimeType) {
044:                if (mimeType == null) {
045:                    return null;
046:                }
047:                return (SERIALIZED_PREFIX + mimeType);
048:            }
049:
050:            public static String decodeJavaMIMEType(String nat) {
051:                if (isJavaMIMEType(nat)) {
052:                    return nat.substring(SERIALIZED_PREFIX.length());
053:                }
054:                return null;
055:            }
056:
057:            public static String encodeDataFlavor(DataFlavor flav) {
058:                if (flav == null) {
059:                    return null;
060:                }
061:                return (SERIALIZED_PREFIX + flav.getMimeType());
062:            }
063:
064:            public static DataFlavor decodeDataFlavor(String nat)
065:                    throws ClassNotFoundException {
066:                if (isJavaMIMEType(nat)) {
067:                    return new DataFlavor(nat.substring(SERIALIZED_PREFIX
068:                            .length()));
069:                }
070:                return null;
071:            }
072:
073:            public static FlavorMap getDefaultFlavorMap() {
074:                DTK dtk = DTK.getDTK();
075:
076:                synchronized (dtk) {
077:                    SystemFlavorMap flavorMap = dtk.getSystemFlavorMap();
078:
079:                    if (flavorMap == null) {
080:                        flavorMap = new SystemFlavorMap(dtk);
081:                        dtk.setSystemFlavorMap(flavorMap);
082:                    }
083:
084:                    return flavorMap;
085:                }
086:            }
087:
088:            private SystemFlavorMap(DTK dtk) {
089:                dtk.initSystemFlavorMap(this );
090:            }
091:
092:            public synchronized List<DataFlavor> getFlavorsForNative(String nat) {
093:                if (nat == null) {
094:                    ArrayList<DataFlavor> result = new ArrayList<DataFlavor>();
095:                    for (String key : native2Flavor.keySet()) {
096:                        result.addAll(native2Flavor.get(key));
097:                    }
098:                    return result;
099:                }
100:
101:                List<DataFlavor> list = native2Flavor.get(nat);
102:                if ((list == null || list.isEmpty()) && isJavaMIMEType(nat)) {
103:                    String decodedNat = decodeJavaMIMEType(nat);
104:                    try {
105:                        DataFlavor flavor = new DataFlavor(decodedNat);
106:                        addMapping(nat, flavor);
107:                        list = native2Flavor.get(nat);
108:                    } catch (ClassNotFoundException e) {
109:                    }
110:                }
111:                return (list != null) ? new ArrayList<DataFlavor>(list)
112:                        : new ArrayList<DataFlavor>();
113:            }
114:
115:            public synchronized List<String> getNativesForFlavor(DataFlavor flav) {
116:                if (flav == null) {
117:                    ArrayList<String> result = new ArrayList<String>();
118:                    for (DataFlavor key : flavor2Native.keySet()) {
119:                        result.addAll(flavor2Native.get(key));
120:                    }
121:                    return result;
122:                }
123:
124:                List<String> list = flavor2Native.get(flav);
125:                if ((list == null || list.isEmpty())
126:                        && flav.isFlavorSerializedObjectType()) {
127:                    String nat = encodeDataFlavor(flav);
128:                    addMapping(nat, flav);
129:                    list = flavor2Native.get(flav);
130:                }
131:                return (list != null) ? new ArrayList<String>(list)
132:                        : new ArrayList<String>();
133:            }
134:
135:            public synchronized Map<String, DataFlavor> getFlavorsForNatives(
136:                    String[] natives) {
137:                HashMap<String, DataFlavor> map = new HashMap<String, DataFlavor>();
138:                Iterator<String> it = (natives != null) ? Arrays
139:                        .asList(natives).iterator() : native2Flavor.keySet()
140:                        .iterator();
141:                while (it.hasNext()) {
142:                    String nat = it.next();
143:                    List<DataFlavor> list = getFlavorsForNative(nat);
144:                    if (list.size() > 0) {
145:                        map.put(nat, list.get(0));
146:                    }
147:                }
148:                return map;
149:            }
150:
151:            public synchronized Map<DataFlavor, String> getNativesForFlavors(
152:                    DataFlavor[] flavors) {
153:                HashMap<DataFlavor, String> map = new HashMap<DataFlavor, String>();
154:                Iterator<DataFlavor> it = (flavors != null) ? Arrays.asList(
155:                        flavors).iterator() : flavor2Native.keySet().iterator();
156:                while (it.hasNext()) {
157:                    DataFlavor flavor = it.next();
158:                    List<String> list = getNativesForFlavor(flavor);
159:                    if (list.size() > 0) {
160:                        map.put(flavor, list.get(0));
161:                    }
162:                }
163:                return map;
164:            }
165:
166:            public synchronized void setNativesForFlavor(DataFlavor flav,
167:                    String[] natives) {
168:                LinkedList<String> list = new LinkedList<String>();
169:
170:                for (String nat : natives) {
171:                    if (!list.contains(nat)) {
172:                        list.add(nat);
173:                    }
174:                }
175:
176:                if (!list.isEmpty()) {
177:                    flavor2Native.put(flav, list);
178:                } else {
179:                    flavor2Native.remove(flav);
180:                }
181:            }
182:
183:            public synchronized void setFlavorsForNative(String nat,
184:                    DataFlavor[] flavors) {
185:                LinkedList<DataFlavor> list = new LinkedList<DataFlavor>();
186:
187:                for (DataFlavor flav : flavors) {
188:                    if (!list.contains(flav)) {
189:                        list.add(flav);
190:                    }
191:                }
192:
193:                if (!list.isEmpty()) {
194:                    native2Flavor.put(nat, list);
195:                } else {
196:                    native2Flavor.remove(nat);
197:                }
198:            }
199:
200:            public synchronized void addUnencodedNativeForFlavor(
201:                    DataFlavor flav, String nat) {
202:                List<String> natives = flavor2Native.get(flav);
203:
204:                if (natives == null) {
205:                    natives = new LinkedList<String>();
206:                    flavor2Native.put(flav, natives);
207:                }
208:                if (!natives.contains(nat)) {
209:                    natives.add(nat);
210:                }
211:            }
212:
213:            public synchronized void addFlavorForUnencodedNative(String nat,
214:                    DataFlavor flav) {
215:                List<DataFlavor> flavors = native2Flavor.get(nat);
216:
217:                if (flavors == null) {
218:                    flavors = new LinkedList<DataFlavor>();
219:                    native2Flavor.put(nat, flavors);
220:                }
221:                if (!flavors.contains(flav)) {
222:                    flavors.add(flav);
223:                }
224:            }
225:
226:            private void addMapping(String nat, DataFlavor flav) {
227:                addUnencodedNativeForFlavor(flav, nat);
228:                addFlavorForUnencodedNative(nat, flav);
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.