KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > macro > CopyRouteRedirector


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/CopyRouteRedirector.java,v 1.5 2004/07/28 09:35:28 ib Exp $
3  * $Revision: 1.5 $
4  * $Date: 2004/07/28 09:35:28 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23 package org.apache.slide.macro;
24
25 // import list
26
import org.apache.slide.common.SlideException;
27
28 /**
29  * A CopyRouteRedirector may be passed to the Macro helper in order to have more
30  * control on the <code>copy</code> operation. A CopyRouteRedirector
31  * may either return the given CopyRoute or any (redirected) CopyRoute.
32  *
33  * @version $Revision: 1.5 $
34  *
35  **/

36 public interface CopyRouteRedirector {
37     
38     
39     /**
40      * A CopyRoute defines the source and the destination URI of a
41      * <code>copy</code> operation.
42      *
43      * @version $Revision: 1.5 $
44      *
45      **/

46     public static class CopyRoute {
47         
48         /**
49          * Message of the IllegalArgumentException that is thrown by constructor
50          * if parameter <code>sourceUri</code> is <code>null</code>.
51          */

52         public static String JavaDoc SOURCE_MUST_NOT_BE_NULL = "Parameter 'sourceUri' must not be null";
53         
54         /**
55          * Message of the IllegalArgumentException that is thrown by constructor
56          * if parameter <code>destinationUri</code> is <code>null</code>.
57          */

58         public static String JavaDoc DESTINATION_MUST_NOT_BE_NULL = "Parameter 'destinationUri' must not be null";
59         
60         
61         /**
62          * The source Uri.
63          */

64         protected String JavaDoc sourceUri = null;
65         
66         /**
67          * The destination Uri.
68          */

69         protected String JavaDoc destinationUri = null;
70         
71         /**
72          * Creates a CopyRoute from the given URIs.
73          *
74          * @param sourceUri the Uri of the source.
75          * Must not be <code>null</code>.
76          * @param destinationUri the Uri of the destination.
77          * Must not be <code>null</code>.
78          *
79          * @throws IllegalArgumentException if one of the parameters is
80          * <code>null</code>.
81          */

82         public CopyRoute(String JavaDoc sourceUri, String JavaDoc destinationUri) throws IllegalArgumentException JavaDoc {
83             
84             if (sourceUri == null) {
85                 throw new IllegalArgumentException JavaDoc(SOURCE_MUST_NOT_BE_NULL);
86             }
87             if (destinationUri == null) {
88                 throw new IllegalArgumentException JavaDoc(DESTINATION_MUST_NOT_BE_NULL);
89             }
90             this.sourceUri = sourceUri;
91             this.destinationUri = destinationUri;
92         }
93         
94         /**
95          * Returns the source Uri.
96          *
97          * @return the source Uri.
98          */

99         public String JavaDoc getSourceUri() {
100             return sourceUri;
101         }
102         
103         /**
104          * Returns the destination Uri.
105          *
106          * @return the destination Uri.
107          */

108         public String JavaDoc getDestinationUri() {
109             return destinationUri;
110         }
111         
112         /**
113          * Returns a String representation of the CopyRoute.
114          *
115          * @return a String representation of the CopyRoute.
116          */

117         public String JavaDoc toString() {
118             return "CopyRoute["+getSourceUri()+", "+getDestinationUri()+"]";
119         }
120         
121         /**
122          * Returns <code>true</code> if the other Object is a CopyRoute
123          * and both routes source and destination URIs are equal.
124          *
125          * @param other the Object to test for equality.
126          *
127          * @return <code>true</code> if the other Object is a CopyRoute
128          * and both routes source and destination URIs are equal.
129          */

130         public boolean equals(Object JavaDoc other) {
131             boolean isEqual = false;
132             if (other instanceof CopyRoute) {
133                 isEqual =
134                     ((CopyRoute)other).getSourceUri().equals(getSourceUri()) &&
135                     ((CopyRoute)other).getDestinationUri().equals(getDestinationUri());
136             }
137             return isEqual;
138         }
139         
140         /**
141          * Returns the hash code of this instance.
142          * Due to specification equal objects must have the same hash code.
143          *
144          * @return the hash code of this instance.
145          */

146         public int hashCode() {
147             return getSourceUri().hashCode() + 13*getDestinationUri().hashCode();
148         }
149     }
150     
151     
152     
153     /**
154      * Returns the (redirected) CopyRoute to use. Must not be <code>null</code>.
155      *
156      * @param copyRoute the original CopyRoute.
157      *
158      * @return the (redirected) CopyRoute to use.
159      *
160      * @throws SlideException this Exception will be passed to the caller
161      * of the Macro helper (contained in the
162      * MacroCopyException).
163      */

164     public CopyRoute getRedirectedCopyRoute(CopyRoute copyRoute) throws SlideException;
165     
166 }
167
168
Popular Tags