001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 021 package org.apache.geronimo.system.plugin; 022 023 import java.io.IOException; 024 import java.util.Collections; 025 import java.util.Map; 026 027 import org.apache.geronimo.gbean.GBeanInfo; 028 import org.apache.geronimo.gbean.GBeanInfoBuilder; 029 import org.apache.geronimo.kernel.repository.ArtifactManager; 030 import org.apache.geronimo.kernel.repository.ListableRepository; 031 import org.apache.geronimo.system.configuration.LocalAttributeManager; 032 import org.apache.geronimo.system.configuration.LocalPluginAttributeStore; 033 import org.apache.geronimo.system.resolver.ExplicitDefaultArtifactResolver; 034 import org.apache.geronimo.system.serverinfo.ServerInfo; 035 036 /** 037 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 038 */ 039 public class ServerInstanceData { 040 041 private String name; 042 private String attributeManagerFrom; 043 private String configFile = "var/config/config.xml"; 044 private String configSubstitutionsFile = "var/config/config-substitutions.properties"; 045 private String configSubstitutionsPrefix = "org.apache.geronimo.config.substitution."; 046 private String artifactAliasesFile = "var/config/artifact_aliases.properties"; 047 048 049 public String getName() { 050 return name; 051 } 052 053 public void setName(String name) { 054 this.name = name; 055 } 056 057 058 public String getAttributeManagerFrom() { 059 return attributeManagerFrom; 060 } 061 062 public void setAttributeManagerFrom(String attributeManagerFrom) { 063 this.attributeManagerFrom = attributeManagerFrom; 064 } 065 066 public String getConfigFile() { 067 return configFile; 068 } 069 070 public void setConfigFile(String configFile) { 071 this.configFile = configFile; 072 } 073 074 public String getConfigSubstitutionsFile() { 075 return configSubstitutionsFile; 076 } 077 078 public void setConfigSubstitutionsFile(String configSubstitutionsFile) { 079 this.configSubstitutionsFile = configSubstitutionsFile; 080 } 081 082 public String getConfigSubstitutionsPrefix() { 083 return configSubstitutionsPrefix; 084 } 085 086 public void setConfigSubstitutionsPrefix(String configSubstitutionsPrefix) { 087 this.configSubstitutionsPrefix = configSubstitutionsPrefix; 088 } 089 090 public String getArtifactAliasesFile() { 091 return artifactAliasesFile; 092 } 093 094 public void setArtifactAliasesFile(String artifactAliasesFile) { 095 this.artifactAliasesFile = artifactAliasesFile; 096 } 097 098 public ServerInstance getServerInstance(ArtifactManager artifactManager, ListableRepository targetRepo, ServerInfo serverInfo, Map<String, org.apache.geronimo.system.plugin.ServerInstance> serverInstances, boolean live) throws IOException { 099 ExplicitDefaultArtifactResolver geronimoArtifactResolver = new ExplicitDefaultArtifactResolver( 100 getArtifactAliasesFile(), 101 artifactManager, 102 Collections.singleton(targetRepo), 103 serverInfo); 104 LocalPluginAttributeStore attributeStore; 105 if (attributeManagerFrom == null) { 106 attributeStore = new LocalAttributeManager(getConfigFile(), 107 getConfigSubstitutionsFile(), 108 getConfigSubstitutionsPrefix(), 109 false, 110 serverInfo); 111 ((LocalAttributeManager)attributeStore).load(); 112 } else { 113 ServerInstance shared = serverInstances.get(attributeManagerFrom); 114 if (shared == null) { 115 throw new IllegalArgumentException("Incorrect configuration: no server instance named '" + attributeManagerFrom + "' defined before being shared from '" + name + "'"); 116 } 117 attributeStore = (LocalPluginAttributeStore) shared.getAttributeStore(); 118 } 119 return new ServerInstance(name, attributeStore, geronimoArtifactResolver); 120 } 121 122 @Override 123 public String toString() { 124 StringBuffer buf = new StringBuffer(); 125 buf.append("ServerInstanceData:\n"); 126 buf.append(" Name: ").append(getName()).append("\n"); 127 buf.append(" AttributeManagerFrom: ").append(getAttributeManagerFrom()).append("\n"); 128 buf.append(" ConfigFile: ").append(getConfigFile()).append("\n"); 129 buf.append(" ConfigSubstitutionsFile: ").append(getConfigSubstitutionsFile()).append("\n"); 130 buf.append(" ConfigSubstitutionsPrefix: ").append(getConfigSubstitutionsPrefix()).append("\n"); 131 buf.append(" ArtifactAliasesFile: ").append(getArtifactAliasesFile()).append("\n"); 132 return buf.toString(); 133 } 134 135 public static final GBeanInfo GBEAN_INFO; 136 137 static { 138 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ServerInstanceData.class, "ServerInstanceData"); 139 infoFactory.addAttribute("name", String.class, true, true); 140 infoFactory.addAttribute("attributeManagerFrom", String.class, true, true); 141 infoFactory.addAttribute("configFile", String.class, true, true); 142 infoFactory.addAttribute("configSubstitutionsFile", String.class, true, true); 143 infoFactory.addAttribute("configSubstitutionsPrefix", String.class, true, true); 144 infoFactory.addAttribute("artifactAliasesFile", String.class, true, true); 145 146 GBEAN_INFO = infoFactory.getBeanInfo(); 147 } 148 149 public static GBeanInfo getGBeanInfo() { 150 return GBEAN_INFO; 151 } 152 }