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.xbean.kernel; 018 019 /** 020 * Indicates that the service factory returned an object from the createService method that is not an instance of every 021 * declared type. 022 * 023 * @author Dain Sundstrom 024 * @version $Id$ 025 * @since 2.0 026 */ 027 public class InvalidServiceTypeException extends Exception { 028 private final ServiceName serviceName; 029 private final Class expectedType; 030 private final Class serviceType; 031 032 /** 033 * Creates an InvalidServiceType caused by the service with the specified name, which returned an object from the 034 * createService method of the specified type that is not an instance of the expected type. 035 * @param serviceName the name of the service that returned an object of the wrong type 036 * @param expectedType the type that was expected 037 * @param serviceType the actual type of the service returned from the factory 038 */ 039 // todo add servicefacotory to the parameters 040 public InvalidServiceTypeException(ServiceName serviceName, Class expectedType, Class serviceType) { 041 super("Expected service type " + expectedType.getName() + ", but service factory created a " + 042 serviceType.getName() + " for service " + serviceName); 043 if (serviceName == null) throw new NullPointerException("serviceName is null"); 044 if (expectedType == null) throw new NullPointerException("expectedType is null"); 045 if (serviceType == null) throw new NullPointerException("serviceType is null"); 046 this.serviceName = serviceName; 047 this.expectedType = expectedType; 048 this.serviceType = serviceType; 049 } 050 051 /** 052 * Gets the name of the service that returned an object of the wrong type. 053 * @return the name of the service that returned an object of the wrong type 054 */ 055 public ServiceName getServiceName() { 056 return serviceName; 057 } 058 059 /** 060 * Gets the type that was expected. 061 * @return the type that was expected 062 */ 063 public Class getExpectedType() { 064 return expectedType; 065 } 066 067 /** 068 * Gets the actual type of the service returned from the factory. 069 * @return the actual type of the service returned from the factory 070 */ 071 public Class getServiceType() { 072 return serviceType; 073 } 074 }