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    
018    package org.apache.geronimo.kernel.repository;
019    
020    import java.util.Stack;
021    import java.io.Serializable;
022    
023    import org.apache.geronimo.gbean.AbstractNameQuery;
024    
025    /**
026     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
027     */
028    public class MissingDependencyException extends Exception {
029        private static final long serialVersionUID = -2557777157677213124L;
030        private Artifact query;
031        private Stack<Artifact> stack;
032    
033    
034        public MissingDependencyException(Artifact query) {
035            super();
036            this.query = query;
037        }
038    
039        public MissingDependencyException(Artifact query, Stack<Artifact> stack) {
040            super();
041            this.query = query;
042            this.stack = stack;
043        }
044    
045        public MissingDependencyException(Artifact query, Artifact parent) {
046            super();
047            this.query = query;
048            this.stack = new Stack<Artifact>();
049            if (parent != null) {
050                this.stack.add(parent);
051            }
052        }
053        public MissingDependencyException(String message, Artifact query, Stack<Artifact> stack) {
054            super(message);
055            this.query = query;
056            this.stack = stack;
057        }
058    
059        public MissingDependencyException(String message, Artifact query, Artifact parent) {
060            super(message);
061            this.query = query;
062            this.stack = new Stack<Artifact>();
063            if (parent != null) {
064                this.stack.add(parent);
065            }
066        }
067    
068        public String getMessage() {
069            String s = super.getMessage();
070            StringBuffer sb = new StringBuffer();
071            if (s != null) {
072                sb.append(s).append("\n");
073            }
074            if (query != null) {
075                sb.append("Missing dependency: ").append(query);
076            }
077            if (stack != null && !stack.isEmpty()) {
078                sb.append("\nParent stack:\n");
079                for (Artifact parent: stack) {
080                    sb.append("    ").append(parent).append("\n");
081                }
082    
083            }
084            return sb.toString();
085        }
086    
087    
088        public Artifact getQuery() {
089            return query;
090        }
091    
092        public void setQuery(Artifact query) {
093            this.query = query;
094        }
095    
096        public Stack<Artifact> getStack() {
097            return stack;
098        }
099    
100        public void setStack(Stack<Artifact> stack) {
101            this.stack = stack;
102        }
103    }