Source Code Cross Referenced for NativeBridge.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » nativebridge » 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 » org package » org.apache.harmony.awt.nativebridge 
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 Sergey V. Kuksenko
019:         * @version $Revision$
020:         */package org.apache.harmony.awt.nativebridge;
021:
022:        import org.apache.harmony.misc.accessors.AccessorFactory;
023:        import org.apache.harmony.misc.accessors.MemoryAccessor;
024:
025:        public class NativeBridge {
026:
027:            private NativeBridge() {
028:            }
029:
030:            private static final NativeBridge instance = new NativeBridge();
031:            private static final MemoryAccessor memAccess = AccessorFactory
032:                    .getMemoryAccessor();
033:            public static final int ptrSize = memAccess.getPointerSize();
034:            public static final boolean is64 = (ptrSize == 8);
035:
036:            /**
037:             * Factory method returns the only instance of the NativeBridge
038:             */
039:            public static NativeBridge getInstance() {
040:                return instance;
041:            }
042:
043:            /**
044:             * Int8Pointer factory methods
045:             */
046:
047:            /**
048:             * Creates pointer to 1-byte data type with given size.
049:             * @param size amount of memory in 1-bytes units that should be allocated.
050:             * @param direct  <code>true</code> for native
051:             * memory usage, <code>false</code> - for java array usage
052:             */
053:            public Int8Pointer createInt8Pointer(int size, boolean direct) {
054:                return new Int8Pointer(size, direct);
055:            }
056:
057:            /**
058:             * Creates modified UTF8 encoded copy of String object in native heap or in java array.
059:             * depending on <code>direct</code> parameter.
060:             * @param str - original string
061:             * @param direct  <code>true</code> to create string in native
062:             * memory, <code>false</code> - using java array
063:             */
064:            public Int8Pointer createStringUTF(String str, boolean direct) {
065:                return createInt8Pointer(str, direct);
066:            }
067:
068:            /**
069:             * Creates modified UTF8 encoded copy of String object in native heap or in java array.
070:             * depending on <code>direct</code> parameter.
071:             * @param str - original string
072:             * @param direct - <code>true</code> to create string in native
073:             * memory, <code>false</code> - using java array
074:             */
075:            public Int8Pointer createInt8Pointer(String str, boolean direct) {
076:                Int8Pointer p = new Int8Pointer(str.length() * 3 + 2, direct);
077:                p.setStringUTF(str);
078:                return p;
079:            }
080:
081:            /**
082:             * Creates pointer to 1-byte data type.
083:             * @param addr - native memory address
084:             */
085:            public Int8Pointer createInt8Pointer(long addr) {
086:                if (addr == 0) {
087:                    return null;
088:                }
089:                return new Int8Pointer(addr);
090:            }
091:
092:            /**
093:             * Creates pointer to 1-byte data type using some void pointer object.
094:             * @param elementPointer  pointer object that should be wrapped
095:             */
096:            public Int8Pointer createInt8Pointer(VoidPointer elementPointer) {
097:                return new Int8Pointer(elementPointer);
098:            }
099:
100:            /**
101:             * Int16Pointer factory methods
102:             */
103:            /**
104:             * Creates pointer to 2-byte data type with given size.
105:             * @param size amount of memory in 2-bytes units that should be allocated.
106:             * @param direct  <code>true</code> for native
107:             * memory usage, <code>false</code> - for java array usage
108:             */
109:            public Int16Pointer createInt16Pointer(int size, boolean direct) {
110:                return new Int16Pointer(size, direct);
111:            }
112:
113:            /**
114:             * Creates pointer to 2-byte data type using some void pointer object.
115:             * @param elementPointer  pointer object that should be wrapped
116:             */
117:            public Int16Pointer createInt16Pointer(VoidPointer elementPointer) {
118:                return new Int16Pointer(elementPointer);
119:            }
120:
121:            /**
122:             * Creates pointer to 2-byte data type.
123:             * @param addr - native memory address
124:             */
125:            public Int16Pointer createInt16Pointer(long addr) {
126:                if (addr == 0) {
127:                    return null;
128:                }
129:                return new Int16Pointer(addr);
130:            }
131:
132:            /**
133:             * Creates UTF16 (Unicode) copy of String object.
134:             * @param str - original string
135:             * @param direct - <code>true</code> to create string in native
136:             * memory, <code>false</code> - using java array
137:             */
138:            public Int16Pointer createInt16Pointer(String str, boolean direct) {
139:                Int16Pointer s = this .createInt16Pointer(str.length() + 2,
140:                        direct);
141:                s.setString(str);
142:                return s;
143:            }
144:
145:            /**
146:             * Creates UTF16 (Unicode) copy of String object.
147:             * @param str - original string
148:             * @param direct - <code>true</code> to create string in native
149:             * memory, <code>false</code> - using java array
150:             */
151:            public Int16Pointer createString(String str, boolean direct) {
152:                return createInt16Pointer(str, direct);
153:            }
154:
155:            /**
156:             * Int32Pointer factory methods
157:             */
158:            /**
159:             * Creates pointer to 4-byte data type with given size.
160:             * @param size amount of memory in 4-bytes units that should be allocated.
161:             * @param direct  <code>true</code> for native
162:             * memory usage, <code>false</code> - for java array usage
163:             */
164:            public Int32Pointer createInt32Pointer(int size, boolean direct) {
165:                return new Int32Pointer(size, direct);
166:            }
167:
168:            /**
169:             * Creates pointer to 4-byte data type using some void pointer object.
170:             * @param elementPointer  pointer object that should be wrapped
171:             */
172:            public Int32Pointer createInt32Pointer(VoidPointer elementPointer) {
173:                return new Int32Pointer(elementPointer);
174:            }
175:
176:            /**
177:             * Creates pointer to 4-byte data type.
178:             * @param addr - native memory address
179:             */
180:            public Int32Pointer createInt32Pointer(long addr) {
181:                if (addr == 0) {
182:                    return null;
183:                }
184:                return new Int32Pointer(addr);
185:            }
186:
187:            /**
188:             * Int64Pointer factory methods
189:             */
190:            /**
191:             * Creates pointer to 8-byte data type with given size.
192:             * @param size amount of memory in 8-bytes units that should be allocated.
193:             * @param direct  <code>true</code> for native
194:             * memory usage, <code>false</code> - for java array usage
195:             */
196:            public Int64Pointer createInt64Pointer(int size, boolean direct) {
197:                return new Int64Pointer(size, direct);
198:            }
199:
200:            /**
201:             * Creates pointer to 8-byte data type using some void pointer object.
202:             * @param elementPointer  pointer object that should be wrapped
203:             */
204:            public Int64Pointer createInt64Pointer(VoidPointer elementPointer) {
205:                return new Int64Pointer(elementPointer);
206:            }
207:
208:            /**
209:             * Creates pointer to 8-byte data type.
210:             * @param addr - native memory address
211:             */
212:            public Int64Pointer createInt64Pointer(long addr) {
213:                if (addr == 0) {
214:                    return null;
215:                }
216:                return new Int64Pointer(addr);
217:            }
218:
219:            /**
220:             * FloatPointer factory methods
221:             */
222:            /**
223:             * Creates pointer to float data type with given size.
224:             * @param size amount of memory in 4-bytes units that should be allocated.
225:             * @param direct  <code>true</code> for native
226:             * memory usage, <code>false</code> - for java array usage
227:             */
228:            public FloatPointer createFloatPointer(int size, boolean direct) {
229:                return new FloatPointer(size, direct);
230:            }
231:
232:            /**
233:             * Creates pointer to float data type using some void pointer object.
234:             * @param elementPointer  pointer object that should be wrapped
235:             */
236:            public FloatPointer createFloatPointer(VoidPointer elementPointer) {
237:                return new FloatPointer(elementPointer);
238:            }
239:
240:            /**
241:             * Creates pointer to float data type.
242:             * @param addr - native memory address
243:             */
244:            public FloatPointer createFloatPointer(long addr) {
245:                if (addr == 0) {
246:                    return null;
247:                }
248:                return new FloatPointer(addr);
249:            }
250:
251:            /**
252:             * FloatPointer factory methods
253:             */
254:            public DoublePointer createDoublePointer(int size, boolean direct) {
255:                return new DoublePointer(size, direct);
256:            }
257:
258:            /**
259:             * Creates pointer to double data type using some void pointer object.
260:             * @param elementPointer  pointer object that should be wrapped
261:             */
262:            public DoublePointer createDoublePointer(VoidPointer elementPointer) {
263:                return new DoublePointer(elementPointer);
264:            }
265:
266:            /**
267:             * Creates pointer to double data type.
268:             * @param addr - native memory address
269:             */
270:            public DoublePointer createDoublePointer(long addr) {
271:                if (addr == 0) {
272:                    return null;
273:                }
274:                return new DoublePointer(addr);
275:            }
276:
277:            /**
278:             * PointerPointer factory methods
279:             */
280:            public PointerPointer createPointerPointer(int size, boolean direct) {
281:                return new PointerPointer(size, direct);
282:            }
283:
284:            public PointerPointer createPointerPointer(long ptrPtr) {
285:                return new PointerPointer(ptrPtr);
286:            }
287:
288:            /**
289:             * Creates pointer to <type>pointer using void pointer object.
290:             * @param p  pointer object that should be wrapped
291:             * @param direct <code>true</code> for native memory usage
292:             */
293:            public PointerPointer createPointerPointer(VoidPointer p,
294:                    boolean direct) {
295:                return new PointerPointer(p, direct);
296:            }
297:
298:            /**
299:             * CLongPointer factory methods
300:             */
301:            /**
302:             * Creates pointer C-lang long data type using some void pointer object.
303:             * @param elementPointer  pointer object that should be wrapped
304:             */
305:            public CLongPointer createCLongPointer(VoidPointer elementPointer) {
306:                return new CLongPointer(elementPointer);
307:            }
308:
309:            /**
310:             * Creates pointer to C-lang long data type with given size.
311:             * @param size amount of memory in 1-bytes units that should be allocated.
312:             * @param direct  <code>true</code> for native
313:             * memory usage, <code>false</code> - for java array usage
314:             */
315:            public CLongPointer createCLongPointer(int size, boolean direct) {
316:                return new CLongPointer(size, direct);
317:            }
318:
319:            /**
320:             * Creates pointer to C-lang long data type.
321:             * @param addr - native memory address
322:             */
323:            public CLongPointer createCLongPointer(long addr) {
324:                if (addr == 0) {
325:                    return null;
326:                }
327:                return new CLongPointer(addr);
328:            }
329:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.