001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.installer.cluster;
021:
022: import com.installshield.product.SoftwareObjectKey;
023: import com.installshield.product.SoftwareVersion;
024: import com.installshield.product.service.product.ProductService;
025: import com.installshield.util.Log;
026: import com.installshield.wizard.WizardAction;
027: import com.installshield.wizard.WizardBeanEvent;
028: import com.installshield.wizard.WizardBuilderSupport;
029: import com.installshield.wizard.service.ServiceException;
030:
031: import java.util.Locale;
032:
033: import org.netbeans.installer.Util;
034:
035: /** This class is used to initialize some system properties at beginning
036: * of installation.
037: */
038: public class SetSystemPropertiesAction extends WizardAction {
039:
040: public void build(WizardBuilderSupport support) {
041: super .build(support);
042: Locale[] locales = new Locale[3];
043: locales[0] = new Locale("zh", "HK");
044: locales[1] = new Locale("zh", "TW");
045: locales[2] = new Locale("zh", "CN");
046: try {
047: support.putClass(Util.class.getName());
048: support.putResourceBundles(
049: "org.netbeans.installer.cluster.Bundle", locales);
050: } catch (Exception ex) {
051: System.out.println(ex.getLocalizedMessage());
052: ex.printStackTrace();
053: }
054: }
055:
056: public void execute(WizardBeanEvent evt) {
057: Util.logSystemInfo(this );
058: resolveProductBeanProperties();
059: }
060:
061: private void resolveProductBeanProperties() {
062: try {
063: ProductService service = (ProductService) getService(ProductService.NAME);
064: String prop;
065: String resolvedProp;
066:
067: prop = (String) service.getProductBeanProperty(
068: ProductService.DEFAULT_PRODUCT_SOURCE,
069: "beanProduct", "name");
070: resolvedProp = resolveString(prop);
071: logEvent(this , Log.DBG, "prop: " + prop + " resolvedProp: "
072: + resolvedProp);
073: service.setRetainedProductBeanProperty(
074: ProductService.DEFAULT_PRODUCT_SOURCE,
075: "beanProduct", "name", resolvedProp);
076:
077: prop = (String) service.getProductBeanProperty(
078: ProductService.DEFAULT_PRODUCT_SOURCE,
079: "beanProduct", "description");
080: resolvedProp = resolveString(prop);
081: logEvent(this , Log.DBG, "prop: " + prop + " resolvedProp: "
082: + resolvedProp);
083: service.setRetainedProductBeanProperty(
084: ProductService.DEFAULT_PRODUCT_SOURCE,
085: "beanProduct", "description", resolvedProp);
086:
087: prop = (String) service.getProductBeanProperty(
088: ProductService.DEFAULT_PRODUCT_SOURCE,
089: "beanProduct", "productNumber");
090: resolvedProp = resolveString(prop);
091: logEvent(this , Log.DBG, "prop: " + prop + " resolvedProp: "
092: + resolvedProp);
093: service.setRetainedProductBeanProperty(
094: ProductService.DEFAULT_PRODUCT_SOURCE,
095: "beanProduct", "productNumber", resolvedProp);
096:
097: prop = (String) service.getProductBeanProperty(
098: ProductService.DEFAULT_PRODUCT_SOURCE,
099: "beanProduct", "vendor");
100: resolvedProp = resolveString(prop);
101: logEvent(this , Log.DBG, "prop: " + prop + " resolvedProp: "
102: + resolvedProp);
103: service.setRetainedProductBeanProperty(
104: ProductService.DEFAULT_PRODUCT_SOURCE,
105: "beanProduct", "vendor", resolvedProp);
106:
107: prop = (String) service.getProductBeanProperty(
108: ProductService.DEFAULT_PRODUCT_SOURCE,
109: "beanProduct", "vendorWebsite");
110: resolvedProp = resolveString(prop);
111: logEvent(this , Log.DBG, "prop: " + prop + " resolvedProp: "
112: + resolvedProp);
113: service.setRetainedProductBeanProperty(
114: ProductService.DEFAULT_PRODUCT_SOURCE,
115: "beanProduct", "vendorWebsite", resolvedProp);
116:
117: SoftwareObjectKey keyObject;
118: SoftwareVersion version;
119: String major, minor, maintenance, key;
120:
121: // ---------------------- Product ---------------------------
122: keyObject = (SoftwareObjectKey) service
123: .getProductBeanProperty(
124: ProductService.DEFAULT_PRODUCT_SOURCE,
125: "beanProduct", "key");
126: key = resolveString("$L(org.netbeans.installer.cluster.Bundle,Product.UID)");
127: logEvent(this , Log.DBG, "Product UID: " + key);
128: keyObject.setUID(key);
129:
130: major = resolveString("$L(org.netbeans.installer.cluster.Bundle,Product.major)");
131: minor = resolveString("$L(org.netbeans.installer.cluster.Bundle,Product.minor)");
132: maintenance = resolveString("$L(org.netbeans.installer.cluster.Bundle,Product.maintenance)");
133:
134: version = new SoftwareVersion();
135: version.setMajor(major);
136: version.setMinor(minor);
137: version.setMaintenance(maintenance);
138: logEvent(this , Log.DBG, "Product version: "
139: + getStringForm(version));
140: keyObject.setVersion(version);
141:
142: service.setRetainedProductBeanProperty(
143: ProductService.DEFAULT_PRODUCT_SOURCE,
144: "beanProduct", "key", keyObject);
145:
146: // ------------------ Profiler Cluster -----------------------------
147: keyObject = (SoftwareObjectKey) service
148: .getProductBeanProperty(
149: ProductService.DEFAULT_PRODUCT_SOURCE,
150: "beanProfilerCluster", "key");
151: key = resolveString("$L(org.netbeans.installer.cluster.Bundle,ProfilerCluster.UID)");
152: logEvent(this , Log.DBG, "Profiler Cluster UID: " + key);
153: keyObject.setUID(key);
154:
155: version = new SoftwareVersion();
156: version.setMajor(major);
157: version.setMinor(minor);
158: version.setMaintenance(maintenance);
159: logEvent(this , Log.DBG, "Profiler Cluster version: "
160: + getStringForm(version));
161: keyObject.setVersion(version);
162:
163: service.setRetainedProductBeanProperty(
164: ProductService.DEFAULT_PRODUCT_SOURCE,
165: "beanProfilerCluster", "key", keyObject);
166: } catch (ServiceException ex) {
167: ex.printStackTrace();
168: Util.logStackTrace(this , ex);
169: }
170: }
171:
172: /** Simplified conversion of SoftwareVersion instance to String. Just for logging. */
173: private String getStringForm(SoftwareVersion version) {
174: String ret = "";
175: if (version.getMajor().length() == 0) {
176: return ret;
177: } else {
178: ret = version.getMajor();
179: }
180: if (version.getMinor().length() == 0) {
181: return ret;
182: } else {
183: ret += "." + version.getMinor();
184: }
185: if (version.getMaintenance().length() == 0) {
186: return ret;
187: } else {
188: ret += "." + version.getMaintenance();
189: }
190: return ret;
191: }
192:
193: }
|