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


0001:        /*
0002:         * $RCSfile: ParameterBlockJAI.java,v $
0003:         *
0004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * Use is subject to license terms.
0007:         *
0008:         * $Revision: 1.1 $
0009:         * $Date: 2005/02/11 04:57:14 $
0010:         * $State: Exp $
0011:         */
0012:        package javax.media.jai;
0013:
0014:        import com.sun.media.jai.util.CaselessStringArrayTable;
0015:        import java.awt.image.renderable.ParameterBlock;
0016:        import java.io.IOException;
0017:        import java.io.NotSerializableException;
0018:        import java.io.ObjectInputStream;
0019:        import java.io.ObjectOutputStream;
0020:        import java.util.Hashtable;
0021:        import java.util.Vector;
0022:        import javax.media.jai.util.CaselessStringKey;
0023:
0024:        /**
0025:         * A convenience subclass of <code>ParameterBlock</code> that
0026:         * allows the use of default parameter values and getting/setting
0027:         * sources and parameters by name. A <code>ParameterBlockJAI</code> is
0028:         * constructed using either an <code>OperationDescriptor</code>,
0029:         * or an operation name (that will be looked up in the appropriate
0030:         * default <code>OperationRegistry</code>) and a mode which should
0031:         * be in <code>OperationDescriptor.getSupportedModes()</code> (such
0032:         * as rendered, renderable, collection or renderableCollection). If
0033:         * the mode is not specified <code>ParameterBlockJAI</code> will by
0034:         * default work with the first mode in the array of <code>String</code>s
0035:         * returned by <code>OperationDescriptor.getSupportedModes()</code>.
0036:         *
0037:         * <p> Once constructed, a <code>ParameterBlockJAI</code> appears to
0038:         * have no sources. It contains all the parameters required by its
0039:         * <code>OperationDescriptor</code> for a specified mode, each having
0040:         * its default value as given by the <code>OperationDescriptor</code>.
0041:         * Such a <code>ParameterBlockJAI</code> may not yet be usable, its
0042:         * sources (if any) are not set, and some or all of its parameters may
0043:         * have inapproriate values. The <code>addSource</code> methods of
0044:         * <code>ParameterBlock</code> may be used to initialize the source values,
0045:         * and the <code>set(value, index)</code> methods may be used to modify
0046:         * new parameter values. The preferred way of setting parameter values
0047:         * is the <code>setParameter(name, value)</code> described below. The
0048:         * <code>add()</code> methods should not be used since the parameter
0049:         * list is already long enough to hold all of the parameters required by
0050:         * the <code>OperationDescriptor</code>.
0051:         *
0052:         * <p> Additionally, <code>ParameterBlockJAI</code> offers
0053:         * <code>setParameter(name, value)</code> methods that take a
0054:         * parameter name; the index of the parameter is determined from the
0055:         * <code>OperationDescriptor</code> and the corresponding parameter
0056:         * is set. (users are strongly recommended to use this method
0057:         * instead of the equivalent <code>set(value, index)</code> or
0058:         * the deprecated <code>set(value, name)</code> methods). As in
0059:         * <code>ParameterBlock</code>, all parameters are stored internally
0060:         * as subclasses of Object and all get/set methods that take or return
0061:         * values of primitive types are simply convenience methods that transform
0062:         * values between the primitive types and their corresponding wrapper
0063:         * classes.
0064:         *
0065:         * <p> The <code>OperationDescriptor</code> that is used to initialize
0066:         * a <code>ParameterBlockJAI</code> at construction is not
0067:         * serializable and thus cannot be serialized using the default
0068:         * serialization mechanism. The operation name is serialized instead and
0069:         * included in the serialized <code>ParameterBlockJAI</code> stream.
0070:         * During de-serialization, the operation name is de-serialized and then
0071:         * looked up in the default <code>OperationRegistry</code> available at
0072:         * the time of de-serialization. If no <code>OperationDescriptor</code>
0073:         * has been registered with this <code>OperationRegistry</code>
0074:         * under the given operation name, a NotSerializableException will
0075:         * be thrown. The serialization of <code>ParameterBlockJAI</code>
0076:         * works correctly only if the <code>OperationDescriptor</code>
0077:         * registered for the operation name in question is identical to the
0078:         * <code>OperationDescriptor</code> that was registered with the
0079:         * <code>OperationRegistry</code> available at serialization time.
0080:         *
0081:         * <p> All parameter names are treated in a case-insensitive but
0082:         * retentive manner.
0083:         *
0084:         * <p> <strong>Warning:</strong> Serialized objects of this class will
0085:         * not be compatible with future releases. The current serialization
0086:         * support is appropriate for short term storage or RMI between
0087:         * applications running the same version of JAI. A future release of JAI
0088:         * will provide support for long term persistence.
0089:         */
0090:        public class ParameterBlockJAI extends ParameterBlock implements 
0091:                ParameterList {
0092:
0093:            /** 
0094:             * The <code>OperationDescriptor</code> associated with this
0095:             * <code>ParameterBlockJAI</code>. 
0096:             */
0097:            private transient OperationDescriptor odesc;
0098:
0099:            /**
0100:             * The operation mode.
0101:             */
0102:            private String modeName;
0103:
0104:            /**
0105:             * The ParameterListDescriptor for the specific mode for the operator.
0106:             */
0107:            private ParameterListDescriptor pld;
0108:
0109:            /**
0110:             * A <code>CaselessStringArrayTable</code> of parameter indices hashed by
0111:             * <code>CaselessStringKey</code> versions of the parameter names.
0112:             */
0113:            private CaselessStringArrayTable paramIndices;
0114:
0115:            /**
0116:             * A <code>CaselessStringArrayTable</code> source indices hashed by
0117:             * <code>CaselessStringKey</code> versions of the source names.
0118:             */
0119:            private CaselessStringArrayTable sourceIndices;
0120:
0121:            /** The number of parameters. Cached for convenience. */
0122:            private int numParameters;
0123:
0124:            /** The names of the parameters. Cached for convenience. */
0125:            private String[] paramNames;
0126:
0127:            /** The Class types of the parameters. */
0128:            private Class[] paramClasses;
0129:
0130:            /** The Class types of the sources. */
0131:            private Class[] sourceClasses;
0132:
0133:            private static String getDefaultMode(OperationDescriptor odesc) {
0134:
0135:                if (odesc == null)
0136:                    throw new IllegalArgumentException(JaiI18N
0137:                            .getString("Generic0"));
0138:
0139:                return odesc.getSupportedModes()[0];
0140:            }
0141:
0142:            /**
0143:             * Constructs a <code>ParameterBlockJAI</code> for
0144:             * use with an operation described by a particular
0145:             * <code>OperationDescriptor</code>. It uses the first
0146:             * mode in the array of <code>String</code>s returned by
0147:             * <code>OperationDescriptor.getSupportedModes()</code>
0148:             * to get the <code>ParameterListDescriptor</code> from
0149:             * <code>OperationDescriptor</code>. The default values of the
0150:             * parameters are filled in.
0151:             *
0152:             * @param odesc the OperationDescriptor describing the parameters
0153:             *		to be managed.
0154:             *
0155:             * @throws IllegalArgumentException if odesc is null
0156:             */
0157:            public ParameterBlockJAI(OperationDescriptor odesc) {
0158:                this (odesc, getDefaultMode(odesc));
0159:            }
0160:
0161:            /**
0162:             * Constructs a <code>ParameterBlockJAI</code> for a particular
0163:             * operation by name. The <code>OperationRegistry</code> associated
0164:             * with the default instance of the <code>JAI</code> class is used
0165:             * to locate the <code>OperationDescriptor</code> associated with
0166:             * the operation name.
0167:             *
0168:             * It uses the first mode in the array of <code>String</code>s
0169:             * returned by <code>OperationDescriptor.getSupportedModes()</code>
0170:             * to get the <code>ParameterListDescriptor</code> from
0171:             * <code>OperationDescriptor</code>. The default values of the
0172:             * parameters are filled in.
0173:             *
0174:             * @param operationName a <code>String</code> giving the name of the operation.
0175:             *
0176:             * @throws IllegalArgumentException if operationName is null.
0177:             */
0178:            public ParameterBlockJAI(String operationName) {
0179:                this ((OperationDescriptor) JAI.getDefaultInstance()
0180:                        .getOperationRegistry().getDescriptor(
0181:                                OperationDescriptor.class, operationName));
0182:            }
0183:
0184:            /**
0185:             * Constructs a <code>ParameterBlockJAI</code> for
0186:             * use with an operation described by a particular
0187:             * <code>OperationDescriptor</code> and a registry mode. The default
0188:             * values of the parameters are filled in.
0189:             *
0190:             * @param odesc the OperationDescriptor describing the parameters
0191:             *		to be managed.
0192:             * @param modeName the operation mode whose paramters are to be managed.
0193:             *
0194:             * @throws IllegalArgumentException if modeName is null or odesc is null
0195:             *
0196:             * @since JAI 1.1
0197:             */
0198:            public ParameterBlockJAI(OperationDescriptor odesc, String modeName) {
0199:
0200:                if ((odesc == null) || (modeName == null))
0201:                    throw new IllegalArgumentException(JaiI18N
0202:                            .getString("Generic0"));
0203:
0204:                this .odesc = odesc;
0205:                this .modeName = modeName;
0206:
0207:                pld = odesc.getParameterListDescriptor(modeName);
0208:
0209:                numParameters = pld.getNumParameters();
0210:                paramNames = pld.getParamNames();
0211:
0212:                paramIndices = new CaselessStringArrayTable(pld.getParamNames());
0213:                sourceIndices = new CaselessStringArrayTable(odesc
0214:                        .getSourceNames());
0215:
0216:                paramClasses = pld.getParamClasses();
0217:                sourceClasses = odesc.getSourceClasses(modeName);
0218:
0219:                Object[] defaults = pld.getParamDefaults();
0220:
0221:                parameters = new Vector(numParameters);
0222:
0223:                for (int i = 0; i < numParameters; i++) {
0224:                    parameters.addElement(defaults[i]);
0225:                }
0226:            }
0227:
0228:            /**
0229:             * Constructs a <code>ParameterBlockJAI</code> for a
0230:             * particular operation by name and a registry mode. The
0231:             * <code>OperationRegistry</code> associated with the default
0232:             * instance of the <code>JAI</code> class is used to locate the
0233:             * <code>OperationDescriptor</code> associated with the operation
0234:             * name. The default values of the parameters are filled in.
0235:             *
0236:             * @param operationName a <code>String</code> giving the name of the
0237:             *        operation.
0238:             * @param modeName the operation mode whose paramters are to be managed.
0239:             *
0240:             * @throws IllegalArgumentException if operationName or modeName is null
0241:             *
0242:             * @since JAI 1.1
0243:             */
0244:            public ParameterBlockJAI(String operationName, String modeName) {
0245:                this ((OperationDescriptor) JAI.getDefaultInstance()
0246:                        .getOperationRegistry().getDescriptor(modeName,
0247:                                operationName), modeName);
0248:            }
0249:
0250:            /**
0251:             * Returns the zero-relative index of a named source within the list of
0252:             * sources.
0253:             *
0254:             * @param sourceName a <code>String</code> containing the parameter name.
0255:             * @throws IllegalArgumentException if source is null or if there is
0256:             *		no source with the specified name.
0257:             *
0258:             * @since JAI 1.1
0259:             */
0260:            public int indexOfSource(String sourceName) {
0261:                return sourceIndices.indexOf(sourceName);
0262:            }
0263:
0264:            /**
0265:             * Returns the zero-relative index of a named parameter within the list of
0266:             * parameters.
0267:             *
0268:             * @param paramName a <code>String</code> containing the parameter name.
0269:             *
0270:             * @throws IllegalArgumentException if paramName is null or if there is
0271:             *		no parameter with the specified name.
0272:             *
0273:             * @since JAI 1.1
0274:             */
0275:            public int indexOfParam(String paramName) {
0276:                return paramIndices.indexOf(paramName);
0277:            }
0278:
0279:            /**
0280:             * Returns the <code>OperationDescriptor</code> associated with this
0281:             * <code>ParameterBlockJAI</code>.
0282:             */
0283:            public OperationDescriptor getOperationDescriptor() {
0284:                return odesc;
0285:            }
0286:
0287:            /**
0288:             * Returns the <code>ParameterListDescriptor</code> that provides
0289:             * descriptions of the parameters associated with the operator
0290:             * and mode.
0291:             *
0292:             * @since JAI 1.1
0293:             */
0294:            public ParameterListDescriptor getParameterListDescriptor() {
0295:                return pld;
0296:            }
0297:
0298:            /**
0299:             * Get the operation mode used to determine parameter names,
0300:             * classes and default values.
0301:             *
0302:             * @since JAI 1.1
0303:             */
0304:            public String getMode() {
0305:                return modeName;
0306:            }
0307:
0308:            /**
0309:             * Sets a named source to a given <code>Object</code> value.
0310:             *
0311:             * @param sourceName a <code>String</code> naming a source.
0312:             * @param source an <code>Object</code> value for the source.
0313:             * 
0314:             * @throws IllegalArgumentException if <code>source</code> is null.
0315:             * @throws IllegalArgumentException if <code>sourceName</code> is null.
0316:             * @throws IllegalArgumentException if <code>source</code> is not
0317:             *                                  an instance of (any of) the
0318:             *                                  expected class(es).
0319:             * @throws IllegalArgumentException if the associated operation has
0320:             *                                  no source with the supplied name.
0321:             *
0322:             * @since JAI 1.1
0323:             */
0324:            public ParameterBlockJAI setSource(String sourceName, Object source) {
0325:                if ((source == null) || (sourceName == null)) {
0326:                    throw new IllegalArgumentException(JaiI18N
0327:                            .getString("Generic0"));
0328:                }
0329:
0330:                int index = indexOfSource(sourceName);
0331:
0332:                if (!sourceClasses[index].isInstance(source)) {
0333:                    throw new IllegalArgumentException(JaiI18N
0334:                            .getString("ParameterBlockJAI4"));
0335:                }
0336:
0337:                if (index >= odesc.getNumSources()) {
0338:                    addSource(source);
0339:                } else {
0340:                    setSource(source, index);
0341:                }
0342:
0343:                return this ;
0344:            }
0345:
0346:            /**
0347:             * Returns an array of <code>Class</code> objects describing the types
0348:             * of the parameters.  This is a more efficient implementation than that
0349:             * of the superclass as the parameter classes are known a priori.
0350:             *
0351:             * @since JAI 1.1
0352:             */
0353:            public Class[] getParamClasses() {
0354:                // Just return the Class array obtained from the OD's PLD.
0355:                return paramClasses;
0356:            }
0357:
0358:            /**
0359:             * Gets the named parameter as an <code>Object</code>.
0360:             *
0361:             * @throws IllegalStateException if the param value is
0362:             *	    <code>ParameterListDescriptor.NO_PARAMETER_DEFAULT</code>
0363:             */
0364:            private Object getObjectParameter0(String paramName) {
0365:
0366:                Object obj = getObjectParameter(indexOfParam(paramName));
0367:
0368:                if (obj == ParameterListDescriptor.NO_PARAMETER_DEFAULT)
0369:                    throw new IllegalStateException(paramName + ":"
0370:                            + JaiI18N.getString("ParameterBlockJAI6"));
0371:
0372:                return obj;
0373:            }
0374:
0375:            /**
0376:             * Gets a named parameter as an Object. Parameters belonging to a
0377:             * primitive type, such as <code>int</code>, will be returned as a
0378:             * member of the corresponding <code>Number</code> subclass, such as
0379:             * <code>Integer</code>.
0380:             *
0381:             * @param paramName the name of the parameter to be returned.
0382:             * @throws IllegalArgumentException if there is no parameter with the
0383:             * specified name.
0384:             * @throws IllegalStateException if the parameter value is still
0385:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0386:             */
0387:            public Object getObjectParameter(String paramName) {
0388:                return getObjectParameter0(paramName);
0389:            }
0390:
0391:            /**
0392:             * A convenience method to return a parameter as a <code>byte</code>.  An
0393:             * exception will be thrown if the parameter is of a different
0394:             * type.
0395:             *
0396:             * @param paramName the name of the parameter to be returned.
0397:             * @throws IllegalArgumentException if there is no parameter with the
0398:             * specified name.
0399:             * @throws ClassCastException if the parameter is of a different type.
0400:             * @throws IllegalStateException if the parameter value is still
0401:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0402:             */
0403:            public byte getByteParameter(String paramName) {
0404:                return ((Byte) getObjectParameter0(paramName)).byteValue();
0405:            }
0406:
0407:            /**
0408:             * A convenience method to return a parameter as a <code>boolean</code>. An
0409:             * exception will be thrown if the parameter is of a different
0410:             * type.
0411:             *
0412:             * @param paramName the name of the parameter to be returned.
0413:             * @throws IllegalArgumentException if there is no parameter with the
0414:             * specified name.
0415:             * @throws ClassCastException if the parameter is of a different type.
0416:             * @throws IllegalStateException if the parameter value is still
0417:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0418:             *
0419:             * @since JAI 1.1
0420:             */
0421:            public boolean getBooleanParameter(String paramName) {
0422:                return ((Boolean) getObjectParameter0(paramName))
0423:                        .booleanValue();
0424:            }
0425:
0426:            /**
0427:             * A convenience method to return a parameter as a <code>char</code>.  An
0428:             * exception will be thrown if the parameter is of a different
0429:             * type.
0430:             *
0431:             * @param paramName the name of the parameter to be returned.
0432:             * @throws IllegalArgumentException if there is no parameter with the
0433:             * specified name.
0434:             * @throws ClassCastException if the parameter is of a different type.
0435:             * @throws IllegalStateException if the parameter value is still
0436:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0437:             */
0438:            public char getCharParameter(String paramName) {
0439:                return ((Character) getObjectParameter0(paramName)).charValue();
0440:            }
0441:
0442:            /**
0443:             * A convenience method to return a parameter as an <code>short</code>.  An
0444:             * exception will be thrown if the parameter is of a different
0445:             * type.
0446:             *
0447:             * @param paramName the name of the parameter to be returned.
0448:             * @throws IllegalArgumentException if there is no parameter with the
0449:             * specified name.
0450:             * @throws ClassCastException if the parameter is of a different type.
0451:             * @throws IllegalStateException if the parameter value is still
0452:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0453:             *
0454:             * @since JAI 1.1
0455:             */
0456:            public short getShortParameter(String paramName) {
0457:                return ((Short) getObjectParameter0(paramName)).shortValue();
0458:            }
0459:
0460:            /**
0461:             * A convenience method to return a parameter as an <code>int</code>.  An
0462:             * exception will be thrown if the parameter is of a different
0463:             * type.
0464:             *
0465:             * @param paramName the name of the parameter to be returned.
0466:             * @throws IllegalArgumentException if there is no parameter with the
0467:             * specified name.
0468:             * @throws ClassCastException if the parameter is of a different type.
0469:             * @throws IllegalStateException if the parameter value is still
0470:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0471:             */
0472:            public int getIntParameter(String paramName) {
0473:                return ((Integer) getObjectParameter0(paramName)).intValue();
0474:            }
0475:
0476:            /**
0477:             * A convenience method to return a parameter as a <code>long</code>.  An
0478:             * exception will be thrown if the parameter is of a different
0479:             * type.
0480:             *
0481:             * @param paramName the name of the parameter to be returned.
0482:             * @throws IllegalArgumentException if there is no parameter with the
0483:             * specified name.
0484:             * @throws ClassCastException if the parameter is of a different type.
0485:             * @throws IllegalStateException if the parameter value is still
0486:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0487:             */
0488:            public long getLongParameter(String paramName) {
0489:                return ((Long) getObjectParameter0(paramName)).longValue();
0490:            }
0491:
0492:            /**
0493:             * A convenience method to return a parameter as a <code>float</code>.  An
0494:             * exception will be thrown if the parameter is of a different
0495:             * type.
0496:             *
0497:             * @param paramName the name of the parameter to be returned.
0498:             * @throws IllegalArgumentException if there is no parameter with the
0499:             * specified name.
0500:             * @throws ClassCastException if the parameter is of a different type.
0501:             * @throws IllegalStateException if the parameter value is still
0502:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0503:             */
0504:            public float getFloatParameter(String paramName) {
0505:                return ((Float) getObjectParameter0(paramName)).floatValue();
0506:            }
0507:
0508:            /**
0509:             * A convenience method to return a parameter as a <code>double</code>.  An
0510:             * exception will be thrown if the parameter is of a different
0511:             * type.
0512:             *
0513:             * @param paramName the name of the parameter to be returned.
0514:             * @throws IllegalArgumentException if there is no parameter with the
0515:             * specified name.
0516:             * @throws ClassCastException if the parameter is of a different type.
0517:             * @throws IllegalStateException if the parameter value is still
0518:             *		ParameterListDescriptor.NO_PARAMETER_DEFAULT
0519:             */
0520:            public double getDoubleParameter(String paramName) {
0521:                return ((Double) getObjectParameter0(paramName)).doubleValue();
0522:            }
0523:
0524:            // NEW ParameterList methods.
0525:
0526:            /**
0527:             * Sets a named parameter to a <code>byte</code> value.
0528:             * Checks are made to verify that the parameter is of the right
0529:             * <code>Class</code> type and that the value is valid.
0530:             *
0531:             * @param paramName a <code>String</code> naming a parameter.
0532:             * @param b a <code>byte</code> value for the parameter.
0533:             * 
0534:             * @throws IllegalArgumentException if paramName is null.
0535:             * @throws IllegalArgumentException if there is no parameter with the
0536:             *          specified name.
0537:             * @throws IllegalArgumentException if the class type of parameter
0538:             *		pointed to by the paramName is not a <code>Byte</code>
0539:             * @throws IllegalArgumentException if the parameter value is invalid.
0540:             *
0541:             * @since JAI 1.1
0542:             */
0543:            public ParameterList setParameter(String paramName, byte b) {
0544:                return setParameter0(paramName, new Byte(b));
0545:            }
0546:
0547:            /**
0548:             * Sets a named parameter to a <code>boolean</code> value.
0549:             * Checks are made to verify that the parameter is of the right
0550:             * <code>Class</code> type and that the value is valid.
0551:             *
0552:             * @param paramName a <code>String</code> naming a parameter.
0553:             * @param b a <code>boolean</code> value for the parameter.
0554:             * 
0555:             * @throws IllegalArgumentException if paramName is null.
0556:             * @throws IllegalArgumentException if there is no parameter with the
0557:             *          specified name.
0558:             * @throws IllegalArgumentException if the class type of parameter
0559:             *		pointed to by the paramName is not a <code>Boolean</code>
0560:             * @throws IllegalArgumentException if the parameter value is invalid.
0561:             *
0562:             * @since JAI 1.1
0563:             */
0564:            public ParameterList setParameter(String paramName, boolean b) {
0565:                return setParameter0(paramName, new Boolean(b));
0566:            }
0567:
0568:            /**
0569:             * Sets a named parameter to a <code>char</code> value.
0570:             * Checks are made to verify that the parameter is of the right
0571:             * <code>Class</code> type and that the value is valid.
0572:             *
0573:             * @param paramName a <code>String</code> naming a parameter.
0574:             * @param c a <code>char</code> value for the parameter. 
0575:             * 
0576:             * @throws IllegalArgumentException if paramName is null.
0577:             * @throws IllegalArgumentException if there is no parameter with the
0578:             *          specified name.
0579:             * @throws IllegalArgumentException if the class type of parameter
0580:             *		pointed to by the paramName is not a <code>Character</code>
0581:             * @throws IllegalArgumentException if the parameter value is invalid.
0582:             *
0583:             * @since JAI 1.1
0584:             */
0585:            public ParameterList setParameter(String paramName, char c) {
0586:                return setParameter0(paramName, new Character(c));
0587:            }
0588:
0589:            /**
0590:             * Sets a named parameter to a <code>short</code> value.
0591:             * Checks are made to verify that the parameter is of the right
0592:             * <code>Class</code> type and that the value is valid.
0593:             *
0594:             * @param paramName a <code>String</code> naming a parameter.
0595:             * @param s a <code>short</code> value for the parameter. 
0596:             * 
0597:             * @throws IllegalArgumentException if paramName is null.
0598:             * @throws IllegalArgumentException if there is no parameter with the
0599:             *          specified name.
0600:             * @throws IllegalArgumentException if the class type of parameter
0601:             *		pointed to by the paramName is not a <code>Short</code>
0602:             * @throws IllegalArgumentException if the parameter value is invalid.
0603:             *
0604:             * @since JAI 1.1
0605:             */
0606:            public ParameterList setParameter(String paramName, short s) {
0607:                return setParameter0(paramName, new Short(s));
0608:            }
0609:
0610:            /**
0611:             * Sets a named parameter to an <code>int</code> value.
0612:             * Checks are made to verify that the parameter is of the right
0613:             * <code>Class</code> type and that the value is valid.
0614:             *
0615:             * @param paramName a <code>String</code> naming a parameter.
0616:             * @param i an <code>int</code> value for the parameter. 
0617:             * 
0618:             * @throws IllegalArgumentException if paramName is null.
0619:             * @throws IllegalArgumentException if there is no parameter with the
0620:             *          specified name.
0621:             * @throws IllegalArgumentException if the class type of parameter
0622:             *		pointed to by the paramName is not a <code>Integer</code>
0623:             * @throws IllegalArgumentException if the parameter value is invalid.
0624:             *
0625:             * @since JAI 1.1
0626:             */
0627:            public ParameterList setParameter(String paramName, int i) {
0628:                return setParameter0(paramName, new Integer(i));
0629:            }
0630:
0631:            /**
0632:             * Sets a named parameter to a <code>long</code> value.
0633:             * Checks are made to verify that the parameter is of the right
0634:             * <code>Class</code> type and that the value is valid.
0635:             *
0636:             * @param paramName a <code>String</code> naming a parameter.
0637:             * @param l a <code>long</code> value for the parameter. 
0638:             * 
0639:             * @throws IllegalArgumentException if paramName is null.
0640:             * @throws IllegalArgumentException if there is no parameter with the
0641:             *          specified name.
0642:             * @throws IllegalArgumentException if the class type of parameter
0643:             *		pointed to by the paramName is not a <code>Long</code>
0644:             * @throws IllegalArgumentException if the parameter value is invalid.
0645:             *
0646:             * @since JAI 1.1
0647:             */
0648:            public ParameterList setParameter(String paramName, long l) {
0649:                return setParameter0(paramName, new Long(l));
0650:            }
0651:
0652:            /**
0653:             * Sets a named parameter to a <code>float</code> value.
0654:             * Checks are made to verify that the parameter is of the right
0655:             * <code>Class</code> type and that the value is valid.
0656:             *
0657:             * @param paramName a <code>String</code> naming a parameter.
0658:             * @param f a <code>float</code> value for the parameter. 
0659:             * 
0660:             * @throws IllegalArgumentException if paramName is null.
0661:             * @throws IllegalArgumentException if there is no parameter with the
0662:             *          specified name.
0663:             * @throws IllegalArgumentException if the class type of parameter
0664:             *		pointed to by the paramName is not a <code>Float</code>
0665:             * @throws IllegalArgumentException if the parameter value is invalid.
0666:             *
0667:             * @since JAI 1.1
0668:             */
0669:            public ParameterList setParameter(String paramName, float f) {
0670:                return setParameter0(paramName, new Float(f));
0671:            }
0672:
0673:            /**
0674:             * Sets a named parameter to a <code>double</code> value.
0675:             * Checks are made to verify that the parameter is of the right
0676:             * <code>Class</code> type and that the value is valid.
0677:             *
0678:             * @param paramName a <code>String</code> naming a parameter.
0679:             * @param d a <code>double</code> value for the parameter. 
0680:             * 
0681:             * @throws IllegalArgumentException if paramName is null.
0682:             * @throws IllegalArgumentException if there is no parameter with the
0683:             *          specified name.
0684:             * @throws IllegalArgumentException if the class type of parameter
0685:             *		pointed to by the paramName is not a <code>Double</code>
0686:             * @throws IllegalArgumentException if the parameter value is invalid.
0687:             *
0688:             * @since JAI 1.1
0689:             */
0690:            public ParameterList setParameter(String paramName, double d) {
0691:                return setParameter0(paramName, new Double(d));
0692:            }
0693:
0694:            /**
0695:             * Sets a named parameter to an <code>Object</code> value.  The value
0696:             * may be <code>null</code>, an instance of the class expected for this
0697:             * parameter, or a <code>DeferredData</code> instance the
0698:             * <code>getDataClass()</code> method of which returns the
0699:             * expected class.  If the object is a <code>DeferredData</code> instance,
0700:             * then its wrapped data value is checked for validity if and only if
0701:             * its <code>isValid()</code> method returns <code>true</code>.  If the
0702:             * object is not a <code>DeferredData</code> instance, then it is
0703:             * always checked for validity.
0704:             *
0705:             * @param paramName a <code>String</code> naming a parameter.
0706:             * @param obj an <code>Object</code> value for the parameter.
0707:             *
0708:             * @throws IllegalArgumentException if paramName is null.
0709:             * @throws IllegalArgumentException if there is no parameter with the
0710:             *          specified name.
0711:             * @throws IllegalArgumentException if the parameter value is invalid.
0712:             *
0713:             * @since JAI 1.1
0714:             */
0715:            public ParameterList setParameter(String paramName, Object obj) {
0716:                return setParameter0(paramName, obj);
0717:            }
0718:
0719:            /**
0720:             * Checks to see if the specified parameter is valid.
0721:             *
0722:             * @param paramName a <code>String</code> naming a parameter.
0723:             * @param obj an Object value for the parameter.
0724:             *
0725:             * @throws IllegalArgumentException if paramName is null.
0726:             * @throws IllegalArgumentException if there is no parameter with the
0727:             *          specified name.
0728:             * @throws IllegalArgumentException if <code>obj</code> is
0729:             *         non-<code>null</code> and not an instance of the class
0730:             *         expected for the indicated parameter or if <code>obj</code>
0731:             *         is an invalid value for the indicated parameter.
0732:             *
0733:             * @return the index of the parameter
0734:             */
0735:            private int checkParameter(String paramName, Object obj) {
0736:                int index = indexOfParam(paramName);
0737:
0738:                if (obj != null) {
0739:
0740:                    if (obj == ParameterListDescriptor.NO_PARAMETER_DEFAULT) {
0741:                        throw new IllegalArgumentException(paramName + ":"
0742:                                + JaiI18N.getString("ParameterBlockJAI8"));
0743:                    }
0744:
0745:                    if (obj instanceof  DeferredData) {
0746:                        DeferredData dd = (DeferredData) obj;
0747:                        if (!paramClasses[index].isAssignableFrom(dd
0748:                                .getDataClass())) {
0749:                            throw new IllegalArgumentException(paramName + ":"
0750:                                    + JaiI18N.getString("ParameterBlockJAI0"));
0751:                        }
0752:
0753:                        if (dd.isValid()
0754:                                && !pld.isParameterValueValid(paramName, dd
0755:                                        .getData())) {
0756:                            throw new IllegalArgumentException(paramName + ":"
0757:                                    + JaiI18N.getString("ParameterBlockJAI2"));
0758:                        }
0759:                    } else if (!paramClasses[index].isInstance(obj)) {
0760:                        throw new IllegalArgumentException(paramName + ":"
0761:                                + JaiI18N.getString("ParameterBlockJAI0"));
0762:                    }
0763:                }
0764:
0765:                if (obj == null || !(obj instanceof  DeferredData)) {
0766:                    if (!pld.isParameterValueValid(paramName, obj)) {
0767:                        throw new IllegalArgumentException(paramName + ":"
0768:                                + JaiI18N.getString("ParameterBlockJAI2"));
0769:                    }
0770:                }
0771:
0772:                return index;
0773:            }
0774:
0775:            /**
0776:             * Sets a named parameter to an Object value.  The value may be
0777:             * <code>null</code>, an instance of the class expected for this
0778:             * parameter, or a <code>DeferredData</code> instance the
0779:             * <code>getDataClass()</code> method of which returns the
0780:             * expected class.  If the object is a <code>DeferredData</code> instance,
0781:             * then its wrapped data value is checked for validity if and only if
0782:             * its <code>isValid()</code> method returns <code>true</code>.
0783:             * If the object is not a <code>DeferredData</code> instance, then it is
0784:             * always checked for validity.
0785:             *
0786:             * @param paramName a <code>String</code> naming a parameter.
0787:             * @param obj an Object value for the parameter.
0788:             *
0789:             * @throws IllegalArgumentException if paramName is null.
0790:             * @throws IllegalArgumentException if there is no parameter with the
0791:             *          specified name.
0792:             * @throws IllegalArgumentException if <code>obj</code> is
0793:             *         non-<code>null</code> and not an instance of the class
0794:             *         expected for the indicated parameter or if <code>obj</code>
0795:             *         is an invalid value for the indicated parameter.
0796:             */
0797:            private ParameterList setParameter0(String paramName, Object obj) {
0798:
0799:                int index = checkParameter(paramName, obj);
0800:
0801:                parameters.setElementAt(obj, index);
0802:                return this ;
0803:            }
0804:
0805:            /* ----- Superclass methods overridden for consistent behavior. ----- */
0806:
0807:            /** 
0808:             * Adds an object to the list of parameters. 
0809:             * 
0810:             * This method always throws an <code>IllegalStateException</code>
0811:             * because the <code>ParameterBlockJAI</code> constructor initializes
0812:             * all parameters with their default values.
0813:             * 
0814:             * @throws IllegalStateException if parameters are added to an already 
0815:             * initialized ParameterBlockJAI
0816:             *
0817:             * @since JAI 1.1
0818:             */
0819:
0820:            public ParameterBlock add(Object obj) {
0821:                throw new IllegalStateException(JaiI18N
0822:                        .getString("ParameterBlockJAI5"));
0823:            }
0824:
0825:            /**
0826:             * Replaces an Object in the list of parameters.
0827:             *
0828:             * @param obj The new value of the parameter.
0829:             * @param index The zero-relative index of the parameter.
0830:             *
0831:             * @throws ArrayIndexOutOfBoundsException if <code>index</code>
0832:             *         is negative or not less than the number of parameters
0833:             *         expected for the associated operation.
0834:             * @throws IllegalArgumentException if <code>obj</code> is
0835:             *         non-<code>null</code> and not an instance of the class
0836:             *         expected for the indicated parameter or if <code>obj</code>
0837:             *         is an invalid value for the indicated parameter.
0838:             *
0839:             * @since JAI 1.1
0840:             */
0841:            public ParameterBlock set(Object obj, int index) {
0842:                if (index < 0 || index >= pld.getNumParameters()) {
0843:                    throw new ArrayIndexOutOfBoundsException();
0844:                }
0845:
0846:                // Not the most efficient implementation but has minimum duplication.
0847:                setParameter0(paramNames[index], obj);
0848:
0849:                return this ;
0850:            }
0851:
0852:            /**
0853:             * Sets the entire <code>Vector</code> of parameters to a given
0854:             * <code>Vector</code>.  The <code>Vector</code> is saved by reference.
0855:             *
0856:             * @throws IllegalArgumentException if the size of the supplied
0857:             *         <code>Vector</code> does not equal the number of parameters
0858:             *         of the associated operation.
0859:             * @throws IllegalArgumentException if a non-<code>null</code>,
0860:             *         non-<code>DeferredData</code> value is not an instance of
0861:             *         the class expected for the indicated parameter or if
0862:             *         <code>obj</code> is an invalid value for the indicated
0863:             *         parameter.
0864:             * @throws IllegalArgumentException if a non-<code>null</code>,
0865:             *         <code>DeferredData</code> value does not wrap an instance of
0866:             *         the class expected for the indicated parameter or if it is
0867:             *         valid but its wrapped value is invalid for the indicated
0868:             *         parameter.
0869:             *
0870:             * @since JAI 1.1
0871:             */
0872:            public void setParameters(Vector parameters) {
0873:                if (parameters == null || parameters.size() != numParameters) {
0874:                    throw new IllegalArgumentException(JaiI18N
0875:                            .getString("ParameterBlockJAI7"));
0876:                }
0877:
0878:                for (int i = 0; i < numParameters; i++) {
0879:                    checkParameter(paramNames[i], parameters.get(i));
0880:                }
0881:
0882:                this .parameters = parameters;
0883:            }
0884:
0885:            /********************** DEPRECATED METHODS *************************/
0886:
0887:            /**
0888:             * Returns the zero-relative index of a named parameter within the list of
0889:             * parameters.
0890:             *
0891:             * @param paramName a <code>String</code> containing the parameter name.
0892:             *
0893:             * @throws IllegalArgumentException if paramName is null or if there is
0894:             *		no parameter with the specified name.
0895:             *
0896:             * @deprecated as of JAI 1.1 - use "indexOfParam" instead.
0897:             *
0898:             * @see #indexOfParam
0899:             */
0900:            public int indexOf(String paramName) {
0901:                return indexOfParam(paramName);
0902:            }
0903:
0904:            /**
0905:             * Sets a named parameter to a <code>byte</code> value.
0906:             *
0907:             * @param paramName a <code>String</code> naming a parameter.
0908:             * @param b a <code>byte</code> value for the parameter.
0909:             * 
0910:             * @throws IllegalArgumentException if paramName is null.
0911:             * @throws IllegalArgumentException if there is no parameter with the
0912:             * specified name.
0913:             *
0914:             * @deprecated as of JAI 1.1 - use <code>setParameter</code> instead.
0915:             *
0916:             * @see #setParameter(String, byte)
0917:             */
0918:            public ParameterBlock set(byte b, String paramName) {
0919:                return set(new Byte(b), paramName);
0920:            }
0921:
0922:            /**
0923:             * Sets a named parameter to a <code>char</code> value.
0924:             *
0925:             * @param paramName a <code>String</code> naming a parameter.
0926:             * @param c a <code>char</code> value for the parameter. 
0927:             * 
0928:             * @throws IllegalArgumentException if paramName is null.
0929:             * @throws IllegalArgumentException if there is no parameter with the
0930:             * specified name.
0931:             *
0932:             * @deprecated as of JAI 1.1 - use <code>setParameter</code> instead.
0933:             *
0934:             * @see #setParameter(String, char)
0935:             */
0936:            public ParameterBlock set(char c, String paramName) {
0937:                return set(new Character(c), paramName);
0938:            }
0939:
0940:            /**
0941:             * Sets a named parameter to a short value.
0942:             *
0943:             * @param paramName a <code>String</code> naming a parameter.
0944:             * @param s a short value for the parameter. 
0945:             * 
0946:             * @throws IllegalArgumentException if paramName is null.
0947:             * @throws IllegalArgumentException if there is no parameter with the
0948:             * specified name.
0949:             *
0950:             * @deprecated as of JAI 1.1 - use <code>setParameter</code> instead.
0951:             *
0952:             * @see #setParameter(String, short)
0953:             */
0954:            public ParameterBlock set(short s, String paramName) {
0955:                return set(new Short(s), paramName);
0956:            }
0957:
0958:            /**
0959:             * Sets a named parameter to an <code>int</code> value.
0960:             *
0961:             * @param paramName a <code>String</code> naming a parameter.
0962:             * @param i an <code>int</code> value for the parameter. 
0963:             * 
0964:             * @throws IllegalArgumentException if paramName is null.
0965:             * @throws IllegalArgumentException if there is no parameter with the
0966:             * specified name.
0967:             *
0968:             * @deprecated as of JAI 1.1 - use <code>setParameter</code> instead.
0969:             *
0970:             * @see #setParameter(String, int)
0971:             */
0972:            public ParameterBlock set(int i, String paramName) {
0973:                return set(new Integer(i), paramName);
0974:            }
0975:
0976:            /**
0977:             * Sets a named parameter to a <code>long</code> value.
0978:             *
0979:             * @param paramName a <code>String</code> naming a parameter.
0980:             * @param l a <code>long</code> value for the parameter. 
0981:             * 
0982:             * @throws IllegalArgumentException if paramName is null.
0983:             * @throws IllegalArgumentException if there is no parameter with the
0984:             * specified name.
0985:             *
0986:             * @deprecated as of JAI 1.1 - use <code>setParameter</code> instead.
0987:             *
0988:             * @see #setParameter(String, long)
0989:             */
0990:            public ParameterBlock set(long l, String paramName) {
0991:                return set(new Long(l), paramName);
0992:            }
0993:
0994:            /**
0995:             * Sets a named parameter to a <code>float</code> value.
0996:             *
0997:             * @param paramName a <code>String</code> naming a parameter.
0998:             * @param f a <code>float</code> value for the parameter. 
0999:             * 
1000:             * @throws IllegalArgumentException if paramName is null.
1001:             * @throws IllegalArgumentException if there is no parameter with the
1002:             * specified name.
1003:             *
1004:             * @deprecated as of JAI 1.1 - use <code>setParameter</code> instead.
1005:             *
1006:             * @see #setParameter(String, float)
1007:             */
1008:            public ParameterBlock set(float f, String paramName) {
1009:                return set(new Float(f), paramName);
1010:            }
1011:
1012:            /**
1013:             * Sets a named parameter to a <code>double</code> value.
1014:             *
1015:             * @param paramName a <code>String</code> naming a parameter.
1016:             * @param d a <code>double</code> value for the parameter. 
1017:             * 
1018:             * @throws IllegalArgumentException if paramName is null.
1019:             * @throws IllegalArgumentException if there is no parameter with the
1020:             * specified name.
1021:             *
1022:             * @deprecated as of JAI 1.1 - use <code>setParameter</code> instead.
1023:             *
1024:             * @see #setParameter(String, double)
1025:             */
1026:            public ParameterBlock set(double d, String paramName) {
1027:                return set(new Double(d), paramName);
1028:            }
1029:
1030:            /**
1031:             * Sets a named parameter to an Object value.
1032:             *
1033:             * @param paramName a <code>String</code> naming a parameter.
1034:             * @param obj an Object value for the parameter.
1035:             *
1036:             * @throws IllegalArgumentException if obj is null, or if the class
1037:             *         type of obj does not match the class type of parameter
1038:             *         pointed to by the paramName.
1039:             * @throws IllegalArgumentException if paramName is null.
1040:             * @throws IllegalArgumentException if there is no parameter with the
1041:             * specified name.
1042:             *
1043:             * @deprecated as of JAI 1.1 - use <code>setParameter</code> instead.
1044:             *
1045:             * @see #setParameter(String, Object)
1046:             */
1047:            public ParameterBlock set(Object obj, String paramName) {
1048:                setParameter0(paramName, obj);
1049:                return this ;
1050:            }
1051:
1052:            // [De]serialization methods.
1053:
1054:            /**
1055:             * Serialize the <code>ParameterBlockJAI</code>.
1056:             * @throws IOException 
1057:             */
1058:            private void writeObject(ObjectOutputStream out) throws IOException {
1059:                // Write the non-static and non-transient fields.
1060:                out.defaultWriteObject();
1061:
1062:                // Write out the operation name of the OperationDescriptor.
1063:                out.writeObject(odesc.getName());
1064:            }
1065:
1066:            /**
1067:             * Deserialize the <code>ParameterBlockJAI</code>.
1068:             *
1069:             * @throws IOException 
1070:             * @throws NotSerializableException if no OperationDescriptor is
1071:             *         registered with the current OperationRegistry under the
1072:             *         deserialized operation name.
1073:             */
1074:            private void readObject(ObjectInputStream in) throws IOException,
1075:                    ClassNotFoundException {
1076:
1077:                // Read the non-static and non-transient fields.
1078:                in.defaultReadObject();
1079:
1080:                // Read the operation name
1081:                String operationName = (String) in.readObject();
1082:
1083:                // Try to get the OperationDescriptor registered under this name
1084:                odesc = (OperationDescriptor) JAI.getDefaultInstance()
1085:                        .getOperationRegistry().getDescriptor(modeName,
1086:                                operationName);
1087:
1088:                if (odesc == null) {
1089:                    throw new NotSerializableException(operationName + " "
1090:                            + JaiI18N.getString("ParameterBlockJAI1"));
1091:                }
1092:            }
1093:
1094:            /**
1095:             * Creates a copy of a <code>ParameterBlockJAI</code>. The source
1096:             * and parameter Vectors are cloned, but the actual sources and
1097:             * parameters are copied by reference. This allows modifications to
1098:             * the order and number of sources and parameters in the clone to be
1099:             * invisible to the original <code>ParameterBlockJAI</code>. Changes
1100:             * to the shared sources or parameters themselves will still be
1101:             * visible.
1102:             *
1103:             * @return an Object clone of the <code>ParameterBlockJAI</code>.
1104:             *
1105:             * @since JAI 1.1
1106:             */
1107:            public Object clone() {
1108:                ParameterBlockJAI theClone = (ParameterBlockJAI) shallowClone();
1109:
1110:                if (sources != null) {
1111:                    theClone.setSources((Vector) sources.clone());
1112:                }
1113:
1114:                if (parameters != null) {
1115:                    // Clone the parameter Vector without doing the parameter
1116:                    // validity checks.
1117:                    theClone.parameters = (Vector) parameters.clone();
1118:                }
1119:                return (Object) theClone;
1120:            }
1121:
1122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.