1 /* 2 * Copyright 2003 The Apache Software Foundation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package net.sf.cglib.core; 17 18 import java.util.Set; 19 20 /** 21 * Customize the generated class name for {@link AbstractClassGenerator}-based utilities. 22 */ 23 public interface NamingPolicy { 24 /** 25 * Choose a name for a generated class. 26 * @param prefix a dotted-name chosen by the generating class (possibly to put the generated class in a particular package) 27 * @param source the fully-qualified class name of the generating class (for example "net.sf.cglib.Enhancer") 28 * @param key A key object representing the state of the parameters; for caching to work properly, equal keys should result 29 * in the same generated class name. The default policy incorporates <code>key.hashCode()</code> into the class name. 30 * @param names a predicate that returns true if the given classname has already been used in the same ClassLoader. 31 * @return the fully-qualified class name 32 */ 33 String getClassName(String prefix, String source, Object key, Predicate names); 34 35 /** 36 * The <code>NamingPolicy</code> in use does not currently, but may 37 * in the future, affect the caching of classes generated by {@link 38 * AbstractClassGenerator}, so this is a reminder that you should 39 * correctly implement <code>equals</code> and <code>hashCode</code> 40 * to avoid generating too many classes. 41 */ 42 boolean equals(Object o); 43 } 44