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.geronimo.common;
018    
019    /**
020     * A problem with an EJB reference
021     *
022     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
023     */
024    public class UnresolvedEJBRefException extends DeploymentException {
025        private final String refName;
026        private final boolean local;
027        private final boolean session;
028        private final String homeInterface;
029        private final String beanInterface;
030    
031        public UnresolvedEJBRefException(String refName, boolean local, boolean session, String homeInterface,
032                                         String beanInterface, boolean foundMultiple) {
033            super(createMessage(refName, local, session, homeInterface, beanInterface, foundMultiple));
034            this.refName = refName;
035            this.local = local;
036            this.session = session;
037            this.homeInterface = homeInterface;
038            this.beanInterface = beanInterface;
039        }
040    
041        public String getRefName() {
042            return refName;
043        }
044    
045        public boolean isLocal() {
046            return local;
047        }
048    
049        public boolean isSession() {
050            return session;
051        }
052    
053        public String getHomeInterface() {
054            return homeInterface;
055        }
056    
057        public String getBeanInterface() {
058            return beanInterface;
059        }
060    
061        private static String createMessage(String refName, boolean local, boolean session, String homeInterface,
062                                         String beanInterface, boolean foundMultiple) {
063            StringBuffer msg = new StringBuffer();
064            if (foundMultiple) {
065                msg.append("Two or more EJBs were found");
066            } else {
067                msg.append("Could not find an EJB");
068            }
069            msg.append(" for reference ").append(refName).append(" to a ");
070            msg.append((local ? "local " : "remote "));
071            msg.append((session ? "session" : "entity"));
072    
073            msg.append(" bean that has the home interface ").append(homeInterface);
074            msg.append(" and the ").append(local ? "local" : "remote");
075            msg.append(" interface ").append(beanInterface);
076    
077            return msg.toString();
078        }
079    }