< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/Repository.java

Print this page


   1 /*
   2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 package com.sun.org.apache.bcel.internal;
  21 
  22 
  23 import com.sun.org.apache.bcel.internal.classfile.JavaClass;
  24 import com.sun.org.apache.bcel.internal.util.SyntheticRepository;
  25 
  26 /**
  27  * The repository maintains informations about class interdependencies, e.g.,
  28  * whether a class is a sub-class of another. Delegates actual class loading
  29  * to SyntheticRepository with current class path by default.
  30  *
  31  * @see com.sun.org.apache.bcel.internal.util.Repository
  32  * @see SyntheticRepository
  33  *
  34  * @version $Id$
  35  * @LastModified: Jun 2019
  36  */
  37 public abstract class Repository {
  38 
  39     private static com.sun.org.apache.bcel.internal.util.Repository repository
  40             = SyntheticRepository.getInstance();
  41 
  42 
  43     /** @return currently used repository instance

  44      */
  45     public static com.sun.org.apache.bcel.internal.util.Repository getRepository() {
  46         return repository;
  47     }
  48 
  49 
  50     /** Set repository instance to be used for class loading

  51      */
  52     public static void setRepository( final com.sun.org.apache.bcel.internal.util.Repository rep ) {
  53         repository = rep;
  54     }
  55 
  56 
  57     /** Lookup class somewhere found on your CLASSPATH, or whereever the

  58      * repository instance looks for it.
  59      *
  60      * @return class object for given fully qualified class name
  61      * @throws ClassNotFoundException if the class could not be found or
  62      * parsed correctly
  63      */
  64     public static JavaClass lookupClass( final String class_name ) throws ClassNotFoundException {
  65         return repository.loadClass(class_name);
  66     }
  67 
  68 
  69     /**
  70      * Try to find class source using the internal repository instance.

  71      * @see Class
  72      * @return JavaClass object for given runtime class
  73      * @throws ClassNotFoundException if the class could not be found or
  74      * parsed correctly
  75      */
  76     public static JavaClass lookupClass( final Class<?> clazz ) throws ClassNotFoundException {
  77         return repository.loadClass(clazz);
  78     }
  79 
  80 
  81     /**
  82      * Clear the repository.
  83      */
  84     public static void clearCache() {
  85         repository.clear();
  86     }
  87 
  88 
  89     /**
  90      * Add clazz to repository if there isn't an equally named class already in there.
  91      *
  92      * @return old entry in repository
  93      */
  94     public static JavaClass addClass( final JavaClass clazz ) {
  95         final JavaClass old = repository.findClass(clazz.getClassName());
  96         repository.storeClass(clazz);
  97         return old;
  98     }
  99 
 100 
 101     /**
 102      * Remove class with given (fully qualified) name from repository.
 103      */
 104     public static void removeClass( final String clazz ) {
 105         repository.removeClass(repository.findClass(clazz));
 106     }
 107 
 108 
 109     /**
 110      * Remove given class from repository.
 111      */
 112     public static void removeClass( final JavaClass clazz ) {
 113         repository.removeClass(clazz);
 114     }
 115 
 116 
 117     /**
 118      * @return list of super classes of clazz in ascending order, i.e.,
 119      * Object is always the last element
 120      * @throws ClassNotFoundException if any of the superclasses can't be found
 121      */
 122     public static JavaClass[] getSuperClasses( final JavaClass clazz ) throws ClassNotFoundException {
 123         return clazz.getSuperClasses();
 124     }
 125 
 126 
 127     /**
 128      * @return list of super classes of clazz in ascending order, i.e.,
 129      * Object is always the last element.
 130      * @throws ClassNotFoundException if the named class or any of its


   1 /*
   2  * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 package com.sun.org.apache.bcel.internal;
  21 
  22 
  23 import com.sun.org.apache.bcel.internal.classfile.JavaClass;
  24 import com.sun.org.apache.bcel.internal.util.SyntheticRepository;
  25 
  26 /**
  27  * The repository maintains informations about class interdependencies, e.g.,
  28  * whether a class is a sub-class of another. Delegates actual class loading
  29  * to SyntheticRepository with current class path by default.
  30  *
  31  * @see com.sun.org.apache.bcel.internal.util.Repository
  32  * @see SyntheticRepository
  33  *
  34  * @LastModified: Jan 2020

  35  */
  36 public abstract class Repository {
  37 
  38     private static com.sun.org.apache.bcel.internal.util.Repository repository
  39             = SyntheticRepository.getInstance();
  40 
  41 
  42     /**
  43      * @return currently used repository instance
  44      */
  45     public static com.sun.org.apache.bcel.internal.util.Repository getRepository() {
  46         return repository;
  47     }
  48 
  49 
  50     /**
  51      * Sets repository instance to be used for class loading
  52      */
  53     public static void setRepository( final com.sun.org.apache.bcel.internal.util.Repository rep ) {
  54         repository = rep;
  55     }
  56 
  57 
  58     /**
  59      * Lookups class somewhere found on your CLASSPATH, or whereever the
  60      * repository instance looks for it.
  61      *
  62      * @return class object for given fully qualified class name
  63      * @throws ClassNotFoundException if the class could not be found or
  64      * parsed correctly
  65      */
  66     public static JavaClass lookupClass( final String class_name ) throws ClassNotFoundException {
  67         return repository.loadClass(class_name);
  68     }
  69 
  70 
  71     /**
  72      * Tries to find class source using the internal repository instance.
  73      *
  74      * @see Class
  75      * @return JavaClass object for given runtime class
  76      * @throws ClassNotFoundException if the class could not be found or
  77      * parsed correctly
  78      */
  79     public static JavaClass lookupClass( final Class<?> clazz ) throws ClassNotFoundException {
  80         return repository.loadClass(clazz);
  81     }
  82 
  83 
  84     /**
  85      * Clear the repository.
  86      */
  87     public static void clearCache() {
  88         repository.clear();
  89     }
  90 
  91 
  92     /**
  93      * Adds clazz to repository if there isn't an equally named class already in there.
  94      *
  95      * @return old entry in repository
  96      */
  97     public static JavaClass addClass( final JavaClass clazz ) {
  98         final JavaClass old = repository.findClass(clazz.getClassName());
  99         repository.storeClass(clazz);
 100         return old;
 101     }
 102 
 103 
 104     /**
 105      * Removes class with given (fully qualified) name from repository.
 106      */
 107     public static void removeClass( final String clazz ) {
 108         repository.removeClass(repository.findClass(clazz));
 109     }
 110 
 111 
 112     /**
 113      * Removes given class from repository.
 114      */
 115     public static void removeClass( final JavaClass clazz ) {
 116         repository.removeClass(clazz);
 117     }
 118 
 119 
 120     /**
 121      * @return list of super classes of clazz in ascending order, i.e.,
 122      * Object is always the last element
 123      * @throws ClassNotFoundException if any of the superclasses can't be found
 124      */
 125     public static JavaClass[] getSuperClasses( final JavaClass clazz ) throws ClassNotFoundException {
 126         return clazz.getSuperClasses();
 127     }
 128 
 129 
 130     /**
 131      * @return list of super classes of clazz in ascending order, i.e.,
 132      * Object is always the last element.
 133      * @throws ClassNotFoundException if the named class or any of its


< prev index next >