001: /*
002: * $RCSfile: RemoteCRIFRegistry.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: */package javax.media.jai.registry;
012:
013: import java.awt.image.renderable.ParameterBlock;
014: import java.awt.image.renderable.RenderContext;
015: import javax.media.jai.OperationRegistry;
016: import javax.media.jai.JAI;
017: import javax.media.jai.remote.RemoteCRIF;
018: import javax.media.jai.remote.RemoteRenderedImage;
019:
020: /**
021: * Utility class to provide type-safe interaction with the
022: * <code>OperationRegistry</code> for <code>RemoteCRIF</code> objects.
023: *
024: * If the <code>OperationRegistry</code> specified as an argument to the
025: * methods in this class is null, then <code>JAI.getOperationRegistry()</code>
026: * will be used.
027: *
028: * @since JAI 1.1
029: */
030: public final class RemoteCRIFRegistry {
031:
032: private static final String MODE_NAME = RemoteRenderableRegistryMode.MODE_NAME;
033:
034: /**
035: * Registers the given <code>RemoteCRIF</code> with the given
036: * <code>OperationRegistry</code> under the given protocolName
037: *
038: * @param registry The <code>OperationRegistry</code> to register the
039: * <code>RemoteCRIF</code> with. If this is
040: * <code>null</code>, then <code>
041: * JAI.getDefaultInstance().getOperationRegistry()</code>
042: * will be used.
043: * @param protocolName The protocolName to register the
044: * <code>RemoteCRIF</code> under.
045: * @param rcrif The <code>RemoteCRIF</code> to register.
046: *
047: * @throws IllegalArgumentException if protocolName is null.
048: * @throws IllegalArgumentException if rcrif is null.
049: * @throws IllegalArgumentException if there is no
050: * <code>RemoteDescriptor</code> registered against the
051: * given protocolName.
052: */
053: public static void register(OperationRegistry registry,
054: String protocolName, RemoteCRIF rcrif) {
055:
056: registry = (registry != null) ? registry : JAI
057: .getDefaultInstance().getOperationRegistry();
058:
059: registry.registerFactory(MODE_NAME, protocolName, null, rcrif);
060: }
061:
062: /**
063: * Unregisters the given <code>RemoteCRIF</code> previously registered
064: * under the given protocolName in the given
065: * <code>OperationRegistry</code>.
066: *
067: * @param registry The <code>OperationRegistry</code> to unregister the
068: * <code>RemoteCRIF</code> from. If this is
069: * <code>null</code>, then <code>
070: * JAI.getDefaultInstance().getOperationRegistry()</code>
071: * will be used.
072: * @param protocolName The protocolName to unregister the
073: * <code>RemoteCRIF</code> from under.
074: * @param rcrif The <code>RemoteCRIF</code> to unregister.
075: *
076: * @throws IllegalArgumentException if protocolName is null.
077: * @throws IllegalArgumentException if rcrif is null.
078: * @throws IllegalArgumentException if there is no
079: * <code>RemoteDescriptor</code> registered against the
080: * given protocolName.
081: * @throws IllegalArgumentException if the rcrif was not previously
082: * registered against protocolName.
083: */
084: public static void unregister(OperationRegistry registry,
085: String protocolName, RemoteCRIF rcrif) {
086:
087: registry = (registry != null) ? registry : JAI
088: .getDefaultInstance().getOperationRegistry();
089:
090: registry
091: .unregisterFactory(MODE_NAME, protocolName, null, rcrif);
092: }
093:
094: /**
095: * Returns the <code>RemoteCRIF</code> registered under the given
096: * protocol name in the specified <code>OperationRegistry</code>.
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 protocolName The name of the remote imaging protocol.
103: *
104: * @throws IllegalArgumentException if protocolName is null.
105: * @throws IllegalArgumentException if there is no
106: * <code>RemoteDescriptor</code> registered against the given
107: * <code>protocolName</code>.
108: */
109: public static RemoteCRIF get(OperationRegistry registry,
110: String protocolName) {
111:
112: registry = (registry != null) ? registry : JAI
113: .getDefaultInstance().getOperationRegistry();
114:
115: return (RemoteCRIF) registry
116: .getFactory(MODE_NAME, protocolName);
117: }
118:
119: /**
120: * Creates a rendering remotely, given the serverName, protocolName,
121: * name of the operation to be performed, a <code>RenderContext</code> and
122: * a <code>ParameterBlock</code> containing the operation's sources
123: * and parameters. The registry is used to determine the
124: * <code>RemoteCRIF</code> to be used to instantiate the operation.
125: *
126: * <p>Since this class is a simple type-safe wrapper around
127: * <code>OperationRegistry</code>'s type-unsafe methods, no additional
128: * argument validation is performed in this method. Thus errors/exceptions
129: * may occur if incorrect values are provided for the input arguments.
130: * If argument validation is desired as part of creating a rendering,
131: * <code>RemoteJAI.createRenderable()</code> may be used instead to
132: * create a <code>RemoteRenderableOp</code> which can then be asked for
133: * a rendering.
134: *
135: * <p>Exceptions thrown by the <code>RemoteRIF</code>s used to create
136: * the rendering will be caught by this method and will not be propagated.
137: *
138: * @param registry The <code>OperationRegistry</code> to use to
139: * create the rendering. If this is
140: * <code>null</code>, then <code>
141: * JAI.getDefaultInstance().getOperationRegistry()</code>
142: * will be used.
143: * @param protocolName The protocol to be used for remote imaging.
144: * @param serverName The name of the server.
145: * @param operationName The name of the operation to be performed remotely.
146: * @param renderContext A <code>RenderContext</code> specifying the
147: * context in which the rendering should be requested.
148: * @param paramBlock The <code>ParameterBlock</code> specifying the
149: * sources and parameters required for the operation.
150: *
151: * @throws IllegalArgumentException if protocolName is null.
152: * @throws IllegalArgumentException if there is no
153: * <code>RemoteDescriptor</code> registered against the given
154: * protocolName.
155: */
156: public static RemoteRenderedImage create(
157: OperationRegistry registry, String protocolName,
158: String serverName, String operationName,
159: RenderContext renderContext, ParameterBlock paramBlock) {
160:
161: registry = (registry != null) ? registry : JAI
162: .getDefaultInstance().getOperationRegistry();
163:
164: Object args[] = { serverName, operationName, renderContext,
165: paramBlock };
166:
167: return (RemoteRenderedImage) registry.invokeFactory(MODE_NAME,
168: protocolName, args);
169: }
170:
171: }
|