1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| package org.hello.ws.impl;
import javax.jws.WebService;
import org.weblab_project.core.model.ComposedUnit;
import org.weblab_project.core.model.Document;
import org.weblab_project.core.model.Resource;
import org.weblab_project.core.model.text.Text;
import org.weblab_project.services.analyser.types.ProcessArgs;
import org.weblab_project.services.analyser.types.ProcessReturn;
import org.weblab_project.services.documentanalysis.Analyser;
import org.weblab_project.services.documentanalysis.ProcessException;
import org.weblab_project.services.exception.WebLabException;
@WebService(endpointInterface = "org.weblab_project.services.documentanalysis.Analyser")
public class HelloService implements Analyser {
public ProcessReturn process(ProcessArgs args) throws ProcessException {
Resource resource = args.getResource();
// add a text unit if it is a Document
if (resource instanceof Document) {
ComposedUnit original = (ComposedUnit) resource;
Text hello = new Text();
// setting a fake content
hello.setContent("Hello !");
// adding URI to the new Text
// /! service should ensure that this URI is unique
// in the composedUnit scope
hello.setUri(original.getUri() + "#"
+ original.getMediaUnit().size());
// adding the Text to the composedUnit
original.getMediaUnit().add(hello);
// if not a Document throw a WebLab exception
} else {
WebLabException ex = new WebLabException();
ex
.setErrorMessage("HelloService parameter must be a Document and not a "
+ resource.getClass() + ".");
ex.setErrorId("E1");
throw new ProcessException("ProcessException : ", ex);
}
// construct and return the response
ProcessReturn out = new ProcessReturn();
out.setResource(resource);
return out;
}
} |
Partager