01: /**
02: * Copyright (C) 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package com.bm.ejb3guice.internal;
16:
17: import net.sf.cglib.core.NamingPolicy;
18: import net.sf.cglib.core.Predicate;
19:
20: /**
21: * Cglib class naming policy for Guice.
22: *
23: * @author crazybob@google.com (Bob Lee)
24: */
25: public class GuiceNamingPolicy implements NamingPolicy {
26:
27: public String getClassName(String prefix, String source,
28: Object key, Predicate names) {
29: StringBuffer sb = new StringBuffer();
30: sb.append((prefix != null) ? (prefix.startsWith("java") ? "$"
31: + prefix : prefix) : "net.sf.cglib.empty.Object");
32: sb.append("$$");
33: sb.append(source.substring(source.lastIndexOf('.') + 1));
34: sb.append("ByGuice$$");
35: sb.append(Integer.toHexString(key.hashCode()));
36: String base = sb.toString();
37: String attempt = base;
38: int index = 2;
39: while (names.evaluate(attempt)) {
40: attempt = base + "_" + index++;
41: }
42:
43: return attempt;
44: }
45: }
|