1 /*
2  * $RCSfile: RemoteRIFRegistry.java,v $
3  *
4  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
5  *
6  * Use is subject to license terms.
7  *
8  * $Revision: 1.1 $
9  * $Date: 2005/02/11 04:57:48 $
10  * $State: Exp $
11  */package com.lightcrafts.mediax.jai.registry;
12 
13 import java.awt.RenderingHints;
14 import java.awt.image.renderable.ParameterBlock;
15 import com.lightcrafts.mediax.jai.OperationRegistry;
16 import com.lightcrafts.mediax.jai.JAI;
17 import com.lightcrafts.mediax.jai.remote.RemoteRIF;
18 import com.lightcrafts.mediax.jai.remote.RemoteRenderedImage;
19 
20 /**
21  * Utility class to provide type-safe interaction with the
22  * <code>OperationRegistry</code> for <code>RemoteRIF</code> objects.
23  *
24  * <p> If the <code>OperationRegistry</code> specified as an argument to
25  * the methods in this class is null, then
26  * <code>JAI.getOperationRegistry()</code> will be used.
27  *
28  * @since JAI 1.1
29  */
30 public final class RemoteRIFRegistry  {
31 
32     private static final String MODE_NAME = RemoteRenderedRegistryMode.MODE_NAME;
33 
34     /**
35      * Registers the given <code>RemoteRIF</code> with the given
36      * <code>OperationRegistry</code> under the given protocolName.
37      *
38      * @param registry     The <code>OperationRegistry</code> to register
39      *                     the <code>RemoteRIF</code> with. If this is
40      *                     <code>null</code>, then <code>
41      *                     JAI.getDefaultInstance().getOperationRegistry()</code>
42      *                     will be used.
43      * @param protocolName The protocolName to register the
44      *                     <code>RemoteRIF</code> under.
45      * @param rrif         The <code>RemoteRIF</code> to register.
46      *
47      * @throws IllegalArgumentException if protocolName is null.
48      * @throws IllegalArgumentException if rrif is null.
49      * @throws IllegalArgumentException if there is no
50      * <code>RemoteDescriptor</code> registered against the
51      * given protocolName.
52      */
register(OperationRegistry registry, String protocolName, RemoteRIF rrif)53     public static void register(OperationRegistry registry,
54                                 String protocolName,
55                                 RemoteRIF rrif) {
56 
57         registry = (registry != null) ? registry :
58 	    JAI.getDefaultInstance().getOperationRegistry();
59 
60 	registry.registerFactory(MODE_NAME, protocolName, null, rrif);
61     }
62 
63     /**
64      * Unregisters the given <code>RemoteRIF</code> previously registered
65      * under the given protocolName in the given
66      * <code>OperationRegistry</code>.
67      *
68      * @param registry     The <code>OperationRegistry</code> to unregister
69      *                     the <code>RemoteRIF</code> from. If this is
70      *                     <code>null</code>, then <code>
71      *                     JAI.getDefaultInstance().getOperationRegistry()</code>
72      *                     will be used.
73      * @param protocolName The protocolName to unregister the
74      *                     <code>RemoteRIF</code> from under.
75      * @param rrif         The <code>RemoteRIF</code> to unregister.
76      *
77      * @throws IllegalArgumentException if protocolName is null.
78      * @throws IllegalArgumentException if rrif is null.
79      * @throws IllegalArgumentException if there is no
80      * <code>RemoteDescriptor</code> registered against the
81      * given protocolName.
82      * @throws IllegalArgumentException if the rrif was not previously
83      * registered against protocolName.
84      */
unregister(OperationRegistry registry, String protocolName, RemoteRIF rrif)85     public static void unregister(OperationRegistry registry,
86                                   String protocolName,
87                                   RemoteRIF rrif) {
88 
89         registry = (registry != null) ? registry :
90 	    JAI.getDefaultInstance().getOperationRegistry();
91 
92 	registry.unregisterFactory(MODE_NAME, protocolName, null, rrif);
93     }
94 
95     /**
96      * Returns the <code>RemoteRIF</code> registered under the given
97      * protocol name in the specified <code>OperationRegistry</code>.
98      *
99      * @param registry     The <code>OperationRegistry</code> to use.
100      *                     If this is <code>null</code>, then <code>
101      *                     JAI.getDefaultInstance().getOperationRegistry()</code>
102      *                     will be used.
103      * @param protocolName The name of the remote imaging protocol.
104      *
105      * @throws IllegalArgumentException if protocolName is null.
106      * @throws IllegalArgumentException if there is no
107      * <code>RemoteDescriptor</code> registered against the given
108      * <code>protocolName</code>.
109      */
get(OperationRegistry registry, String protocolName)110     public static RemoteRIF get(OperationRegistry registry,
111 				String protocolName) {
112 
113 	registry = (registry != null) ? registry :
114 	    JAI.getDefaultInstance().getOperationRegistry();
115 
116 	return (RemoteRIF)registry.getFactory(MODE_NAME, protocolName);
117     }
118 
119     /**
120      * Constructs a <code>RemoteRenderedImage</code> representing the
121      * results of remotely applying the given operation to the source(s),
122      * and parameters specified in the specified <code>ParameterBlock</code>,
123      * using the specified rendering hints. The registry
124      * is used to determine the <code>RemoteRIF</code> to be used to
125      * instantiate the operation.
126      *
127      * <p>Since this class is a simple type-safe wrapper around
128      * <code>OperationRegistry</code>'s type-unsafe methods, no additional
129      * argument validation is performed in this method. Thus errors/exceptions
130      * may occur if incorrect values are provided for the input arguments.
131      * If argument validation is desired as part of creating a rendering,
132      * <code>RemoteJAI.create()</code> may be used instead.
133      *
134      * <p>Exceptions thrown by the <code>RemoteRIF</code>s used to create
135      * the rendering will be caught by this method and will not be propagated.
136      *
137      * @param registry      The <code>OperationRegistry</code> to use to
138      *                      create the rendering. If this is
139      *                      <code>null</code>, then <code>
140      *                     JAI.getDefaultInstance().getOperationRegistry()</code>
141      *                      will be used.
142      * @param protocolName  The protocol to be used for remote imaging.
143      * @param serverName    The name of the server.
144      * @param operationName The name of the operation to be performed remotely.
145      * @param paramBlock    The <code>ParameterBlock</code> specifying the
146      *                      sources and parameters required for the operation.
147      * @param renderHints   A <code>RenderingHints</code> object containing
148      *                      rendering hints.
149      *
150      * @throws IllegalArgumentException if protocolName is null.
151      * @throws IllegalArgumentException if there is no
152      * <code>RemoteDescriptor</code> registered against the given
153      * protocolName.
154      */
create(OperationRegistry registry, String protocolName, String serverName, String operationName, ParameterBlock paramBlock, RenderingHints renderHints)155     public static RemoteRenderedImage create(OperationRegistry registry,
156 					     String protocolName,
157 					     String serverName,
158 					     String operationName,
159 					     ParameterBlock paramBlock,
160 					     RenderingHints renderHints) {
161 
162 	registry = (registry != null) ? registry :
163 	    JAI.getDefaultInstance().getOperationRegistry();
164 
165 	Object args[] = { serverName, operationName, paramBlock, renderHints };
166 
167 	return (RemoteRenderedImage)
168 		registry.invokeFactory(MODE_NAME, protocolName, args);
169     }
170 }
171