01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.tools;
06:
07: import com.tc.properties.TCProperties;
08: import com.tc.properties.TCPropertiesImpl;
09: import com.tc.util.VendorVmSignature;
10: import com.tc.util.VendorVmSignatureException;
11:
12: import java.util.Properties;
13:
14: public class BootJarSignature {
15:
16: private final String signature;
17:
18: BootJarSignature(final Properties props)
19: throws UnsupportedVMException {
20: try {
21: VendorVmSignature vendorVmSignature = new VendorVmSignature(
22: props);
23: this .signature = vendorVmSignature.getSignature();
24: } catch (VendorVmSignatureException e) {
25: throw new UnsupportedVMException(e.getMessage());
26: }
27: }
28:
29: BootJarSignature(final String signature) {
30: this .signature = signature;
31: }
32:
33: public String getSignature() {
34: return signature;
35: }
36:
37: public String toString() {
38: return getSignature();
39: }
40:
41: /**
42: * For now just do a regular string equality check on the signature; this can be a place to hide ugly compatibility
43: * stuff as needed
44: *
45: * @return <code>true</code> if <code>signature</code> is compatible with the current object instance.
46: */
47: public boolean isCompatibleWith(
48: final BootJarSignature bootJarSignature) {
49: TCProperties props = TCPropertiesImpl.getProperties()
50: .getPropertiesFor("l1");
51: boolean isCheckRequired = props
52: .getBoolean("jvm.check.compatibility");
53: return isCheckRequired ? signature
54: .equals(bootJarSignature.signature) : true;
55: }
56:
57: static BootJarSignature getSignatureForThisVM()
58: throws UnsupportedVMException {
59: return new BootJarSignature(System.getProperties());
60: }
61:
62: /**
63: * Calculates the filename for the DSO Boot JAR for the current VM
64: *
65: * @return A String representing DSO Boot JAR filename
66: */
67: public static String getBootJarNameForThisVM()
68: throws UnsupportedVMException {
69: BootJarSignature signatureForThisVM = getSignatureForThisVM();
70: return BootJar.JAR_NAME_PREFIX + signatureForThisVM + ".jar";
71: }
72:
73: /**
74: * README: This main() method is called from the dso-java[.bat] script. It isn't for simple test purposes or anything.
75: * Specificallly, there is a contract here.....running main() should output the expected name of the dso boot jar for
76: * the VM running this method. If you think you want to change what this method does, you better have a look at the
77: * calling scripts ;-)
78: */
79: public static void main(String args[]) {
80: try {
81: System.out.println(getBootJarNameForThisVM());
82: } catch (Throwable t) {
83: System.err.println("ERROR: " + t.getMessage());
84: System.exit(1);
85: }
86: System.exit(0);
87: }
88:
89: }
|