01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.workflow.serverimpl.httpconnector.handlers;
17:
18: import org.outerj.daisy.repository.Repository;
19: import org.outerj.daisy.repository.ConcurrentUpdateException;
20: import org.outerj.daisy.workflow.WorkflowManager;
21: import org.outerj.daisy.workflow.WfPoolManager;
22: import org.outerj.daisy.workflow.WfPool;
23: import org.outerj.daisy.httpconnector.spi.HttpUtil;
24: import org.outerj.daisy.httpconnector.spi.RequestHandlerSupport;
25: import org.outerj.daisy.xmlutil.LocalSAXParserFactory;
26: import org.outerj.daisy.util.HttpConstants;
27: import org.apache.xmlbeans.XmlOptions;
28: import org.outerx.daisy.x10Workflow.PoolDocument;
29:
30: import javax.servlet.http.HttpServletRequest;
31: import javax.servlet.http.HttpServletResponse;
32: import java.util.Map;
33:
34: public class PoolHandler extends AbstractWorkflowRequestHandler {
35: public void handleRequest(Map matchMap, HttpServletRequest request,
36: HttpServletResponse response, Repository repository,
37: RequestHandlerSupport support) throws Exception {
38: long id = HttpUtil.parseId("pool", (String) matchMap.get("1"));
39:
40: WorkflowManager workflowManager = (WorkflowManager) repository
41: .getExtension("WorkflowManager");
42: WfPoolManager poolManager = workflowManager.getPoolManager();
43:
44: if (request.getMethod().equals(HttpConstants.GET)) {
45: WfPool pool = poolManager.getPool(id);
46: pool.getXml().save(response.getOutputStream());
47: } else if (request.getMethod().equals(HttpConstants.POST)) {
48: XmlOptions xmlOptions = new XmlOptions()
49: .setLoadUseXMLReader(LocalSAXParserFactory
50: .newXmlReader());
51: PoolDocument poolDocument = PoolDocument.Factory.parse(
52: request.getInputStream(), xmlOptions);
53:
54: WfPool pool = poolManager.getPool(id);
55: if (pool.getUpdateCount() != poolDocument.getPool()
56: .getUpdateCount())
57: throw new ConcurrentUpdateException(WfPool.class
58: .getName(), String.valueOf(pool.getId()));
59:
60: pool.setAllFromXml(poolDocument.getPool());
61: pool.save();
62:
63: pool.getXml().save(response.getOutputStream());
64: } else if (request.getMethod().equals(HttpConstants.DELETE)) {
65: poolManager.deletePool(id);
66: } else {
67: response.sendError(HttpConstants._405_Method_Not_Allowed);
68: }
69: }
70:
71: public String getPathPattern() {
72: return "/pool/*";
73: }
74: }
|