public Set instantiate() throws IOException {
FileObject targetFolder = Templates.getTargetFolder(wizard);
DataFolder targetDataFolder = DataFolder.findFolder(targetFolder);
String targetName = Templates.getTargetName(wizard);
FileObject templateFileObject = Templates.getTemplate(wizard);
DataObject templateDataObject = DataObject.find(templateFileObject);
final String extension = "java";
if (StringUtils.nullOrEmpty(targetName)) { // NOI18N
targetName = "NewActionBean"; // NOI18N
}
String uniqueTargetName = targetName;
int i = 2;
while (targetFolder.getFileObject(uniqueTargetName, extension) != null) {
uniqueTargetName = targetName + i;
i++;
}
final String name = uniqueTargetName;
Map<String, Object> replacements = new HashMap<String, Object>(4);
replacements.put(EXTEND_ACTION_BEAN, wizard.getProperty(EXTEND_ACTION_BEAN));
replacements.put(ACTION_BEAN_CLASS, wizard.getProperty(ACTION_BEAN_CLASS));
replacements.put(OVERRIDE_CONTEXT_METHODS, wizard.getProperty(OVERRIDE_CONTEXT_METHODS));
replacements.put(CONTEXT_CLASS, wizard.getProperty(CONTEXT_CLASS));
replacements.put(USE_URL_BINDING, wizard.getProperty(USE_URL_BINDING));
replacements.put(URL_BINDING, wizard.getProperty(URL_BINDING));
DataObject newOne =
templateDataObject.createFromTemplate(targetDataFolder, name, replacements);
OpenCookie openCookie = newOne.getCookie(OpenCookie.class);
if (openCookie != null) {
openCookie.open();
}
return Collections.singleton(newOne.getPrimaryFile());
}