Providing Server Elements
The server can contain multiple ServerElement objects which represent objects on the server (usually existing modules). They are displayed in the Project Explorer under the server and can be arranged in a hierarchical structure:
The refreshServerContent() method from the Connection interface is responsible for providing and updating server elements. The following example shows an implementation of the method for a WebDAV server.
public void refreshServerContent() throws ConnectionException { if (isConnected() && siteHandle != null) { try { refreshServer(siteHandle); } catch (DAVException e) { server.getServerElements().clear(); disconnect(); throw new ConnectionException(e); } } else { server.getServerElements().clear(); } } private void refreshServer(CollectionHandle site) throws DAVException { boolean showSubfolders = Boolean.parseBoolean(WebDavConstants .getConfigParamValue(server.getServerConfig(), WebDavConstants.SHOW_SUBFOLDERS)); HashSet<String> existingFileNames = new HashSet<String>(); HashSet<String> existingDirNames = new HashSet<String>(); Set<AbstractResourceHandle> members = site.getMembers(); for (Iterator iter = server.getServerElements().iterator(); iter .hasNext();) { ServerElement se = (ServerElement) iter.next(); String name = se.getName(); if (se instanceof ModuleContainer) { boolean exist = false; for (AbstractResourceHandle member : members) { if (isCollectionMember(member) && name.equals(getMemberName(member))) { if (showSubfolders) { refreshCollection((CollectionHandle) member, (ContainerElement) se); } exist = true; existingDirNames.add(name); } } if (!exist) { iter.remove(); } } else if (se instanceof ServerModule) { boolean exist = false; for (AbstractResourceHandle member : members) { if (!isCollectionMember(member) && name.equals(getMemberName(member))) { setModuleProperties((ServerModule) se, member); exist = true; existingFileNames.add(name); } } if (!exist) { iter.remove(); } } } for (AbstractResourceHandle member : members) { String memberName = getMemberName(member); if (isCollectionMember(member)) { if (!existingDirNames.contains(memberName)) { ModuleContainer moduleContainer = DeployFactory.eINSTANCE .createModuleContainer(); moduleContainer.setName(memberName); if (showSubfolders) { refreshCollection((CollectionHandle) member, moduleContainer); } server.getServerElements().add(moduleContainer); } } else { if (!existingFileNames.contains(memberName)) { ServerModule module = DeployFactory.eINSTANCE .createServerModule(); module.setName(memberName); setModuleProperties(module, member); server.getServerElements().add(module); } } } }
During the method invocation, we connect to the WebDAV server and obtain remote resources’ information. Then we create corresponding server modules and/or update their state and properties.
When the user disconnects from the server, all server elements should be removed.
In a future implementation, the server elements could be enhanced to better support hierarchical structures of server objects.