KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > jmx > remote > server > ServerVersionMatcher


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /* VersionMatcher.java
25  * $Id: ServerVersionMatcher.java,v 1.3 2005/12/25 04:26:36 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 04:26:36 $
28  * Indentation Information:
29  * 0. Please (try to) preserve these settings.
30  * 1. Tabs are preferred over spaces.
31  * 2. In vi/vim -
32  * :set tabstop=4 :set shiftwidth=4 :set softtabstop=4
33  * 3. In S1 Studio -
34  * 1. Tools->Options->Editor Settings->Java Editor->Tab Size = 4
35  * 2. Tools->Options->Indentation Engines->Java Indentation Engine->Expand Tabs to Spaces = False.
36  * 3. Tools->Options->Indentation Engines->Java Indentation Engine->Number of Spaces per Tab = 4.
37  */

38
39 package com.sun.enterprise.admin.jmx.remote.server;
40
41 import java.util.logging.Logger JavaDoc;
42 import com.sun.enterprise.admin.jmx.remote.protocol.Version;
43 /**
44  *
45  * @author <a HREF="mailto:Kedar.Mhaswade@sun.com">Kedar Mhaswade</a>
46  * @since S1AS8.0
47  * @version $Revision: 1.3 $
48  */

49 public class ServerVersionMatcher {
50     
51     private static final ServerVersionMatcher matcher = new ServerVersionMatcher();
52     private static final Logger JavaDoc logger = Logger.getLogger("com.sun.enterprise.admin.jmx.remote.finer.logger");
53     private ServerVersionMatcher() {
54     }
55     
56     public static ServerVersionMatcher getMatcher() {
57         return ( matcher );
58     }
59     /**
60      * Returns true if and only if the client version and server version are
61      * compatible. The server version matches with client version if and only if
62      * <ul>
63      * <li> Client Major Version is <= Server Major Version </li>
64      * <li> Client Minor Version is <= Server Minor Version </li>
65      * <li> Upgrade Data is compatible in both the versions </li>
66      * </ul>
67      */

68     public boolean match(Version client, Version server) {
69         return (majorCompatible(client, server) &&
70                 minorCompatible(client, server) &&
71                 upgradeCompatible(client, server) );
72     }
73     
74     boolean majorCompatible(Version c, Version s) {
75         //client version can at most equal server version
76
boolean compatible = false;
77         final int cmv = c.getMajorVersion();
78         final int smv = s.getMajorVersion();
79         if (cmv < smv) {
80             logger.finer("S1AS JSR 160 - Using Backword compatibility, as client version: " +
81             cmv + " is smaller than server version: " + smv);
82             logger.finer("It is better to upgrade the client software");
83             compatible = true;
84         }
85         else if (cmv == smv) {
86             compatible = true;
87         }
88         else {
89             logger.finer("S1AS JSR 160 - Version Compatibility failed, as client version: " +
90             cmv + " is higher than server version: " + smv);
91             logger.finer("Server software has to be upgraded to atleast major version: " + cmv);
92             compatible = false;
93         }
94         return ( compatible );
95     }
96
97     boolean minorCompatible(Version c, Version s) {
98         //client version can at most equal server version
99
boolean compatible = false;
100         final int cmv = c.getMinorVersion();
101         final int smv = s.getMinorVersion();
102         if (cmv < smv) {
103             logger.finer("S1AS JSR 160 - Using Backword compatibility, as client version: " +
104             cmv + " is smaller than server version: " + smv);
105             logger.finer("It is better to upgrade the client software");
106             compatible = true;
107         }
108         else if (cmv == smv) {
109             compatible = true;
110         }
111         else {
112             logger.finer("S1AS JSR 160 - Version Compatibility failed, as client version: " +
113             cmv + " is higher than server version: " + smv);
114             logger.finer("Server software has to be upgraded to atleast major version: " + cmv);
115             compatible = false;
116         }
117         return ( compatible );
118     }
119     
120     boolean upgradeCompatible(Version c, Version s) {
121         final String JavaDoc[] cud = c.getUpgradeData();
122         final String JavaDoc[] sud = s.getUpgradeData();
123         boolean uc = true;
124         uc = uc && (cud.length == sud.length); //lengths must be the same
125
if (uc) {
126             for (int i = 0 ; i < cud.length ; i++) {
127                 if (cud[i] != null && sud[i] != null) {
128                     uc = uc && cud[i].equals(sud[i]);
129                     if (!uc) {
130                         break;
131                     }
132                 }
133             }
134         }
135         return ( uc );
136     }
137 }
138
Popular Tags