Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.apache.cayenne.modeler;
 
 import java.io.File;
 import java.net.URL;
 import java.util.List;
 
A default implementation of ClassLoadingService used in CayenneModeler.

Author(s):
Andrei Adamchik
Since:
1.1
 
 public class FileClassLoadingService implements ClassLoadingService {
 
     private static Logger logObj = Logger.getLogger(FileClassLoadingService.class);
 
     private FileClassLoader classLoader;
     protected List pathFiles;
 
     public FileClassLoadingService() {
         this. = new ArrayList(15);
     }

    
Returns class for a given name, loading it if needed from configured locations.
 
     public synchronized Class loadClass(String classNamethrows ClassNotFoundException {
         return nonNullClassLoader().loadClass(className);
     }

    
Returns a ClassLoader based on the current configured CLASSPATH settings.
 
     public ClassLoader getClassLoader() {
         return nonNullClassLoader();
     }

    
Returns an unmodifiable list of configured CLASSPATH locations.
 
     public synchronized List getPathFiles() {
         return Collections.unmodifiableList();
     }
 
     public synchronized void setPathFiles(Collection files) {
 
         .clear();
          = null;
 
         Iterator it = files.iterator();
         while (it.hasNext()) {
             addFile((Fileit.next());
         }
     }

    
Adds a new location to the list of configured locations.
 
     private void addFile(File file) {
         file = file.getAbsoluteFile();
 
         if (.contains(file)) {
             return;
         }
 
         if ( != null) {
             try {
                 .addURL(file.toURL());
             }
             catch (MalformedURLException ex) {
                 .warn("Invalid classpath entry, ignoring: " + file);
                 return;
            }
        }
        .add(file);
        .debug("Added CLASSPATH entry...: " + file.getAbsolutePath());
    }
    private synchronized FileClassLoader nonNullClassLoader() {
        // init class loader on demand
        if ( == null) {
             = new FileClassLoader(getClass().getClassLoader(), );
        }
        return ;
    }
    // URLClassLoader with addURL method exposed.
    static class FileClassLoader extends URLClassLoader {
        FileClassLoader(ClassLoader parent) {
            super(new URL[0], parent);
        }
        FileClassLoader(ClassLoader parentList files) {
            this(parent);
            Iterator it = files.iterator();
            while (it.hasNext()) {
                File file = (Fileit.next();
                // I guess here we have to quetly ignore invalid URLs...
                try {
                    addURL(file.toURL());
                }
                catch (MalformedURLException ex) {
                }
            }
        }
        public void addURL(URL url) {
            super.addURL(url);
        }
    }
New to GrepCode? Check out our FAQ X