}
try
{
final ResourceKey contentBase = runtime.getProcessingContext().getContentBase();
final ResourceManager resManager = runtime.getProcessingContext().getResourceManager();
final ResourceKey key;
if (value instanceof ResourceKey)
{
key = (ResourceKey) value;
}
else if (value instanceof Blob)
{
final Blob b = (Blob) value;
final byte[] data = IOUtils.getInstance().readBlob(b);
key = resManager.createKey(data);
}
else if (value instanceof String)
{
final Object baseURL = element.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.CONTENT_BASE);
if (baseURL != null)
{
final ResourceKey baseKey = resManager.createKey(baseURL);
key = resManager.deriveKey(baseKey, (String) value);
}
else
{
key = resManager.deriveKey(contentBase, (String) value);
}
}
else
{
key = resManager.createKey(value);
}
if (key == null)
{
return null;
}
Class target;
Object targetRaw = element.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.TARGET_TYPE);
if (targetRaw instanceof String)
{
final ClassLoader loader = ObjectUtilities.getClassLoader(ExternalElementType.class);
target = Class.forName((String) targetRaw, false, loader);
if (target == null)
{
return null;
}
}
else
{
target = SubReport.class;
}
final Resource resource = resManager.create(key, contentBase, target);
final Object resourceContent = resource.getResource();
if (resourceContent instanceof Element)
{
return resourceContent;
}