001 /* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 package org.apache.commons.classscan.builtin; 015 016 import java.util.Collection; 017 018 import org.apache.commons.classscan.model.MetaClass; 019 import org.apache.commons.classscan.spi.model.SpiMetaClassLoader; 020 import org.apache.commons.classscan.spi.model.SpiMetaClassPathElement; 021 import org.apache.commons.classscan.spi.model.SpiMetaRegistry; 022 import org.apache.commons.classscan.util.NameSet; 023 024 public class BootstrapMetaClassLoader extends UrlMetaClassLoader { 025 026 BootstrapMetaClassLoader(SpiMetaRegistry registry) { 027 super(registry, null); 028 } 029 030 @Override 031 void addLocations(SpiMetaRegistry registry, ClassLoader classLoader) { 032 SpiMetaClassPathElement primitives= getPrimitiveClassPathElement(); 033 addLocation(primitives); 034 super.addLocations(registry, classLoader); 035 } 036 037 private SpiMetaClassPathElement getPrimitiveClassPathElement() { 038 final NameSet<PrimitiveClass> primitives = new NameSet<PrimitiveClass>(PrimitiveClass.values()); 039 040 return new SpiMetaClassPathElement() { 041 042 @Override 043 public Collection<? extends MetaClass> getMetaClasses() { 044 return primitives; 045 } 046 047 @Override 048 public MetaClass getMetaClass(String className) { 049 return primitives.getValue(className); 050 } 051 052 @Override 053 public String getName() { 054 return "<builtin-primitives>"; 055 } 056 057 @Override 058 public boolean resolve(SpiMetaClassLoader classLoader) { 059 return true; 060 } 061 062 @Override 063 public MetaClass resolveMetaClass(SpiMetaClassLoader classLoader, String className) { 064 return primitives.getValue(className); 065 } 066 }; 067 } 068 069 @Override 070 public MetaClass findMetaClass(String className) { 071 return getMetaClass(className); 072 } 073 074 @Override 075 public MetaClass resolveMetaClass(String className) { 076 return resolveInPath(className); 077 } 078 }