1 23 24 38 39 package com.sun.enterprise.admin.jmx.remote.server; 40 41 import java.util.logging.Logger ; 42 import com.sun.enterprise.admin.jmx.remote.protocol.Version; 43 49 public class ServerVersionMatcher { 50 51 private static final ServerVersionMatcher matcher = new ServerVersionMatcher(); 52 private static final Logger 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 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 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 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 [] cud = c.getUpgradeData(); 122 final String [] sud = s.getUpgradeData(); 123 boolean uc = true; 124 uc = uc && (cud.length == sud.length); 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 |