Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.repository » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    *  http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   package org.apache.geronimo.kernel.repository;
   21   
   22   import java.io.Serializable;
   23   import java.util.HashSet;
   24   import java.util.Set;
   25   
   26   /**
   27    *
   28    * @version $Rev:$ $Date:$
   29    */
   30   public class ClassLoadingRule implements Serializable {
   31       private final Set<String> classPrefixes;
   32       private final Set<String> resourcePrefixes;
   33       
   34       public ClassLoadingRule() {
   35           classPrefixes = new HashSet<String>();
   36           resourcePrefixes = new HashSet<String>();
   37       }
   38   
   39       public Set<String> getClassPrefixes() {
   40           return classPrefixes;
   41       }
   42   
   43       public boolean isFilteredClass(String name) {
   44           return isMatching(classPrefixes, name);
   45       }
   46       
   47       public boolean isFilteredResource(String name) {
   48           return isMatching(resourcePrefixes, name);
   49       }
   50       
   51       public void addClassPrefixes(Set<String> classPrefixes) {
   52           this.classPrefixes.addAll(classPrefixes);
   53   
   54           Set<String> resources = toResources(classPrefixes);
   55           resourcePrefixes.addAll(resources);
   56       }
   57   
   58       public void setClassPrefixes(Set<String> classPrefixes) {
   59           this.classPrefixes.clear();
   60           resourcePrefixes.clear();
   61           addClassPrefixes(classPrefixes);
   62       }
   63       
   64       public void merge(ClassLoadingRule classLoadingRuleToMerge) {
   65           addClassPrefixes(classLoadingRuleToMerge.classPrefixes);
   66       }
   67   
   68       protected Set<String> toResources(Set<String> classPrefixes) {
   69           Set<String> resources = new HashSet<String>();
   70           for (String className : classPrefixes) {
   71               resources.add(className.replace('.', '/'));
   72           }
   73           return resources;
   74       }
   75       
   76       protected boolean isMatching(Set<String> prefixes, String name) {
   77           for (String prefix : prefixes) {
   78               if (name.startsWith(prefix)) {
   79                   return true;
   80               }
   81           }
   82           return false;
   83       }
   84   
   85   }

Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.repository » [javadoc | source]