1 /* 2 * Copyright (c) 2007, Fraunhofer-Gesellschaft 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * (1) Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the disclaimer at the end. 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * (2) Neither the name of Fraunhofer nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * DISCLAIMER 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 */ 35 package org.ogf.graap.wsag.security.core.server; 36 37 import java.io.IOException; 38 import java.io.InputStream; 39 import java.net.URL; 40 import java.util.Enumeration; 41 42 import org.ogf.graap.wsag.api.configuration.WSAG4JConfiguration; 43 44 /** 45 * WSAG4JClassLoader 46 * 47 * @author Oliver Waeldrich 48 * 49 */ 50 public class MerlinClassLoader extends ClassLoader 51 { 52 53 private ClassLoader loader; 54 55 /** 56 * Use the specified class loader as standard <code>ClassLoader</code>. Only resource resolving is 57 * customized by WSAG4J resource lookup. 58 * 59 * @param loader 60 * the class loader to use 61 */ 62 public MerlinClassLoader( ClassLoader loader ) 63 { 64 this.loader = loader; 65 } 66 67 /** 68 * @param name 69 * {@inheritDoc} 70 * @return {@inheritDoc} 71 */ 72 public URL getResource( String name ) 73 { 74 URL resource = loader.getResource( name ); 75 76 if ( resource == null ) 77 { 78 try 79 { 80 resource = WSAG4JConfiguration.findResourceURL( name ); 81 } 82 catch ( Exception e ) 83 { 84 return resource; 85 } 86 } 87 88 return resource; 89 } 90 91 /** 92 * @param name 93 * {@inheritDoc} 94 * @return {@inheritDoc} 95 * @see java.lang.ClassLoader#getResourceAsStream(java.lang.String) 96 */ 97 public InputStream getResourceAsStream( String name ) 98 { 99 InputStream resource = loader.getResourceAsStream( name ); 100 101 if ( resource == null ) 102 { 103 try 104 { 105 resource = WSAG4JConfiguration.findResource( name ); 106 } 107 catch ( Exception e ) 108 { 109 return resource; 110 } 111 } 112 return resource; 113 } 114 115 /** 116 * 117 * @see java.lang.ClassLoader#clearAssertionStatus() 118 */ 119 public void clearAssertionStatus() 120 { 121 loader.clearAssertionStatus(); 122 } 123 124 /** 125 * {@inheritDoc} 126 * 127 * @see java.lang.Object#equals(java.lang.Object) 128 */ 129 public boolean equals( Object obj ) 130 { 131 return loader.equals( obj ); 132 } 133 134 /** 135 * {@inheritDoc} 136 */ 137 public int hashCode() 138 { 139 return loader.hashCode(); 140 } 141 142 /** 143 * @param name 144 * {@inheritDoc} 145 * @return {@inheritDoc} 146 * @throws IOException 147 * @see java.lang.ClassLoader#getResources(java.lang.String) 148 */ 149 public Enumeration<URL> getResources( String name ) throws IOException 150 { 151 return loader.getResources( name ); 152 } 153 154 /** 155 * @param name 156 * {@inheritDoc} 157 * @return {@inheritDoc} 158 * @throws ClassNotFoundException 159 * @see java.lang.ClassLoader#loadClass(java.lang.String) 160 */ 161 public Class<?> loadClass( String name ) throws ClassNotFoundException 162 { 163 return loader.loadClass( name ); 164 } 165 166 /** 167 * {@inheritDoc} 168 * 169 * @see java.lang.ClassLoader#setClassAssertionStatus(java.lang.String, boolean) 170 */ 171 public void setClassAssertionStatus( String className, boolean enabled ) 172 { 173 loader.setClassAssertionStatus( className, enabled ); 174 } 175 176 /** 177 * {@inheritDoc} 178 * 179 * @see java.lang.ClassLoader#setDefaultAssertionStatus(boolean) 180 */ 181 public void setDefaultAssertionStatus( boolean enabled ) 182 { 183 loader.setDefaultAssertionStatus( enabled ); 184 } 185 186 /** 187 * {@inheritDoc} 188 * 189 * @see java.lang.ClassLoader#setPackageAssertionStatus(java.lang.String, boolean) 190 */ 191 public void setPackageAssertionStatus( String packageName, boolean enabled ) 192 { 193 loader.setPackageAssertionStatus( packageName, enabled ); 194 } 195 }