2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.vm;
21 import gov.nasa.jpf.JPF;
22 import gov.nasa.jpf.util.JPFLogger;
25 import java.util.ArrayList;
28 * this is a lookup mechanism for class files that is based on an ordered
29 * list of directory or jar entries
31 public class ClassPath implements Restorable<ClassPath>{
33 static class CPMemento implements Memento<ClassPath> {
35 ArrayList<ClassFileContainer> pathElements;
37 CPMemento (ClassPath cp){
39 this.pathElements = new ArrayList<ClassFileContainer>(cp.pathElements);
43 public ClassPath restore (ClassPath ignored) {
44 cp.pathElements = this.pathElements;
50 static JPFLogger logger = JPF.getLogger("gov.nasa.jpf.jvm.classfile");
52 protected ArrayList<ClassFileContainer> pathElements;
56 pathElements = new ArrayList<ClassFileContainer>();
60 public Memento<ClassPath> getMemento (MementoFactory factory) {
61 return factory.getMemento(this);
64 public Memento<ClassPath> getMemento(){
65 return new CPMemento(this);
68 public void addClassFileContainer (ClassFileContainer pathElement){
69 assert pathElement != null;
70 pathElements.add(pathElement);
74 public String[] getPathNames(){
75 String[] pn = new String[pathElements.size()];
77 for (int i=0; i<pn.length; i++){
78 pn[i] = pathElements.get(i).getName();
85 public String toString(){
86 StringBuilder sb = new StringBuilder();
87 int len = pathElements.size();
90 for (ClassFileContainer e : pathElements){
91 sb.append(e.getName());
93 sb.append(File.pathSeparator);
99 protected static void error(String msg) throws ClassParseException {
100 throw new ClassParseException(msg);
103 public ClassFileMatch findMatch (String clsName) throws ClassParseException {
104 for (ClassFileContainer container : pathElements){
105 ClassFileMatch match = container.getMatch(clsName);
107 logger.fine("found ", clsName, " in ", container.getName());