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.http.packaging;
018
019 import java.util.ArrayList;
020 import java.util.List;
021
022 import javax.jbi.messaging.MessageExchange;
023
024 import org.apache.servicemix.common.Endpoint;
025 import org.apache.servicemix.common.packaging.Consumes;
026 import org.apache.servicemix.common.xbean.AbstractXBeanServiceUnitAnalyzer;
027 import org.apache.servicemix.http.HttpEndpoint;
028
029 /**
030 * Implementation of the ServiceUnitAnalyzer can be used in tooling to provide a
031 * way to parse the artifact for the service unit and provide a list of consumes
032 * and provides
033 *
034 * @author Philip Dodds
035 * @see org.apache.servicemix.common.packaging.ServiceUnitAnalyzer , {@link org.apache.servicemix.common.packaging.ServiceUnitAnalyzer}
036 * @since 3.0
037 */
038 public class HttpServiceUnitAnalyzer extends AbstractXBeanServiceUnitAnalyzer {
039
040 protected List getConsumes(Endpoint endpoint) {
041 List consumesList = new ArrayList();
042 Consumes consumes;
043 if (endpoint.getRole().equals(MessageExchange.Role.CONSUMER)) {
044 consumes = new Consumes();
045 HttpEndpoint httpEndpoint = (HttpEndpoint) endpoint;
046 consumes.setEndpointName(httpEndpoint.getTargetEndpoint());
047 consumes.setInterfaceName(httpEndpoint.getTargetInterfaceName());
048 consumes.setServiceName(httpEndpoint.getTargetService());
049 if (consumes.isValid()) {
050 consumesList.add(consumes);
051 } else {
052 consumes = new Consumes();
053 consumes.setEndpointName(endpoint.getEndpoint());
054 consumes.setInterfaceName(endpoint.getInterfaceName());
055 consumes.setServiceName(endpoint.getService());
056 consumesList.add(consumes);
057 }
058 }
059
060 return consumesList;
061 }
062
063 protected String getXBeanFile() {
064 return "xbean.xml";
065 }
066
067 protected boolean isValidEndpoint(Object bean) {
068 return bean instanceof HttpEndpoint;
069 }
070
071 }