KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ungoverned > moduleloader > search > compatibility > ExactCompatibilityPolicy


1 /*
2  * ModuleLoader - A generic, policy-driven class loader.
3  * Copyright (c) 2004, Richard S. Hall
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of the ungoverned.org nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Contact: Richard S. Hall (heavy@ungoverned.org)
33  * Contributor(s):
34  *
35 **/

36 package org.ungoverned.moduleloader.search.compatibility;
37
38 import org.ungoverned.moduleloader.search.CompatibilityPolicy;
39
40 /**
41  * This class implements a simple version numbering compatibility policy for the
42  * <tt>ImportSearchPolicy</tt> where only exact version numbers are considered
43  * to be compatible. This policy simply returns the result of
44  * "<tt>leftId.equals(rightId) && leftVersion.equals(rightVersion)</tt>". Any
45  * calls to the <tt>compare()</tt> method result in an exception since this
46  * policy has no basis for comparing identifiers and versions.
47  * @see org.ungoverned.moduleloader.search.CompatibilityPolicy
48  * @see org.ungoverned.moduleloader.search.ImportSearchPolicy
49 **/

50 public class ExactCompatibilityPolicy implements CompatibilityPolicy
51 {
52     /**
53      * Compares two versioned identifiers, but since this policy has
54      * no understanding of how to compare identifiers, it always throws
55      * an <tt>IllegalArgumentException</tt>.
56      * @param leftId the identifier to test for compatibility.
57      * @param leftVersion the version number to test for compatibility.
58      * @param rightId the identifier used as the compatibility base line.
59      * @param rightVersion the version used as the compatibility base line.
60      * @return <tt>0</tt> if the identifiers are equal, <tt>-1</tt> if the
61      * left identifier is less then the right identifier, and <tt>1</tt>
62      * if the left identifier is greater than the right identifier.
63      * @throws java.lang.IllegalArgumentException if the two identifiers
64      * are not comparable, i.e., they refer to completely different
65      * entities.
66     **/

67     public int compare(
68         Object JavaDoc leftId, Object JavaDoc leftVersion,
69         Object JavaDoc rightId, Object JavaDoc rightVersion)
70     {
71         throw new IllegalArgumentException JavaDoc("Identifiers are not comparable.");
72     }
73
74     /**
75      * Returns whether the first import/export target is compatible
76      * with the second. This method simply uses the "<tt>equals()</tt>" method
77      * to test both the identifier and the verison number.
78      * @param leftId the identifier to test for compatibility.
79      * @param leftVersion the version number to test for compatibility.
80      * @param rightId the identifier used as the compatibility base line.
81      * @param rightVersion the version used as the compatibility base line.
82      * @return <tt>true</tt> if the left version number object is compatible
83      * with the right version number object, otherwise <tt>false</tt>.
84     **/

85     public boolean isCompatible(
86         Object JavaDoc leftId, Object JavaDoc leftVersion,
87         Object JavaDoc rightId, Object JavaDoc rightVersion)
88     {
89         return leftId.equals(rightId) && leftVersion.equals(rightVersion);
90     }
91 }
Popular Tags