01: /*
02: * $RCSfile: PropertyGeneratorFromSource.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:57:17 $
10: * $State: Exp $
11: */
12: package javax.media.jai;
13:
14: import java.util.Vector;
15: import com.sun.media.jai.util.PropertyGeneratorImpl;
16:
17: /**
18: * A class that implements the <code>PropertyGenerator</code> interface.
19: * This class is used when a property is to be calculated from a particular
20: * source. All properties except the named one are ignored. If the given
21: * source index out of range the property will be undefined, in particular
22: * no exception will be thrown.
23: *
24: */
25: class PropertyGeneratorFromSource extends PropertyGeneratorImpl {
26:
27: int sourceIndex;
28: String propertyName;
29:
30: PropertyGeneratorFromSource(int sourceIndex, String propertyName) {
31: super (new String[] { propertyName },
32: new Class[] { Object.class }, // could be anything
33: new Class[] { OperationNode.class });
34:
35: if (propertyName == null) {
36: throw new IllegalArgumentException(JaiI18N
37: .getString("Generic0"));
38: }
39:
40: this .sourceIndex = sourceIndex;
41: this .propertyName = propertyName;
42: }
43:
44: public Object getProperty(String name, Object opNode) {
45: if (name == null || opNode == null) {
46: throw new IllegalArgumentException(JaiI18N
47: .getString("Generic0"));
48: }
49:
50: if (sourceIndex >= 0 && opNode instanceof OperationNode
51: && propertyName.equalsIgnoreCase(name)) {
52: OperationNode op = (OperationNode) opNode;
53: Vector sources = op.getParameterBlock().getSources();
54: if (sources != null && sourceIndex < sources.size()) {
55: Object src = sources.elementAt(sourceIndex);
56: if (src instanceof PropertySource) {
57: return ((PropertySource) src).getProperty(name);
58: }
59: }
60: }
61:
62: return java.awt.Image.UndefinedProperty;
63: }
64: }
|