Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.system.configuration;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanInfoFactory;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.gbean.GReferenceInfo;
import org.apache.geronimo.gbean.MultiGBeanInfoFactory;
import org.apache.geronimo.gbean.ReferencePatterns;
import org.apache.geronimo.kernel.InvalidGBeanException;
import org.apache.geronimo.kernel.config.Configuration;
import org.apache.geronimo.kernel.config.InvalidConfigException;
import org.apache.geronimo.kernel.config.ManageableAttributeStore;
import org.apache.geronimo.kernel.config.PersistentConfigurationList;
import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
import org.apache.geronimo.system.configuration.condition.ParserUtils;
import org.apache.geronimo.system.plugin.model.AttributesType;
import org.apache.geronimo.system.plugin.model.GbeanType;
import org.apache.geronimo.system.plugin.model.ModuleType;
import org.apache.geronimo.system.serverinfo.ServerInfo;
import org.xml.sax.SAXException;
import org.osgi.framework.Bundle;
import org.apache.felix.utils.properties.Properties;
/**
* Stores managed attributes in an XML file on the local filesystem.
*
* @version $Rev: 1460822 $ $Date: 2013-03-26 02:32:05 +0800 (Tue, 26 Mar 2013) $
*/
public class LocalAttributeManager implements LocalPluginAttributeStore, PersistentConfigurationList, GBeanLifecycle {
private static final Logger log = LoggerFactory.getLogger(LocalAttributeManager.class);
private static final String CONFIG_FILE_PROPERTY = "org.apache.geronimo.config.file";
private final static String SUBSTITUTIONS_FILE_PROPERTY = "org.apache.geronimo.config.substitutions.file";
private final static String SUBSTITUTION_PREFIX_PREFIX = "org.apache.geronimo.config.substitution.prefix";
private static final String BACKUP_EXTENSION = ".bak";
private static final String TEMP_EXTENSION = ".working";
private static final int SAVE_BUFFER_MS = 5000;
private final ServerInfo serverInfo;
private final String configFile;
private final boolean readOnly;
private JexlExpressionParser expressionParser;
private File attributeFile;
private File backupFile;
private File tempFile;
private ServerOverride serverOverride;
private Timer timer;
private TimerTask currentTask;
private boolean kernelFullyStarted;
private String prefix;
private File configSubstitutionsFile;
private Properties localConfigSubstitutions;
private String resolvedPropertiesFile;
private final GBeanInfoFactory infoFactory;
private static final byte[] INSTRUCTION = ("# Put variables and their substitution values in this file. \n"
+ "# They will be used when processing the corresponding config.xml. \n"
+ "# Values in this file can be overridden by environment variables and system properties \n"
+ "# by prefixing the property name with 'org.apache.geronimo.config.substitution.' \n"
+ "# For example, an entry such as hostName=localhost \n"
+ "# can be overridden by an environment variable or system property org.apache.geronimo.config.substitution.hostName=foo \n"
+ "# When running multiple instances of Geronimo choose a PortOffset value such that none of the ports conflict. \n"
+ "# For example, try PortOffset=10 \n").getBytes();
public LocalAttributeManager(String configFile, String configSubstitutionsFileName, String configSubstitutionsPrefix, boolean readOnly, ServerInfo serverInfo) {
this.configFile = System.getProperty(CONFIG_FILE_PROPERTY, configFile);
resolvedPropertiesFile = System.getProperty(SUBSTITUTIONS_FILE_PROPERTY, configSubstitutionsFileName);
configSubstitutionsFile = resolvedPropertiesFile == null? null: serverInfo.resolveServer(resolvedPropertiesFile);
localConfigSubstitutions = loadConfigSubstitutions(configSubstitutionsFile);
prefix = System.getProperty(SUBSTITUTION_PREFIX_PREFIX, configSubstitutionsPrefix);
Map configSubstitutions = loadAllConfigSubstitutions(localConfigSubstitutions, prefix);
expressionParser = new JexlExpressionParser(configSubstitutions);
this.readOnly = readOnly;
this.serverInfo = serverInfo;
serverOverride = new ServerOverride();
log.debug("setting configSubstitutionsFile to: {}", configSubstitutionsFile);
infoFactory = newGBeanInfoFactory();
}
protected GBeanInfoFactory newGBeanInfoFactory() {
return new MultiGBeanInfoFactory();
}
public boolean isReadOnly() {
return readOnly;
}
public String getConfigFile() {
return configFile;
}
public String getConfigSubstitutionsFile() {
return resolvedPropertiesFile;
}
public String getConfigSubstitutionsPrefix() {
return prefix;
}
public Map getConfigSubstitutionsVariables() {
return expressionParser.getVariables();
}
public synchronized Collection applyOverrides(Artifact configName, Collection untypedGbeanDatas, Bundle bundle) throws InvalidConfigException {
// clone the datas since we will be modifying this collection
Collection gbeanDatas = new ArrayList(untypedGbeanDatas);
ConfigurationOverride configuration = serverOverride.getConfiguration(configName);
if (configuration == null) {
return gbeanDatas;
}
// index the incoming datas
Map