}
File test = new File(directory, name);
if(!test.exists() || !test.canRead()) {
throw new IllegalArgumentException("Cannot access keystore "+test.getAbsolutePath()+"!");
}
AbstractName aName;
AbstractName myName = kernel.getAbstractNameFor(this);
aName = kernel.getNaming().createSiblingName(myName, name, NameFactory.KEYSTORE_INSTANCE);
GBeanData data = new GBeanData(aName, FileKeystoreInstance.getGBeanInfo());
try {
String path = configuredDir.toString();
if(!path.endsWith("/")) {
path += "/";
}
data.setAttribute("keystorePath", new URI(path +name));
} catch (URISyntaxException e) {
throw new IllegalStateException("Can't resolve keystore path: "+e.getMessage(), e);
}
data.setReferencePattern("ServerInfo", kernel.getAbstractNameFor(serverInfo));
data.setAttribute("keystoreName", name);
if(type == null) {
if(name.lastIndexOf(".") == -1) {
type = KeystoreUtil.defaultType;
log.warn("keystoreType for new keystore \""+name+"\" set to default type \""+type+"\".");
} else {
type = name.substring(name.lastIndexOf(".")+1);
log.warn("keystoreType for new keystore \""+name+"\" set to \""+type+"\" based on file extension.");
}
}
data.setAttribute("keystoreType", type);
EditableConfigurationManager mgr = ConfigurationUtil.getEditableConfigurationManager(kernel);
if(mgr != null) {
try {
mgr.addGBeanToConfiguration(myName.getArtifact(), data, true);
return (KeystoreInstance) kernel.getProxyManager().createProxy(aName, KeystoreInstance.class);
} catch (InvalidConfigException e) {
log.error("Should never happen", e);
throw new IllegalStateException("Unable to add Keystore GBean ("+e.getMessage()+")", e);
} finally {