* @param session the ChromatticSession used to access the JCR store
* @return the ProducerInfosMapping element representing the collection of ProducerInfos
*/
private ProducerInfosMapping getProducerInfosMapping(ChromatticSession session)
{
ProducerInfosMapping producerInfosMapping = session.findByPath(ProducerInfosMapping.class, PRODUCER_INFOS_PATH);
if (producerInfosMapping == null)
{
// we don't currently have any persisted data in JCR so first create the JCR node
producerInfosMapping = session.insert(ProducerInfosMapping.class, ProducerInfosMapping.NODE_NAME);
if (loadFromXMLIfNeeded)
{
// loading initial data is requested so do it
XMLConsumerRegistry fromXML = new XMLConsumerRegistry(configurationIS);
fromXML.reloadConsumers();
// Save to JCR
List<ProducerInfoMapping> infos = producerInfosMapping.getProducerInfos();
List<WSRPConsumer> xmlConsumers = fromXML.getConfiguredConsumers();
for (WSRPConsumer consumer : xmlConsumers)
{
ProducerInfo info = consumer.getProducerInfo();
// create the ProducerInfoMapping children node
ProducerInfoMapping pim = producerInfosMapping.createProducerInfo(info.getId());
// need to add to parent first to attach newly created ProducerInfoMapping
infos.add(pim);
// init it from ProducerInfo
pim.initFrom(info);
// update ProducerInfo with the persistence key
info.setKey(pim.getKey());
// populate the cache with the newly created consumer
consumerCache.putConsumer(info.getId(), consumer);
}
producerInfosMapping.setLastModified(SupportsLastModified.now());
session.save();
}
}
return producerInfosMapping;