001: /*
002: * $RCSfile: RCIFRegistry.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:48 $
010: * $State: Exp $
011: */
012: package javax.media.jai.registry;
013:
014: import java.awt.image.renderable.ParameterBlock;
015: import java.util.Vector;
016: import javax.media.jai.CollectionImage;
017: import javax.media.jai.CollectionOp;
018: import javax.media.jai.JAI;
019: import javax.media.jai.OperationNode;
020: import javax.media.jai.OperationRegistry;
021: import javax.media.jai.PropertySource;
022: import javax.media.jai.RenderableCollectionImageFactory;
023:
024: /**
025: * Utility class to provide type-safe interaction
026: * with the <code>OperationRegistry</code> for
027: * <code>RenderableCollectionImageFactory</code> objects.
028: *
029: * If the <code>OperationRegistry</code> is <code>null</code>, then
030: * <code>JAI.getDefaultInstance().getOperationRegistry()</code> will be used.
031: *
032: * @see CollectionImage
033: * @since JAI 1.1
034: */
035: public final class RCIFRegistry {
036:
037: private static final String MODE_NAME = RenderableCollectionRegistryMode.MODE_NAME;
038:
039: /**
040: * Register a RCIF with a particular operation against a specified
041: * mode.
042: *
043: * @param registry the <code>OperationRegistry</code> to register with.
044: * if this is <code>null</code>, then <code>
045: * JAI.getDefaultInstance().getOperationRegistry()</code>
046: * will be used.
047: * @param operationName the operation name as a <code>String</code>
048: * @param rcif the <code>RenderableCollectionImageFactory</code> to be registered
049: *
050: * @throws IllegalArgumentException if operationName or rcif is
051: * <code>null</code>
052: * @throws IllegalArgumentException if there is no <code>
053: * OperationDescriptor</code> registered against
054: * the <code>operationName</code>
055: */
056: public static void register(OperationRegistry registry,
057: String operationName, RenderableCollectionImageFactory rcif) {
058:
059: registry = (registry != null) ? registry : JAI
060: .getDefaultInstance().getOperationRegistry();
061:
062: registry.registerFactory(MODE_NAME, operationName, null, rcif);
063: }
064:
065: /**
066: * Unregister a RCIF previously registered with a operation against
067: * the specified mode.
068: *
069: * @param registry the <code>OperationRegistry</code> to unregister from.
070: * if this is <code>null</code>, then <code>
071: * JAI.getDefaultInstance().getOperationRegistry()</code>
072: * will be used.
073: * @param operationName the operation name as a <code>String</code>
074: * @param rcif the <code>RenderableCollectionImageFactory</code> to be unregistered
075: *
076: * @throws IllegalArgumentException if operationName or rcif is
077: * <code>null</code>
078: * @throws IllegalArgumentException if there is no <code>
079: * OperationDescriptor</code> registered against
080: * the <code>operationName</code>
081: * @throws IllegalArgumentException if the rcif was not previously
082: * registered against operationName
083: */
084: public static void unregister(OperationRegistry registry,
085: String operationName, RenderableCollectionImageFactory rcif) {
086:
087: registry = (registry != null) ? registry : JAI
088: .getDefaultInstance().getOperationRegistry();
089:
090: registry
091: .unregisterFactory(MODE_NAME, operationName, null, rcif);
092: }
093:
094: /**
095: * Returns the <code>RenderableCollectionImageFactory</code> object
096: * registered against the operation name.
097: *
098: * @param registry the <code>OperationRegistry</code> to use.
099: * if this is <code>null</code>, then <code>
100: * JAI.getDefaultInstance().getOperationRegistry()</code>
101: * will be used.
102: * @param operationName the operation name as a <code>String</code>
103: *
104: * @return a registered <code>RenderableCollectionImageFactory</code> object
105: *
106: * @throws IllegalArgumentException if operationName is <code>null</code>
107: * @throws IllegalArgumentException if there is no <code>
108: * OperationDescriptor</code> registered against
109: * the <code>operationName</code>
110: */
111: public static RenderableCollectionImageFactory get(
112: OperationRegistry registry, String operationName) {
113:
114: registry = (registry != null) ? registry : JAI
115: .getDefaultInstance().getOperationRegistry();
116:
117: return (RenderableCollectionImageFactory) registry.getFactory(
118: MODE_NAME, operationName);
119: }
120:
121: /**
122: * Creates a renderable <code>CollectionImage</code> given
123: * a ParameterBlock containing the operation's sources and
124: * parameters. The registry is used to determine the RCIF to be
125: * used to instantiate the operation.
126: *
127: * @param registry the <code>OperationRegistry</code> to use.
128: * if this is <code>null</code>, then <code>
129: * JAI.getDefaultInstance().getOperationRegistry()</code>
130: * will be used.
131: * @param operationName the operation name as a <code>String</code>
132: * @param paramBlock the operation's ParameterBlock.
133: *
134: * @throws IllegalArgumentException if operationName is <code>null</code>
135: * @throws IllegalArgumentException if there is no <code>
136: * OperationDescriptor</code> registered against
137: * the <code>operationName</code>
138: */
139: public static CollectionImage create(OperationRegistry registry,
140: String operationName, ParameterBlock paramBlock) {
141:
142: registry = (registry != null) ? registry : JAI
143: .getDefaultInstance().getOperationRegistry();
144:
145: Object args[] = { paramBlock };
146:
147: return (CollectionImage) registry.invokeFactory(MODE_NAME,
148: operationName, args);
149: }
150:
151: /**
152: * Constructs and returns a <code>PropertySource</code> suitable for
153: * use by a given <code>CollectionOp</code>. The
154: * <code>PropertySource</code> includes properties copied from prior
155: * nodes as well as those generated at the node itself. Additionally,
156: * property suppression is taken into account. The actual implementation
157: * of <code>getPropertySource()</code> may make use of deferred
158: * execution and caching.
159: *
160: * @param op the <code>CollectionOp</code> requesting its
161: * <code>PropertySource</code>.
162: *
163: * @throws IllegalArgumentException if <code>op</code> is <code>null</code>
164: * @throws IllegalArgumentException if <code>op.isRenderable()</code>
165: * returns <code>false</code>
166: */
167: public static PropertySource getPropertySource(CollectionOp op) {
168:
169: if (op == null)
170: throw new IllegalArgumentException("op - "
171: + JaiI18N.getString("Generic0"));
172:
173: if (!op.isRenderable())
174: throw new IllegalArgumentException("op - "
175: + JaiI18N.getString("CIFRegistry1"));
176:
177: return op.getRegistry().getPropertySource((OperationNode) op);
178: }
179: }
|