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.Map;
025    
026    import org.apache.geronimo.kernel.repository.ArtifactManager;
027    import org.apache.geronimo.kernel.repository.ListableRepository;
028    import org.apache.geronimo.system.configuration.LocalPluginAttributeStore;
029    import org.apache.geronimo.system.resolver.LocalAliasedArtifactResolver;
030    import org.apache.geronimo.system.serverinfo.ServerInfo;
031    import org.apache.geronimo.gbean.GBeanInfo;
032    import org.apache.geronimo.gbean.GBeanInfoBuilder;
033    
034    /**
035     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
036     */
037    public class ReferenceServerInstanceData extends ServerInstanceData {
038    
039        private final LocalPluginAttributeStore attributeStore;
040        private final LocalAliasedArtifactResolver artifactResolver;
041    
042    
043        public ReferenceServerInstanceData() {
044            attributeStore = null;
045            artifactResolver = null;
046        }
047    
048        public ReferenceServerInstanceData(LocalPluginAttributeStore attributeStore, LocalAliasedArtifactResolver artifactResolver) {
049            this.attributeStore = attributeStore;
050            this.artifactResolver = artifactResolver;
051        }
052    
053        @Override
054        public String getConfigFile() {
055            return attributeStore.getConfigFile();
056        }
057    
058        @Override
059        public String getConfigSubstitutionsFile() {
060            return attributeStore.getConfigSubstitutionsFile();
061        }
062    
063        @Override
064        public String getConfigSubstitutionsPrefix() {
065            return attributeStore.getConfigSubstitutionsPrefix();
066        }
067    
068        @Override
069        public String getArtifactAliasesFile() {
070            return artifactResolver.getArtifactAliasesFile();
071        }
072    
073        @Override
074        public ServerInstance getServerInstance(ArtifactManager artifactManager, ListableRepository targetRepo, ServerInfo serverInfo, Map<String, ServerInstance> serverInstances, boolean live) throws IOException {
075            if (live) {
076                return new ServerInstance(getName(), attributeStore, artifactResolver);
077            } else {
078                return super.getServerInstance(artifactManager, targetRepo, serverInfo, serverInstances, live);
079            }
080        }
081    
082        @Override
083         public String toString() {
084             StringBuffer buf = new StringBuffer();
085             buf.append("ReferenceServerInstanceData:\n");
086             buf.append("  Name: ").append(getName()).append("\n");
087             buf.append("  ConfigFile: ").append(getConfigFile()).append("\n");
088             buf.append("  ConfigSubstitutionsFile: ").append(getConfigSubstitutionsFile()).append("\n");
089             buf.append("  ConfigSubstitutionsPrefix: ").append(getConfigSubstitutionsPrefix()).append("\n");
090             buf.append("  ArtifactAliasesFile: ").append(getArtifactAliasesFile()).append("\n");
091             return buf.toString();
092         }
093    
094        public static final GBeanInfo GBEAN_INFO;
095    
096        static {
097            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ReferenceServerInstanceData.class, "ServerInstanceData");
098            infoFactory.addAttribute("name", String.class, true, true);
099            infoFactory.addReference("AttributeStore", LocalPluginAttributeStore.class, "AttributeStore");
100            infoFactory.addReference("ArtifactResolver", LocalAliasedArtifactResolver.class, "ArtifactResolver");
101    
102            infoFactory.setConstructor(new String[] {"AttributeStore", "ArtifactResolver"});
103    
104            GBEAN_INFO = infoFactory.getBeanInfo();
105        }
106    
107        public static GBeanInfo getGBeanInfo() {
108            return GBEAN_INFO;
109        }
110    }