001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.bpmscript.jbi.component;
018:
019: import java.io.ByteArrayOutputStream;
020:
021: import javax.xml.namespace.QName;
022:
023: import org.apache.servicemix.common.BaseLifeCycle;
024: import org.apache.servicemix.common.Endpoint;
025: import org.apache.servicemix.jbi.util.FileUtil;
026: import org.springframework.core.io.Resource;
027:
028: /**
029: *
030: * @org.apache.xbean.XBean element="component"
031: * description="My component"
032: */
033: public class InMemoryBpmScriptSpringComponent extends
034: BpmScriptSpringComponent {
035:
036: /* (non-Javadoc)
037: * @see org.servicemix.common.BaseComponent#createLifeCycle()
038: */
039: protected BaseLifeCycle createLifeCycle() {
040: return new LifeCycle();
041: }
042:
043: public InMemoryBpmScriptLifeCycle getInMemoryBpmScriptLifeCycle() {
044: return (InMemoryBpmScriptLifeCycle) getLifeCycle();
045: }
046:
047: public void setAlarmEndpoint(Endpoint alarmEndpoint) {
048: getInMemoryBpmScriptLifeCycle().setAlarmEndpoint(alarmEndpoint);
049: }
050:
051: /**
052: * @author gnodet
053: */
054: public class LifeCycle extends InMemoryBpmScriptLifeCycle {
055:
056: public LifeCycle() {
057: super (InMemoryBpmScriptSpringComponent.this );
058: }
059:
060: /* (non-Javadoc)
061: * @see org.servicemix.common.BaseLifeCycle#doInit()
062: */
063: protected void doInit() throws Exception {
064: super .doInit();
065: if (endpoints != null) {
066: for (int i = 0; i < endpoints.length; i++) {
067: ProcessEndpoint processEndpoint = (ProcessEndpoint) endpoints[i];
068: String processId = processManager.createProcess(
069: "spring", processEndpoint.getEndpoint(),
070: true);
071: Resource resource = resourceLoader
072: .getResource(processEndpoint
073: .getSourceResource());
074: ByteArrayOutputStream out = new ByteArrayOutputStream();
075: FileUtil.copyInputStream(resource.getInputStream(),
076: out);
077: processManager.addSourceToProcess(processId,
078: "main", out.toString(), true);
079: processManager.setProcessAsPrimary(processId);
080: processEndpoint.setProcessId(processId);
081: processEndpoint
082: .setProcessInstanceManager(processInstanceManager);
083: processEndpoint.setProcessExecutor(processExecutor);
084: processEndpoint.setService(new QName(
085: defaultNamespace, processEndpoint
086: .getEndpoint()));
087: endpoints[i].setServiceUnit(processServiceUnit);
088: endpoints[i].validate();
089: processServiceUnit.addEndpoint(endpoints[i]);
090: component.getRegistry().registerEndpoint(
091: processEndpoint);
092: }
093: }
094: }
095:
096: /* (non-Javadoc)
097: * @see org.servicemix.common.BaseLifeCycle#doStart()
098: */
099: protected void doStart() throws Exception {
100: super .doStart();
101: }
102:
103: /* (non-Javadoc)
104: * @see org.servicemix.common.BaseLifeCycle#doStop()
105: */
106: protected void doStop() throws Exception {
107: super .doStop();
108: }
109:
110: /* (non-Javadoc)
111: * @see org.servicemix.common.BaseLifeCycle#doShutDown()
112: */
113: protected void doShutDown() throws Exception {
114: super.doShutDown();
115: }
116: }
117:
118: }
|