001    /**
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.ksb.api.bus.support;
017    
018    import org.kuali.rice.core.api.util.ClassLoaderUtils;
019    import org.kuali.rice.ksb.api.KsbApiConstants;
020    import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
021    
022    import java.util.ArrayList;
023    import java.util.List;
024    
025    /**
026     * @author Kuali Rice Team (rice.collab@kuali.org)
027     */
028    public class JavaServiceDefinition extends AbstractServiceDefinition {
029            
030            private List<String> serviceInterfaces = new ArrayList<String>();
031    
032            @Override
033            public String getType() {
034                    return KsbApiConstants.ServiceTypes.HTTP_INVOKER;
035            }
036            
037            public List<String> getServiceInterfaces() {
038                    return this.serviceInterfaces;
039            }
040            public void setServiceInterfaces(List<String> serviceInterfaces) {
041                    this.serviceInterfaces = serviceInterfaces;
042            }
043            public void setServiceInterface(String serviceName) {
044                this.serviceInterfaces.add(serviceName);
045            }
046            public String getServiceInterface() {
047                    return this.serviceInterfaces.get(0);
048            }
049            
050            @Override
051            public void validate() {
052                    super.validate();
053                    if (this.serviceInterfaces == null || this.serviceInterfaces.isEmpty()) {
054                            Class<?>[] interfaces = ClassLoaderUtils.getInterfacesToProxy(getService(), null, null);
055                            for (Class<?> serviceInterfaceClass : interfaces) {
056                                this.serviceInterfaces.add(serviceInterfaceClass.getName());
057                            }
058                    }
059            }
060            
061            protected ServiceConfiguration configure() {
062                    return JavaServiceConfiguration.fromServiceDefinition(this);
063            }
064            
065            /**
066         * Defines some internal constants used on this class.
067         */
068        static class Constants {
069            final static String ROOT_ELEMENT_NAME = "javaServiceDefinition";
070            final static String TYPE_NAME = "JavaServiceDefinitionType";
071        }
072    
073        /**
074         * A private class which exposes constants which define the XML element names to use
075         * when this object is marshalled to XML.
076         */
077        protected static class Elements {
078            protected final static String SERVICE_INTERFACES = "serviceInterfaces";
079            protected final static String SERVICE_INTERFACE = "serviceInterface";
080        }
081            
082    }