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.apache.servicemix.script;
018
019 import java.util.ArrayList;
020 import java.util.Iterator;
021 import java.util.List;
022
023 import javax.jbi.messaging.MessageExchange;
024 import javax.jbi.messaging.MessagingException;
025
026 import org.apache.servicemix.common.ExchangeProcessor;
027 import org.apache.servicemix.common.endpoints.ProviderEndpoint;
028
029 /**
030 * @org.apache.xbean.XBean element="exchangeProcessor"
031 */
032 public class ScriptExchangeProcessorEndpoint extends ProviderEndpoint {
033
034 private ExchangeProcessor implementation;
035
036 private List helpers = new ArrayList();
037
038 public List getHelpers() {
039 return helpers;
040 }
041
042 public void setHelpers(List helpers) {
043 this.helpers = helpers;
044 for (Iterator iterator = helpers.iterator(); iterator.hasNext();) {
045 Object nextHelper = iterator.next();
046 if (nextHelper instanceof ScriptHelper) {
047 ((ScriptHelper) nextHelper).setScriptExchangeProcessorEndpoint(this);
048 }
049 }
050 }
051
052 public ExchangeProcessor getImplementation() {
053 return implementation;
054 }
055
056 public void setImplementation(ExchangeProcessor implementation) {
057 this.implementation = implementation;
058 }
059
060 public void start() throws Exception {
061 super.start();
062 logger = this.serviceUnit.getComponent().getLogger();
063 if (implementation != null) {
064 implementation.start();
065 }
066 }
067
068 public void stop() throws Exception {
069 if (implementation != null) {
070 try {
071 implementation.stop();
072 } catch (Exception e) {
073 e.printStackTrace();
074 }
075 }
076 super.stop();
077 }
078
079 public void process(MessageExchange exchange) throws Exception {
080 if (implementation != null) {
081 implementation.process(exchange);
082 }
083 }
084
085 protected void fail(MessageExchange messageExchange, Exception e) throws MessagingException {
086 super.fail(messageExchange, e);
087 }
088
089 protected void send(MessageExchange messageExchange) throws MessagingException {
090 super.send(messageExchange);
091 }
092
093 protected void sendSync(MessageExchange messageExchange) throws MessagingException {
094 super.sendSync(messageExchange);
095 }
096
097 protected void done(MessageExchange messageExchange) throws MessagingException {
098 super.done(messageExchange);
099 }
100 }