throw new IllegalStateException("The system has not been set");
}
public void deploy(DeploymentUnit unit, ClassLoadingTranslatorsMetaData deployment) throws DeploymentException
{
Module module = AttachmentLocator.searchAncestors(unit, Module.class);
if (module == null || (module instanceof ClassLoaderPolicyModule == false))
return;
Map<Translator, TranslatorScope> added = new HashMap<Translator, TranslatorScope>();
try
{
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());