Coverage Report - org.codehaus.plexus.component.repository.exception.ComponentLookupException
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentLookupException
34 %
10/29
0 %
0/2
1,2
 
 1  
 package org.codehaus.plexus.component.repository.exception;
 2  
 
 3  
 import java.io.ByteArrayOutputStream;
 4  
 import java.io.PrintStream;
 5  
 
 6  
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 7  
 
 8  
 /*
 9  
  * Copyright 2001-2006 Codehaus Foundation.
 10  
  *
 11  
  * Licensed under the Apache License, Version 2.0 (the "License");
 12  
  * you may not use this file except in compliance with the License.
 13  
  * You may obtain a copy of the License at
 14  
  *
 15  
  *      http://www.apache.org/licenses/LICENSE-2.0
 16  
  *
 17  
  * Unless required by applicable law or agreed to in writing, software
 18  
  * distributed under the License is distributed on an "AS IS" BASIS,
 19  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 20  
  * See the License for the specific language governing permissions and
 21  
  * limitations under the License.
 22  
  */
 23  
 
 24  
 /**
 25  
  * The exception which is thrown by a component repository when
 26  
  * the requested component cannot be found.
 27  
  *
 28  
  * @author Jason van Zyl
 29  
  * @version $Id$
 30  
  */
 31  
 public class ComponentLookupException
 32  
     extends Exception
 33  
 {
 34  31
     private String LS = System.getProperty( "line.separator" );
 35  
 
 36  
     private String role;
 37  
 
 38  
     private String roleHint;
 39  
 
 40  
     private ClassRealm realm;
 41  
 
 42  
     public ComponentLookupException( String message, String role, String roleHint )
 43  
     {
 44  28
         super( message );
 45  
 
 46  28
         this.role = role;
 47  
 
 48  28
         this.roleHint = roleHint;
 49  28
     }
 50  
 
 51  
     public ComponentLookupException( String message, String role, String roleHint, Throwable cause )
 52  
     {
 53  0
         super( message, cause );
 54  
 
 55  0
         this.role = role;
 56  
 
 57  0
         this.roleHint = roleHint;
 58  0
     }
 59  
 
 60  
     public ComponentLookupException( String message, String role, String roleHint, ClassRealm realm )
 61  
     {
 62  0
         super( message );
 63  
 
 64  0
         this.role = role;
 65  
 
 66  0
         this.roleHint = roleHint;
 67  
 
 68  0
         this.realm = realm;
 69  0
     }
 70  
 
 71  
     public ComponentLookupException( String message, String role, String roleHint, ClassRealm realm, Throwable cause )
 72  
     {
 73  3
         super( message, cause );
 74  
 
 75  3
         this.role = role;
 76  
 
 77  3
         this.roleHint = roleHint;
 78  
 
 79  3
         this.realm = realm;
 80  3
     }
 81  
 
 82  
     public String getMessage()
 83  
     {
 84  0
         StringBuilder sb = new StringBuilder()
 85  
             .append( super.getMessage() ).append( LS )
 86  
             .append( "      role: ").append( role ).append( LS )
 87  
             .append( "  roleHint: ").append( roleHint ).append( LS )
 88  
             .append("classRealm: ");
 89  
 
 90  0
         if ( realm != null )
 91  
         {
 92  0
             sb.append( realm.getId() ).append( LS );
 93  0
             ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 );
 94  0
             PrintStream ps = new PrintStream( os );
 95  0
             realm.display( ps );
 96  0
             sb.append( os.toString() );
 97  0
         }
 98  
         else
 99  
         {
 100  0
             sb.append( "none specified" );
 101  
         }
 102  
 
 103  0
         return sb.toString();
 104  
     }
 105  
 }