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