/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package org.glassfish.config.support; import java.beans.PropertyVetoException; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.stream.XMLInputFactory; import static javax.xml.stream.XMLStreamConstants.END_DOCUMENT; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStreamReader; import com.sun.enterprise.config.serverbeans.*; import com.sun.enterprise.util.EarlyLogger; import com.sun.enterprise.util.LocalStringManagerImpl; import com.sun.grizzly.config.dom.*; import org.glassfish.api.admin.config.ConfigurationUpgrade; import org.glassfish.api.admin.ServerEnvironment; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.component.PostConstruct; import org.jvnet.hk2.config.*; import org.jvnet.hk2.config.types.Property; import org.jvnet.hk2.config.types.PropertyBag; /** * Upgrade service to add the default-config if it doesn't exist. * 3.0.1 and v2.x developer profile do not have default-config. * The data to populate the default-config is taken from * glassfish3\glassfish\lib\templates\domain.xml. This class uses the StAX * parser and depends on the exact order of the elements in the template, and * the original contents of the template when glassfish was installed. * The DefaultConfigUpgrade may not work if the template has been changed from * its original. * * @author Jennifer Chou */ @Service public class DefaultConfigUpgrade implements ConfigurationUpgrade, PostConstruct { /* * Required to make gms changes before any changes to a cluster * or config can be saved. This is because GMS changed attribute * names from v2 to 3.1. (Issue 15195.) */ @Inject(name = "gmsupgrade", optional = true) ConfigurationUpgrade precondition = null; @Inject Configs configs; //@Inject This sets com.sun.aas.installRoot = user temp directory //ServerEnvironment env; private static final String DEFAULT_CONFIG = "default-config"; private static final String INSTALL_ROOT = "com.sun.aas.installRoot"; private static final LocalStringManagerImpl localStrings = new LocalStringManagerImpl(DefaultConfigUpgrade.class); @Override public void postConstruct() { Config defaultConfig = configs.getConfigByName(DEFAULT_CONFIG); if (defaultConfig != null) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.INFO, localStrings.getLocalString( "DefaultConfigUpgrade.existingDefaultConfig", "Existing default-config detected during upgrade. No need to create default-config.")); return; } String installRoot = System.getProperty(INSTALL_ROOT); if (installRoot == null) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.INFO, localStrings.getLocalString( "DefaultConfigUpgrade.installRootIsNull", "System Property com.sun.aas.installRoot is null. We could be running in unit tests." + "Exiting DefaultConfigUpgrade")); return; } Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.INFO, localStrings.getLocalString( "DefaultConfigUpgrade.runningDefaulConfigUgrade", "default-config not detected during upgrade. Running DefaultConfigUpgrade to create default-config.")); String template = getDomainXmlTemplate(); if (template == null) { throw new RuntimeException(localStrings.getLocalString( "DefaultConfigUpgrade.problemGettingDomainXmlTemplate", "DefaultConfigUpgrade failed. Problem getting domain.xml template.")); } try { ConfigSupport.apply(new MinDefaultConfigCode(), configs); defaultConfig = configs.getConfigByName(DEFAULT_CONFIG); createParser(template); createDefaultConfigAttr(defaultConfig); createHttpServiceConfig(defaultConfig); createIiopServiceConfig(defaultConfig); createAdminServiceConfig(defaultConfig); createWebContainerConfig(defaultConfig); createEjbContainerConfig(defaultConfig); createJmsServiceConfig(defaultConfig); createLogServiceConfig(defaultConfig); createSecurityServiceConfig(defaultConfig); createTransactionServiceConfig(defaultConfig); createDiagnosticServiceConfig(defaultConfig); createJavaConfig(defaultConfig); createAvailabilityService(defaultConfig); createNetworkConfig(defaultConfig); createThreadPools(defaultConfig); createManagementRules(defaultConfig); createSystemProperties(defaultConfig); } catch (TransactionFailure ex) { EarlyLogger.add(Level.SEVERE, "Failure during upgrade - could not create default-config: " + ex); throw new RuntimeException(ex); } catch (FileNotFoundException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, null, ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (parser != null) { parser.close(); } } catch (Exception e) { // ignore } try { if (reader != null) { reader.close(); } } catch (Exception e) { // ignore } } } private String getDomainXmlTemplate() { String installRoot = System.getProperty(INSTALL_ROOT); String template = null; if (installRoot != null) { boolean isGFInstall = installRoot.endsWith("glassfish"); // is this reliable? template = installRoot + File.separator + "lib" + File.separator + "templates" + File.separator + "domain.xml"; File f = new File(template); if (isGFInstall && !f.exists()) {// During unit test the INSTALL_ROOT is the user temp dir so we don't check if template exists during unit test throw new RuntimeException(localStrings.getLocalString( "DefaultConfigUpgrade.missingDomainXmlTemplate", "DefaultConfigUpgrade failed. Missing domain.xml template here " + template, template)); } else { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.INFO, localStrings.getLocalString( "DefaultConfigUpgrade.foundDomainXmlTemaplate", "Found domain.xml template to create default-config: " + template, template)); } } else { throw new RuntimeException(localStrings.getLocalString( "DefaultConfigUpgrade.cantFindInstallRoot", "DefaultConfigUpgrade failed. Can't find domain.xml template." + "Install root system property, " + INSTALL_ROOT + " is null.", INSTALL_ROOT)); } return template; } private void createDefaultConfigAttr(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("config") && parser.getAttributeValue(null, "name").equals(DEFAULT_CONFIG)) { ConfigSupport.apply(new DefaultConfigCode(), defaultConfig); break; } } } } private void createHttpServiceConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("http-service")) { ConfigSupport.apply(new HttpServiceConfigCode(), defaultConfig); break; } } } } private void createIiopServiceConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("iiop-service")) { ConfigSupport.apply(new IiopServiceConfigCode(), defaultConfig); break; } } } } private void createAdminServiceConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("admin-service")) { System.out.println("**** admin service"); ConfigSupport.apply(new AdminServiceConfigCode(), defaultConfig); break; } } } } private void createWebContainerConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("web-container")) { SessionManager sm = defaultConfig.getWebContainer().getSessionConfig().getSessionManager(); ConfigSupport.apply(new WebContainerConfigCode(), sm); break; } } } } private void createEjbContainerConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("ejb-container")) { ConfigSupport.apply(new EjbContainerConfigCode(), defaultConfig); break; } } } } private void createJmsServiceConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("jms-service")) { ConfigSupport.apply(new JmsServiceConfigCode(), defaultConfig); break; } } } } private void createLogServiceConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("log-service")) { ConfigSupport.apply(new LogServiceConfigCode(), defaultConfig); break; } } } } private void createSecurityServiceConfig(Config defaultConfig) { while (true) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("security-service")) { ConfigSupport.apply(new SecurityServiceConfigCode(), defaultConfig); break; } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failure creating SecurityService Config", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing security-service", ex); } } } private void createTransactionServiceConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("transaction-service")) { ConfigSupport.apply(new TransactionServiceConfigCode(), defaultConfig); break; } } } } private void createDiagnosticServiceConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("diagnostic-service")) { ConfigSupport.apply(new DiagnosticServiceConfigCode(), defaultConfig); break; } } } } private void createJavaConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("java-config")) { ConfigSupport.apply(new JavaConfigCode(), defaultConfig); break; } } } } private void createAvailabilityService(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("availability-service")) { ConfigSupport.apply(new AvailabilityServiceConfigCode(), defaultConfig); break; } } } } private void createNetworkConfig(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("network-config")) { ConfigSupport.apply(new NetworkConfigCode(), defaultConfig); break; } } } } private void createThreadPools(Config defaultConfig) throws TransactionFailure, XMLStreamException { while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("thread-pools")) { ConfigSupport.apply(new ThreadPoolsConfigCode(), defaultConfig); break; } } } } private void createManagementRules(Config defaultConfig) throws TransactionFailure, XMLStreamException { ConfigSupport.apply(new ManagementRulesConfigCode(), defaultConfig); } private void createSystemProperties(Config defaultConfig) throws TransactionFailure, XMLStreamException { ConfigSupport.apply(new SystemPropertyConfigCode(), defaultConfig); } /* * Creates the default-config object with the required elements (marked with @NotNull) */ private class MinDefaultConfigCode implements SingleConfigCode { public Object run(Configs configs) throws PropertyVetoException, TransactionFailure { Config defaultConfig = configs.createChild(Config.class); defaultConfig.setName(DEFAULT_CONFIG); Dom.unwrap(defaultConfig).addDefaultChildren(); configs.getConfig().add(defaultConfig); return defaultConfig; } } private class DefaultConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { config.setDynamicReconfigurationEnabled( parser.getAttributeValue(null, "dynamic-reconfiguration-enabled")); return config; } } /* * Creates the http-service object using data from glassfish3\glassfish\lib\templates\domain.xml * * * * * * * */ private class HttpServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { HttpService httpService = config.createChild(HttpService.class); config.setHttpService(httpService); AccessLog al = httpService.createChild(AccessLog.class); httpService.setAccessLog(al); createVirtualServer(httpService); return config; } } private void createVirtualServer(HttpService hs) throws PropertyVetoException { try { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("http-service"))) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("virtual-server")) { VirtualServer vs = hs.createChild(VirtualServer.class); hs.getVirtualServer().add(vs); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); if (attr.equals("id")) { vs.setId(parser.getAttributeValue(i)); } if (attr.equals("network-listeners")) { vs.setNetworkListeners(parser.getAttributeValue(i)); } } createVirtualServerProperty(vs); } } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failed to create HttpService VirtualService config object", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing http-service virtual-server in domain.xml template", ex); } } private void createVirtualServerProperty(VirtualServer vs) throws PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("virtual-server"))) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("property")) { Property p = vs.createChild(Property.class); vs.getProperty().add(p); createProperty(p); } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failed creating VirtualServer Property config object", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing virtual-server property element in domain.xml template", ex); } } } /* * Creates the iiop-service object using data from glassfish3\glassfish\lib\templates\domain.xml * * * * * * * * * * */ private class IiopServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { IiopService iiopService = config.createChild(IiopService.class); config.setIiopService(iiopService); createOrb(iiopService); createIiopListener(iiopService); return null; } } /* */ private void createOrb(IiopService is) throws PropertyVetoException { while (true) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("orb")) { Orb orb = is.createChild(Orb.class); is.setOrb(orb); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); if (attr.equals("use-thread-pool-ids")) { orb.setUseThreadPoolIds(parser.getAttributeValue(i)); } } break; } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failure creating IiopService Orb config object", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing iiop-service orb element in domain.xml template", ex); } } } /* Loop through all iiop-listener elements in template and create IiopListener config objects. * * * (1 example) */ private void createIiopListener(IiopService is) throws PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("iiop-service"))) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("iiop-listener")) { IiopListener il = is.createChild(IiopListener.class); is.getIiopListener().add(il); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); if (attr.equals("port")) { il.setPort(parser.getAttributeValue(i)); } if (attr.equals("id")) { il.setId(parser.getAttributeValue(i)); } if (attr.equals("address")) { il.setAddress(parser.getAttributeValue(i)); } if (attr.equals("security-enabled")) { il.setSecurityEnabled(parser.getAttributeValue(i)); } } createIiopListenerSsl(il); } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failure creating IiopService IiopListener config object", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing iiop-service iiop-listener element in domain.xml template", ex); } } } private void createIiopListenerSsl(IiopListener il) throws PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("iiop-listener"))) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("ssl") && il != null) { Ssl ssl = il.createChild(Ssl.class); il.setSsl(ssl); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); if (attr.equals("classname")) { ssl.setClassname(parser.getAttributeValue(i)); } if (attr.equals("cert-nickname")) { ssl.setCertNickname(parser.getAttributeValue(i)); } if (attr.equals("client-auth-enabled")) { ssl.setClientAuthEnabled(parser.getAttributeValue(i)); } } } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failed to create IiopListener Ssl config object", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing iiop-listner ssl element in domain.xml template", ex); } } } /* * Creates the admin-service object using data from glassfish3\glassfish\lib\templates\domain.xml * * * * * * */ private class AdminServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { AdminService adminService = config.createChild(AdminService.class); config.setAdminService(adminService); //dasConfig cannot be null. Add a dummy. DasConfig dc = adminService.createChild(DasConfig.class); adminService.setDasConfig(dc); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("system-jmx-connector-name")) { adminService.setSystemJmxConnectorName(val); } if (attr.equals("type")) { adminService.setType(val); } } createJmxConnector(adminService); createAdminServiceProperty(adminService); return null; } } /* */ private void createJmxConnector(AdminService as) throws PropertyVetoException { while (true) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("jmx-connector")) { JmxConnector jc = as.createChild(JmxConnector.class); as.getJmxConnector().add(jc); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("address")) { jc.setAddress(val); } if (attr.equals("auth-realm-name")) { jc.setAuthRealmName(val); } if (attr.equals("name")) { jc.setName(val); } if (attr.equals("port")) { jc.setPort(val); } if (attr.equals("protocol")) { jc.setProtocol(val); } if (attr.equals("security-enabled")) { jc.setSecurityEnabled(val); } } break; } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failed to create AdminService JmxConnector config object.", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, "Problem parsing admin-service jmx-connector", ex); } } } /* */ private void createAdminServiceProperty(AdminService as) throws PropertyVetoException { while (true) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("property")) { Property p = as.createChild(Property.class); as.getProperty().add(p); createProperty(p); break; } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failed to create AdminService Property config object", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing asadmin-service property element in domain.xml template", ex); } } } /* * Creates the web-container object using data from glassfish3\glassfish\lib\templates\domain.xml * The required elements elements were already created in MinDefaultConfigCode, so only * need to add store-properties. * * * * * * * * * */ private class WebContainerConfigCode implements SingleConfigCode { public Object run(SessionManager sm) throws PropertyVetoException, TransactionFailure { try { /* */ while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("session-manager") && sm != null) { StoreProperties sp = sm.createChild(StoreProperties.class); sm.setStoreProperties(sp); break; } } } } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, null, ex); } return null; } } /* * Creates the ejb-container object using data from glassfish3\glassfish\lib\templates\domain.xml * * * */ private class EjbContainerConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { EjbContainer ec = config.createChild(EjbContainer.class); config.setEjbContainer(ec); EjbTimerService ets = ec.createChild(EjbTimerService.class); ec.setEjbTimerService(ets); /* */ for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("session-store")) { ec.setSessionStore(val); } } return config; } } /* * Creates the jms-service object using data from glassfish3\glassfish\lib\templates\domain.xml * * * */ private class JmsServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { JmsService js = config.createChild(JmsService.class); config.setJmsService(js); /* */ for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("type")) { js.setType(val); } if (attr.equals("default-jms-host")) { js.setDefaultJmsHost(val); } if (attr.equals("addresslist-behavior")) { js.setAddresslistBehavior(val); } } try { /* */ while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("jms-host") && js != null) { JmsHost jh = js.createChild(JmsHost.class); js.getJmsHost().add(jh); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("name")) { jh.setName(val); } if (attr.equals("host")) { jh.setHost(val); } if (attr.equals("port")) { jh.setPort(val); } if (attr.equals("admin-user-name")) { jh.setAdminUserName(val); } if (attr.equals("admin-password")) { jh.setAdminPassword(val); } if (attr.equals("lazy-init")) { jh.setLazyInit(val); } } break; } } } } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, null, ex); } return config; } } /* * Creates the log-service object using data from glassfish3\glassfish\lib\templates\domain.xml * * * */ private class LogServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { LogService ls = config.createChild(LogService.class); config.setLogService(ls); /* */ for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("log-rotation-limit-in-bytes")) { ls.setLogRotationLimitInBytes(val); } if (attr.equals("file")) { ls.setFile(val); } } try { /* */ while (true) { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("module-log-levels") && ls != null) { ModuleLogLevels mll = ls.createChild(ModuleLogLevels.class); ls.setModuleLogLevels(mll); break; } } } } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, null, ex); } return config; } } /* * Creates the security-service object using data from glassfish3\glassfish\lib\templates\domain.xml * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ private class SecurityServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { SecurityService ss = config.createChild(SecurityService.class); config.setSecurityService(ss); createAuthRealm(ss); createJaccProvider(ss); createAuditModule(ss); createMessageSecurityConfig(ss); return config; } } /* Loop through all auth-realm elements in the template and create AuthRealm config objects. * One example from template: * * * * */ private void createAuthRealm(SecurityService ss) throws PropertyVetoException { while (!(parser.getEventType() == START_ELEMENT && parser.getLocalName().equals("jacc-provider"))) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("auth-realm") && ss != null) { AuthRealm ar = ss.createChild(AuthRealm.class); ss.getAuthRealm().add(ar); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("classname")) { ar.setClassname(val); } if (attr.equals("name")) { ar.setName(val); } } createAuthRealmProperty(ar); } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failure creating AuthRealm", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, "Problem parsing auth-realm", ex); } } } private void createAuthRealmProperty(AuthRealm ar) throws PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("auth-realm"))) { String attr = null; String val = null; try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("property") && ar != null) { Property p = ar.createChild(Property.class); ar.getProperty().add(p); createProperty(p); } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Create AuthRealm Property failed. Attr = " + attr + " Val = " + val, ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing auth-realm property", ex); } } } /* Loop through all jacc-provider elements in the template and create JaccProvider config objects. * Cursor should already be at first jacc-provider START_ELEMENT. * from template: * * * * */ private void createJaccProvider(SecurityService ss) throws PropertyVetoException { while (!(parser.getEventType() == START_ELEMENT && parser.getLocalName().equals("audit-module"))) { try { if (parser.getEventType() == START_ELEMENT || parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("jacc-provider") && ss != null) { JaccProvider jp = ss.createChild(JaccProvider.class); ss.getJaccProvider().add(jp); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("policy-provider")) { jp.setPolicyProvider(val); } if (attr.equals("name")) { jp.setName(val); } if (attr.equals("policy-configuration-factory-provider")) { jp.setPolicyConfigurationFactoryProvider(val); } } createJaccProviderProperty(jp); } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failure creating JaccProvider", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, "Problem parsing jacc-provider", ex); } } } private void createJaccProviderProperty(JaccProvider jp) throws PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("jacc-provider"))) { String attr = null; String val = null; try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("property") && jp != null) { Property p = jp.createChild(Property.class); jp.getProperty().add(p); for (int i = 0; i < parser.getAttributeCount(); i++) { attr = parser.getAttributeLocalName(i); val = parser.getAttributeValue(i); if (attr.equals("name")) { p.setName(val); } if (attr.equals("value")) { p.setValue(val); } } } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Create JaccProvider Property failed. Attr = " + attr + " Val = " + val, ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing jacc-provider property", ex); } } } /* Cursor should be already be at audit-module START_ELEMENT in the template. * Create AuditModle config object. * from template: * * * */ private void createAuditModule(SecurityService ss) throws PropertyVetoException { try { if (parser.getLocalName().equals("audit-module") && ss != null) { AuditModule am = ss.createChild(AuditModule.class); ss.getAuditModule().add(am); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("classname")) { am.setClassname(val); } if (attr.equals("name")) { am.setName(val); } } createAuditModuleProperty(am); } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failure creating AuditModule config object", ex); } } private void createAuditModuleProperty(AuditModule am) throws PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("audit-module"))) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("property") && am != null) { Property p = am.createChild(Property.class); am.getProperty().add(p); createProperty(p); } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Create JaccProvider Property failed.", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing jacc-provider property", ex); } } } /* Create MessageSecurityConfig * from template: * * * ................... * * * .............. * * * ........................... * * * ............................. * * */ private void createMessageSecurityConfig(SecurityService ss) throws PropertyVetoException { while (true) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("message-security-config") && ss != null) { MessageSecurityConfig msc = ss.createChild(MessageSecurityConfig.class); ss.getMessageSecurityConfig().add(msc); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("auth-layer")) { msc.setAuthLayer(val); } } createProviderConfig(msc); break; } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failure creating JaccProvider", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, "Problem parsing jacc-provider", ex); } } } /* Loop through all provider-config elements in the template and create ProviderConfig config objects. * Cursor should already be at first jacc-provider START_ELEMENT. * 1 example from template: * * * * * * * * */ private void createProviderConfig(MessageSecurityConfig msc) throws PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("message-security-config"))) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("provider-config") && msc != null) { ProviderConfig pc = msc.createChild(ProviderConfig.class); msc.getProviderConfig().add(pc); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("provider-type")) { pc.setProviderType(val); } if (attr.equals("provider-id")) { pc.setProviderId(val); } if (attr.equals("class-name")) { pc.setClassName(val); } } createRequestPolicy(pc); createResponsePolicy(pc); createProviderConfigProperty(pc); } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failure creating ProviderConfig", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, "Problem parsing provider-config", ex); } } } /* */ private void createRequestPolicy(ProviderConfig pc) throws PropertyVetoException { while (true) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("request-policy") && pc != null) { RequestPolicy rp = pc.createChild(RequestPolicy.class); pc.setRequestPolicy(rp); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("auth-source")) { rp.setAuthSource(val); } } break; } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Create ProviderConfig RequestPolicy failed.", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing request-policy property", ex); } } } /* */ private void createResponsePolicy(ProviderConfig pc) throws PropertyVetoException { while (true) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("response-policy") && pc != null) { ResponsePolicy rp = pc.createChild(ResponsePolicy.class); pc.setResponsePolicy(rp); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("auth-source")) { rp.setAuthSource(val); } } break; } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Create ProviderConfig RequestPolicy failed.", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing request-policy property", ex); } } } private void createProviderConfigProperty(ProviderConfig pc) throws PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("provider-config"))) { try { if (parser.next() == START_ELEMENT) { if (parser.getLocalName().equals("property") && pc != null) { Property p = pc.createChild(Property.class); pc.getProperty().add(p); createProperty(p); } } } catch (TransactionFailure ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Create ProviderConfig Property failed", ex); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Problem parsing provider-config property", ex); } } } /* * Creates the transaction-service object using data from glassfish3\glassfish\lib\templates\domain.xml * */ private class TransactionServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { TransactionService ts = config.createChild(TransactionService.class); config.setTransactionService(ts); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("tx-log-dir")) { ts.setTxLogDir(val); } if (attr.equals("automatic-recovery")) { ts.setAutomaticRecovery(val); } } return config; } } /* * Creates the diagnostic-service object using data from glassfish3\glassfish\lib\templates\domain.xml * */ private class DiagnosticServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { DiagnosticService ds = config.createChild(DiagnosticService.class); config.setDiagnosticService(ds); return config; } } /* * Creates the java-config object using data from glassfish3\glassfish\lib\templates\domain.xml * */ private class JavaConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { JavaConfig jc = config.createChild(JavaConfig.class); config.setJavaConfig(jc); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("debug-options")) { jc.setDebugOptions(val); } if (attr.equals("system-classpath")) { jc.setSystemClasspath(val); } if (attr.equals("classpath-suffix")) { jc.setClasspathSuffix(val); } } try { // All some jvm option createJvmOptions(jc); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, null, ex); } return config; } } private void createJvmOptions(JavaConfig jc) throws XMLStreamException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("java-config"))) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("jvm-options") && jc != null) { jc.getJvmOptions().add(parser.getElementText()); } } } } /* * Creates the availability-service object using data from glassfish3\glassfish\lib\templates\domain.xml * * * * * */ private class AvailabilityServiceConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { AvailabilityService as = config.createChild(AvailabilityService.class); config.setAvailabilityService(as); try { createWebContainerAvailability(as); createEjbContainerAvailability(as); createJmsAvailability(as); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, null, ex); } return config; } } /* */ private void createWebContainerAvailability(AvailabilityService as) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("web-container-availability") && as != null) { WebContainerAvailability wca = as.createChild(WebContainerAvailability.class); as.setWebContainerAvailability(wca); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("availability-enabled")) { wca.setAvailabilityEnabled(val); } if (attr.equals("persistence-frequency")) { wca.setPersistenceFrequency(val); } if (attr.equals("persistence-scope")) { wca.setPersistenceScope(val); } } break; } } } } /* */ private void createEjbContainerAvailability(AvailabilityService as) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("ejb-container-availability") && as != null) { EjbContainerAvailability eca = as.createChild(EjbContainerAvailability.class); as.setEjbContainerAvailability(eca); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("availability-enabled")) { eca.setAvailabilityEnabled(val); } if (attr.equals("sfsb-store-pool-name")) { eca.setSfsbStorePoolName(val); } } break; } } } } /* */ private void createJmsAvailability(AvailabilityService as) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("jms-availability") && as != null) { JmsAvailability ja = as.createChild(JmsAvailability.class); as.setJmsAvailability(ja); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("availability-enabled")) { ja.setAvailabilityEnabled(val); } } break; } } } } /* * Creates the network-config object using data from glassfish3\glassfish\lib\templates\domain.xml * */ private class NetworkConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { NetworkConfig nc = config.createChild(NetworkConfig.class); config.setNetworkConfig(nc); try { createProtocols(nc); createNetworkListeners(nc); createTransports(nc); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failed to create protocols", ex); } return config; } } /* * * * * * * * * * * * * * * * * */ private void createProtocols(NetworkConfig nc) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("protocols") && nc != null) { Protocols ps = nc.createChild(Protocols.class); nc.setProtocols(ps); createProtocol(ps); break; } } } } /* (1 example with most attributes) */ private void createProtocol(Protocols ps) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("protocols"))) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("protocol") && ps != null) { Protocol p = ps.createChild(Protocol.class); ps.getProtocol().add(p); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("security-enabled")) { p.setSecurityEnabled(val); } if (attr.equals("name")) { p.setName(val); } } createHttp(p); createSsl(p); } } } } /* (1 example with most attributes)*/ private void createHttp(Protocol p) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("http") && p != null) { Http h = p.createChild(Http.class); p.setHttp(h); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("default-virtual-server")) { h.setDefaultVirtualServer(val); } if (attr.equals("max-connections")) { h.setMaxConnections(val); } } createFileCache(h); break; } } } } /* (1 example with most attributes)*/ private void createFileCache(Http h) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("file-cache") && h != null) { FileCache fc = h.createChild(FileCache.class); h.setFileCache(fc); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("enabled")) { fc.setEnabled(val); } } break; } } } } /* */ private void createSsl(Protocol p) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("protocol"))) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("ssl") && p != null) { Ssl ssl = p.createChild(Ssl.class); p.setSsl(ssl); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("classname")) { ssl.setClassname(val); } if (attr.equals("ssl3-enabled")) { ssl.setSsl3Enabled(val); } if (attr.equals("cert-nickname")) { ssl.setCertNickname(val); } } break; } } } } /* * * * * */ private void createNetworkListeners(NetworkConfig nc) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("network-listeners") && nc != null) { NetworkListeners nls = nc.createChild(NetworkListeners.class); nc.setNetworkListeners(nls); createNetworkListener(nls); break; } } } } /* Loop through all the network-listener elements inside network-listeners of the template * and create the NetworkListener config objects with attribute values from the template. * (1 example) */ private void createNetworkListener(NetworkListeners nls) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("network-listeners"))) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("network-listener") && nls != null) { NetworkListener nl = nls.createChild(NetworkListener.class); nls.getNetworkListener().add(nl); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("address")) { nl.setAddress(val); } if (attr.equals("port")) { nl.setPort(val); } if (attr.equals("protocol")) { nl.setProtocol(val); } if (attr.equals("transport")) { nl.setTransport(val); } if (attr.equals("name")) { nl.setName(val); } if (attr.equals("thread-pool")) { nl.setThreadPool(val); } } } } } } /* * * */ private void createTransports(NetworkConfig nc) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("transports") && nc != null) { Transports ts = nc.createChild(Transports.class); nc.setTransports(ts); createTransport(ts); break; } } } } /* */ private void createTransport(Transports ts) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (true) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("transport") && ts != null) { Transport t = ts.createChild(Transport.class); ts.getTransport().add(t); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("name")) { t.setName(val); } } break; } } } } /* * Creates the thread-pools object using data from glassfish3\glassfish\lib\templates\domain.xml * * * * */ private class ThreadPoolsConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { ThreadPools tps = config.createChild(ThreadPools.class); config.setThreadPools(tps); try { createThreadPool(tps); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log( Level.SEVERE, "Failed to create protocols", ex); } return config; } } /* * Loop through all the thread-pool elements inside thread-pools of the template * and create the ThreadPool config objects with attribute values from the template. * One example of thread-pool element: * */ private void createThreadPool(ThreadPools ts) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("thread-pools"))) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("thread-pool") && ts != null) { ThreadPool t = ts.createChild(ThreadPool.class); ts.getThreadPool().add(t); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("max-thread-pool-size")) { t.setMaxThreadPoolSize(val); } if (attr.equals("idle-thread-timeout-in-seconds")) { t.setIdleThreadTimeoutSeconds(val); } if (attr.equals("name")) { t.setName(val); } } } } } } /* * Creates the management-rules object using data from glassfish3\glassfish\lib\templates\domain.xml * */ private class ManagementRulesConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { ManagementRules mr = config.createChild(ManagementRules.class); config.setManagementRules(mr); return config; } } /* * Creates the system-property elements using data from glassfish3\glassfish\lib\templates\domain.xml */ private class SystemPropertyConfigCode implements SingleConfigCode { public Object run(Config config) throws PropertyVetoException, TransactionFailure { try { createSystemProperty(config); } catch (XMLStreamException ex) { Logger.getLogger(DefaultConfigUpgrade.class.getName()).log(Level.SEVERE, null, ex); } return config; } } /* Loop through all the system-property elements inside default-config of the template * and create the SystemProperty config objects with attribute values from the template. * * * * * * * * * * */ private void createSystemProperty(Config defaultConfig) throws XMLStreamException, TransactionFailure, PropertyVetoException { while (!(parser.getEventType() == END_ELEMENT && parser.getLocalName().equals("config"))) { int eventType = parser.next(); if (eventType == START_ELEMENT) { if (parser.getLocalName().equals("system-property") && defaultConfig != null) { SystemProperty sp = defaultConfig.createChild(SystemProperty.class); defaultConfig.getSystemProperty().add(sp); for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("name")) { sp.setName(val); } if (attr.equals("value")) { sp.setValue(val); } } } } } } private void createProperty(Property p) throws PropertyVetoException { for (int i = 0; i < parser.getAttributeCount(); i++) { String attr = parser.getAttributeLocalName(i); String val = parser.getAttributeValue(i); if (attr.equals("name")) { p.setName(val); } if (attr.equals("value")) { p.setValue(val); } } } private void createParser(String template) throws FileNotFoundException, XMLStreamException { if (template != null) { reader = new InputStreamReader(new FileInputStream(template)); parser = XMLInputFactory.newInstance().createXMLStreamReader( template, reader); } } private XMLStreamReader parser; private InputStreamReader reader; }