public String getUri() { if (module != null) return module.getUri(); if (moduleFile != null) return moduleFile.getURI(); return null; }
private ModuleRef getModuleRefByName(String moduleName) { List moduleList = earFile.getModuleRefs(); for (int i = 0; i < moduleList.size(); i++) { ModuleRef ref = (ModuleRef) moduleList.get(i); Module module = ref.getModule(); if (moduleName.equals(module.getUri())) { return ref; } } return null; }
/** * Gets the first module matching the specified uri * @param uri The uri of a module to find. * @return The first matching module or null if no module is found. */ public Module getFirstModule(String uri){ if (uri == null) return null; java.util.Iterator allModules = getModules().iterator(); while (allModules.hasNext()){ Module aModule = (Module)allModules.next(); if(uri.equals(aModule.getUri())) return aModule; } return null; } /**
protected void validateModuleURIExtension(Module module) { String newUri = module.getUri(); if (newUri != null && newUri.length() > 0) { if (module instanceof EjbModule && !newUri.endsWith(".jar")) { //$NON-NLS-1$ String[] params = new String[1]; params[0] = module.getUri(); IResource target = earHelper.getProject().getFile(ArchiveConstants.APPLICATION_DD_URI); String tmp = NLS.bind(EARValidationMessageResourceHandler.INVALID_URI_FOR_MODULE_ERROR_, params); addLocalizedWarning(tmp, target); } else if (module instanceof WebModule && !newUri.endsWith(".war")) { //$NON-NLS-1$ String[] params = new String[1]; params[0] = module.getUri(); IResource target = earHelper.getProject().getFile(ArchiveConstants.APPLICATION_DD_URI); String tmp = NLS.bind(EARValidationMessageResourceHandler.INVALID_URI_FOR_MODULE_ERROR_, params); addLocalizedWarning(tmp, target); } } }
public Module getModule(String uri, String altDD) { List allModules = getModules(); for (int i = 0; i < allModules.size(); i++) { Module aModule = (Module) allModules.get(i); if (StringUtil.stringsEqual(uri, aModule.getUri()) && StringUtil.stringsEqual(altDD, aModule.getAltDD())) return aModule; } return null; } /**
/** * Validate the alt dd * * @param Module m - A module. * @param String altDD - An altDD */ protected void validateAltDD(Module m, String altDD) { //isDuplicate will test if it is a file or a loaded resource if ("".equals(altDD)) { //$NON-NLS-1$ String[] params = new String[2]; params[0] = m.getUri(); params[1] = earFile.getName(); String tmp = NLS.bind(EARValidationMessageResourceHandler.MESSAGE_EMPTY_ALT_DD_ERROR_, params); addLocalizedError(tmp, appDD); } else if (altDD != null && !earFile.isDuplicate(altDD)) { String[] params = new String[3]; params[0] = m.getUri(); params[1] = altDD; params[2] = earFile.getName(); String tmp = NLS.bind(EARValidationMessageResourceHandler.MESSAGE_INVALID_ALT_DD_WARN_, params); addLocalizedWarning(tmp, appDD); }// if }// validateAltDD
String filename = m.getUri(); if ((filename == null) || (filename.length() == 0)) { addLocalizedError(EARValidationMessageResourceHandler.MESSAGE_EAR_NO_MODULE_URI, null); if (!duplicateURI.add(key)) { String[] params = new String[2]; params[0] = m.getUri(); params[1] = earFile.getName(); String tmp = NLS.bind(EARValidationMessageResourceHandler.MESSAGE_EAR_DUPLICATE_URI_ERROR_, params);
public LooseModule findLooseModule(Module m, EARFile ear) { LooseApplication app = findLooseApplication(ear.getURI()); return app == null ? null : findLooseModule(app, m.getUri(), m.getAltDD()); }
protected Object primAddCopyRef(ModuleFile aModuleFile) throws DuplicateObjectException { //force this list to get initialized before the add EList refs = getModuleRefs(); if (aModuleFile.isEARFile()) //If it's an ear then just treat it like any other archive return super.addCopy(aModuleFile); checkAddValid(aModuleFile); ModuleFile copy = getCommonArchiveFactory().copy(aModuleFile); Module newModule = createModuleForCopying(aModuleFile); getFiles().add(copy); copy.initializeClassLoader(); if (!copy.getURI().equals(newModule.getUri())) copy.setURI(newModule.getUri()); getDeploymentDescriptor().getModules().add(newModule); ModuleRef aRef = createModuleRef(newModule, copy); refs.add(aRef); return aRef; }
protected void initModuleFileFromEAR() { checkEARFile(); ModuleFile aFile = null; try { aFile = (ModuleFile) getEarFile().getFile(module.getUri()); } catch (FileNotFoundException ex) { //Ignore } catch (ClassCastException ex) { //Ignore } checkType(module, aFile); setModuleFile(aFile); }
/** * Checks if the uri mapping already exists. * * @param String * currentURI - The current uri of the module. * @return boolean */ public boolean uriExists(String currentURI) { StructureEdit edit = null; try { edit = StructureEdit.getStructureEditForRead(getProject()); if (edit!=null && edit.getComponent()!=null) { List referencedComps = edit.getComponent().getReferencedComponents(); for (int i=0; i<referencedComps.size(); i++) { ReferencedComponent ref = (ReferencedComponent) referencedComps.get(i); Object module = ref.getDependentObject(); if (module!=null && module instanceof Module) { String existingURI = ((Module)module).getUri(); if (existingURI!=null && existingURI.equals(currentURI)) return true; } } } } finally { if (edit != null) edit.dispose(); } return false; }
protected void renameRolesInModuleDDs(String existingRoleName, String newRoleName) { List modules = getDeploymentDescriptor().getModules(); for (int i = 0; i < modules.size(); i++) { Module m = (Module) modules.get(i); try { if (m.isEjbModule()) getDeploymentDescriptor((EjbModule) m).renameSecurityRole(existingRoleName, newRoleName); else if (m.isWebModule()) getDeploymentDescriptor((WebModule) m).renameSecurityRole(existingRoleName, newRoleName); } catch (Exception e) { throw new DeploymentDescriptorLoadException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.dd_in_ear_load_EXC_, (new Object[]{m.getUri(), getURI()})), e); // = "Exception occurred loading deployment descriptor for module "{0}" in ear file "{1}"" } } }
public void validateModuleMaps(IVirtualComponent component) { IVirtualFile ddFile = component.getRootFolder().getFile(J2EEConstants.APPLICATION_DD_URI); if( ddFile.exists()){ EList modules = appDD.getModules(); if (!modules.isEmpty()) { EARArtifactEdit edit = null; try{ edit = EARArtifactEdit.getEARArtifactEditForRead( component.getProject() ); for (int i = 0; i < modules.size(); i++) { Module module = (Module) modules.get(i); String uri = module.getUri(); IVirtualComponent referencedComp = edit.getModuleByManifestURI( uri ); if( referencedComp == null ){ String[] params = new String[]{uri, component.getProject().getName()}; String tmp = NLS.bind(EARValidationMessageResourceHandler.MISSING_PROJECT_FORMODULE_WARN_, params); addLocalizedWarning(tmp, null); } validateModuleURIExtension(module); } }finally{ if( edit != null ) edit.dispose(); } } } }
/** * @see com.ibm.etools.commonarchive.EARFile */ public SecurityRole addCopy(SecurityRole aRole, Module aModule) throws DuplicateObjectException { EObject dd = null; try { dd = getDeploymentDescriptor(aModule); } catch (Exception e) { throw new DeploymentDescriptorLoadException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.dd_in_ear_load_EXC_, (new Object[]{aModule.getUri(), getURI()})), e); // = "Exception occurred loading deployment descriptor for module "{0}" in ear file "{1}"" } String roleName = aRole.getRoleName(); SecurityRole copy = (SecurityRole) EtoolsCopyUtility.createCopy(aRole); if (aModule.isEjbModule()) { EJBJar ejbJar = (EJBJar) dd; if (ejbJar.containsSecurityRole(roleName)) throw new DuplicateObjectException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.dup_sec_role_module_EXC_, (new Object[]{aModule.getUri(), roleName})), ejbJar.getAssemblyDescriptor().getSecurityRoleNamed(roleName)); // = "Deployment descriptor for {0} already contains a security role named {1}" getAssemblyDescriptorAddIfNecessary(ejbJar).getSecurityRoles().add(copy); } else if (aModule.isWebModule()) { WebApp webApp = (WebApp) dd; if (webApp.containsSecurityRole(roleName)) throw new DuplicateObjectException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.dup_sec_role_module_EXC_, (new Object[]{aModule.getUri(), roleName})), webApp.getSecurityRoleNamed(roleName));// = "Deployment descriptor for {0} already contains a security role named {1}" webApp.getSecurityRoles().add(copy); } addCopyIfNotExists(aRole); return copy; }
/** * @see com.ibm.etools.commonarchive.EARFile */ public void rollUpRoles(Module aModule) { List securityRoles = null; try { if (aModule.isWebModule()) securityRoles = getDeploymentDescriptor((WebModule) aModule).getSecurityRoles(); else if (aModule.isEjbModule()) securityRoles = getAssemblyDescriptorAddIfNecessary(getDeploymentDescriptor((EjbModule) aModule)).getSecurityRoles(); } catch (Exception e) { throw new DeploymentDescriptorLoadException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.dd_in_ear_load_EXC_, (new Object[]{aModule.getUri(), getURI()})), e); // = "Exception occurred loading deployment descriptor for module "{0}" in ear file "{1}"" } if (securityRoles == null) return; for (int i = 0; i < securityRoles.size(); i++) { addCopyIfNotExists((SecurityRole) securityRoles.get(i)); } }
/** * @see EARFile */ public void pushDownRole(SecurityRole role, Module aModule) { try { if (aModule.isWebModule()) { WebApp dd = getDeploymentDescriptor((WebModule) aModule); if (dd.getSecurityRoleNamed(role.getRoleName()) == null) dd.getSecurityRoles().add(EtoolsCopyUtility.createCopy(role)); } else if (aModule.isEjbModule()) { AssemblyDescriptor assembly = getAssemblyDescriptorAddIfNecessary(getDeploymentDescriptor((EjbModule) aModule)); if (assembly.getSecurityRoleNamed(role.getRoleName()) == null) assembly.getSecurityRoles().add(EtoolsCopyUtility.createCopy(role)); } } catch (Exception e) { throw new DeploymentDescriptorLoadException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.dd_in_ear_load_EXC_, (new Object[]{aModule.getUri(), getURI()})), e); // = "Exception occurred loading deployment descriptor for module "{0}" in ear file "{1}"" } }
/** * @see com.ibm.etools.commonarchive.EARFile */ public EList getRolesFromModule(Module aModule) { EList roleList = new org.eclipse.emf.common.util.BasicEList(); try { if (aModule.isWebModule()) roleList = getDeploymentDescriptor((WebModule) aModule).getSecurityRoles(); else if (aModule.isEjbModule()) roleList = getAssemblyDescriptorAddIfNecessary(getDeploymentDescriptor((EjbModule) aModule)).getSecurityRoles(); } catch (Exception e) { throw new DeploymentDescriptorLoadException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.dd_in_ear_load_EXC_, (new Object[]{aModule.getUri(), getURI()})), e); // = "Exception occurred loading deployment descriptor for module "{0}" in ear file "{1}"" } return roleList; }
protected Archive openNestedArchive(Module m, ArchiveOptions archiveOptions) throws OpenFailureException { String aUri = m.getUri(); try { /* * Since we have a clue about the type of archive to open Use the appropriate open * method, so if a failure occurrs, we can get a more specific message */ if (m.isWebModule()) return getCommonArchiveFactory().openWARFile(archiveOptions, aUri); else if (m.isEjbModule()) return getCommonArchiveFactory().openEJBJarFile(archiveOptions, aUri); else if (m.isJavaModule()) return getCommonArchiveFactory().openApplicationClientFile(archiveOptions, aUri); else if (m.isConnectorModule()) return getCommonArchiveFactory().openRARFile(archiveOptions, aUri); } catch (OpenFailureException ex) { throw new OpenFailureException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.nested_open_fail_EXC_, (new Object[]{aUri, getURI()})), ex); // = "Unable to open module file "{0}" in EAR file "{1}"" } //Should never reach the code below return null; }
protected void checkType(Module moduleDescriptor, File aFile) { if (aFile == null) { String message = CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.A_file_does_not_exist_for_module, new Object[]{moduleDescriptor.getUri()}); throw new NoModuleFileException(message); } //Added for defect 113929 boolean isValid = true; String type = CommonArchiveResourceHandler.Module_file; if (moduleDescriptor.isWebModule() && !aFile.isWARFile()) { isValid = false; type = CommonArchiveResourceHandler.A_WAR_file; } else if (moduleDescriptor.isEjbModule() && !aFile.isEJBJarFile()) { isValid = false; type = CommonArchiveResourceHandler.An_EJB_JAR_file; } else if (moduleDescriptor.isJavaModule() && !aFile.isApplicationClientFile()) { isValid = false; type = CommonArchiveResourceHandler.An_Application_Client_JAR_file; } else if (moduleDescriptor.isConnectorModule() && !aFile.isRARFile()) { isValid = false; type = CommonArchiveResourceHandler.A_RAR_file; } else if (!aFile.isModuleFile()) isValid = false; if (isValid) return; String earUri = ""; //$NON-NLS-1$ if (getEarFile() != null) earUri = getEarFile().getURI(); String message = CommonArchiveResourceHandler.getString("File_not_correct_type", new Object[]{aFile.getURI(), earUri, type}); //$NON-NLS-1$ throw new ArchiveRuntimeException(message); }