Blame |
Last modification |
View Log
| Download
| RSS feed
package br.gov.al.saude.srv.web;
import java.text.MessageFormat;
import java.util.*;
import javax.naming.*;
import javax.naming.spi.ObjectFactory;
public class PropertiesFactory
implements ObjectFactory{
public PropertiesFactory
(){
}
@
SuppressWarnings("rawtypes")
public Object getObjectInstance
(Object objetoReferencia,
Name name,
Context nameCtx,
Hashtable environment
) throws Exception {
if(estaNulo
(objetoReferencia
))
return new Properties();
if(isInstanciaSuportada
(objetoReferencia
))
return criarPropertiesAtravesDeEnumeracaoDeRefAddr
((Reference)objetoReferencia
);
else
throw new IllegalArgumentException(MessageFormat.
format(PATTERN_MENSAGEM_TIPO_NAO_SUPORTADO,
new Object[] {
objetoReferencia.
getClass().
getName(),
String.
valueOf(name
)
}));
}
private boolean isInstanciaSuportada
(Object objetoReferencia
){
return objetoReferencia
instanceof Reference;
}
private boolean estaNulo
(Object obj
){
return obj ==
null;
}
@
SuppressWarnings("rawtypes")
private Properties criarPropertiesAtravesDeEnumeracaoDeRefAddr
(Reference ref
){
Properties props =
new Properties();
RefAddr element
;
for(Enumeration all = ref.
getAll(); all.
hasMoreElements(); props.
setProperty(element.
getType(),
String.
valueOf(element.
getContent())))
element =
(RefAddr)all.
nextElement();
return props
;
}
private static final String PATTERN_MENSAGEM_TIPO_NAO_SUPORTADO =
"O tipo {0} não suportado por este factory, era esperado um javax.naming.Reference para construir o properties para o resource: {1}.";
}