String LOAD_ERROR = "No pathes for XML files were specified. " +
"Check that the property exists in " +
"TurbineResources.props and were loaded.";
log.error(LOAD_ERROR);
throw new InitializationException(LOAD_ERROR);
}
Set xmlFiles = new HashSet();
long timeStamp = 0;
for (Iterator it = xmlPathes.iterator(); it.hasNext();)
{
// Files are webapp.root relative
String xmlPath = Turbine.getRealPath((String) it.next());
File xmlFile = new File(xmlPath);
log.debug("Path for XML File: " + xmlFile);
if (!xmlFile.canRead())
{
String READ_ERR = "Could not read input file " + xmlPath;
log.error(READ_ERR);
throw new InitializationException(READ_ERR);
}
xmlFiles.add(xmlPath);
log.debug("Added " + xmlPath + " as File to parse");
// Get the timestamp of the youngest file to be compared with
// a serialized file. If it is younger than the serialized file,
// then we have to parse the XML anyway.
timeStamp =
(xmlFile.lastModified() > timeStamp) ? xmlFile.lastModified() : timeStamp;
}
Map serializedMap = loadSerialized(serialDataPath, timeStamp);
if (serializedMap != null)
{
// Use the serialized data as XML groups. Don't parse.
appDataElements = serializedMap;
log.debug("Using the serialized map");
}
else
{
// Parse all the given XML files
appDataElements = new HashMap();
for (Iterator it = xmlFiles.iterator(); it.hasNext();)
{
String xmlPath = (String) it.next();
AppData appData = null;
log.debug("Now parsing: " + xmlPath);
try
{
XmlToAppData xmlApp = new XmlToAppData();
appData = xmlApp.parseFile(xmlPath);
}
catch (Exception e)
{
log.error("Could not parse XML file " + xmlPath, e);
throw new InitializationException("Could not parse XML file " +
xmlPath, e);
}
appDataElements.put(appData, xmlPath);
log.debug("Saving appData for " + xmlPath);
}
saveSerialized(serialDataPath, appDataElements);
}
try
{
for (Iterator it = appDataElements.keySet().iterator(); it.hasNext();)
{
AppData appData = (AppData) it.next();
int maxPooledGroups = 0;
List glist = appData.getGroups();
String groupPrefix = appData.getGroupPrefix();
for (int i = glist.size() - 1; i >= 0; i--)
{
XmlGroup g = (XmlGroup) glist.get(i);
String groupName = g.getName();
boolean registerUnqualified = registerGroup(groupName, g, appData, true);
if (!registerUnqualified)
{
log.info("Ignored redefinition of Group " + groupName
+ " or Key " + g.getKey()
+ " from " + appDataElements.get(appData));
}
if (groupPrefix != null)
{
StringBuffer qualifiedName = new StringBuffer();
qualifiedName.append(groupPrefix)
.append(':')
.append(groupName);
// Add the fully qualified group name. Do _not_ check for
// the existence of the key if the unqualified registration succeeded
// (because then it was added by the registerGroup above).
if (!registerGroup(qualifiedName.toString(), g, appData, !registerUnqualified))
{
log.error("Could not register fully qualified name " + qualifiedName
+ ", maybe two XML files have the same prefix. Ignoring it.");
}
}
maxPooledGroups =
Math.max(maxPooledGroups,
Integer.parseInt(g.getPoolCapacity()));
}
KeyedPoolableObjectFactory factory =
new Group.GroupFactory(appData);
keyedPools.put(appData, new StackKeyedObjectPool(factory, maxPooledGroups));
}
setInit(true);
}
catch (Exception e)
{
throw new InitializationException(
"TurbineIntakeService failed to initialize", e);
}
}