Source Code Cross Referenced for JAIRMIUtil.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » com » sun » media » jai » rmi » 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 » 6.0 JDK Modules » Java Advanced Imaging » com.sun.media.jai.rmi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: JAIRMIUtil.java,v $
003:         *
004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Use is subject to license terms.
007:         *
008:         * $Revision: 1.1 $
009:         * $Date: 2005/02/11 04:56:51 $
010:         * $State: Exp $
011:         */package com.sun.media.jai.rmi;
012:
013:        import java.awt.RenderingHints;
014:        import java.awt.image.RenderedImage;
015:        import java.awt.image.renderable.ParameterBlock;
016:        import java.io.Serializable;
017:        import java.util.Vector;
018:        import java.util.Hashtable;
019:        import javax.media.jai.RenderedOp;
020:        import javax.media.jai.PlanarImage;
021:        import javax.media.jai.remote.RemoteRenderedOp;
022:        import javax.media.jai.remote.SerializableRenderedImage;
023:
024:        /**
025:         * A class containing utility methods used for the implementation of
026:         * the "jairmi" protocol.
027:         */
028:        public final class JAIRMIUtil {
029:
030:            /**
031:             * Replaces any element in the source Vector which is an ID
032:             * with the server-side node that is associated with the
033:             * given ID.
034:             */
035:            public static Vector replaceIdWithSources(Vector srcs,
036:                    Hashtable nodes, String opName, RenderingHints hints) {
037:
038:                Vector replacedSrcs = new Vector();
039:                Object obj;
040:                for (int i = 0; i < srcs.size(); i++) {
041:                    obj = srcs.elementAt(i);
042:                    if (obj instanceof  String) {
043:                        String serverNodeDesc = (String) obj;
044:                        int index = serverNodeDesc.indexOf("::");
045:                        boolean diffServer = index != -1;
046:                        if (diffServer) {
047:                            // If the source is on a different server, create
048:                            // a RMIServerProxy to access it.
049:                            replacedSrcs.add(new RMIServerProxy(serverNodeDesc,
050:                                    opName, hints));
051:                        } else {
052:                            // If the source is on the same server, get it
053:                            // from the nodes Hashtable and set it as a source
054:                            // in the sources Vector.
055:                            replacedSrcs.add(nodes.get(Long
056:                                    .valueOf(serverNodeDesc)));
057:                        }
058:                    } else {
059:                        PlanarImage pi = PlanarImage
060:                                .wrapRenderedImage((RenderedImage) obj);
061:                        replacedSrcs.add(pi);
062:                    }
063:                }
064:
065:                return replacedSrcs;
066:            }
067:
068:            /**
069:             * Replaces any source that is an <code>RMIServerProxy</code> with
070:             * the id of the server-side node that is represented by the
071:             * <code>RMIServerProxy</code>.
072:             */
073:            public static Vector replaceSourcesWithId(Vector srcs,
074:                    String serverName) {
075:
076:                Vector replacedSrcs = new Vector();
077:                Object obj;
078:                for (int i = 0; i < srcs.size(); i++) {
079:                    obj = srcs.elementAt(i);
080:                    if (obj instanceof  RMIServerProxy) {
081:                        RMIServerProxy rmisp = (RMIServerProxy) obj;
082:                        if (rmisp.getServerName().equalsIgnoreCase(serverName)) {
083:                            replacedSrcs.add(rmisp.getRMIID().toString());
084:                        } else {
085:                            String str = new String(rmisp.getServerName()
086:                                    + "::" + rmisp.getRMIID());
087:                            replacedSrcs.add(str);
088:                        }
089:                    } else if (obj instanceof  RemoteRenderedOp) {
090:                        RemoteRenderedOp rrop = (RemoteRenderedOp) obj;
091:                        Object ai = rrop.getRendering();
092:                        if (ai instanceof  RMIServerProxy) {
093:                            RMIServerProxy rmisp = (RMIServerProxy) ai;
094:                            if (rmisp.getServerName().equalsIgnoreCase(
095:                                    serverName)) {
096:                                replacedSrcs.add(rmisp.getRMIID().toString());
097:                            } else {
098:                                String str = new String(rmisp.getServerName()
099:                                        + "::" + rmisp.getRMIID());
100:                                replacedSrcs.add(str);
101:                            }
102:                        } else {
103:                            RenderedImage ri = (RenderedImage) ai;
104:                            replacedSrcs.add(new SerializableRenderedImage(ri));
105:                        }
106:                    } else if (obj instanceof  RenderedOp) {
107:                        RenderedOp rop = (RenderedOp) obj;
108:                        replacedSrcs.add(new SerializableRenderedImage(
109:                                (RenderedImage) rop.getRendering()));
110:                    } else if (obj instanceof  Serializable) {
111:                        replacedSrcs.add(obj);
112:                    } else if (obj instanceof  RenderedImage) {
113:                        RenderedImage ri = (RenderedImage) obj;
114:                        replacedSrcs.add(new SerializableRenderedImage(ri));
115:                    }
116:                }
117:
118:                return replacedSrcs;
119:            }
120:
121:            /**
122:             * Replace an image with an equivalent representation that can be accessed
123:             * on the server.
124:             */
125:            public static Object replaceImage(RenderedImage obj,
126:                    String this ServerName) {
127:
128:                if (obj instanceof  RMIServerProxy) {
129:
130:                    RMIServerProxy rmisp = (RMIServerProxy) obj;
131:                    if (rmisp.getServerName().equalsIgnoreCase(this ServerName))
132:                        return "::" + rmisp.getRMIID();
133:                    else
134:                        return rmisp.getServerName() + "::" + rmisp.getRMIID()
135:                                + ";;" + rmisp.getOperationName();
136:
137:                } else if (obj instanceof  RenderedOp) {
138:
139:                    RenderedImage rendering = ((RenderedOp) obj).getRendering();
140:                    return replaceImage(rendering, this ServerName);
141:
142:                } else if (obj instanceof  RenderedImage) {
143:
144:                    if (obj instanceof  Serializable)
145:                        return obj;
146:                    else
147:                        return new SerializableRenderedImage(obj);
148:                }
149:
150:                return obj;
151:            }
152:
153:            public static void checkClientParameters(ParameterBlock pb,
154:                    String this ServerName) {
155:
156:                // XXX 07/18/01, aastha TODO
157:                // This code should check every parameter to test Serializability
158:                // If parameter is Serializable, then keep it as is
159:                // If not serializable then use SerializerFactory to serialize it
160:                // If that doesn't work, throw an Exception
161:                // Note that parameters that are images may still need to be treated
162:                // differently as in the code below.
163:
164:                if (pb == null)
165:                    return;
166:
167:                int numParams = pb.getNumParameters();
168:                Vector params = pb.getParameters();
169:
170:                Object obj;
171:                for (int i = 0; i < numParams; i++) {
172:                    obj = params.elementAt(i);
173:
174:                    if (obj == null) {
175:
176:                        continue;
177:
178:                    } else if (obj instanceof  RenderedImage) {
179:
180:                        pb.set(
181:                                replaceImage((RenderedImage) obj,
182:                                        this ServerName), i);
183:
184:                    }
185:                }
186:            }
187:
188:            public static void checkClientParameters(Vector parameters,
189:                    String this ServerName) {
190:
191:                // XXX 07/18/01, aastha TODO
192:                // This code should check every parameter to test Serializability
193:                // If parameter is Serializable, then keep it as is
194:                // If not serializable then use SerializerFactory to serialize it
195:                // If that doesn't work, throw an Exception
196:                // Note that parameters that are images may still need to be treated
197:                // differently as in the code below.
198:
199:                if (parameters == null)
200:                    return;
201:
202:                Object obj;
203:                for (int i = 0; i < parameters.size(); i++) {
204:                    obj = parameters.elementAt(i);
205:
206:                    if (obj == null) {
207:
208:                        continue;
209:
210:                    } else if (obj instanceof  RenderedImage) {
211:
212:                        parameters.set(i, replaceImage((RenderedImage) obj,
213:                                this ServerName));
214:
215:                    }
216:                }
217:            }
218:
219:            /**
220:             * Method to convert a String representation of an image into the
221:             * image itself. The String representation is supplied by the client
222:             * generally as a parameter in the ParameterBlock.
223:             */
224:            public static Object replaceStringWithImage(String s,
225:                    Hashtable nodes) {
226:                String paramServerName, opName;
227:                int index1 = s.indexOf("::");
228:                int index2 = s.indexOf(";;");
229:                Long id;
230:
231:                if (index1 == -1) {
232:                    return s;
233:                } else if (index2 == -1) {
234:                    id = Long.valueOf(s.substring(index1 + 2));
235:                    return nodes.get(id);
236:
237:                } else {
238:                    // Extract the RMI ID from the servername string and 
239:                    // replace the original serverName string with one of
240:                    // the usual type.
241:                    id = Long.valueOf(s.substring(index1 + 2, index2));
242:                    paramServerName = s.substring(0, index1);
243:                    opName = s.substring(index2 + 2);
244:
245:                    // Create an RMIServerProxy to access the image on
246:                    // the other server.
247:                    return new RMIServerProxy((paramServerName + "::" + id),
248:                            opName, null);
249:                }
250:            }
251:
252:            /**
253:             * Method to check whether any of the parameters in the ParameterBlock
254:             * are replacement representations of images.
255:             */
256:            public static void checkServerParameters(ParameterBlock pb,
257:                    Hashtable nodes) {
258:
259:                if (pb == null)
260:                    return;
261:
262:                int numParams = pb.getNumParameters();
263:                Vector params = pb.getParameters();
264:
265:                Object obj;
266:                for (int i = 0; i < numParams; i++) {
267:                    obj = params.elementAt(i);
268:
269:                    if (obj == null) {
270:                        continue;
271:                    } else if (obj instanceof  String) {
272:                        pb.set(replaceStringWithImage((String) obj, nodes), i);
273:                    }
274:                }
275:            }
276:
277:            /**
278:             * Method to check whether any of the parameters in the ParameterBlock
279:             * are replacement representations of images.
280:             */
281:            public static void checkServerParameters(Vector parameters,
282:                    Hashtable nodes) {
283:
284:                if (parameters == null)
285:                    return;
286:
287:                Object obj;
288:                for (int i = 0; i < parameters.size(); i++) {
289:                    obj = parameters.elementAt(i);
290:
291:                    if (obj == null) {
292:                        continue;
293:                    } else if (obj instanceof  String) {
294:                        parameters.set(i, replaceStringWithImage((String) obj,
295:                                nodes));
296:                    }
297:                }
298:            }
299:
300:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.