0001: /*
0002: * $RCSfile: OperationDescriptorImpl.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:12 $
0010: * $State: Exp $
0011: */
0012: package javax.media.jai;
0013:
0014: import com.sun.media.jai.util.CaselessStringArrayTable;
0015: import java.awt.RenderingHints;
0016: import java.awt.image.RenderedImage;
0017: import java.awt.image.renderable.ParameterBlock;
0018: import java.util.Collection;
0019: import java.util.Hashtable;
0020: import java.util.Iterator;
0021: import java.util.ListResourceBundle;
0022: import java.util.Locale;
0023: import java.util.ResourceBundle;
0024: import javax.media.jai.util.Range;
0025:
0026: /**
0027: * This class provides an abstract implementation of the
0028: * <code>OperationDescriptor</code> interface that is suitable for
0029: * subclassing.
0030: *
0031: * @see OperationDescriptor
0032: * @see RegistryElementDescriptor
0033: *
0034: */
0035: public abstract class OperationDescriptorImpl implements
0036: OperationDescriptor, java.io.Serializable {
0037:
0038: private boolean deprecated = false;
0039:
0040: /**
0041: * The resource tags and their corresponding data, stored as an
0042: * two-dimensional <code>String</code> array.
0043: *
0044: * @since JAI 1.1
0045: */
0046: protected final String[][] resources;
0047:
0048: /**
0049: * An array of operation modes supported by this operator.
0050: * Must be a non-empty subset of "rendered", "renderable",
0051: * "collection" and "renderableCollection" or other image
0052: * operator modes to be defined later.
0053: *
0054: * @since JAI 1.1
0055: */
0056: protected final String[] supportedModes;
0057:
0058: /**
0059: * A <code>CaselessStringArrayTable</code> mapping the mode names to
0060: * their indices in the above arrays in a case-insensitive manner.
0061: */
0062: private CaselessStringArrayTable modeIndices;
0063:
0064: /**
0065: * An array of <code>String</code>s that are the names of the
0066: * sources of this operation. The names must be listed in the
0067: * order corresponding to the source <code>Class</code>es.
0068: *
0069: * @since JAI 1.1
0070: */
0071: protected final String[] sourceNames;
0072:
0073: /**
0074: * A 2D array of source classes for each source for each mode.
0075: * sourceClasses[m][i] specifies the <code>Class</code> for
0076: * supportedModes[m] and sourceNames[i].
0077: */
0078: private Class[][] sourceClasses;
0079:
0080: /**
0081: * A <code>CaselessStringArrayTable</code> mapping the source names to
0082: * their indices in the above arrays in a case-insensitive manner.
0083: */
0084: private CaselessStringArrayTable sourceIndices;
0085:
0086: /**
0087: * An array of <code>ParameterListDescriptor</code> for each mode.
0088: */
0089: private ParameterListDescriptor[] paramListDescriptors;
0090:
0091: /**
0092: * The array of parameter names. We need this because
0093: * ParameterListDescriptor works only with parameter names and not
0094: * parameter indices. But many of the deprecated methods and
0095: * the validation of ParameterBlock has to happen through
0096: * parameter indices.
0097: */
0098: String[] paramNames;
0099:
0100: /** The global name of this operation. */
0101: private String name = null;
0102:
0103: // Constructors...
0104:
0105: /**
0106: * Do some of the initialization common to all constructors.
0107: */
0108: private String[] checkSources(String[][] resources,
0109: String[] supportedModes, String[] sourceNames,
0110: Class[][] sourceClasses) {
0111:
0112: if ((resources == null) || (resources.length == 0))
0113: throw new IllegalArgumentException("resources: "
0114: + JaiI18N.getString("Generic2"));
0115:
0116: if ((supportedModes == null) || (supportedModes.length == 0))
0117: throw new IllegalArgumentException("supportedModes: "
0118: + JaiI18N.getString("Generic2"));
0119:
0120: // Validate source related arguments.
0121:
0122: int numModes = supportedModes.length;
0123:
0124: if (sourceClasses != null) {
0125:
0126: if (sourceClasses.length != numModes)
0127: throw new IllegalArgumentException(JaiI18N.formatMsg(
0128: "OperationDescriptorImpl0",
0129: new Object[] { "sourceClasses",
0130: new Integer(numModes) }));
0131:
0132: int numSources = (sourceClasses[0] == null) ? 0
0133: : sourceClasses[0].length;
0134:
0135: if (sourceNames == null) {
0136: sourceNames = getDefaultSourceNames(numSources);
0137:
0138: } else if (sourceNames.length != numSources) {
0139:
0140: throw new IllegalArgumentException(JaiI18N.formatMsg(
0141: "OperationDescriptorImpl1", new Object[] {
0142: new Integer(sourceNames.length),
0143: new Integer(numSources) }));
0144: }
0145:
0146: for (int i = 0; i < sourceClasses.length; i++) {
0147: int ns = (sourceClasses[i] == null) ? 0
0148: : sourceClasses[i].length;
0149:
0150: if (numSources != ns) {
0151: throw new IllegalArgumentException(JaiI18N
0152: .formatMsg("OperationDescriptorImpl2",
0153: new Object[] { new Integer(ns),
0154: new Integer(numSources),
0155: supportedModes[i] }));
0156: }
0157: }
0158:
0159: } else if ((sourceNames != null) && (sourceNames.length != 0)) {
0160: throw new IllegalArgumentException(JaiI18N.formatMsg(
0161: "OperationDescriptorImpl1", new Object[] {
0162: new Integer(sourceNames.length),
0163: new Integer(0) }));
0164: }
0165:
0166: return sourceNames;
0167: }
0168:
0169: /**
0170: * Constructor. Note that <code>sourceClasses[m][i]</code>
0171: * corresponds to the mode <code>supportedModes[m]</code>
0172: * and the source <code>sourceNames[i]</code>. Similarly
0173: * <code>paramClasses[m][i]</code> corresponds to the
0174: * mode <code>supportedModes[m]</code> and the parameter
0175: * <code> paramNames[i]</code>. The same holds true for
0176: * <code>paramDefaults</code> and <code>validParamValues</code>
0177: *
0178: * @param resources The resource tags and their corresponding data.
0179: * @param supportedModes The modes that this operator supports.
0180: * maybe one or more of "rendered", "renderable", "collection",
0181: * and "renderableCollection" (or other image operation related
0182: * modes that maybe defined later). Must support at least one mode.
0183: * @param sourceNames The source names. It may be <code>null</code>
0184: * if this operation has no sources or if the default source
0185: * naming convention ("source0", "source1", etc.) is to be used.
0186: * @param sourceClasses The source types required by this operation
0187: * for each of the above supported modes. can be null
0188: * if this operation has no sources. The number of
0189: * sources for each mode must be the same.
0190: * @param paramNames The localized parameter names. It may be
0191: * <code>null</code> if this operation has no parameters.
0192: * @param paramClasses The parameter types required by this operation.
0193: * for each mode. It may be <code>null</code> if this operation
0194: * has no parameters. The number of parameters for each mode
0195: * must be the same.
0196: * @param paramDefaults The parameter default values for each parameter
0197: * for each mode. It may be <code>null</code> if this
0198: * operation has no parameters, or none of the parameters has
0199: * a default value for any mode. The parameter defaults for an
0200: * individual mode may be null, if there are no defaults for
0201: * that mode.
0202: * @param validParamValues defines the valid values for each parameter
0203: * for each mode. this can be <code>null</code> if the operation
0204: * has no parameters. Otherwise each element can be filled in as
0205: * defined in {@link
0206: * ParameterListDescriptorImpl#ParameterListDescriptorImpl(
0207: * Object, String[], Class[], Object[], Object[])}
0208: *
0209: * @throws IllegalArgumentException if <code>resources</code> is
0210: * <code>null</code>.
0211: * @throws IllegalArgumentException if supportedModes is <code>null</code>
0212: * @throws IllegalArgumentException if the number of <code>sourceClasses</code>
0213: * for each mode is not the same or is not equal to the number
0214: * of sourceNames (if non-null).
0215: * @throws IllegalArgumentException if this operation has parameters and
0216: * <code>paramClasses</code> or <code>paramNames</code> is
0217: * <code>null</code>.
0218: * @throws IllegalArgumentException if <code>sourceNames</code>
0219: * is non-<code>null</code> and its length does not equal
0220: * the number of sources of this operation.
0221: * @throws IllegalArgumentException if this operation has parameters
0222: * and <code>paramClasses</code>, <code>paramNames</code>,
0223: * and <code>paramDefaults</code> (if all are not
0224: * <code>null</code>) do not all have the same number of elements.
0225: *
0226: * @since JAI 1.1
0227: */
0228: public OperationDescriptorImpl(String[][] resources,
0229: String[] supportedModes, String[] sourceNames,
0230: Class[][] sourceClasses, String[] paramNames,
0231: Class[][] paramClasses, Object[][] paramDefaults,
0232: Object[][] validParamValues) {
0233:
0234: sourceNames = checkSources(resources, supportedModes,
0235: sourceNames, sourceClasses);
0236:
0237: this .resources = resources;
0238: this .supportedModes = supportedModes;
0239: this .sourceNames = sourceNames;
0240: this .sourceClasses = sourceClasses;
0241: this .paramNames = paramNames;
0242:
0243: this .modeIndices = new CaselessStringArrayTable(supportedModes);
0244: this .sourceIndices = new CaselessStringArrayTable(sourceNames);
0245:
0246: // Validate parameter related arguments.
0247:
0248: int numParams = (paramNames == null) ? 0 : paramNames.length;
0249: int numModes = supportedModes.length;
0250:
0251: if (numParams == 0) {
0252: if ((paramClasses != null)
0253: && (paramClasses.length != numModes))
0254: throw new IllegalArgumentException(JaiI18N
0255: .formatMsg("OperationDescriptorImpl0",
0256: new Object[] { "paramClasses",
0257: new Integer(numModes) }));
0258:
0259: } else {
0260:
0261: if ((paramClasses == null)
0262: || (paramClasses.length != numModes))
0263: throw new IllegalArgumentException(JaiI18N
0264: .formatMsg("OperationDescriptorImpl0",
0265: new Object[] { "paramClasses",
0266: new Integer(numModes) }));
0267: }
0268:
0269: if ((paramDefaults != null)
0270: && (paramDefaults.length != numModes))
0271: throw new IllegalArgumentException(JaiI18N.formatMsg(
0272: "OperationDescriptorImpl0", new Object[] {
0273: "paramDefaults", new Integer(numModes) }));
0274:
0275: if ((validParamValues != null)
0276: && (validParamValues.length != numModes))
0277: throw new IllegalArgumentException(JaiI18N
0278: .formatMsg("OperationDescriptorImpl0",
0279: new Object[] { "validParamValues",
0280: new Integer(numModes) }));
0281:
0282: // Create the ParameterListDescriptor-s for each mode.
0283:
0284: paramListDescriptors = new ParameterListDescriptor[numModes];
0285:
0286: for (int i = 0; i < numModes; i++) {
0287: paramListDescriptors[i] = new ParameterListDescriptorImpl(
0288: this , paramNames, paramClasses[i],
0289: paramDefaults == null ? null : paramDefaults[i],
0290: validParamValues == null ? null
0291: : validParamValues[i]);
0292: }
0293: }
0294:
0295: /**
0296: * Constructor. This assumes that all modes have the same
0297: * set of parameter classes, defaults and valid values. Note
0298: * that <code>sourceClasses[m][i]</code> corresponds to
0299: * the mode <code>supportedModes[m]</code> and the source
0300: * <code>sourceNames[i]</code>.
0301: *
0302: * @param resources The resource tags and their corresponding data.
0303: * @param supportedModes The modes that this operator supports.
0304: * maybe one or more of "rendered", "renderable", "collection",
0305: * and "renderableCollection". Must support at least one mode.
0306: * @param sourceNames The source names. It may be <code>null</code>
0307: * if this operation has no sources or if the default source
0308: * naming convention ("source0", "source1", etc.) is to be used.
0309: * @param sourceClasses The source types required by this operation
0310: * for each of the above supported modes. can be null
0311: * if this operation has no sources. The number of
0312: * sources for each mode must be the same.
0313: * @param paramNames The localized parameter names. It may be
0314: * <code>null</code> if this operation has no parameters.
0315: * @param paramClasses The parameter types required by this operation.
0316: * It may be <code>null</code> if this operation has no parameters.
0317: * @param paramDefaults The parameter default values for each parameter
0318: * It may be <code>null</code> if this operation has no
0319: * parameters, or none of the parameters has a default value.
0320: * @param validParamValues defines the valid values for each parameter
0321: * for all modes. this can be <code>null</code> if the operation
0322: * has no parameters. Otherwise it can be filled in as
0323: * defined in {@link
0324: * ParameterListDescriptorImpl#ParameterListDescriptorImpl(
0325: * Object, String[], Class[], Object[], Object[])}
0326: *
0327: * @throws IllegalArgumentException if <code>resources</code> is
0328: * <code>null</code>.
0329: * @throws IllegalArgumentException if supportedModes is <code>null</code>
0330: * @throws IllegalArgumentException if the number of <code>sourceClasses</code>
0331: * for each mode is not the same or is not equal to the number
0332: * of sourceNames (if non-null).
0333: * @throws IllegalArgumentException if this operation has parameters and
0334: * <code>paramClasses</code> or <code>paramNames</code> is
0335: * <code>null</code>.
0336: * @throws IllegalArgumentException if <code>sourceNames</code>
0337: * is non-<code>null</code> and its length does not equal
0338: * the number of sources of this operation.
0339: * @throws IllegalArgumentException if this operation has parameters
0340: * and <code>paramClasses</code>, <code>paramNames</code>,
0341: * and <code>paramDefaults</code> (if all are not
0342: * <code>null</code>) do not all have the same number of elements.
0343: *
0344: * @since JAI 1.1
0345: */
0346: public OperationDescriptorImpl(String[][] resources,
0347: String[] supportedModes, String[] sourceNames,
0348: Class[][] sourceClasses, String[] paramNames,
0349: Class[] paramClasses, Object[] paramDefaults,
0350: Object[] validParamValues) {
0351:
0352: sourceNames = checkSources(resources, supportedModes,
0353: sourceNames, sourceClasses);
0354:
0355: this .resources = resources;
0356: this .supportedModes = supportedModes;
0357: this .sourceNames = sourceNames;
0358: this .sourceClasses = sourceClasses;
0359: this .paramNames = paramNames;
0360:
0361: this .modeIndices = new CaselessStringArrayTable(supportedModes);
0362: this .sourceIndices = new CaselessStringArrayTable(sourceNames);
0363:
0364: // Create one ParameterListDescriptor and use the same for each mode.
0365:
0366: ParameterListDescriptor pld = new ParameterListDescriptorImpl(
0367: this , paramNames, paramClasses, paramDefaults,
0368: validParamValues);
0369:
0370: paramListDescriptors = new ParameterListDescriptor[supportedModes.length];
0371:
0372: for (int i = 0; i < supportedModes.length; i++) {
0373: paramListDescriptors[i] = pld;
0374: }
0375: }
0376:
0377: /**
0378: * Constructor. This assumes that all modes have the same
0379: * set of parameter classes, defaults and valid values. The
0380: * source names are automatically generated using the default
0381: * source naming convertion ("source0", "source1", etc.). The
0382: * source class list is automatically generated using
0383: * <code>makeDefaultSourceClassList()</code> from <code>numSources</code>
0384: * and <code>supportedModes</code>
0385: *
0386: * @param resources The resource tags and their corresponding data.
0387: * @param supportedModes The modes that this operator supports.
0388: * maybe one or more of "rendered", "renderable", "collection",
0389: * and "renderableCollection". Must support at least one mode.
0390: * @param numSources The number of sources.
0391: * @param paramNames The localized parameter names. It may be
0392: * <code>null</code> if this operation has no parameters.
0393: * @param paramClasses The parameter types required by this operation.
0394: * It may be <code>null</code> if this operation has no parameters.
0395: * @param paramDefaults The parameter default values for each parameter
0396: * It may be <code>null</code> if this operation has no
0397: * parameters, or none of the parameters has a default value.
0398: * @param validParamValues defines the valid values for each parameter
0399: * for all modes. this can be <code>null</code> if the operation
0400: * has no parameters. Otherwise it can be filled in as
0401: * defined in {@link
0402: * ParameterListDescriptorImpl#ParameterListDescriptorImpl(
0403: * Object, String[], Class[], Object[], Object[])}
0404: *
0405: * @throws IllegalArgumentException if <code>resources</code> is
0406: * <code>null</code>.
0407: * @throws IllegalArgumentException if supportedModes is <code>null</code>
0408: * @throws IllegalArgumentException if this operation has parameters and
0409: * <code>paramClasses</code> or <code>paramNames</code> is
0410: * <code>null</code>.
0411: * @throws IllegalArgumentException if this operation has parameters
0412: * and <code>paramClasses</code>, <code>paramNames</code>,
0413: * and <code>paramDefaults</code> (if all are not
0414: * <code>null</code>) do not all have the same number of elements.
0415: *
0416: * @since JAI 1.1
0417: */
0418: public OperationDescriptorImpl(String[][] resources,
0419: String[] supportedModes, int numSources,
0420: String[] paramNames, Class[] paramClasses,
0421: Object[] paramDefaults, Object[] validParamValues) {
0422:
0423: Class[][] sourceClasses = makeDefaultSourceClassList(
0424: supportedModes, numSources);
0425:
0426: String[] sourceNames = checkSources(resources, supportedModes,
0427: null, sourceClasses);
0428:
0429: this .resources = resources;
0430: this .supportedModes = supportedModes;
0431: this .sourceNames = sourceNames;
0432: this .sourceClasses = sourceClasses;
0433: this .paramNames = paramNames;
0434:
0435: this .modeIndices = new CaselessStringArrayTable(supportedModes);
0436: this .sourceIndices = new CaselessStringArrayTable(sourceNames);
0437:
0438: // Create one ParameterListDescriptor and use the same for each mode.
0439:
0440: ParameterListDescriptor pld = new ParameterListDescriptorImpl(
0441: this , paramNames, paramClasses, paramDefaults,
0442: validParamValues);
0443:
0444: paramListDescriptors = new ParameterListDescriptor[supportedModes.length];
0445:
0446: for (int i = 0; i < supportedModes.length; i++) {
0447: paramListDescriptors[i] = pld;
0448: }
0449: }
0450:
0451: /**
0452: * Constructor which accepts a <code>ParameterListDescriptor</code>
0453: * to describe the parameters for each mode. Note
0454: * that <code>sourceClasses[m][i]</code> corresponds to
0455: * the mode <code>supportedModes[m]</code> and the source
0456: * <code>sourceNames[i]</code>.
0457: *
0458: * @param resources The resource tags and their corresponding data.
0459: * @param supportedModes The modes that this operator supports.
0460: * maybe one or more of "rendered", "renderable", "collection",
0461: * and "renderableCollection". Must support at least one mode.
0462: * @param sourceNames The source names. It may be <code>null</code>
0463: * if this operation has no sources or if the default source
0464: * naming convention ("source0", "source1", etc.) is to be used.
0465: * @param sourceClasses The source types required by this operation
0466: * for each of the above supported modes. can be null
0467: * if this operation has no sources. The number of
0468: * sources for each mode must be the same.
0469: * @param pld the parameter list descriptor for each mode.
0470: * Can be <code>null</code> if there are no parameters.
0471: *
0472: * @throws IllegalArgumentException if <code>resources</code> is
0473: * <code>null</code>.
0474: * @throws IllegalArgumentException if supportedModes is <code>null</code>
0475: * @throws IllegalArgumentException if the number of <code>sourceClasses</code>
0476: * for each mode is not the same or is not equal to the number
0477: * of sourceNames (if non-null).
0478: * @throws IllegalArgumentException if <code>sourceNames</code>
0479: * is non-<code>null</code> and its length does not equal
0480: * the number of sources of this operation.
0481: *
0482: * @since JAI 1.1
0483: */
0484: public OperationDescriptorImpl(String[][] resources,
0485: String[] supportedModes, String[] sourceNames,
0486: Class[][] sourceClasses, ParameterListDescriptor[] pld) {
0487:
0488: sourceNames = checkSources(resources, supportedModes,
0489: sourceNames, sourceClasses);
0490:
0491: this .resources = resources;
0492: this .supportedModes = supportedModes;
0493: this .sourceNames = sourceNames;
0494: this .sourceClasses = sourceClasses;
0495:
0496: this .modeIndices = new CaselessStringArrayTable(supportedModes);
0497: this .sourceIndices = new CaselessStringArrayTable(sourceNames);
0498:
0499: if ((pld != null) && (pld.length != supportedModes.length)) {
0500: throw new IllegalArgumentException(JaiI18N.formatMsg(
0501: "OperationDescriptorImpl0", new Object[] {
0502: "ParameterListDescriptor's",
0503: new Integer(supportedModes.length) }));
0504: }
0505:
0506: if (pld == null) {
0507:
0508: ParameterListDescriptor tpld = new ParameterListDescriptorImpl();
0509:
0510: paramListDescriptors = new ParameterListDescriptor[supportedModes.length];
0511:
0512: for (int i = 0; i < supportedModes.length; i++)
0513: paramListDescriptors[i] = tpld;
0514:
0515: this .paramNames = null;
0516: } else {
0517: paramListDescriptors = pld;
0518: this .paramNames = paramListDescriptors[0].getParamNames();
0519: }
0520: }
0521:
0522: /**
0523: * Constructor. This assumes that all modes use the same
0524: * <code>ParameterListDescriptor</code>. Note
0525: * that <code>sourceClasses[m][i]</code> corresponds to
0526: * the mode <code>supportedModes[m]</code> and the source
0527: * <code>sourceNames[i]</code>.
0528: *
0529: * @param resources The resource tags and their corresponding data.
0530: * @param supportedModes The modes that this operator supports.
0531: * maybe one or more of "rendered", "renderable", "collection",
0532: * and "renderableCollection". Must support at least one mode.
0533: * @param sourceNames The source names. It may be <code>null</code>
0534: * if this operation has no sources or if the default source
0535: * naming convention ("source0", "source1", etc.) is to be used.
0536: * @param sourceClasses The source types required by this operation
0537: * for each of the above supported modes. can be null
0538: * if this operation has no sources. The number of
0539: * sources for each mode must be the same.
0540: * @param pld the parameter list descriptor for all modes.
0541: * Can be <code>null</code> if there are no parameters.
0542: *
0543: * @throws IllegalArgumentException if <code>resources</code> is
0544: * <code>null</code>.
0545: * @throws IllegalArgumentException if supportedModes is <code>null</code>
0546: * @throws IllegalArgumentException if the number of <code>sourceClasses</code>
0547: * for each mode is not the same or is not equal to the number
0548: * of sourceNames (if non-null).
0549: * @throws IllegalArgumentException if <code>sourceNames</code>
0550: * is non-<code>null</code> and its length does not equal
0551: * the number of sources of this operation.
0552: *
0553: * @since JAI 1.1
0554: */
0555: public OperationDescriptorImpl(String[][] resources,
0556: String[] supportedModes, String[] sourceNames,
0557: Class[][] sourceClasses, ParameterListDescriptor pld) {
0558:
0559: sourceNames = checkSources(resources, supportedModes,
0560: sourceNames, sourceClasses);
0561:
0562: this .resources = resources;
0563: this .supportedModes = supportedModes;
0564: this .sourceNames = sourceNames;
0565: this .sourceClasses = sourceClasses;
0566:
0567: this .modeIndices = new CaselessStringArrayTable(supportedModes);
0568: this .sourceIndices = new CaselessStringArrayTable(sourceNames);
0569:
0570: if (pld == null)
0571: pld = new ParameterListDescriptorImpl();
0572:
0573: this .paramNames = pld.getParamNames();
0574:
0575: paramListDescriptors = new ParameterListDescriptor[supportedModes.length];
0576:
0577: for (int i = 0; i < supportedModes.length; i++) {
0578: paramListDescriptors[i] = pld;
0579: }
0580: }
0581:
0582: /** Gets the default source names. */
0583: private String[] getDefaultSourceNames(int numSources) {
0584:
0585: String[] defaultSourceNames = new String[numSources];
0586: for (int i = 0; i < numSources; i++) {
0587: defaultSourceNames[i] = "source" + i;
0588: }
0589: return defaultSourceNames;
0590: }
0591:
0592: // BEGIN : RegistryElementDescriptor methods
0593:
0594: /**
0595: * Returns the name of this operation; this is the same as the
0596: * <code>GlobalName</code> value in the resources and is visible
0597: * to all. This is also descriptor name under which it is registered
0598: * in the <code>OperationRegistry</code>.
0599: *
0600: * @return A <code>String</code> representing the operation's
0601: * global name.
0602: *
0603: * @throws MissingResourceException if the <code>GlobalName</code>
0604: * resource value is not supplied in the <code>resources</code>.
0605: */
0606: public String getName() {
0607: if (name == null) {
0608: name = (String) getResourceBundle(Locale.getDefault())
0609: .getObject("GlobalName");
0610: }
0611: return name;
0612: }
0613:
0614: /**
0615: * The registry modes supported by this descriptor. Known modes
0616: * include those returned by <code>RegistryMode.getModes()</code>
0617: *
0618: * @return an array of <code>String</code>s specifying the supported modes.
0619: *
0620: * @see RegistryMode
0621: * @see RegistryElementDescriptor
0622: *
0623: * @since JAI 1.1
0624: */
0625: public String[] getSupportedModes() {
0626: return supportedModes;
0627: }
0628:
0629: /**
0630: * Does this descriptor support the specified registry mode ?.
0631: * The <code>modeName</code>s are treated in a case-insensitive
0632: * (but retentive) manner.
0633: *
0634: * @param modeName the registry mode name
0635: *
0636: * @return true, if the implementation of this descriptor supports
0637: * the specified mode. false otherwise.
0638: *
0639: * @throws IllegalArgumentException if <code>modeName</code> is null
0640: *
0641: * @see RegistryElementDescriptor
0642: *
0643: * @since JAI 1.1
0644: */
0645: public boolean isModeSupported(String modeName) {
0646:
0647: if (modeName == null)
0648: throw new IllegalArgumentException(JaiI18N
0649: .getString("Generic0"));
0650:
0651: return modeIndices.contains(modeName);
0652: }
0653:
0654: /**
0655: * Does this descriptor support properties ?
0656: *
0657: * @return The default implementation in this class returns
0658: * <code>true</code> so that properties are always supported.
0659: * Operations that do not wish to support properties must
0660: * override this implementation.
0661: *
0662: * @see PropertyGenerator
0663: * @see RegistryElementDescriptor
0664: *
0665: * @since JAI 1.1
0666: */
0667: public boolean arePropertiesSupported() {
0668: return true;
0669: }
0670:
0671: /**
0672: * Returns an array of <code>PropertyGenerator</code>s implementing
0673: * the property inheritance for this operator that may be used as
0674: * a basis for the operation's property management. The default
0675: * implementation returns <code>null</code>, indicating that source
0676: * properties are simply copied. Subclasses should override this
0677: * method if they wish to produce inherited properties.
0678: *
0679: * <p><strong> For the sake of backward compatibilty, if a
0680: * deprecated constructor was used to create this object,
0681: * then this method simply calls its deprecated equivalent,
0682: * <code>getPropertyGenerators()</code>, if the modeName is either
0683: * "rendered" or "renderable". </strong>
0684: *
0685: * @param modeName the registry mode name
0686: *
0687: * @return An array of <code>PropertyGenerator</code>s, or
0688: * <code>null</code> if this operation does not have any of
0689: * its own <code>PropertyGenerator</code>s.
0690: *
0691: * @throws IllegalArgumentException if <code>modeName</code> is null
0692: * or if it is not one of the supported modes.
0693: * @throws UnsupportedOperationException if <code>arePropertiesSupported</code>
0694: * returns <code>false</code>
0695: *
0696: * @see RegistryElementDescriptor
0697: *
0698: * @since JAI 1.1
0699: */
0700: public PropertyGenerator[] getPropertyGenerators(String modeName) {
0701:
0702: if (modeName == null)
0703: throw new IllegalArgumentException(JaiI18N
0704: .getString("Generic0"));
0705:
0706: if (deprecated) {
0707: if (modeName.equalsIgnoreCase("rendered")
0708: || modeName.equalsIgnoreCase("renderable"))
0709: return getPropertyGenerators();
0710: }
0711:
0712: if (!arePropertiesSupported()) {
0713: throw new UnsupportedOperationException(JaiI18N.formatMsg(
0714: "OperationDescriptorImpl3",
0715: new Object[] { modeName }));
0716: }
0717:
0718: return null;
0719: }
0720:
0721: /**
0722: * Returns the <code>ParameterListDescriptor</code> that describes
0723: * the associated parameters (NOT sources). This method returns
0724: * null if there are no parameters for the specified modeName.
0725: * If the specified modeName supports parameters but the
0726: * implementing class does not have parameters, then this method
0727: * returns a non-null <code>ParameterListDescriptor</code> whose
0728: * <code>getNumParameters()</code> returns 0.
0729: *
0730: * @param modeName the registry mode name.
0731: *
0732: * @throws IllegalArgumentException if <code>modeName</code> is null
0733: * or if it is not one of the supported modes.
0734: *
0735: * @see RegistryElementDescriptor
0736: *
0737: * @since JAI 1.1
0738: */
0739: public ParameterListDescriptor getParameterListDescriptor(
0740: String modeName) {
0741: return paramListDescriptors[modeIndices.indexOf(modeName)];
0742: }
0743:
0744: // END : RegistryElementDescriptor methods
0745:
0746: /**
0747: * Returns the resource data for this operation. It must contain
0748: * <code>String</code> data for the following tags: "GlobalName",
0749: * "LocalName", "Vendor", "Description", "DocURL", and "Version".
0750: * Additional resources should be supplied when appropriate.
0751: *
0752: * <p> The default implementation simply returns a reference to
0753: * the local "resources" variable, which should be supplied by
0754: * each subclass by way of the superclass constructor. It also
0755: * ignores the <code>Locale</code> argument, and always returns
0756: * the <code>String</code>s in the default <code>Locale</code>.
0757: *
0758: * @param locale The <code>Locale</code> in which to localize the
0759: * resource data.
0760: *
0761: * @return A two-dimensional array of <code>String</code>s containing
0762: * the mandatory and optional resource tags and their
0763: * corresponding resource data. (String[i][0] is
0764: * the tag for the i-th resource and String[i][1] is the
0765: * corresponding data)
0766: */
0767: public String[][] getResources(Locale locale) {
0768: return resources;
0769: }
0770:
0771: /**
0772: * Returns the resource data for this operation in a
0773: * <code>ResourceBundle</code>. The resource data are taken from the
0774: * <code>getResources()</code> method.
0775: *
0776: * <p> The default implementation ignores the <code>Locale</code>
0777: * argument, and always returns the resources in the default
0778: * <code>Locale</code>.
0779: *
0780: * @param locale The <code>Locale</code> in which to localize the
0781: * resource data.
0782: *
0783: * @return A <code>ResourceBundle</code> containing mandatory and
0784: * optional resource information.
0785: */
0786: public ResourceBundle getResourceBundle(Locale locale) {
0787: final Locale l = locale;
0788: return new ListResourceBundle() {
0789: public Object[][] getContents() {
0790: return getResources(l);
0791: }
0792: }; // from return statement
0793: }
0794:
0795: /**
0796: * Returns the number of sources required by this operation.
0797: * All modes have the same number of sources.
0798: */
0799: public int getNumSources() {
0800: return sourceNames.length;
0801: }
0802:
0803: /**
0804: * Returns an array of <code>Class</code>es that describe the types
0805: * of sources required by this operation for the specified mode.
0806: * If this operation has no sources, this method returns <code>null</code>.
0807: *
0808: * @param modeName the operation mode name
0809: *
0810: * @throws IllegalArgumentException if modeName is <code>null</code>
0811: * or if it is not one of the supported modes.
0812: *
0813: * @since JAI 1.1
0814: */
0815: public Class[] getSourceClasses(String modeName) {
0816: checkModeName(modeName);
0817:
0818: Class[] sc = sourceClasses[modeIndices.indexOf(modeName)];
0819:
0820: if ((sc != null) && (sc.length <= 0))
0821: return null;
0822:
0823: return sc;
0824: }
0825:
0826: /**
0827: * Returns an array of <code>String</code>s that are the names
0828: * of the sources of this operation. If this operation has no
0829: * sources, this method returns <code>null</code>. If this
0830: * operation has sources but their names were not provided at
0831: * construction time, then the returned names will be of the
0832: * form "source0", "source1", etc.
0833: *
0834: * @since JAI 1.1
0835: */
0836: public String[] getSourceNames() {
0837:
0838: if ((sourceNames == null) || (sourceNames.length <= 0))
0839: return null;
0840:
0841: return sourceNames;
0842: }
0843:
0844: /**
0845: * Returns a <code>Class</code> that describes the type of
0846: * destination this operation produces for the specified mode.
0847: *
0848: * <p><strong> For the sake of backward compatibilty, if a
0849: * deprecated constructor was used to create this object, then this
0850: * method simply calls its deprecated equivalent, if the modeName is
0851: * either "rendered" or "renderable". </strong>
0852: *
0853: * @param modeName the operation mode name
0854: *
0855: * @throws IllegalArgumentException if modeName is <code>null</code>
0856: * or if it is not one of the supported modes.
0857: *
0858: * @since JAI 1.1
0859: */
0860: public Class getDestClass(String modeName) {
0861:
0862: checkModeName(modeName);
0863:
0864: if (deprecated) {
0865:
0866: if (modeName.equalsIgnoreCase("rendered"))
0867: return getDestClass();
0868:
0869: if (modeName.equalsIgnoreCase("renderable"))
0870: return getRenderableDestClass();
0871: }
0872:
0873: return RegistryMode.getMode(modeName).getProductClass();
0874: }
0875:
0876: /**
0877: * Returns <code>true</code> if this operation supports the
0878: * specified mode, and is capable of handling the given input
0879: * source(s) for the specified mode. The default implementation
0880: * ensures that the <code>ParameterBlock</code> has at least
0881: * the required number of sources. It also verifies the class type
0882: * of the first <code>getNumSources()</code> and makes sure
0883: * that none of them are <code>null</code>. Any extra sources in
0884: * the <code>ParameterBlock</code> are ignored. Subclasses should
0885: * override this implementation if their requirement on the
0886: * sources are different from the default. This method is used by
0887: * <code>validateArguments</code> to validate the sources.
0888: *
0889: * <p><strong> For the sake of backward compatibilty, if a
0890: * deprecated constructor was used to create this object, then this
0891: * method simply calls its deprecated equivalent, if the <code>modeName</code> is
0892: * either "rendered" or "renderable". </strong>
0893: *
0894: * @param modeName the operation mode name
0895: * @param args a <code>ParameterBlock</code> that has the sources
0896: * @param msg A string that may contain error messages.
0897: *
0898: * @throws IllegalArgumentException if any of the input parameters are <code>null</code>.
0899: *
0900: * @since JAI 1.1
0901: *
0902: * @see #validateArguments
0903: */
0904: protected boolean validateSources(String modeName,
0905: ParameterBlock args, StringBuffer msg) {
0906: if (modeName == null)
0907: throw new IllegalArgumentException(JaiI18N
0908: .getString("Generic0"));
0909:
0910: if (deprecated) {
0911:
0912: if (modeName.equalsIgnoreCase("rendered"))
0913: return validateSources(args, msg);
0914:
0915: if (modeName.equalsIgnoreCase("renderable"))
0916: return validateRenderableSources(args, msg);
0917: }
0918:
0919: return validateSources(getSourceClasses(modeName), args, msg);
0920: }
0921:
0922: /**
0923: * Returns <code>true</code> if this operation is capable of
0924: * handling the input parameters for the specified mode. The default
0925: * implementation validates the number of parameters, the class type
0926: * of each parameter, and null parameter. For non-null parameters,
0927: * it also checks to see if the parameter value is valid. Subclasses
0928: * should override this implementation if their requirement on the
0929: * parameter objects are different from the default. This is used by
0930: * <code>validateArguments</code> to validate the parameters.
0931: *
0932: * <p> JAI allows unspecified tailing parameters if these parameters
0933: * have default values. This method automatically sets these unspecified
0934: * parameters to their default values. However, if a parameter, which
0935: * has a default value, is followed by one or more parameters that
0936: * have no default values, this parameter must be specified in the
0937: * <code>ParameterBlock</code>; else this method returns
0938: * <code>false</code>.
0939: *
0940: * <p> This method sets all the undefined parameters in the
0941: * <code>ParameterBlock</code> to their default values, if the default
0942: * values are specified.
0943: *
0944: * <p> Note that <code>DeferredData</code> parameters will not be
0945: * recognized as valid unless the parameter is defined to have class
0946: * <code>DeferredData.class</code>.
0947: *
0948: * <p><strong> For the sake of backward compatibilty, if a
0949: * deprecated constructor was used to create this object, then this
0950: * method simply calls its deprecated equivalent, if the <code>modeName</code> is
0951: * either "rendered" or "renderable". </strong>
0952: *
0953: * @throws IllegalArgumentException if any of the input parameters are <code>null</code>.
0954: *
0955: * @since JAI 1.1
0956: *
0957: * @see #validateArguments
0958: * @see ParameterListDescriptorImpl#isParameterValueValid
0959: */
0960: protected boolean validateParameters(String modeName,
0961: ParameterBlock args, StringBuffer msg) {
0962: if (modeName == null)
0963: throw new IllegalArgumentException(JaiI18N
0964: .getString("Generic0"));
0965:
0966: if (deprecated) {
0967: if (modeName.equalsIgnoreCase("rendered")
0968: || modeName.equalsIgnoreCase("renderable"))
0969: return validateParameters(args, msg);
0970: }
0971:
0972: return validateParameters(getParameterListDescriptor(modeName),
0973: args, msg);
0974: }
0975:
0976: /**
0977: * Returns <code>true</code> if this operation/mode is capable of
0978: * handling the input source(s) and/or parameter(s)
0979: * specified in the <code>ParameterBlock</code>, or
0980: * <code>false</code> otherwise, in which case an explanatory
0981: * message may be appended to the <code>StringBuffer</code>.
0982: *
0983: * <p> This method is the standard place where input arguments are
0984: * validated against this operation's specification for the specified
0985: * mode. It is called by <code>JAI.create()</code> as a part of its
0986: * validation process. Thus it is strongly recommended that the
0987: * application programs use the <code>JAI.create()</code> methods to
0988: * instantiate all the rendered operations.
0989: *
0990: * <p> The default implementation of this method makes sure that
0991: * this operator supports the specified mode and then calls
0992: * <code>validateSources</code> and <code>validateParameters</code>.
0993: *
0994: * <p> This method sets all the undefined parameters in the
0995: * <code>ParameterBlock</code> to their default values, if the default
0996: * values are specified.
0997: *
0998: * <p> Note that <code>DeferredData</code> parameters will not be
0999: * recognized as valid unless the parameter is defined to have class
1000: * <code>DeferredData.class</code>.
1001: *
1002: * @param modeName the operation mode name
1003: * @param args Input arguments, including source(s) and/or parameter(s).
1004: * @param msg A string that may contain error messages.
1005: *
1006: * @throws IllegalArgumentException if <code>modeName</code> is <code>null</code>
1007: *
1008: * @since JAI 1.1
1009: *
1010: * @see #validateSources
1011: * @see #validateParameters
1012: */
1013: public boolean validateArguments(String modeName,
1014: ParameterBlock args, StringBuffer msg) {
1015: return (isModeSupported(modeName)
1016: && validateSources(modeName, args, msg) && validateParameters(
1017: modeName, args, msg));
1018: }
1019:
1020: /**
1021: * Returns <code>true</code> if the operation should be computed
1022: * immediately for all supported modes of this operation during
1023: * the call to <code>JAI.create()</code>; that is, the operation
1024: * is placed in immediate mode. If <code>true</code>, and
1025: * the computation fails, <code>null</code> will be returned
1026: * from <code>JAI.create()</code>. If <code>false</code>,
1027: * <code>JAI.create()</code> will return an instance of the
1028: * appropriate destination class that may be asked to compute itself
1029: * at a later time; this computation may fail at that time.
1030: *
1031: * <p> Operations that rely on an external resource, such as
1032: * a source file, or that produce externally-visible side
1033: * effects, such as writing to an output file, should return
1034: * <code>true</code> from this method. Operations that rely
1035: * only on their sources and parameters usually wish to return
1036: * <code>false</code> in order to defer rendering as long as
1037: * possible.
1038: *
1039: * <p> The default implementation in this class returns
1040: * <code>false</code> so that deferred execution is invoked.
1041: * Operations that wish to be placed in the immediate mode must
1042: * override this implementation.
1043: */
1044: public boolean isImmediate() {
1045: return false;
1046: }
1047:
1048: /**
1049: * Calculates the region over which two distinct renderings
1050: * of an operation may be expected to differ.
1051: *
1052: * <p> The class of the returned object will vary as a function of
1053: * the mode of the operation. For rendered and renderable two-
1054: * dimensional images this will be an instance of a class which
1055: * implements <code>java.awt.Shape</code>.
1056: *
1057: * @param modeName The name of the mode.
1058: * @param oldParamBlock The previous sources and parameters.
1059: * @param oldHints The previous hints.
1060: * @param newParamBlock The current sources and parameters.
1061: * @param newHints The current hints.
1062: * @param node The affected node in the processing chain.
1063: *
1064: * @return <code>null</code> to indicate that there is no
1065: * common region of validity.
1066: *
1067: * @throws IllegalArgumentException if <code>modeName</code>
1068: * is <code>null</code> or if the operation requires either
1069: * sources or parameters and either <code>oldParamBlock</code>
1070: * or <code>newParamBlock</code> is <code>null</code>.
1071: * @throws IllegalArgumentException if <code>oldParamBlock</code> or
1072: * <code>newParamBlock</code> do not contain sufficient sources
1073: * or parameters for the operation in question.
1074: *
1075: * @since JAI 1.1
1076: */
1077: public Object getInvalidRegion(String modeName,
1078: ParameterBlock oldParamBlock, RenderingHints oldHints,
1079: ParameterBlock newParamBlock, RenderingHints newHints,
1080: OperationNode node) {
1081: if (modeName == null)
1082: throw new IllegalArgumentException(JaiI18N
1083: .getString("Generic0"));
1084:
1085: return null;
1086: }
1087:
1088: /**
1089: * Get the default source class for the supported mode.
1090: *
1091: * "rendered" - java.awt.image.RenderedImage.class
1092: * "renderable" - java.awt.image.renderable.RenderableImage.class
1093: * "collection" - java.util.Collection.class
1094: * "renderableCollection" - java.util.Collection.class
1095: *
1096: * @since JAI 1.1
1097: */
1098: protected static Class getDefaultSourceClass(String modeName) {
1099:
1100: if ("rendered".equalsIgnoreCase(modeName))
1101: return java.awt.image.RenderedImage.class;
1102:
1103: if ("renderable".equalsIgnoreCase(modeName))
1104: return java.awt.image.renderable.RenderableImage.class;
1105:
1106: if ("collection".equalsIgnoreCase(modeName))
1107: return java.util.Collection.class;
1108:
1109: if ("renderableCollection".equalsIgnoreCase(modeName))
1110: return java.util.Collection.class;
1111:
1112: return null;
1113: }
1114:
1115: /**
1116: * Create a list of per mode source classes for each supported mode
1117: * which can then be passed on to the constructor. Uses
1118: * <code>getDefaultSourceClass(modeName)</code> to construct this
1119: * list.
1120: *
1121: * @since JAI 1.1
1122: */
1123: protected static Class[][] makeDefaultSourceClassList(
1124: String[] supportedModes, int numSources) {
1125:
1126: if ((supportedModes == null) || (supportedModes.length == 0))
1127: return null;
1128:
1129: int count = supportedModes.length;
1130:
1131: Class classes[][] = new Class[count][numSources];
1132:
1133: for (int i = 0; i < count; i++) {
1134:
1135: Class sourceClass = getDefaultSourceClass(supportedModes[i]);
1136:
1137: for (int j = 0; j < numSources; j++)
1138: classes[i][j] = sourceClass;
1139: }
1140:
1141: return classes;
1142: }
1143:
1144: /********************** DEPRECATED Constructors ********************/
1145:
1146: /**
1147: * Create a list of supported modes using the deprecated is*Supported
1148: * methods.
1149: */
1150: private String[] makeSupportedModeList() {
1151:
1152: int count = 0;
1153:
1154: if (isRenderedSupported())
1155: count++;
1156: if (isRenderableSupported())
1157: count++;
1158:
1159: String modes[] = new String[count];
1160:
1161: count = 0;
1162:
1163: if (isRenderedSupported())
1164: modes[count++] = "rendered";
1165: if (isRenderableSupported())
1166: modes[count++] = "renderable";
1167:
1168: return modes;
1169: }
1170:
1171: /**
1172: * Create a list of per mode source classes for use by deprecated
1173: * constructors.
1174: */
1175: private Class[][] makeSourceClassList(Class[] sourceClasses,
1176: Class[] renderableSourceClasses) {
1177: int count = 0;
1178:
1179: if (isRenderedSupported())
1180: count++;
1181: if (isRenderableSupported())
1182: count++;
1183:
1184: Class classes[][] = new Class[count][];
1185:
1186: count = 0;
1187:
1188: if (isRenderedSupported())
1189: classes[count++] = sourceClasses;
1190: if (isRenderableSupported())
1191: classes[count++] = renderableSourceClasses;
1192:
1193: return classes;
1194: }
1195:
1196: /**
1197: * Create a list of valid parameter values, one for each param.
1198: */
1199: private Object[] makeValidParamValueList(Class[] paramClasses) {
1200:
1201: if (paramClasses == null)
1202: return null;
1203:
1204: int numParams = paramClasses.length;
1205:
1206: Object validValues[] = null;
1207:
1208: for (int i = 0; i < numParams; i++) {
1209: Number min = getParamMinValue(i);
1210: Number max = getParamMaxValue(i);
1211:
1212: if ((min == null) && (max == null))
1213: continue;
1214:
1215: if (validValues == null)
1216: validValues = new Object[numParams];
1217:
1218: validValues[i] = new Range(min.getClass(),
1219: (Comparable) min, (Comparable) max);
1220: }
1221:
1222: return validValues;
1223: }
1224:
1225: /**
1226: * Constructor.
1227: *
1228: * @param resources The resource tags and their corresponding data.
1229: * @param sourceClasses The source types required by this operation
1230: * in the rendered mode. It may be <code>null</code>
1231: * if this operation does not support the rendered mode, or
1232: * if it has no sources.
1233: * @param renderableSourceClasses The source types required by this
1234: * operation in the renderable mode. It may be
1235: * <code>null</code> if this operation does not support the
1236: * renderable mode, or if it has no sources.
1237: * @param paramClasses The parameter types required by this operation.
1238: * It may be <code>null</code> if this operation has no
1239: * parameters.
1240: * @param paramNames The localized parameter names. It may be
1241: * <code>null</code> if this operation has no parameters.
1242: * @param paramDefaults The parameter default values. It may be
1243: * <code>null</code> if this operation has no parameters,
1244: * or none of the parameters has a default value.
1245: *
1246: * @throws IllegalArgumentException if <code>resources</code> is
1247: * <code>null</code>.
1248: * @throws IllegalArgumentException if this operation supports the
1249: * rendered mode, and it has sources, and
1250: * <code>sourceClasses</code> is <code>null</code>.
1251: * @throws IllegalArgumentException if this operation supports the
1252: * renderable mode, and it has sources, and
1253: * <code>renderableSourceClasses</code> is <code>null</code>.
1254: * @throws IllegalArgumentException if <code>sourceClasses</code>
1255: * and <code>renderableSourceClasses</code> (if both are not
1256: * <code>null</code>) do not have the same number of elements.
1257: * @throws IllegalArgumentException if this operation has parameters and
1258: * <code>paramClasses</code> or <code>paramNames</code> is
1259: * <code>null</code>.
1260: * @throws IllegalArgumentException if this operation has parameters
1261: * and <code>paramClasses</code>, <code>paramNames</code>,
1262: * and <code>paramDefaults</code> (if all are not
1263: * <code>null</code>) do not all have the same number of elements.
1264: *
1265: * @deprecated as of JAI 1.1 in favor of
1266: * constructors where supported modes are explicitly specified.
1267: * Uses <code>isRenderedSupported()</code> and <code>
1268: * isRenderableSupported()</code> to figure out the supported modes.
1269: *
1270: * @see OperationDescriptorImpl#OperationDescriptorImpl(String[][],
1271: * String[], String[], Class [][], String[], Class [], Object[], Object[])
1272: */
1273: public OperationDescriptorImpl(String[][] resources,
1274: Class[] sourceClasses, Class[] renderableSourceClasses,
1275: Class[] paramClasses, String[] paramNames,
1276: Object[] paramDefaults) {
1277: this .deprecated = true;
1278:
1279: String[] supportedModes = makeSupportedModeList();
1280: Class[][] sourceClassList = makeSourceClassList(sourceClasses,
1281: renderableSourceClasses);
1282:
1283: String[] sourceNames = checkSources(resources, supportedModes,
1284: null, sourceClassList);
1285:
1286: Object[] validParamValues = makeValidParamValueList(paramClasses);
1287:
1288: this .resources = resources;
1289: this .supportedModes = supportedModes;
1290: this .sourceNames = sourceNames;
1291: this .sourceClasses = sourceClassList;
1292: this .paramNames = paramNames;
1293:
1294: this .modeIndices = new CaselessStringArrayTable(supportedModes);
1295: this .sourceIndices = new CaselessStringArrayTable(sourceNames);
1296:
1297: // Create one ParameterListDescriptor and use the same for each mode.
1298:
1299: ParameterListDescriptor pld = new ParameterListDescriptorImpl(
1300: this , paramNames, paramClasses, paramDefaults,
1301: validParamValues);
1302:
1303: paramListDescriptors = new ParameterListDescriptor[supportedModes.length];
1304:
1305: for (int i = 0; i < supportedModes.length; i++) {
1306: paramListDescriptors[i] = pld;
1307: }
1308: }
1309:
1310: /**
1311: * Constructor for operations that support either the rendered
1312: * or the renderable or both modes. The class type for all the
1313: * source(s) of the rendered mode (if supported) is set to
1314: * <code>java.awt.image.RenderedImage.class</code>.
1315: * The class type for all the source(s) of the renderable mode (if
1316: * supported) is set to
1317: * <code>java.awt.image.renderable.RenderableImage</code>.
1318: *
1319: * @param resources The resource tags and their corresponding data.
1320: * @param numSources The number of sources required by this operation.
1321: * It should not be negative. A negative value indicates this
1322: * operation has no sources.
1323: * @param paramClasses The parameter types required by this operation.
1324: * It may be <code>null</code> if this operation has no
1325: * parameters.
1326: * @param paramNames The localized parameter names. It may be
1327: * <code>null</code> if this operation has no parameters.
1328: * @param paramDefaults The parameter default values. It may be
1329: * <code>null</code> if this operation has no parameters,
1330: * or none of the parameters has a default value.
1331: *
1332: * @throws IllegalArgumentException if <code>resources</code> is
1333: * <code>null</code>.
1334: * @throws IllegalArgumentException if this operation has parameters and
1335: * <code>paramClasses</code> or <code>paramNames</code> is
1336: * <code>null</code>.
1337: * @throws IllegalArgumentException if this operation has parameters
1338: * and <code>paramClasses</code>, <code>paramNames</code>,
1339: * and <code>paramDefaults</code> (if not <code>null</code>)
1340: * do not all have the same number of elements.
1341: *
1342: * @deprecated as of JAI 1.1 in favor of
1343: * constructors where supported modes are explicitly specified.
1344: * Uses <code>isRenderedSupported()</code> and <code>
1345: * isRenderableSupported()</code> to figure out the supported modes.
1346: *
1347: * @see OperationDescriptorImpl#OperationDescriptorImpl(String[][],
1348: * String[], int, String[], Class [], Object[], Object[])
1349: */
1350: public OperationDescriptorImpl(String[][] resources,
1351: int numSources, Class[] paramClasses, String[] paramNames,
1352: Object[] paramDefaults) {
1353: this .deprecated = true;
1354:
1355: String[] supportedModes = makeSupportedModeList();
1356: Class[][] sourceClassList = makeDefaultSourceClassList(
1357: supportedModes, numSources);
1358:
1359: String[] sourceNames = checkSources(resources, supportedModes,
1360: null, sourceClassList);
1361:
1362: Object[] validParamValues = makeValidParamValueList(paramClasses);
1363:
1364: this .resources = resources;
1365: this .supportedModes = supportedModes;
1366: this .sourceNames = sourceNames;
1367: this .sourceClasses = sourceClassList;
1368: this .paramNames = paramNames;
1369:
1370: this .modeIndices = new CaselessStringArrayTable(supportedModes);
1371: this .sourceIndices = new CaselessStringArrayTable(sourceNames);
1372:
1373: // Create one ParameterListDescriptor and use the same for each mode.
1374:
1375: ParameterListDescriptor pld = new ParameterListDescriptorImpl(
1376: this , paramNames, paramClasses, paramDefaults,
1377: validParamValues);
1378:
1379: paramListDescriptors = new ParameterListDescriptor[supportedModes.length];
1380:
1381: for (int i = 0; i < supportedModes.length; i++) {
1382: paramListDescriptors[i] = pld;
1383: }
1384: }
1385:
1386: /**
1387: * Constructor for operations that supports only the rendered mode
1388: * and requires no parameters.
1389: *
1390: * @param resources The resource tags and their corresponding data.
1391: * @param sourceClasses The source types required by this operation
1392: * in the rendered mode. It may be <code>null</code>
1393: * if this operation has no sources.
1394: *
1395: * @throws IllegalArgumentException if <code>resources</code> is
1396: * <code>null</code>.
1397: *
1398: * @deprecated as of JAI 1.1 in favor of constructors where the mode
1399: * specfic information is explicitly specified.
1400: *
1401: * @see OperationDescriptorImpl#OperationDescriptorImpl(String[][],
1402: * String[], String[], Class [][], String[], Class [], Object[], Object[])
1403: */
1404: public OperationDescriptorImpl(String[][] resources,
1405: Class[] sourceClasses) {
1406: this (resources, sourceClasses, null, null, null, null);
1407: }
1408:
1409: /**
1410: * Constructor for operations that supports either the rendered
1411: * or the renderable or both modes and requires no parameters.
1412: *
1413: * @param resources The resource tags and their corresponding data.
1414: * @param sourceClasses The source types required by this operation
1415: * in the rendered mode. It may be <code>null</code>
1416: * if this operation does not support the rendered mode, or
1417: * if it has no sources.
1418: * @param renderableSourceClasses The source types required by this
1419: * operation in the renderable mode. It may be
1420: * <code>null</code> if this operation does not support the
1421: * renderable mode, or if it has no sources.
1422: *
1423: * @throws IllegalArgumentException if <code>resources</code> is
1424: * <code>null</code>.
1425: * @throws IllegalArgumentException if this operation supports the
1426: * rendered mode, and it has sources, and
1427: * <code>sourceClasses</code> is <code>null</code>.
1428: * @throws IllegalArgumentException if this operation supports the
1429: * renderable mode, and it has sources, and
1430: * <code>renderableSourceClasses</code> is <code>null</code>.
1431: * @throws IllegalArgumentException if <code>sourceClasses</code>
1432: * and <code>renderableSourceClasses</code> (if both are not
1433: * <code>null</code>) do not have the same number of elements.
1434: *
1435: * @deprecated as of JAI 1.1 in favor of constructors where the mode
1436: * specfic information is explicitly specified.
1437: *
1438: * @see OperationDescriptorImpl#OperationDescriptorImpl(String[][],
1439: * String[], String[], Class [][], String[], Class [], Object[], Object[])
1440: */
1441: public OperationDescriptorImpl(String[][] resources,
1442: Class[] sourceClasses, Class[] renderableSourceClasses) {
1443: this (resources, sourceClasses, renderableSourceClasses, null,
1444: null, null);
1445: }
1446:
1447: /**
1448: * Constructor for operations that supports either the rendered
1449: * or the renderable or both modes and requires no sources.
1450: *
1451: * @throws IllegalArgumentException if <code>resources</code> is
1452: * <code>null</code>.
1453: * @throws IllegalArgumentException if this operation has parameters and
1454: * <code>paramClasses</code> or <code>paramNames</code> is
1455: * <code>null</code>.
1456: * @throws IllegalArgumentException if this operation has parameters
1457: * and <code>paramClasses</code>, <code>paramNames</code>,
1458: * and <code>paramDefaults</code> (if not <code>null</code>)
1459: * do not all have the same number of elements.
1460: *
1461: * @deprecated as of JAI 1.1 in favor of constructors where the mode
1462: * specfic information is explicitly specified.
1463: *
1464: * @see OperationDescriptorImpl#OperationDescriptorImpl(String[][],
1465: * String[], int, String[], Class [], Object[], Object[])
1466: */
1467: public OperationDescriptorImpl(String[][] resources,
1468: Class[] paramClasses, String[] paramNames,
1469: Object[] paramDefaults) {
1470: this (resources, null, null, paramClasses, paramNames,
1471: paramDefaults);
1472: }
1473:
1474: /**
1475: * Constructor for operations that support the rendered mode and
1476: * possibly the renderable mode and require no parameters. The
1477: * class type for all the source(s) of the rendered mode is set to
1478: * <code>java.awt.image.RenderedImage.class</code>.
1479: * The class type for all the source(s) of the renderable mode (if
1480: * supported) is set to
1481: * <code>java.awt.image.renderable.RenderableImage</code>.
1482: *
1483: * @param resources The resource tags and their corresponding data.
1484: * @param numSources The number of sources required by this operation.
1485: * It should not be negative. A negative value indicates this
1486: * operation has no sources.
1487: *
1488: * @throws IllegalArgumentException if <code>resources</code> is
1489: * <code>null</code>.
1490: *
1491: * @deprecated as of JAI 1.1 in favor of constructors where the mode
1492: * specfic information is explicitly specified.
1493: *
1494: * @see OperationDescriptorImpl#OperationDescriptorImpl(String[][],
1495: * String[], int, String[], Class [], Object[], Object[])
1496: */
1497: public OperationDescriptorImpl(String[][] resources, int numSources) {
1498: this (resources, numSources, null, null, null);
1499: }
1500:
1501: /********************** DEPRECATED METHODS *************************/
1502:
1503: /**
1504: * Returns an array of <code>PropertyGenerator</code>s implementing
1505: * the property inheritance for this operation. The default
1506: * implementation returns <code>null</code>, indicating that source
1507: * properties are simply copied. Subclasses should override
1508: * this method if they wish to produce inherited properties.
1509: *
1510: * @deprecated as of JAI 1.1 in favor of the equivalent method
1511: * that specifies the mode name.
1512: *
1513: * @see #getPropertyGenerators
1514: */
1515: public PropertyGenerator[] getPropertyGenerators() {
1516: return deprecated ? null : getPropertyGenerators("rendered");
1517: }
1518:
1519: /**
1520: * Returns <code>true</code> if this operation supports the
1521: * rendered mode. The default implementation in this
1522: * class returns <code>true</code>.
1523: *
1524: * @deprecated as of JAI 1.1 in favor of <code>isModeSupported("rendered")</code>
1525: *
1526: * @see #isModeSupported
1527: */
1528: public boolean isRenderedSupported() {
1529: return deprecated ? true : isModeSupported("rendered");
1530: }
1531:
1532: /**
1533: * Returns the source class types of this operation for the rendered
1534: * mode. If this operation has no sources, this method returns <code>null</code>.
1535: *
1536: * @deprecated as of JAI 1.1 in favor of <code>getSourceClasses("rendered")</code>
1537: *
1538: * @throws IllegalArgumentException if the <code>rendered</code> mode
1539: * is not supported.
1540: *
1541: * @see #getSourceClasses
1542: */
1543: public Class[] getSourceClasses() {
1544: return getSourceClasses("rendered");
1545: }
1546:
1547: /**
1548: * Returns the destination class type of this operation for the
1549: * rendered mode. The default implementation in this class returns
1550: * <code>java.awt.image.RenderedImage.class</code> if this operation
1551: * supports the rendered mode, or <code>null</code> otherwise.
1552: *
1553: * @deprecated as of JAI 1.1 in favor of <code>getDestClass("rendered")</code>
1554: *
1555: * @see #getDestClass
1556: */
1557: public Class getDestClass() {
1558: if (deprecated) {
1559: return (isRenderedSupported() ? java.awt.image.RenderedImage.class
1560: : null);
1561: } else {
1562: return getDestClass("rendered");
1563: }
1564: }
1565:
1566: /**
1567: * Returns <code>true</code> if this operation supports the rendered
1568: * mode, and is capable of handling the input arguments for the
1569: * rendered mode. The default implementation validates both the
1570: * source(s) and the parameter(s).
1571: *
1572: * <p> Note that <code>DeferredData</code> parameters will not be
1573: * recognized as valid unless the parameter is defined to have class
1574: * <code>DeferredData.class</code>.
1575: *
1576: * <p> Additional validations should be added by each individual
1577: * operation based on its specification.
1578: *
1579: * @throws IllegalArgumentException if <code>args</code> is <code>null</code>.
1580: * @throws IllegalArgumentException if <code>msg</code> is <code>null</code>
1581: * and the validation fails.
1582: *
1583: * @deprecated as of JAI 1.1 in favor of <code>validateArguments("rendered", ...)</code>
1584: *
1585: * @see #validateArguments
1586: */
1587: public boolean validateArguments(ParameterBlock args,
1588: StringBuffer msg) {
1589: if (deprecated) {
1590: return (validateSources(args, msg) && validateParameters(
1591: args, msg));
1592: } else {
1593: return validateArguments("rendered", args, msg);
1594: }
1595: }
1596:
1597: /********************* Renderable Mode Methods (deprecated) ********/
1598:
1599: /**
1600: * Returns <code>true</code> if this operation supports the
1601: * renderable mode. The default implementation in this
1602: * class returns <code>false</code>. Operations that support
1603: * the renderable mode must override this implementation.
1604: *
1605: * @deprecated as of JAI 1.1 in favor of <code>isModeSupported("renderable")</code>
1606: *
1607: * @see #isModeSupported
1608: */
1609: public boolean isRenderableSupported() {
1610: return deprecated ? false : isModeSupported("renderable");
1611: }
1612:
1613: /**
1614: * Returns the source class types of this operation for the
1615: * renderable mode. If this operation has no sources this method
1616: * returns <code>null</code>.
1617: *
1618: * @deprecated as of JAI 1.1 in favor of <code>getSourceClasses("renderable")</code>
1619: *
1620: * @throws IllegalArgumentException if the <code>renderable</code> mode
1621: * is not supported.
1622: *
1623: * @see #getSourceClasses
1624: */
1625: public Class[] getRenderableSourceClasses() {
1626: return getSourceClasses("renderable");
1627: }
1628:
1629: /**
1630: * Returns the destination class type of this operation for the
1631: * renderable mode. The default implementation in this class returns
1632: * <code>java.awt.image.renderable.RenderableImage.class</code> if
1633: * this operation supports the renderable mode, or <code>null</code>
1634: * otherwise.
1635: *
1636: * @deprecated as of JAI 1.1 in favor of <code>getDestClass("renderable")</code>
1637: *
1638: * @see #getDestClass
1639: */
1640: public Class getRenderableDestClass() {
1641: if (deprecated) {
1642: return (isRenderableSupported() ? java.awt.image.renderable.RenderableImage.class
1643: : null);
1644: } else {
1645: return getDestClass("renderable");
1646: }
1647: }
1648:
1649: /**
1650: * Returns <code>true</code> if this operation supports the
1651: * renderable mode, and is capable of handling the input
1652: * arguments for the renderable mode. The default implementation
1653: * validates both the source(s) and the parameter(s).
1654: *
1655: * <p> If this operation does not support the renderable mode,
1656: * this method returns <code>false</code> regardless of the input
1657: * arguments.
1658: *
1659: * <p> Note that <code>DeferredData</code> parameters will not be
1660: * recognized as valid unless the parameter is defined to have class
1661: * <code>DeferredData.class</code>.
1662: *
1663: * <p> Additional validations should be added by each individual
1664: * operation based on its specification.
1665: *
1666: * @throws IllegalArgumentException if <code>args</code> is <code>null</code>.
1667: * @throws IllegalArgumentException if <code>msg</code> is <code>null</code>
1668: * and the validation fails.
1669: *
1670: * @deprecated as of JAI 1.1 in favor of <code>validateArguments("renderable", ...)</code>
1671: *
1672: * @see #validateArguments
1673: */
1674: public boolean validateRenderableArguments(ParameterBlock args,
1675: StringBuffer msg) {
1676: if (deprecated) {
1677: return (validateRenderableSources(args, msg) && validateParameters(
1678: args, msg));
1679: } else {
1680: return validateArguments("renderable", args, msg);
1681: }
1682: }
1683:
1684: /************************ Parameter Methods (deprecated) ***********/
1685:
1686: /**
1687: * The ParameterListDescriptor for the first supported mode. Used
1688: * by deprecated methods where modeName is not specified.
1689: */
1690: private ParameterListDescriptor getDefaultPLD() {
1691: return getParameterListDescriptor(getSupportedModes()[0]);
1692: }
1693:
1694: /**
1695: * Returns the number of parameters (not including sources)
1696: * required by this operation.
1697: *
1698: * @deprecated as of JAI 1.1 in favor of <code>
1699: * getParameterListDescriptor(modeName).getNumParameters()</code>
1700: * This will for the time being return the above value for
1701: * modeName = getSupportedModes()[0]
1702: *
1703: * @see ParameterListDescriptor#getNumParameters
1704: */
1705: public int getNumParameters() {
1706: return getDefaultPLD().getNumParameters();
1707: }
1708:
1709: /**
1710: * Returns the parameter class types of this operation.
1711: * If this operation has no parameters, this method returns
1712: * <code>null</code>.
1713: *
1714: * @deprecated as of JAI 1.1 in favor of <code>
1715: * getParameterListDescriptor(modeName).getParamClasses()</code>
1716: * This will for the time being return the above value for
1717: * modeName = getSupportedModes()[0]
1718: *
1719: * @see ParameterListDescriptor#getParamClasses
1720: */
1721: public Class[] getParamClasses() {
1722: return getDefaultPLD().getParamClasses();
1723: }
1724:
1725: /**
1726: * Returns the localized parameter names of this operation.
1727: * If this operation has no parameters, this method returns
1728: * <code>null</code>.
1729: *
1730: * @deprecated as of JAI 1.1 in favor of <code>
1731: * getParameterListDescriptor(modeName).getParamNames()</code>
1732: * This will for the time being return the above value for
1733: * modeName = getSupportedModes()[0]
1734: *
1735: * @see ParameterListDescriptor#getParamNames
1736: */
1737: public String[] getParamNames() {
1738: return getDefaultPLD().getParamNames();
1739: }
1740:
1741: /**
1742: * Returns the default values of the parameters for this operation.
1743: * If this operation has no parameters, this method returns
1744: * <code>null</code>. If a parameter does not have a default value,
1745: * the constant
1746: * <code>OperationDescriptor.NO_PARAMETER_DEFAULT</code> will be
1747: * returned. The <code>validateArguments()</code> and
1748: * <code>validateRenderableArguments</code> method will return
1749: * <code>false</code> if an input parameter without a default value
1750: * is supplied as <code>null</code>, or if an unspecified tailing
1751: * parameter does not have a default value.
1752: *
1753: * @deprecated as of JAI 1.1 in favor of <code>
1754: * getParameterListDescriptor(modeName).getParamDefaults()</code>
1755: * This will for the time being return the above value for
1756: * modeName = getSupportedModes()[0]
1757: *
1758: * @see ParameterListDescriptor#getParamDefaults
1759: */
1760: public Object[] getParamDefaults() {
1761: return getDefaultPLD().getParamDefaults();
1762: }
1763:
1764: /**
1765: * Returns the default value of specified parameter. The default
1766: * value may be <code>null</code>. If a parameter has no default
1767: * value, this method returns
1768: * <code>OperationDescriptor.NO_PARAMETER_DEFAULT</code>.
1769: *
1770: * @param index The index of the parameter whose default
1771: * value is queried.
1772: *
1773: * @throws IllegalArgumentException if this operation has no parameters.
1774: * @throws ArrayIndexOutOfBoundsException if there is no parameter
1775: * corresponding to the specified <code>index</code>.
1776: *
1777: * @deprecated as of JAI 1.1 in favor of <code>
1778: * getParameterListDescriptor(modeName).getParamDefaultValue(...)</code>
1779: * This will for the time being return the above value for
1780: * modeName = getSupportedModes()[0]
1781: *
1782: * @see ParameterListDescriptor#getParamDefaultValue
1783: */
1784: public Object getParamDefaultValue(int index) {
1785: return getDefaultPLD().getParamDefaultValue(paramNames[index]);
1786: }
1787:
1788: /**
1789: * Returns the minimum legal value of a specified numeric parameter
1790: * for this operation. If the specified parameter is non-numeric,
1791: * this method returns <code>null</code>.
1792: *
1793: * <p> The return value should be of the class types corresponding to
1794: * the parameter's primitive type, that is, <code>Byte</code> for a
1795: * <code>byte</code> parameter, <code>Integer</code> for an
1796: * <code>int</code> parameter, and so forth.
1797: *
1798: * <p> The default implementation returns the minimum value
1799: * in the parameter data type's full range.
1800: *
1801: * @param index The index of the parameter to be queried.
1802: *
1803: * @return A <code>Number</code> representing the minimum legal value,
1804: * or <code>null</code> if the specified parameter is not
1805: * numeric.
1806: *
1807: * @throws IllegalArgumentException if this operation has no parameters.
1808: * @throws ArrayIndexOutOfBoundsException if there is no parameter
1809: * corresponding to the specified <code>index</code>.
1810: *
1811: * @deprecated as of JAI 1.1 in favor of <code>
1812: * getParameterListDescriptor(modeName).getParamValueRange()</code>
1813: * This will for the time being use <code>getSupportedModes()[0]
1814: * </code> for modeName.
1815: *
1816: * <p>If the parameter is not a sub-class of the <code>Number</code>
1817: * class then this method returns null.
1818: *
1819: * <p>Else if the above getParamValueRange() returns a non-null
1820: * <code>Range</code> then it returns the <code>getMinValue()</code>
1821: * of that <code>Range</code>.
1822: *
1823: * <p>Else for <code>Float</code> and <code>Double</code> parameters
1824: * it returns the corresponding <code>-MAX_VALUE</code> and
1825: * <code>MIN_VALUE</code> for other <code>Number</code> classes.
1826: *
1827: * @see ParameterListDescriptor#getParamValueRange
1828: * @see ParameterListDescriptor#getEnumeratedParameterValues
1829: * @see ParameterListDescriptor#isParameterValueValid
1830: */
1831: public Number getParamMinValue(int index) {
1832: return null;
1833: }
1834:
1835: /**
1836: * Returns the maximum legal value of a specified numeric parameter
1837: * for this operation. If the specified parameter is non-numeric,
1838: * this method returns <code>null</code>.
1839: *
1840: * <p> The return value should be of the class type corresponding to
1841: * the parameter's primitive type, that is, <code>Byte</code> for a
1842: * <code>byte</code> parameter, <code>Integer</code> for an
1843: * <code>int</code> parameter, and so forth.
1844: *
1845: * <p> The default implementation returns the maximum value
1846: * in the parameter data type's full range.
1847: *
1848: * @param index The index of the parameter to be queried.
1849: *
1850: * @return A <code>Number</code> representing the maximum legal value,
1851: * or <code>null</code> if the specified parameter is not
1852: * numeric.
1853: *
1854: * @throws IllegalArgumentException if this operation has no parameters.
1855: * @throws ArrayIndexOutOfBoundsException if there is no parameter
1856: * corresponding to the specified <code>index</code>.
1857: *
1858: * @deprecated as of JAI 1.1 in favor of <code>
1859: * getParameterListDescriptor(modeName).getParamValueRange()</code>
1860: * This will for the time being use <code>getSupportedModes()[0]
1861: * </code> for modeName.
1862: *
1863: * <p>If the parameter is not a sub-class of the <code>Number</code>
1864: * class then this method returns null.
1865: *
1866: * <p>Else if the above getParamValueRange() returns a non-null
1867: * <code>Range</code> then it returns the <code>getMaxValue()</code>
1868: * of that <code>Range</code>.
1869: *
1870: * <p>Else returns the <code>MAX_VALUE</code> of the corresponding
1871: * <code>Number</code> class.
1872: *
1873: * @see ParameterListDescriptor#getParamValueRange
1874: * @see ParameterListDescriptor#getEnumeratedParameterValues
1875: * @see ParameterListDescriptor#isParameterValueValid
1876: */
1877: public Number getParamMaxValue(int index) {
1878: return null;
1879: }
1880:
1881: /**
1882: * Returns <code>true</code> if this operation supports the rendered
1883: * mode, and is capable of handling the given input source(s) for the
1884: * rendered mode. The default implementation validates the number of
1885: * sources, the class type of each source, and null sources. Subclasses
1886: * should override this implementation if their requirement on the
1887: * sources are different from the default.
1888: *
1889: * @throws IllegalArgumentException if <code>args</code> is <code>null</code>.
1890: * @throws IllegalArgumentException if <code>msg</code> is <code>null</code>
1891: * and the validation fails.
1892: *
1893: * @deprecated as of JAI 1.1 in favor of <code>
1894: * validateSources("rendered", ...)</code>
1895: *
1896: * @see #validateSources
1897: */
1898: protected boolean validateSources(ParameterBlock args,
1899: StringBuffer msg) {
1900: if (deprecated) {
1901: return (isRenderedSupported() && validateSources(
1902: getSourceClasses(), args, msg));
1903: } else {
1904: return validateSources("rendered", args, msg);
1905: }
1906: }
1907:
1908: /**
1909: * Returns <code>true</code> if this operation supports the
1910: * renderable mode, and is capable of handling the given input
1911: * source(s) for the renderable mode. The default
1912: * implementation validates the number of sources, the class type of
1913: * each source, and null sources. Subclasses should override this
1914: * implementation if their requirement on the sources are
1915: * different from the default.
1916: *
1917: * @throws IllegalArgumentException if <code>args</code> is <code>null</code>.
1918: * @throws IllegalArgumentException if <code>msg</code> is <code>null</code>
1919: * and the validation fails.
1920: *
1921: * @deprecated as of JAI 1.1 in favor of <code>
1922: * validateSources("renderable", ...)</code>
1923: *
1924: * @see #validateSources
1925: */
1926: protected boolean validateRenderableSources(ParameterBlock args,
1927: StringBuffer msg) {
1928: if (deprecated) {
1929: return (isRenderableSupported() && validateSources(
1930: getRenderableSourceClasses(), args, msg));
1931: } else {
1932: return validateSources("renderable", args, msg);
1933: }
1934: }
1935:
1936: /**
1937: * Returns <code>true</code> if this operation is capable of handling
1938: * the given input parameters. The default implementation validates the
1939: * number of parameters, the class type of each parameter, and null
1940: * parameters. For those non-null numeric parameters, it also checks to
1941: * see if the parameter value is within the minimum and maximum range.
1942: * Subclasses should override this implementation if their requirements
1943: * for the parameter objects are different from the default.
1944: *
1945: * <p> JAI allows unspecified tailing parameters if these parameters
1946: * have default values. This method automatically sets these unspecified
1947: * parameters to their default values. However, if a parameter, which
1948: * has a default value, is followed by one or more parameters that
1949: * have no default values, this parameter must be specified in the
1950: * <code>ParameterBlock</code>; else this method returns
1951: * <code>false</code>.
1952: *
1953: * <p> Note that <code>DeferredData</code> parameters will not be
1954: * recognized as valid unless the parameter is defined to have class
1955: * <code>DeferredData.class</code>.
1956: *
1957: * @throws IllegalArgumentException if <code>args</code> is <code>null</code>.
1958: * @throws IllegalArgumentException if <code>msg</code> is <code>null</code>
1959: * and the validation fails.
1960: *
1961: * @deprecated as of JAI 1.1 in favor of <code>
1962: * validateParameters(getSupportedModes()[0], ...)</code>
1963: *
1964: * @see #validateParameters
1965: */
1966: protected boolean validateParameters(ParameterBlock args,
1967: StringBuffer msg) {
1968: return validateParameters(getDefaultPLD(), args, msg);
1969: }
1970:
1971: /**
1972: * Returns the minimum number of parameters must be supplied in
1973: * the <code>ParameterBlock</code>.
1974: */
1975: private int getMinNumParameters(ParameterListDescriptor pld) {
1976: // The number of parameters this operation should have.
1977: int numParams = pld.getNumParameters();
1978:
1979: Object paramDefaults[] = pld.getParamDefaults();
1980:
1981: for (int i = numParams - 1; i >= 0; i--) {
1982: if (paramDefaults[i] == ParameterListDescriptor.NO_PARAMETER_DEFAULT) {
1983: break;
1984: } else {
1985: numParams--;
1986: }
1987: }
1988:
1989: return numParams;
1990: }
1991:
1992: private boolean validateSources(Class[] sources,
1993: ParameterBlock args, StringBuffer msg) {
1994:
1995: if ((args == null) || (msg == null))
1996: throw new IllegalArgumentException(JaiI18N
1997: .getString("Generic0"));
1998:
1999: // The number of sources this operation requires.
2000: int numSources = getNumSources();
2001:
2002: // Check for the correct number of sources.
2003: if (args.getNumSources() < numSources) {
2004: msg.append(JaiI18N
2005: .formatMsg("OperationDescriptorImpl6",
2006: new Object[] { getName(),
2007: new Integer(numSources) }));
2008: return false;
2009: }
2010:
2011: for (int i = 0; i < numSources; i++) {
2012: Object s = args.getSource(i);
2013:
2014: // Check for null source.
2015: if (s == null) {
2016: msg.append(JaiI18N.formatMsg(
2017: "OperationDescriptorImpl7",
2018: new Object[] { getName() }));
2019: return false;
2020: }
2021:
2022: // Check for the correct class of each supplied source.
2023: Class c = sources[i];
2024: if (!c.isInstance(s)) {
2025: msg.append(JaiI18N.formatMsg(
2026: "OperationDescriptorImpl8", new Object[] {
2027: getName(), new Integer(i),
2028: new String(c.toString()),
2029: new String(s.getClass().toString()) }));
2030: return false;
2031: }
2032: }
2033:
2034: return true;
2035: }
2036:
2037: private boolean validateParameters(ParameterListDescriptor pld,
2038: ParameterBlock args, StringBuffer msg) {
2039:
2040: if ((args == null) || (msg == null))
2041: throw new IllegalArgumentException(JaiI18N
2042: .getString("Generic0"));
2043:
2044: // The number of parameters this operation should have.
2045: int numParams = pld.getNumParameters();
2046:
2047: // The number of parameters supplied.
2048: int argNumParams = args.getNumParameters();
2049:
2050: Object paramDefaults[] = pld.getParamDefaults();
2051:
2052: // Check for the correct number of parameters.
2053: if (argNumParams < numParams) {
2054: // The minimum number of parameters this operation must have.
2055: if (argNumParams < getMinNumParameters(pld)) {
2056: msg.append(JaiI18N.formatMsg(
2057: "OperationDescriptorImpl9", new Object[] {
2058: getName(), new Integer(numParams) }));
2059:
2060: return false;
2061:
2062: } else { // use default values
2063: for (int i = argNumParams; i < numParams; i++) {
2064: args.add(paramDefaults[i]);
2065: }
2066: }
2067: }
2068:
2069: for (int i = 0; i < numParams; i++) {
2070: Object p = args.getObjectParameter(i);
2071:
2072: /* Check for null parameter. */
2073: if (p == null) {
2074: p = paramDefaults[i]; // get the default parameter value
2075:
2076: if (p == OperationDescriptor.NO_PARAMETER_DEFAULT) {
2077: msg.append(JaiI18N.formatMsg(
2078: "OperationDescriptorImpl11", new Object[] {
2079: getName(), new Integer(i) }));
2080: return false;
2081:
2082: } else {
2083: args.set(p, i); // replace null parameter with default
2084: }
2085: }
2086:
2087: // Now check if the parameter value is valid
2088: try {
2089: if (!pld.isParameterValueValid(paramNames[i], p)) {
2090: msg.append(JaiI18N
2091: .formatMsg("OperationDescriptorImpl10",
2092: new Object[] { getName(),
2093: pld.getParamNames()[i] }));
2094: return false;
2095: }
2096: } catch (IllegalArgumentException e) {
2097: msg.append(getName() + " - " + e.getLocalizedMessage());
2098: return false;
2099: }
2100: }
2101:
2102: return true;
2103: }
2104:
2105: /**
2106: * Make sure that <code>modeName</code> is not <code>null</code> and
2107: * is one of the supported modes.
2108: */
2109: private void checkModeName(String modeName) {
2110:
2111: if (modeName == null)
2112: throw new IllegalArgumentException(JaiI18N
2113: .getString("OperationDescriptorImpl12"));
2114:
2115: if (modeIndices.contains(modeName) == false) {
2116: throw new IllegalArgumentException(JaiI18N.formatMsg(
2117: "OperationDescriptorImpl13", new Object[] {
2118: getName(), modeName }));
2119: }
2120:
2121: }
2122:
2123: }
|