Implementing Operations for ServerElements
To implement operations for server elements, you must define the following:
- Types of elements
- Possible states for a defined element type
- Operations that can be performed
- Operations that can be performed when an element is in a particular state
It is also necessary to set the correct type and state for every server element created when calling the refreshServer method.
The following code fragment shows how to create and configure all necessary elements to implement a WebDAV module (file) delete operation.
private OperationImpl deleteFileOperation;
private ServerElementType fileType;
private ServerElementState publishedState;
private void initialiseServerElementTypes() {
DeployFactory f = DeployFactory.eINSTANCE;
fileType = f.createServerElementType();
// states. States should not be shared between different element types
publishedState = f.createServerElementState();
publishedState.setName("Published");
// all states server element type could be in
fileType.getStates().add(publishedState);
// operations
deleteFileOperation = new OperationImpl() {
@Override
public Object execute(ServerElement serverElement)
throws DeploymentException {
try {
return deleteRemoteFile(serverElement);
} finally {
refreshServerContent();
}
}
};
deleteFileOperation.setName("Delete");
// all available operations for server element type
fileType.getOperations().add(deleteFileOperation);
// possible operations for states
publishedState.getPossibleOperations().add(deleteFileOperation);
}
Also when you create modules using the refreshServer method, you must set an element’s type and state as follows:
serverElement.setServerElementType(fileType); serverElement.setServerElementState(publishedState);
Copyright © Cloud Software Group, Inc. All rights reserved.
