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


001:        /*
002:         * $RCSfile: FileLoadDescriptor.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.3 $
009:         * $Date: 2005/11/29 00:08:56 $
010:         * $State: Exp $
011:         */
012:        package javax.media.jai.operator;
013:
014:        import com.sun.media.jai.codec.ImageDecodeParam;
015:        import java.awt.RenderingHints;
016:        import java.awt.image.RenderedImage;
017:        import java.awt.image.renderable.ParameterBlock;
018:        import java.io.File;
019:        import java.io.InputStream;
020:        import javax.media.jai.JAI;
021:        import javax.media.jai.OperationDescriptorImpl;
022:        import javax.media.jai.ParameterBlockJAI;
023:        import javax.media.jai.RenderedOp;
024:        import javax.media.jai.registry.RenderedRegistryMode;
025:
026:        /**
027:         * An <code>OperationDescriptor</code> describing the "FileLoad" operation.
028:         *
029:         * <p>In the default instance the <code>validateParameters()</code> method
030:         * checks that the named file exists and is readable.  If not, it will return
031:         * <code>false</code>, causing <code>JAI.createNS()</code> to throw an
032:         * <code>IllegalArgumentException</code>.
033:         *
034:         * In special cases like when an image is loaded from a Remote system, 
035:         * the above check for existence of a file on the local system could be bypassed.
036:         * This is done by setting the <code>Boolean</code> variable <code>checkFileLocally</code> to <code>FALSE</code> in the <code>ParameterBlock</code>
037:         * 
038:         * <p> The allowable formats are those registered with the
039:         * <code>com.sun.media.jai.codec.ImageCodec</code> class.
040:         *
041:         * <p> The second parameter contains an instance of
042:         * <code>ImageDecodeParam</code> to be used during the decoding.
043:         * It may be set to <code>null</code> in order to perform default
044:         * decoding, or equivalently may be omitted.
045:         *
046:         * <p><b> The classes in the <code>com.sun.media.jai.codec</code>
047:         * package are not a committed part of the JAI API.  Future releases
048:         * of JAI will make use of new classes in their place.  This
049:         * class will change accordingly.</b>
050:         * 
051:         * <p><table border=1>
052:         * <caption>Resource List</caption>
053:         * <tr><th>Name</th>        <th>Value</th></tr>
054:         * <tr><td>GlobalName</td>  <td>fileload</td></tr>
055:         * <tr><td>LocalName</td>   <td>fileload</td></tr>
056:         * <tr><td>Vendor</td>      <td>com.sun.media.jai</td></tr>
057:         * <tr><td>Description</td> <td>Reads an image from a file.</td></tr>
058:         * <tr><td>DocURL</td>      <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/FileLoadDescriptor.html</td></tr>
059:         * <tr><td>Version</td>     <td>1.0</td></tr>
060:         * <tr><td>arg0Desc</td>    <td>The path of the file to read from.</td></tr>
061:         * <tr><td>arg1Desc</td>    <td>The ImageDecodeParam to use.</td></tr>
062:         * <tr><td>arg2Desc</td>    <td>Boolean specifying if File existence should be checked locally.</td></tr>
063:         * </table></p>
064:         *
065:         * <p><table border=1>
066:         * <caption>Parameter List</caption>
067:         * <tr><th>Name</th>          <th>Class Type</th>
068:         *                            <th>Default Value</th></tr>
069:         * <tr><td>filename</td>      <td>java.lang.String</td>
070:         *                            <td>NO_PARAMETER_DEFAULT</td>
071:         * <tr><td>param</td>         <td>com.sun.media.jai.codec.ImageDecodeParam</td>
072:         *                            <td>null</td>
073:         * <tr><td>checkFileLocally</td> <td>java.lang.Boolean</td>
074:         *                            <td>TRUE</td>
075:         * </table></p>
076:         *
077:         * @see javax.media.jai.OperationDescriptor
078:         */
079:        public class FileLoadDescriptor extends OperationDescriptorImpl {
080:
081:            /**
082:             * The resource strings that provide the general documentation and
083:             * specify the parameter list for the "FileLoad" operation.
084:             */
085:            private static final String[][] resources = {
086:                    { "GlobalName", "FileLoad" },
087:                    { "LocalName", "FileLoad" },
088:                    { "Vendor", "com.sun.media.jai" },
089:                    { "Description", JaiI18N.getString("FileLoadDescriptor0") },
090:                    {
091:                            "DocURL",
092:                            "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/FileLoadDescriptor.html" },
093:                    { "Version", JaiI18N.getString("DescriptorVersion") },
094:                    { "arg0Desc", JaiI18N.getString("FileLoadDescriptor1") },
095:                    { "arg1Desc", JaiI18N.getString("FileLoadDescriptor4") },
096:                    { "arg2Desc", JaiI18N.getString("FileLoadDescriptor5") } };
097:
098:            /** The parameter names for the "FileLoad" operation. */
099:            private static final String[] paramNames = { "filename", "param",
100:                    "checkFileLocally" };
101:
102:            /** The parameter class types for the "FileLoad" operation. */
103:            private static final Class[] paramClasses = {
104:                    java.lang.String.class,
105:                    com.sun.media.jai.codec.ImageDecodeParam.class,
106:                    java.lang.Boolean.class };
107:
108:            /** The parameter default values for the "FileLoad" operation. */
109:            private static final Object[] paramDefaults = {
110:                    NO_PARAMETER_DEFAULT, null, Boolean.TRUE };
111:
112:            /** Constructor. */
113:            public FileLoadDescriptor() {
114:                super (resources, 0, paramClasses, paramNames, paramDefaults);
115:            }
116:
117:            /**
118:             * Validates the input parameters.
119:             *
120:             * <p> In addition to the standard checks performed by the
121:             * superclass method, this method by default checks that the source file
122:             * exists and is readable. This check may be bypassed by setting the
123:             * <code>checkFileLocally</code> parameter to <code>FALSE</code>
124:             */
125:            protected boolean validateParameters(ParameterBlock args,
126:                    StringBuffer msg) {
127:                if (!super .validateParameters(args, msg)) {
128:                    return false;
129:                }
130:
131:                Boolean checkFile = (Boolean) args.getObjectParameter(2);
132:                if (checkFile.booleanValue()) {
133:                    String filename = (String) args.getObjectParameter(0);
134:                    File f = new File(filename);
135:                    boolean fileExists = f.exists();
136:                    if (!fileExists) {
137:                        // Check if the file is accessible as an InputStream resource.
138:                        // This would be the case if the application and the image file
139:                        // are packaged in a JAR file
140:                        InputStream is = this .getClass().getClassLoader()
141:                                .getResourceAsStream(filename);
142:                        if (is == null) {
143:                            msg.append("\"" + filename + "\": "
144:                                    + JaiI18N.getString("FileLoadDescriptor2"));
145:                            return false;
146:                        }
147:                    } else { // file exists
148:                        if (!f.canRead()) {
149:                            msg.append("\"" + filename + "\": "
150:                                    + JaiI18N.getString("FileLoadDescriptor3"));
151:                            return false;
152:                        }
153:                    }
154:                }
155:                return true;
156:            }
157:
158:            /**
159:             * Reads an image from a file.
160:             *
161:             * <p>Creates a <code>ParameterBlockJAI</code> from all
162:             * supplied arguments except <code>hints</code> and invokes
163:             * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
164:             *
165:             * @see JAI
166:             * @see ParameterBlockJAI
167:             * @see RenderedOp
168:             *
169:             * @param filename The path of the file to read from.
170:             * @param param The ImageDecodeParam to use.
171:             * May be <code>null</code>.
172:             * @param checkFileLocally Boolean specifying if File existence should be checked locally
173:             * May be <code>null</code>.
174:             * @param hints The <code>RenderingHints</code> to use.
175:             * May be <code>null</code>.
176:             * @return The <code>RenderedOp</code> destination.
177:             * @throws IllegalArgumentException if <code>filename</code> is <code>null</code>.
178:             */
179:            public static RenderedOp create(String filename,
180:                    ImageDecodeParam param, Boolean checkFileLocally,
181:                    RenderingHints hints) {
182:                ParameterBlockJAI pb = new ParameterBlockJAI("FileLoad",
183:                        RenderedRegistryMode.MODE_NAME);
184:
185:                pb.setParameter("filename", filename);
186:                pb.setParameter("param", param);
187:                pb.setParameter("checkFileLocally", checkFileLocally);
188:
189:                return JAI.create("FileLoad", pb, hints);
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.