List<ClassLoadingTranslatorMetaData> translators = deployment.getTranslators();
if (translators != null)
{
ClassLoaderPolicyModule clpm = (ClassLoaderPolicyModule) module;
ClassLoaderDomain domain = system.getDomain(module.getDeterminedDomainName());
ClassLoaderPolicy policy = clpm.getPolicy();
ClassLoader cl = unit.getClassLoader();
for (ClassLoadingTranslatorMetaData cltmd : translators)
{
TranslatorScope scope = cltmd.getScope();
if (scope == null)
throw new IllegalArgumentException("Null scope for: " + cltmd);
String className = cltmd.getClassName();
Object instance = cl.loadClass(className).newInstance();
String methodName = cltmd.getMethod();
Translator translator;
if (methodName != null)
translator = new ReflectionTranslator(instance, methodName);
else
translator = Translator.class.cast(instance);
scope.addTranslator(system, domain, policy, translator);
added.put(translator, scope);
}
unit.addAttachment(TRANSLATORS_KEY, added);
}
}
catch (Exception e)
{
ClassLoaderPolicyModule clpm = (ClassLoaderPolicyModule) module;
ClassLoaderDomain domain = system.getDomain(module.getDeterminedDomainName());
ClassLoaderPolicy policy = clpm.getPolicy();
for (Map.Entry<Translator, TranslatorScope> entry : added.entrySet())
{
entry.getValue().removeTranslator(system, domain, policy, entry.getKey());
}