}
private Object getResource(Entry entry, Properties properties) {
OMNode omNode;
RegistryEntry re = registry.getRegistryEntry(entry.getKey());
omNode = registry.lookup(entry.getKey());
if (re == null) {
return null;
}
if ((!entry.isCached() || (re.getVersion() == Long.MIN_VALUE ||
re.getVersion() != entry.getVersion())) || re.getLastModified() >= lastExecutionTime) {
entry.setEntryProperties(registry.getResourceProperties(entry.getKey()));
entry.setVersion(re.getVersion());
// if we get here, we have received the raw omNode from the
// registry and our previous copy (if we had one) has expired or is not valid
Object expiredValue = entry.getValue();
// if we have a XMLToObjectMapper for this entry, use it to convert this
// resource into the appropriate object - e.g. sequence or endpoint
if (entry.getMapper() != null) {
entry.setValue(entry.getMapper().getObjectFromOMNode(omNode, properties));
if (entry.getValue() instanceof SequenceMediator) {
SequenceMediator seq = (SequenceMediator) entry.getValue();
seq.setDynamic(true);
seq.setRegistryKey(entry.getKey());
seq.init(synapseEnvironment);
} else if (entry.getValue() instanceof Endpoint) {
Endpoint ep = (Endpoint) entry.getValue();
ep.init(synapseEnvironment);
}
} else {
// if the type of the object is known to have a mapper, create the
// resultant Object using the known mapper, and cache this Object
// else cache the raw OMNode
entry.setValue(omNode);
}
if (expiredValue != null) {
// Destroy the old resource so that everything is properly cleaned up
if (expiredValue instanceof SequenceMediator) {
((SequenceMediator) expiredValue).destroy();
} else if (expiredValue instanceof Endpoint) {
((Endpoint) expiredValue).destroy();
}
}
entry.setVersion(re.getVersion());
}
// renew cache lease for another cachable duration (as returned by the
// new getRegistryEntry() call
if (re.getCachableDuration() > 0) {
entry.setExpiryTime(
System.currentTimeMillis() + re.getCachableDuration());
} else {
entry.setExpiryTime(-1);
}
return entry.getValue();