├── .gitignore ├── LICENSE.txt ├── README-ENG.md ├── README.md ├── command.bat ├── compare.png ├── jbeanbox ├── maven_clean.bat ├── maven_clean_install.bat ├── maven_eclipse_clean.bat ├── maven_eclipse_eclipse.bat ├── maven_test.bat ├── pom.xml └── src │ ├── main │ └── java │ │ ├── com │ │ └── github │ │ │ └── drinkjava2 │ │ │ ├── asm │ │ │ ├── AnnotationVisitor.java │ │ │ ├── AnnotationWriter.java │ │ │ ├── Attribute.java │ │ │ ├── ByteVector.java │ │ │ ├── ClassReader.java │ │ │ ├── ClassTooLargeException.java │ │ │ ├── ClassVisitor.java │ │ │ ├── ClassWriter.java │ │ │ ├── ConstantDynamic.java │ │ │ ├── Constants.java │ │ │ ├── Context.java │ │ │ ├── CurrentFrame.java │ │ │ ├── Edge.java │ │ │ ├── FieldVisitor.java │ │ │ ├── FieldWriter.java │ │ │ ├── Frame.java │ │ │ ├── Handle.java │ │ │ ├── Handler.java │ │ │ ├── Label.java │ │ │ ├── MethodTooLargeException.java │ │ │ ├── MethodVisitor.java │ │ │ ├── MethodWriter.java │ │ │ ├── ModuleVisitor.java │ │ │ ├── ModuleWriter.java │ │ │ ├── Opcodes.java │ │ │ ├── Symbol.java │ │ │ ├── SymbolTable.java │ │ │ ├── Type.java │ │ │ ├── TypePath.java │ │ │ ├── TypeReference.java │ │ │ └── package-info.java │ │ │ ├── cglib │ │ │ ├── Readme.java │ │ │ ├── beans │ │ │ │ ├── BeanCopier.java │ │ │ │ ├── BeanGenerator.java │ │ │ │ ├── BeanMap.java │ │ │ │ ├── BeanMapEmitter.java │ │ │ │ ├── BulkBean.java │ │ │ │ ├── BulkBeanEmitter.java │ │ │ │ ├── BulkBeanException.java │ │ │ │ ├── FixedKeySet.java │ │ │ │ └── ImmutableBean.java │ │ │ ├── core │ │ │ │ ├── AbstractClassGenerator.java │ │ │ │ ├── Block.java │ │ │ │ ├── ClassEmitter.java │ │ │ │ ├── ClassGenerator.java │ │ │ │ ├── ClassInfo.java │ │ │ │ ├── ClassNameReader.java │ │ │ │ ├── ClassesKey.java │ │ │ │ ├── CodeEmitter.java │ │ │ │ ├── CodeGenerationException.java │ │ │ │ ├── CollectionUtils.java │ │ │ │ ├── Constants.java │ │ │ │ ├── Converter.java │ │ │ │ ├── Customizer.java │ │ │ │ ├── DebuggingClassWriter.java │ │ │ │ ├── DefaultGeneratorStrategy.java │ │ │ │ ├── DefaultNamingPolicy.java │ │ │ │ ├── DuplicatesPredicate.java │ │ │ │ ├── EmitUtils.java │ │ │ │ ├── GeneratorStrategy.java │ │ │ │ ├── KeyFactory.java │ │ │ │ ├── Local.java │ │ │ │ ├── LocalVariablesSorter.java │ │ │ │ ├── MethodInfo.java │ │ │ │ ├── MethodInfoTransformer.java │ │ │ │ ├── MethodWrapper.java │ │ │ │ ├── NamingPolicy.java │ │ │ │ ├── ObjectSwitchCallback.java │ │ │ │ ├── Predicate.java │ │ │ │ ├── ProcessArrayCallback.java │ │ │ │ ├── ProcessSwitchCallback.java │ │ │ │ ├── ReflectUtils.java │ │ │ │ ├── RejectModifierPredicate.java │ │ │ │ ├── Signature.java │ │ │ │ ├── TinyBitSet.java │ │ │ │ ├── Transformer.java │ │ │ │ ├── TypeUtils.java │ │ │ │ └── VisibilityPredicate.java │ │ │ ├── proxy │ │ │ │ ├── BridgeMethodResolver.java │ │ │ │ ├── Callback.java │ │ │ │ ├── CallbackFilter.java │ │ │ │ ├── CallbackGenerator.java │ │ │ │ ├── CallbackHelper.java │ │ │ │ ├── CallbackInfo.java │ │ │ │ ├── Dispatcher.java │ │ │ │ ├── DispatcherGenerator.java │ │ │ │ ├── Enhancer.java │ │ │ │ ├── Factory.java │ │ │ │ ├── FixedValue.java │ │ │ │ ├── FixedValueGenerator.java │ │ │ │ ├── InterfaceMaker.java │ │ │ │ ├── InvocationHandler.java │ │ │ │ ├── InvocationHandlerGenerator.java │ │ │ │ ├── LazyLoader.java │ │ │ │ ├── LazyLoaderGenerator.java │ │ │ │ ├── MethodInterceptor.java │ │ │ │ ├── MethodInterceptorGenerator.java │ │ │ │ ├── MethodProxy.java │ │ │ │ ├── Mixin.java │ │ │ │ ├── MixinBeanEmitter.java │ │ │ │ ├── MixinEmitter.java │ │ │ │ ├── MixinEverythingEmitter.java │ │ │ │ ├── NoOp.java │ │ │ │ ├── NoOpGenerator.java │ │ │ │ ├── Proxy.java │ │ │ │ ├── ProxyRefDispatcher.java │ │ │ │ └── UndeclaredThrowableException.java │ │ │ ├── reflect │ │ │ │ ├── ConstructorDelegate.java │ │ │ │ ├── FastClass.java │ │ │ │ ├── FastClassEmitter.java │ │ │ │ ├── FastConstructor.java │ │ │ │ ├── FastMember.java │ │ │ │ ├── FastMethod.java │ │ │ │ ├── MethodDelegate.java │ │ │ │ └── MulticastDelegate.java │ │ │ ├── transform │ │ │ │ ├── AbstractClassFilterTransformer.java │ │ │ │ ├── AbstractClassLoader.java │ │ │ │ ├── AbstractClassTransformer.java │ │ │ │ ├── AnnotationVisitorTee.java │ │ │ │ ├── ClassEmitterTransformer.java │ │ │ │ ├── ClassFilter.java │ │ │ │ ├── ClassFilterTransformer.java │ │ │ │ ├── ClassReaderGenerator.java │ │ │ │ ├── ClassTransformer.java │ │ │ │ ├── ClassTransformerChain.java │ │ │ │ ├── ClassTransformerFactory.java │ │ │ │ ├── ClassTransformerTee.java │ │ │ │ ├── ClassVisitorTee.java │ │ │ │ ├── FieldVisitorTee.java │ │ │ │ ├── MethodFilter.java │ │ │ │ ├── MethodFilterTransformer.java │ │ │ │ ├── MethodVisitorTee.java │ │ │ │ ├── TransformingClassGenerator.java │ │ │ │ ├── TransformingClassLoader.java │ │ │ │ └── impl │ │ │ │ │ ├── AbstractInterceptFieldCallback.java │ │ │ │ │ ├── AccessFieldTransformer.java │ │ │ │ │ ├── AddDelegateTransformer.java │ │ │ │ │ ├── AddInitTransformer.java │ │ │ │ │ ├── AddPropertyTransformer.java │ │ │ │ │ ├── AddStaticInitTransformer.java │ │ │ │ │ ├── FieldProvider.java │ │ │ │ │ ├── FieldProviderTransformer.java │ │ │ │ │ ├── InterceptFieldCallback.java │ │ │ │ │ ├── InterceptFieldEnabled.java │ │ │ │ │ ├── InterceptFieldFilter.java │ │ │ │ │ ├── InterceptFieldTransformer.java │ │ │ │ │ ├── UndeclaredThrowableStrategy.java │ │ │ │ │ └── UndeclaredThrowableTransformer.java │ │ │ └── util │ │ │ │ ├── ParallelSorter.java │ │ │ │ ├── ParallelSorterEmitter.java │ │ │ │ ├── SorterTemplate.java │ │ │ │ └── StringSwitcher.java │ │ │ └── jbeanbox │ │ │ ├── AopUtils.java │ │ │ ├── BeanBox.java │ │ │ ├── BeanBoxContext.java │ │ │ ├── BeanBoxException.java │ │ │ ├── BeanBoxUtils.java │ │ │ ├── ClassScanner.java │ │ │ ├── EMPTY.java │ │ │ ├── JBEANBOX.java │ │ │ ├── NameMatchUtil.java │ │ │ ├── PrototypeBean.java │ │ │ ├── ProxyBean.java │ │ │ ├── ReflectionUtils.java │ │ │ ├── ValueTranslator.java │ │ │ └── annotation │ │ │ ├── AOP.java │ │ │ ├── COMPONENT.java │ │ │ ├── INJECT.java │ │ │ ├── NAMED.java │ │ │ ├── POSTCONSTRUCT.java │ │ │ ├── PREDESTROY.java │ │ │ ├── PROTOTYPE.java │ │ │ ├── QUALIFILER.java │ │ │ └── VALUE.java │ │ ├── javax │ │ ├── annotation │ │ │ ├── PostConstruct.java │ │ │ └── PreDestroy.java │ │ └── inject │ │ │ ├── Inject.java │ │ │ ├── Named.java │ │ │ ├── Provider.java │ │ │ ├── Qualifier.java │ │ │ ├── Scope.java │ │ │ └── Singleton.java │ │ └── org │ │ ├── aopalliance │ │ ├── aop │ │ │ ├── Advice.java │ │ │ └── AspectException.java │ │ └── intercept │ │ │ ├── Interceptor.java │ │ │ ├── Invocation.java │ │ │ ├── Joinpoint.java │ │ │ ├── MethodInterceptor.java │ │ │ └── MethodInvocation.java │ │ └── springframework │ │ ├── beans │ │ └── factory │ │ │ └── annotation │ │ │ ├── Autowired.java │ │ │ ├── Qualifier.java │ │ │ └── Value.java │ │ └── stereotype │ │ ├── Component.java │ │ ├── Controller.java │ │ ├── Repository.java │ │ └── Service.java │ └── test │ └── java │ └── com │ └── github │ └── drinkjava2 │ └── jbeanbox │ ├── AnnotationInjectTest.java │ ├── AnnotationSuperclassTest.java │ ├── BeanBoxTest.java │ ├── BeanBoxUtilsTest.java │ ├── CircularDependencyTest.java │ ├── ClassScannerTest.java │ ├── HelloWorld.java │ ├── JavaInjectTest.java │ ├── JavaSuperclassTest.java │ ├── NameMatchUtilTest.java │ ├── QualiferTest.java │ ├── SingletonPrototypeTest.java │ ├── aop │ ├── AnnotationAopTest.java │ ├── JavaAopTest.java │ └── NameMatchingAopTest.java │ ├── benchmark │ ├── BenchmarkTest.java │ ├── BoxConfig1.java │ ├── BoxConfig2.java │ ├── SimpleSpeedTest.java │ └── objects │ │ ├── A.java │ │ ├── B.java │ │ ├── C.java │ │ ├── D1.java │ │ ├── D2.java │ │ └── E.java │ └── reflection_utils │ ├── CreateMethodTest.java │ ├── Parent.java │ ├── ReflectionUtilsTest.java │ └── Son.java ├── jbeanboxdi ├── JumpOutSourceCode.bat ├── README.md └── pom.xml └── release_note.md /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | target/ 3 | bin/ 4 | .project 5 | .classpath 6 | .settings/ 7 | *~ 8 | *.orig 9 | *.new 10 | .idea/ 11 | *.iml 12 | *.ipr 13 | test/**/build/ 14 | examples/**/build/ -------------------------------------------------------------------------------- /README-ENG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drinkjava2/jBeanBox/37d768b16bd028b744b1e9d1f3441a9c3f99e6f4/README-ENG.md -------------------------------------------------------------------------------- /command.bat: -------------------------------------------------------------------------------- 1 | cmd -------------------------------------------------------------------------------- /compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drinkjava2/jBeanBox/37d768b16bd028b744b1e9d1f3441a9c3f99e6f4/compare.png -------------------------------------------------------------------------------- /jbeanbox/maven_clean.bat: -------------------------------------------------------------------------------- 1 | mvn clean -------------------------------------------------------------------------------- /jbeanbox/maven_clean_install.bat: -------------------------------------------------------------------------------- 1 | call mvn clean install 2 | @pause -------------------------------------------------------------------------------- /jbeanbox/maven_eclipse_clean.bat: -------------------------------------------------------------------------------- 1 | mvn eclipse:clean -------------------------------------------------------------------------------- /jbeanbox/maven_eclipse_eclipse.bat: -------------------------------------------------------------------------------- 1 | call mvn eclipse:eclipse 2 | call pause -------------------------------------------------------------------------------- /jbeanbox/maven_test.bat: -------------------------------------------------------------------------------- 1 | call mvn clean test 2 | @pause -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/asm/CurrentFrame.java: -------------------------------------------------------------------------------- 1 | // ASM: a very small and fast Java bytecode manipulation framework 2 | // Copyright (c) 2000-2011 INRIA, France Telecom 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions 7 | // are met: 8 | // 1. Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 2. Redistributions in binary form must reproduce the above copyright 11 | // notice, this list of conditions and the following disclaimer in the 12 | // documentation and/or other materials provided with the distribution. 13 | // 3. Neither the name of the copyright holders nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | // THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package com.github.drinkjava2.asm; 30 | 31 | /** 32 | * Information about the input stack map frame at the "current" instruction of a method. This is 33 | * implemented as a Frame subclass for a "basic block" containing only one instruction. 34 | * 35 | * @author Eric Bruneton 36 | */ 37 | final class CurrentFrame extends Frame { 38 | 39 | CurrentFrame(final Label owner) { 40 | super(owner); 41 | } 42 | 43 | /** 44 | * Sets this CurrentFrame to the input stack map frame of the next "current" instruction, i.e. the 45 | * instruction just after the given one. It is assumed that the value of this object when this 46 | * method is called is the stack map frame status just before the given instruction is executed. 47 | */ 48 | @Override 49 | void execute( 50 | final int opcode, final int arg, final Symbol symbolArg, final SymbolTable symbolTable) { 51 | super.execute(opcode, arg, symbolArg, symbolTable); 52 | Frame successor = new Frame(null); 53 | merge(symbolTable, successor, 0); 54 | copyFrom(successor); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/asm/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * jBeanBox's repackaging of ASM 3 | * 7.0 for internal use only). 4 | * 5 | *

6 | * This repackaging technique avoids any potential conflicts with dependencies 7 | * on ASM at the application level or from third-party libraries and frameworks. 8 | */ 9 | package com.github.drinkjava2.asm; 10 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/Readme.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.drinkjava2.cglib;//NOSONAR 3 | 4 | /** 5 | * To avoid jar conflict if a project need use other version CGLIB, I included cglib3.2.0 source code in this project 6 | * and changed its package name 7 | * 8 | * @author Yong 9 | * @since 2.4.1 10 | * 11 | */ 12 | class Readme {// NOSONAR 13 | } -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/beans/BulkBeanException.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.beans; 17 | @SuppressWarnings("serial") 18 | public class BulkBeanException extends RuntimeException 19 | { 20 | private int index; 21 | private Throwable cause; 22 | 23 | public BulkBeanException(String message, int index) { 24 | super(message); 25 | this.index = index; 26 | } 27 | 28 | public BulkBeanException(Throwable cause, int index) { 29 | super(cause.getMessage()); 30 | this.index = index; 31 | this.cause = cause; 32 | } 33 | 34 | public int getIndex() { 35 | return index; 36 | } 37 | 38 | public Throwable getCause() { 39 | return cause; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/beans/FixedKeySet.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.beans; 17 | 18 | import java.util.*; 19 | 20 | @SuppressWarnings({"rawtypes","unchecked"}) 21 | public /* need it for class loading */ class FixedKeySet extends AbstractSet { 22 | private Set set; 23 | private int size; 24 | 25 | 26 | public FixedKeySet(String[] keys) { 27 | size = keys.length; 28 | set = Collections.unmodifiableSet(new HashSet(Arrays.asList(keys))); 29 | } 30 | 31 | public Iterator iterator() { 32 | return set.iterator(); 33 | } 34 | 35 | public int size() { 36 | return size; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/Block.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Label; 19 | 20 | public class Block 21 | { 22 | private CodeEmitter e; 23 | private Label start; 24 | private Label end; 25 | 26 | public Block(CodeEmitter e) { 27 | this.e = e; 28 | start = e.mark(); 29 | } 30 | 31 | public CodeEmitter getCodeEmitter() { 32 | return e; 33 | } 34 | 35 | public void end() { 36 | if (end != null) { 37 | throw new IllegalStateException("end of label already set"); 38 | } 39 | end = e.mark(); 40 | } 41 | 42 | public Label getStart() { 43 | return start; 44 | } 45 | 46 | public Label getEnd() { 47 | return end; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/ClassGenerator.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.ClassVisitor; 19 | 20 | public interface ClassGenerator { 21 | void generateClass(ClassVisitor v) throws Exception; 22 | } 23 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/ClassInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Type; 19 | 20 | abstract public class ClassInfo { 21 | 22 | protected ClassInfo() { 23 | } 24 | 25 | abstract public Type getType(); 26 | abstract public Type getSuperType(); 27 | abstract public Type[] getInterfaces(); 28 | abstract public int getModifiers(); 29 | 30 | public boolean equals(Object o) { 31 | if (o == null) 32 | return false; 33 | if (!(o instanceof ClassInfo)) 34 | return false; 35 | return getType().equals(((ClassInfo)o).getType()); 36 | } 37 | 38 | public int hashCode() { 39 | return getType().hashCode(); 40 | } 41 | 42 | public String toString() { 43 | // TODO: include modifiers, superType, interfaces 44 | return getType().getClassName(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/ClassNameReader.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import java.util.*; 19 | 20 | import com.github.drinkjava2.asm.ClassReader; 21 | import com.github.drinkjava2.asm.ClassVisitor; 22 | import com.github.drinkjava2.asm.Opcodes; 23 | 24 | // TODO: optimize (ClassReader buffers entire class before accept) 25 | @SuppressWarnings({"rawtypes","unchecked"}) 26 | public class ClassNameReader { 27 | private ClassNameReader() { 28 | } 29 | 30 | private static final EarlyExitException EARLY_EXIT = new EarlyExitException(); 31 | @SuppressWarnings("serial") 32 | private static class EarlyExitException extends RuntimeException { } 33 | 34 | public static String getClassName(ClassReader r) { 35 | 36 | return getClassInfo(r)[0]; 37 | 38 | } 39 | 40 | public static String[] getClassInfo(ClassReader r) { 41 | final List array = new ArrayList(); 42 | try { 43 | r.accept(new ClassVisitor(Opcodes.ASM5, null) { 44 | public void visit(int version, 45 | int access, 46 | String name, 47 | String signature, 48 | String superName, 49 | String[] interfaces) { 50 | array.add( name.replace('/', '.') ); 51 | if(superName != null){ 52 | array.add( superName.replace('/', '.') ); 53 | } 54 | for(int i = 0; i < interfaces.length; i++ ){ 55 | array.add( interfaces[i].replace('/', '.') ); 56 | } 57 | 58 | throw EARLY_EXIT; 59 | } 60 | }, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); 61 | } catch (EarlyExitException e) { } 62 | 63 | return (String[])array.toArray( new String[]{} ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/ClassesKey.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | public class ClassesKey { 19 | private static final Key FACTORY = (Key)KeyFactory.create(Key.class, KeyFactory.OBJECT_BY_CLASS); 20 | 21 | interface Key { 22 | Object newInstance(Object[] array); 23 | } 24 | 25 | private ClassesKey() { 26 | } 27 | 28 | public static Object create(Object[] array) { 29 | return FACTORY.newInstance(array); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/CodeGenerationException.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | /** 19 | * @version $Id: CodeGenerationException.java,v 1.3 2004/06/24 21:15:21 herbyderby Exp $ 20 | */ 21 | @SuppressWarnings("serial") 22 | public class CodeGenerationException extends RuntimeException { 23 | private Throwable cause; 24 | 25 | public CodeGenerationException(Throwable cause) { 26 | super(cause.getClass().getName() + "-->" + cause.getMessage()); 27 | this.cause = cause; 28 | } 29 | 30 | public Throwable getCause() { 31 | return cause; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/CollectionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.core; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collection; 20 | import java.util.HashMap; 21 | import java.util.Iterator; 22 | import java.util.LinkedList; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * @author Chris Nokleberg 28 | * @version $Id: CollectionUtils.java,v 1.7 2004/06/24 21:15:21 herbyderby Exp $ 29 | */ 30 | @SuppressWarnings({"rawtypes","unchecked"}) 31 | public class CollectionUtils { 32 | private CollectionUtils() { } 33 | 34 | public static Map bucket(Collection c, Transformer t) { 35 | Map buckets = new HashMap(); 36 | for (Iterator it = c.iterator(); it.hasNext();) { 37 | Object value = (Object)it.next(); 38 | Object key = t.transform(value); 39 | List bucket = (List)buckets.get(key); 40 | if (bucket == null) { 41 | buckets.put(key, bucket = new LinkedList()); 42 | } 43 | bucket.add(value); 44 | } 45 | return buckets; 46 | } 47 | 48 | public static void reverse(Map source, Map target) { 49 | for (Iterator it = source.keySet().iterator(); it.hasNext();) { 50 | Object key = it.next(); 51 | target.put(source.get(key), key); 52 | } 53 | } 54 | 55 | public static Collection filter(Collection c, Predicate p) { 56 | Iterator it = c.iterator(); 57 | while (it.hasNext()) { 58 | if (!p.evaluate(it.next())) { 59 | it.remove(); 60 | } 61 | } 62 | return c; 63 | } 64 | 65 | public static List transform(Collection c, Transformer t) { 66 | List result = new ArrayList(c.size()); 67 | for (Iterator it = c.iterator(); it.hasNext();) { 68 | result.add(t.transform(it.next())); 69 | } 70 | return result; 71 | } 72 | 73 | public static Map getIndexMap(List list) { 74 | Map indexes = new HashMap(); 75 | int index = 0; 76 | for (Iterator it = list.iterator(); it.hasNext();) { 77 | indexes.put(it.next(), new Integer(index++)); 78 | } 79 | return indexes; 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/Converter.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | @SuppressWarnings({"rawtypes"}) 18 | public interface Converter { 19 | Object convert(Object value, Class target, Object context); 20 | } 21 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/Customizer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Type; 19 | 20 | public interface Customizer { 21 | void customize(CodeEmitter e, Type type); 22 | } 23 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/DefaultGeneratorStrategy.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.ClassWriter; 19 | 20 | public class DefaultGeneratorStrategy implements GeneratorStrategy { 21 | public static final DefaultGeneratorStrategy INSTANCE = new DefaultGeneratorStrategy(); 22 | 23 | public byte[] generate(ClassGenerator cg) throws Exception { 24 | DebuggingClassWriter cw = getClassVisitor(); 25 | transform(cg).generateClass(cw); 26 | return transform(cw.toByteArray()); 27 | } 28 | 29 | protected DebuggingClassWriter getClassVisitor() throws Exception { 30 | return new DebuggingClassWriter(ClassWriter.COMPUTE_FRAMES); 31 | } 32 | 33 | protected final ClassWriter getClassWriter() { 34 | // Cause compile / runtime errors for people who implemented the old 35 | // interface without using @Override 36 | throw new UnsupportedOperationException("You are calling " + 37 | "getClassWriter, which no longer exists in this cglib version."); 38 | } 39 | 40 | protected byte[] transform(byte[] b) throws Exception { 41 | return b; 42 | } 43 | 44 | protected ClassGenerator transform(ClassGenerator cg) throws Exception { 45 | return cg; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/DefaultNamingPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.core; 17 | 18 | import java.util.Set; 19 | 20 | /** 21 | * The default policy used by {@link AbstractClassGenerator}. 22 | * Generates names such as 23 | *

com.github.drinkjava2.cglib.Foo$$EnhancerByCGLIB$$38272841

24 | * This is composed of a prefix based on the name of the superclass, a fixed 25 | * string incorporating the CGLIB class responsible for generation, and a 26 | * hashcode derived from the parameters used to create the object. If the same 27 | * name has been previously been used in the same ClassLoader, a 28 | * suffix is added to ensure uniqueness. 29 | */ 30 | @SuppressWarnings({"unused" }) 31 | public class DefaultNamingPolicy implements NamingPolicy { 32 | public static final DefaultNamingPolicy INSTANCE = new DefaultNamingPolicy(); 33 | 34 | public String getClassName(String prefix, String source, Object key, Predicate names) { 35 | if (prefix == null) { 36 | prefix = "com.github.drinkjava2.cglib.empty.Object"; 37 | } else if (prefix.startsWith("java")) { 38 | prefix = "$" + prefix; 39 | } 40 | String base = 41 | prefix + "$$" + 42 | source.substring(source.lastIndexOf('.') + 1) + 43 | getTag() + "$$" + 44 | Integer.toHexString(key.hashCode()); 45 | String attempt = base; 46 | int index = 2; 47 | while (names.evaluate(attempt)) 48 | attempt = base + "_" + index++; 49 | return attempt; 50 | } 51 | 52 | /** 53 | * Returns a string which is incorporated into every generated class name. 54 | * By default returns "ByCGLIB" 55 | */ 56 | protected String getTag() { 57 | return "ByCGLIB"; 58 | } 59 | 60 | public int hashCode() { 61 | return getTag().hashCode(); 62 | } 63 | 64 | public boolean equals(Object o) { 65 | return (o instanceof DefaultNamingPolicy) && ((DefaultNamingPolicy) o).getTag().equals(getTag()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/DuplicatesPredicate.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import java.lang.reflect.Method; 19 | import java.util.*; 20 | @SuppressWarnings({"rawtypes","unchecked" }) 21 | public class DuplicatesPredicate implements Predicate { 22 | private Set unique = new HashSet(); 23 | 24 | public boolean evaluate(Object arg) { 25 | return unique.add(MethodWrapper.create((Method)arg)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/GeneratorStrategy.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | /** 19 | * The GeneratorStrategyClass. By providing your 22 | * own strategy you may examine or modify the generated class before 23 | * it is loaded. Typically this will be accomplished by subclassing 24 | * {@link DefaultGeneratorStrategy} and overriding the appropriate 25 | * protected method. 26 | * @see AbstractClassGenerator#setStrategy 27 | */ 28 | public interface GeneratorStrategy { 29 | /** 30 | * Generate the class. 31 | * @param cg a class generator on which you can call {@link ClassGenerator#generateClass} 32 | * @return a byte array containing the bits of a valid Class 33 | */ 34 | byte[] generate(ClassGenerator cg) throws Exception; 35 | 36 | /** 37 | * The GeneratorStrategy in use does not currently, but may 38 | * in the future, affect the caching of classes generated by {@link 39 | * AbstractClassGenerator}, so this is a reminder that you should 40 | * correctly implement equals and hashCode 41 | * to avoid generating too many classes. 42 | */ 43 | boolean equals(Object o); 44 | } 45 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/Local.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Type; 19 | 20 | public class Local 21 | { 22 | private Type type; 23 | private int index; 24 | 25 | public Local(int index, Type type) { 26 | this.type = type; 27 | this.index = index; 28 | } 29 | 30 | public int getIndex() { 31 | return index; 32 | } 33 | 34 | public Type getType() { 35 | return type; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/MethodInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Type; 19 | 20 | abstract public class MethodInfo { 21 | 22 | protected MethodInfo() { 23 | } 24 | 25 | abstract public ClassInfo getClassInfo(); 26 | abstract public int getModifiers(); 27 | abstract public Signature getSignature(); 28 | abstract public Type[] getExceptionTypes(); 29 | 30 | public boolean equals(Object o) { 31 | if (o == null) 32 | return false; 33 | if (!(o instanceof MethodInfo)) 34 | return false; 35 | return getSignature().equals(((MethodInfo)o).getSignature()); 36 | } 37 | 38 | public int hashCode() { 39 | return getSignature().hashCode(); 40 | } 41 | 42 | public String toString() { 43 | // TODO: include modifiers, exceptions 44 | return getSignature().toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/MethodInfoTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 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 com.github.drinkjava2.cglib.core; 17 | 18 | import java.lang.reflect.*; 19 | @SuppressWarnings({"rawtypes" }) 20 | public class MethodInfoTransformer implements Transformer 21 | { 22 | private static final MethodInfoTransformer INSTANCE = new MethodInfoTransformer(); 23 | 24 | public static MethodInfoTransformer getInstance() { 25 | return INSTANCE; 26 | } 27 | 28 | public Object transform(Object value) { 29 | if (value instanceof Method) { 30 | return ReflectUtils.getMethodInfo((Method)value); 31 | } else if (value instanceof Constructor) { 32 | return ReflectUtils.getMethodInfo((Constructor)value); 33 | } else { 34 | throw new IllegalArgumentException("cannot get method info for " + value); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/MethodWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.core; 17 | 18 | import java.lang.reflect.Method; 19 | import java.util.*; 20 | @SuppressWarnings({"rawtypes","unchecked" }) 21 | public class MethodWrapper { 22 | private static final MethodWrapperKey KEY_FACTORY = 23 | (MethodWrapperKey)KeyFactory.create(MethodWrapperKey.class); 24 | 25 | /** Internal interface, only public due to ClassLoader issues. */ 26 | public interface MethodWrapperKey { 27 | public Object newInstance(String name, String[] parameterTypes, String returnType); 28 | } 29 | 30 | private MethodWrapper() { 31 | } 32 | 33 | public static Object create(Method method) { 34 | return KEY_FACTORY.newInstance(method.getName(), 35 | ReflectUtils.getNames(method.getParameterTypes()), 36 | method.getReturnType().getName()); 37 | } 38 | 39 | public static Set createSet(Collection methods) { 40 | Set set = new HashSet(); 41 | for (Iterator it = methods.iterator(); it.hasNext();) { 42 | set.add(create((Method)it.next())); 43 | } 44 | return set; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/NamingPolicy.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | /** 19 | * Customize the generated class name for {@link AbstractClassGenerator}-based utilities. 20 | */ 21 | public interface NamingPolicy { 22 | /** 23 | * Choose a name for a generated class. 24 | * @param prefix a dotted-name chosen by the generating class (possibly to put the generated class in a particular package) 25 | * @param source the fully-qualified class name of the generating class (for example "com.github.drinkjava2.cglib.Enhancer") 26 | * @param key A key object representing the state of the parameters; for caching to work properly, equal keys should result 27 | * in the same generated class name. The default policy incorporates key.hashCode() into the class name. 28 | * @param names a predicate that returns true if the given classname has already been used in the same ClassLoader. 29 | * @return the fully-qualified class name 30 | */ 31 | String getClassName(String prefix, String source, Object key, Predicate names); 32 | 33 | /** 34 | * The NamingPolicy in use does not currently, but may 35 | * in the future, affect the caching of classes generated by {@link 36 | * AbstractClassGenerator}, so this is a reminder that you should 37 | * correctly implement equals and hashCode 38 | * to avoid generating too many classes. 39 | */ 40 | boolean equals(Object o); 41 | } 42 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/ObjectSwitchCallback.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Label; 19 | 20 | public interface ObjectSwitchCallback { 21 | void processCase(Object key, Label end) throws Exception; 22 | void processDefault() throws Exception; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/Predicate.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | public interface Predicate { 19 | boolean evaluate(Object arg); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/ProcessArrayCallback.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Type; 19 | 20 | public interface ProcessArrayCallback { 21 | void processElement(Type type); 22 | } 23 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/ProcessSwitchCallback.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Label; 19 | 20 | public interface ProcessSwitchCallback { 21 | void processCase(int key, Label end) throws Exception; 22 | void processDefault() throws Exception; 23 | } 24 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/RejectModifierPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 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 com.github.drinkjava2.cglib.core; 17 | 18 | import java.lang.reflect.*; 19 | 20 | public class RejectModifierPredicate implements Predicate { 21 | private int rejectMask; 22 | 23 | public RejectModifierPredicate(int rejectMask) { 24 | this.rejectMask = rejectMask; 25 | } 26 | 27 | public boolean evaluate(Object arg) { 28 | return (((Member)arg).getModifiers() & rejectMask) == 0; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/Signature.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | import com.github.drinkjava2.asm.Type; 19 | 20 | /** 21 | * A representation of a method signature, containing the method name, 22 | * return type, and parameter types. 23 | */ 24 | public class Signature { 25 | private String name; 26 | private String desc; 27 | 28 | public Signature(String name, String desc) { 29 | // TODO: better error checking 30 | if (name.indexOf('(') >= 0) { 31 | throw new IllegalArgumentException("Name '" + name + "' is invalid"); 32 | } 33 | this.name = name; 34 | this.desc = desc; 35 | } 36 | 37 | public Signature(String name, Type returnType, Type[] argumentTypes) { 38 | this(name, Type.getMethodDescriptor(returnType, argumentTypes)); 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public String getDescriptor() { 46 | return desc; 47 | } 48 | 49 | public Type getReturnType() { 50 | return Type.getReturnType(desc); 51 | } 52 | 53 | public Type[] getArgumentTypes() { 54 | return Type.getArgumentTypes(desc); 55 | } 56 | 57 | public String toString() { 58 | return name + desc; 59 | } 60 | 61 | public boolean equals(Object o) { 62 | if (o == null) 63 | return false; 64 | if (!(o instanceof Signature)) 65 | return false; 66 | Signature other = (Signature)o; 67 | return name.equals(other.name) && desc.equals(other.desc); 68 | } 69 | 70 | public int hashCode() { 71 | return name.hashCode() ^ desc.hashCode(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/TinyBitSet.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | public class TinyBitSet { 19 | private static int[] T = new int[256]; 20 | private int value = 0; 21 | 22 | private static int gcount(int x) { 23 | int c = 0; 24 | while (x != 0) { 25 | c++; 26 | x &= (x - 1); 27 | } 28 | return c; 29 | } 30 | 31 | static { 32 | for(int j = 0; j < 256; j++) { 33 | T[j] = gcount(j); 34 | } 35 | } 36 | 37 | private static int topbit(int i) { 38 | int j; 39 | for (j = 0; i != 0; i ^= j) { 40 | j = i & -i; 41 | } 42 | return j; 43 | } 44 | 45 | private static int log2(int i) { 46 | int j = 0; 47 | for (j = 0; i != 0; i >>= 1) { 48 | j++; 49 | } 50 | return j; 51 | } 52 | 53 | public int length() { 54 | return log2(topbit(value)); 55 | } 56 | 57 | public int cardinality() { 58 | int w = value; 59 | int c = 0; 60 | while (w != 0) { 61 | c += T[w & 255]; 62 | w >>= 8; 63 | } 64 | return c; 65 | } 66 | 67 | public boolean get(int index) { 68 | return (value & (1 << index)) != 0; 69 | } 70 | 71 | public void set(int index) { 72 | value |= (1 << index); 73 | } 74 | 75 | public void clear(int index) { 76 | value &= ~(1 << index); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/Transformer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.core; 17 | 18 | public interface Transformer { 19 | Object transform(Object value); 20 | } 21 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/core/VisibilityPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.core; 17 | 18 | import java.lang.reflect.*; 19 | 20 | import com.github.drinkjava2.asm.Type; 21 | @SuppressWarnings({"rawtypes" }) 22 | public class VisibilityPredicate implements Predicate { 23 | private boolean protectedOk; 24 | private String pkg; 25 | private boolean samePackageOk; 26 | 27 | public VisibilityPredicate(Class source, boolean protectedOk) { 28 | this.protectedOk = protectedOk; 29 | // same package is not ok for the bootstrap loaded classes. In all other cases we are 30 | // generating classes in the same classloader 31 | this.samePackageOk = source.getClassLoader() != null; 32 | pkg = TypeUtils.getPackageName(Type.getType(source)); 33 | } 34 | 35 | public boolean evaluate(Object arg) { 36 | Member member = (Member)arg; 37 | int mod = member.getModifiers(); 38 | if (Modifier.isPrivate(mod)) { 39 | return false; 40 | } else if (Modifier.isPublic(mod)) { 41 | return true; 42 | } else if (Modifier.isProtected(mod) && protectedOk) { 43 | // protected is fine if 'protectedOk' is true (for subclasses) 44 | return true; 45 | } else { 46 | // protected/package private if the member is in the same package as the source class 47 | // and we are generating into the same classloader. 48 | return samePackageOk 49 | && pkg.equals(TypeUtils.getPackageName(Type.getType(member.getDeclaringClass()))); 50 | } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/Callback.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | /** 19 | * All callback interfaces used by {@link Enhancer} extend this interface. 20 | * @see MethodInterceptor 21 | * @see NoOp 22 | * @see LazyLoader 23 | * @see Dispatcher 24 | * @see InvocationHandler 25 | * @see FixedValue 26 | */ 27 | public interface Callback 28 | { 29 | } 30 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/CallbackFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | /** 21 | * Map methods of subclasses generated by {@link Enhancer} to a particular 22 | * callback. The type of the callbacks chosen for each method affects 23 | * the bytecode generated for that method in the subclass, and cannot 24 | * change for the life of the class. 25 | */ 26 | public interface CallbackFilter { 27 | /** 28 | * Map a method to a callback. 29 | * @param method the intercepted method 30 | * @return the index into the array of callbacks (as specified by {@link Enhancer#setCallbacks}) to use for the method, 31 | */ 32 | int accept(Method method); 33 | 34 | /** 35 | * The CallbackFilter in use affects which cached class 36 | * the Enhancer will use, so this is a reminder that 37 | * you should correctly implement equals and 38 | * hashCode for custom CallbackFilter 39 | * implementations in order to improve performance. 40 | */ 41 | boolean equals(Object o); 42 | } 43 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/CallbackGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | import java.util.List; 19 | 20 | import com.github.drinkjava2.cglib.core.ClassEmitter; 21 | import com.github.drinkjava2.cglib.core.CodeEmitter; 22 | import com.github.drinkjava2.cglib.core.MethodInfo; 23 | import com.github.drinkjava2.cglib.core.Signature; 24 | @SuppressWarnings({"rawtypes" }) 25 | interface CallbackGenerator 26 | { 27 | void generate(ClassEmitter ce, Context context, List methods) throws Exception; 28 | void generateStatic(CodeEmitter e, Context context, List methods) throws Exception; 29 | 30 | interface Context 31 | { 32 | ClassLoader getClassLoader(); 33 | CodeEmitter beginMethod(ClassEmitter ce, MethodInfo method); 34 | int getOriginalModifiers(MethodInfo method); 35 | int getIndex(MethodInfo method); 36 | void emitCallback(CodeEmitter ce, int index); 37 | Signature getImplSignature(MethodInfo method); 38 | void emitInvoke(CodeEmitter e, MethodInfo method); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/Dispatcher.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | /** 19 | * Dispatching {@link Enhancer} callback. This is identical to the 20 | * {@link LazyLoader} interface but needs to be separate so that Enhancer 21 | * knows which type of code to generate. 22 | */ 23 | public interface Dispatcher extends Callback { 24 | /** 25 | * Return the object which the original method invocation should 26 | * be dispatched. This method is called for every method invocation. 27 | * @return an object that can invoke the method 28 | */ 29 | Object loadObject() throws Exception; 30 | } 31 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/FixedValue.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | /** 19 | * {@link Enhancer} callback that simply returns the value to return 20 | * from the proxied method. No information about what method 21 | * is being called is available to the callback, and the type of 22 | * the returned object must be compatible with the return type of 23 | * the proxied method. This makes this callback primarily useful 24 | * for forcing a particular method (through the use of a {@link CallbackFilter} 25 | * to return a fixed value with little overhead. 26 | */ 27 | public interface FixedValue extends Callback { 28 | /** 29 | * Return the object which the original method invocation should 30 | * return. This method is called for every method invocation. 31 | * @return an object matching the type of the return value for every 32 | * method this callback is mapped to 33 | */ 34 | Object loadObject() throws Exception; 35 | } 36 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/FixedValueGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | import java.util.Iterator; 19 | import java.util.List; 20 | 21 | import com.github.drinkjava2.asm.Type; 22 | import com.github.drinkjava2.cglib.core.ClassEmitter; 23 | import com.github.drinkjava2.cglib.core.CodeEmitter; 24 | import com.github.drinkjava2.cglib.core.MethodInfo; 25 | import com.github.drinkjava2.cglib.core.Signature; 26 | import com.github.drinkjava2.cglib.core.TypeUtils; 27 | @SuppressWarnings({"rawtypes" }) 28 | class FixedValueGenerator implements CallbackGenerator { 29 | public static final FixedValueGenerator INSTANCE = new FixedValueGenerator(); 30 | private static final Type FIXED_VALUE = 31 | TypeUtils.parseType("com.github.drinkjava2.cglib.proxy.FixedValue"); 32 | private static final Signature LOAD_OBJECT = 33 | TypeUtils.parseSignature("Object loadObject()"); 34 | 35 | public void generate(ClassEmitter ce, Context context, List methods) { 36 | for (Iterator it = methods.iterator(); it.hasNext();) { 37 | MethodInfo method = (MethodInfo)it.next(); 38 | CodeEmitter e = context.beginMethod(ce, method); 39 | context.emitCallback(e, context.getIndex(method)); 40 | e.invoke_interface(FIXED_VALUE, LOAD_OBJECT); 41 | e.unbox_or_zero(e.getReturnType()); 42 | e.return_value(); 43 | e.end_method(); 44 | } 45 | } 46 | 47 | public void generateStatic(CodeEmitter e, Context context, List methods) { } 48 | } 49 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/InvocationHandler.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | /** 21 | * {@link java.lang.reflect.InvocationHandler} replacement (unavailable under JDK 1.2). 22 | * This callback type is primarily for use by the {@link Proxy} class but 23 | * may be used with {@link Enhancer} as well. 24 | * @author Neeme Praks neeme@apache.org 25 | * @version $Id: InvocationHandler.java,v 1.3 2004/06/24 21:15:20 herbyderby Exp $ 26 | */ 27 | public interface InvocationHandler 28 | extends Callback 29 | { 30 | /** 31 | * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object) 32 | */ 33 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/LazyLoader.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | /** 19 | * Lazy-loading {@link Enhancer} callback. 20 | */ 21 | public interface LazyLoader extends Callback { 22 | /** 23 | * Return the object which the original method invocation should be 24 | * dispatched. Called as soon as the first lazily-loaded method in 25 | * the enhanced instance is invoked. The same object is then used 26 | * for every future method call to the proxy instance. 27 | * @return an object that can invoke the method 28 | */ 29 | Object loadObject() throws Exception; 30 | } 31 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/MethodInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002,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 com.github.drinkjava2.cglib.proxy; 17 | 18 | /** 19 | * General-purpose {@link Enhancer} callback which provides for "around advice". 20 | * @author Juozas Baliuka baliuka@mwm.lt 21 | * @version $Id: MethodInterceptor.java,v 1.8 2004/06/24 21:15:20 herbyderby Exp $ 22 | */ 23 | public interface MethodInterceptor 24 | extends Callback 25 | { 26 | /** 27 | * All generated proxied methods call this method instead of the original method. 28 | * The original method may either be invoked by normal reflection using the Method object, 29 | * or by using the MethodProxy (faster). 30 | * @param obj "this", the enhanced object 31 | * @param method intercepted Method 32 | * @param args argument array; primitive types are wrapped 33 | * @param proxy used to invoke super (non-intercepted method); may be called 34 | * as many times as needed 35 | * @throws Throwable any exception may be thrown; if so, super method will not be invoked 36 | * @return any value compatible with the signature of the proxied method. Method returning void will ignore this value. 37 | * @see MethodProxy 38 | */ 39 | public Object intercept(Object obj, java.lang.reflect.Method method, Object[] args, 40 | MethodProxy proxy) throws Throwable; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/MixinBeanEmitter.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import com.github.drinkjava2.asm.ClassVisitor; 21 | import com.github.drinkjava2.cglib.core.ReflectUtils; 22 | 23 | /** 24 | * @author Chris Nokleberg 25 | * @version $Id: MixinBeanEmitter.java,v 1.2 2004/06/24 21:15:20 herbyderby Exp $ 26 | */ 27 | @SuppressWarnings({"rawtypes" }) 28 | class MixinBeanEmitter extends MixinEmitter { 29 | public MixinBeanEmitter(ClassVisitor v, String className, Class[] classes) { 30 | super(v, className, classes, null); 31 | } 32 | 33 | protected Class[] getInterfaces(Class[] classes) { 34 | return null; 35 | } 36 | 37 | protected Method[] getMethods(Class type) { 38 | return ReflectUtils.getPropertyMethods(ReflectUtils.getBeanProperties(type), true, true); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/MixinEverythingEmitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | import java.lang.reflect.Method; 19 | import java.lang.reflect.Modifier; 20 | import java.util.*; 21 | 22 | import com.github.drinkjava2.asm.ClassVisitor; 23 | import com.github.drinkjava2.cglib.core.CollectionUtils; 24 | import com.github.drinkjava2.cglib.core.ReflectUtils; 25 | import com.github.drinkjava2.cglib.core.RejectModifierPredicate; 26 | 27 | /** 28 | * @author Chris Nokleberg 29 | * @version $Id: MixinEverythingEmitter.java,v 1.3 2004/06/24 21:15:19 herbyderby Exp $ 30 | */ 31 | @SuppressWarnings({"rawtypes","unchecked" }) 32 | class MixinEverythingEmitter extends MixinEmitter { 33 | 34 | public MixinEverythingEmitter(ClassVisitor v, String className, Class[] classes) { 35 | super(v, className, classes, null); 36 | } 37 | 38 | protected Class[] getInterfaces(Class[] classes) { 39 | List list = new ArrayList(); 40 | for (int i = 0; i < classes.length; i++) { 41 | ReflectUtils.addAllInterfaces(classes[i], list); 42 | } 43 | return (Class[])list.toArray(new Class[list.size()]); 44 | } 45 | 46 | protected Method[] getMethods(Class type) { 47 | List methods = new ArrayList(Arrays.asList(type.getMethods())); 48 | CollectionUtils.filter(methods, new RejectModifierPredicate(Modifier.FINAL | Modifier.STATIC)); 49 | return (Method[])methods.toArray(new Method[methods.size()]); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/NoOp.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | /** 19 | * Methods using this {@link Enhancer} callback will delegate directly to the 20 | * default (super) implementation in the base class. 21 | */ 22 | public interface NoOp extends Callback 23 | { 24 | /** 25 | * A thread-safe singleton instance of the NoOp callback. 26 | */ 27 | public static final NoOp INSTANCE = new NoOp() { }; 28 | } 29 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/NoOpGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | import java.util.Iterator; 19 | import java.util.List; 20 | 21 | import com.github.drinkjava2.cglib.core.ClassEmitter; 22 | import com.github.drinkjava2.cglib.core.CodeEmitter; 23 | import com.github.drinkjava2.cglib.core.EmitUtils; 24 | import com.github.drinkjava2.cglib.core.MethodInfo; 25 | import com.github.drinkjava2.cglib.core.TypeUtils; 26 | @SuppressWarnings({"rawtypes" }) 27 | class NoOpGenerator 28 | implements CallbackGenerator 29 | { 30 | public static final NoOpGenerator INSTANCE = new NoOpGenerator(); 31 | 32 | public void generate(ClassEmitter ce, Context context, List methods) { 33 | for (Iterator it = methods.iterator(); it.hasNext();) { 34 | MethodInfo method = (MethodInfo)it.next(); 35 | if (TypeUtils.isBridge(method.getModifiers()) || ( 36 | TypeUtils.isProtected(context.getOriginalModifiers(method)) && 37 | TypeUtils.isPublic(method.getModifiers()))) { 38 | CodeEmitter e = EmitUtils.begin_method(ce, method); 39 | e.load_this(); 40 | e.load_args(); 41 | context.emitInvoke(e, method); 42 | e.return_value(); 43 | e.end_method(); 44 | } 45 | } 46 | } 47 | 48 | public void generateStatic(CodeEmitter e, Context context, List methods) { } 49 | } 50 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/ProxyRefDispatcher.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.proxy; 17 | 18 | /** 19 | * Dispatching {@link Enhancer} callback. This is the same as the 20 | * {@link Dispatcher} except for the addition of an argument 21 | * which references the proxy object. 22 | */ 23 | public interface ProxyRefDispatcher extends Callback { 24 | /** 25 | * Return the object which the original method invocation should 26 | * be dispatched. This method is called for every method invocation. 27 | * @param proxy a reference to the proxy (generated) object 28 | * @return an object that can invoke the method 29 | */ 30 | Object loadObject(Object proxy) throws Exception; 31 | } 32 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/proxy/UndeclaredThrowableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002,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 | 17 | package com.github.drinkjava2.cglib.proxy; 18 | 19 | import com.github.drinkjava2.cglib.core.CodeGenerationException; 20 | 21 | /** 22 | * Used by {@link Proxy} as a replacement for java.lang.reflect.UndeclaredThrowableException. 23 | * @author Juozas Baliuka 24 | */ 25 | @SuppressWarnings("serial") 26 | public class UndeclaredThrowableException extends CodeGenerationException { 27 | /** 28 | * Creates a new instance of UndeclaredThrowableException without detail message. 29 | */ 30 | public UndeclaredThrowableException(Throwable t) { 31 | super(t); 32 | } 33 | 34 | public Throwable getUndeclaredThrowable() { 35 | return getCause(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/reflect/FastConstructor.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.reflect; 17 | 18 | import java.lang.reflect.Constructor; 19 | import java.lang.reflect.InvocationTargetException; 20 | @SuppressWarnings({"rawtypes" }) 21 | public class FastConstructor extends FastMember 22 | { 23 | FastConstructor(FastClass fc, Constructor constructor) { 24 | super(fc, constructor, fc.getIndex(constructor.getParameterTypes())); 25 | } 26 | 27 | public Class[] getParameterTypes() { 28 | return ((Constructor)member).getParameterTypes(); 29 | } 30 | 31 | public Class[] getExceptionTypes() { 32 | return ((Constructor)member).getExceptionTypes(); 33 | } 34 | 35 | public Object newInstance() throws InvocationTargetException { 36 | return fc.newInstance(index, null); 37 | } 38 | 39 | public Object newInstance(Object[] args) throws InvocationTargetException { 40 | return fc.newInstance(index, args); 41 | } 42 | 43 | public Constructor getJavaConstructor() { 44 | return (Constructor)member; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/reflect/FastMember.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.reflect; 17 | 18 | import java.lang.reflect.Member; 19 | @SuppressWarnings({"rawtypes" }) 20 | abstract public class FastMember 21 | { 22 | protected FastClass fc; 23 | protected Member member; 24 | protected int index; 25 | 26 | protected FastMember(FastClass fc, Member member, int index) { 27 | this.fc = fc; 28 | this.member = member; 29 | this.index = index; 30 | } 31 | 32 | abstract public Class[] getParameterTypes(); 33 | abstract public Class[] getExceptionTypes(); 34 | 35 | public int getIndex() { 36 | return index; 37 | } 38 | 39 | public String getName() { 40 | return member.getName(); 41 | } 42 | 43 | public Class getDeclaringClass() { 44 | return fc.getJavaClass(); 45 | } 46 | 47 | public int getModifiers() { 48 | return member.getModifiers(); 49 | } 50 | 51 | public String toString() { 52 | return member.toString(); 53 | } 54 | 55 | public int hashCode() { 56 | return member.hashCode(); 57 | } 58 | 59 | public boolean equals(Object o) { 60 | if (o == null || !(o instanceof FastMember)) { 61 | return false; 62 | } 63 | return member.equals(((FastMember)o).member); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/reflect/FastMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.reflect; 17 | 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.lang.reflect.Method; 20 | 21 | import com.github.drinkjava2.asm.Type; 22 | import com.github.drinkjava2.cglib.core.Signature; 23 | @SuppressWarnings({"rawtypes" }) 24 | public class FastMethod extends FastMember 25 | { 26 | FastMethod(FastClass fc, Method method) { 27 | super(fc, method, helper(fc, method)); 28 | } 29 | 30 | private static int helper(FastClass fc, Method method) { 31 | int index = fc.getIndex(new Signature(method.getName(), Type.getMethodDescriptor(method))); 32 | if (index < 0) { 33 | Class[] types = method.getParameterTypes(); 34 | System.err.println("hash=" + method.getName().hashCode() + " size=" + types.length); 35 | for (int i = 0; i < types.length; i++) { 36 | System.err.println(" types[" + i + "]=" + types[i].getName()); 37 | } 38 | throw new IllegalArgumentException("Cannot find method " + method); 39 | } 40 | return index; 41 | } 42 | 43 | public Class getReturnType() { 44 | return ((Method)member).getReturnType(); 45 | } 46 | 47 | public Class[] getParameterTypes() { 48 | return ((Method)member).getParameterTypes(); 49 | } 50 | 51 | public Class[] getExceptionTypes() { 52 | return ((Method)member).getExceptionTypes(); 53 | } 54 | 55 | public Object invoke(Object obj, Object[] args) throws InvocationTargetException { 56 | return fc.invoke(index, obj, args); 57 | } 58 | 59 | public Method getJavaMethod() { 60 | return (Method)member; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/AbstractClassTransformer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.ClassVisitor; 19 | import com.github.drinkjava2.asm.Opcodes; 20 | 21 | abstract public class AbstractClassTransformer extends ClassTransformer { 22 | protected AbstractClassTransformer() { 23 | super(Opcodes.ASM5); 24 | } 25 | 26 | public void setTarget(ClassVisitor target) { 27 | cv = target; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/AnnotationVisitorTee.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.AnnotationVisitor; 19 | import com.github.drinkjava2.asm.Opcodes; 20 | 21 | public class AnnotationVisitorTee extends AnnotationVisitor { 22 | private AnnotationVisitor av1, av2; 23 | 24 | public static AnnotationVisitor getInstance(AnnotationVisitor av1, AnnotationVisitor av2) { 25 | if (av1 == null) 26 | return av2; 27 | if (av2 == null) 28 | return av1; 29 | return new AnnotationVisitorTee(av1, av2); 30 | } 31 | 32 | public AnnotationVisitorTee(AnnotationVisitor av1, AnnotationVisitor av2) { 33 | super(Opcodes.ASM5); 34 | this.av1 = av1; 35 | this.av2 = av2; 36 | } 37 | 38 | public void visit(String name, Object value) { 39 | av2.visit(name, value); 40 | av2.visit(name, value); 41 | } 42 | 43 | public void visitEnum(String name, String desc, String value) { 44 | av1.visitEnum(name, desc, value); 45 | av2.visitEnum(name, desc, value); 46 | } 47 | 48 | public AnnotationVisitor visitAnnotation(String name, String desc) { 49 | return getInstance(av1.visitAnnotation(name, desc), 50 | av2.visitAnnotation(name, desc)); 51 | } 52 | 53 | public AnnotationVisitor visitArray(String name) { 54 | return getInstance(av1.visitArray(name), av2.visitArray(name)); 55 | } 56 | 57 | public void visitEnd() { 58 | av1.visitEnd(); 59 | av2.visitEnd(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/ClassEmitterTransformer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.cglib.core.ClassEmitter; 19 | 20 | abstract public class ClassEmitterTransformer extends ClassEmitter { 21 | } 22 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/ClassFilter.java: -------------------------------------------------------------------------------- 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 | 17 | package com.github.drinkjava2.cglib.transform; 18 | 19 | /** 20 | * 21 | * @author baliuka 22 | */ 23 | public interface ClassFilter { 24 | 25 | boolean accept(String className); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/ClassFilterTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.transform; 17 | 18 | public class ClassFilterTransformer extends AbstractClassFilterTransformer { 19 | private ClassFilter filter; 20 | 21 | public ClassFilterTransformer(ClassFilter filter, ClassTransformer pass) { 22 | super(pass); 23 | this.filter = filter; 24 | } 25 | 26 | protected boolean accept(int version, int access, String name, String signature, String superName, String[] interfaces) { 27 | return filter.accept(name.replace('/', '.')); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/ClassReaderGenerator.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.Attribute; 19 | import com.github.drinkjava2.asm.ClassReader; 20 | import com.github.drinkjava2.asm.ClassVisitor; 21 | import com.github.drinkjava2.cglib.core.ClassGenerator; 22 | 23 | public class ClassReaderGenerator implements ClassGenerator { 24 | private final ClassReader r; 25 | private final Attribute[] attrs; 26 | private final int flags; 27 | 28 | public ClassReaderGenerator(ClassReader r, int flags) { 29 | this(r, null, flags); 30 | } 31 | 32 | public ClassReaderGenerator(ClassReader r, Attribute[] attrs, int flags) { 33 | this.r = r; 34 | this.attrs = (attrs != null) ? attrs : new Attribute[0]; 35 | this.flags = flags; 36 | } 37 | 38 | public void generateClass(ClassVisitor v) { 39 | r.accept(v, attrs, flags); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/ClassTransformer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.ClassVisitor; 19 | import com.github.drinkjava2.asm.Opcodes; 20 | 21 | public abstract class ClassTransformer extends ClassVisitor { 22 | public ClassTransformer() { 23 | super(Opcodes.ASM5); 24 | } 25 | public ClassTransformer(int opcode) { 26 | super(opcode); 27 | } 28 | public abstract void setTarget(ClassVisitor target); 29 | } 30 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/ClassTransformerChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.ClassVisitor; 19 | import com.github.drinkjava2.asm.MethodVisitor; 20 | 21 | public class ClassTransformerChain extends AbstractClassTransformer { 22 | private ClassTransformer[] chain; 23 | 24 | public ClassTransformerChain(ClassTransformer[] chain) { 25 | this.chain = (ClassTransformer[])chain.clone(); 26 | } 27 | 28 | public void setTarget(ClassVisitor v) { 29 | super.setTarget(chain[0]); 30 | ClassVisitor next = v; 31 | for (int i = chain.length - 1; i >= 0; i--) { 32 | chain[i].setTarget(next); 33 | next = chain[i]; 34 | } 35 | } 36 | 37 | public MethodVisitor visitMethod(int access, 38 | String name, 39 | String desc, 40 | String signature, 41 | String[] exceptions) { 42 | return cv.visitMethod(access, name, desc, signature, exceptions); 43 | } 44 | 45 | public String toString() { 46 | StringBuffer sb = new StringBuffer(); 47 | sb.append("ClassTransformerChain{"); 48 | for (int i = 0; i < chain.length; i++) { 49 | if (i > 0) { 50 | sb.append(", "); 51 | } 52 | sb.append(chain[i].toString()); 53 | } 54 | sb.append("}"); 55 | return sb.toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/ClassTransformerFactory.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | public interface ClassTransformerFactory { 19 | ClassTransformer newInstance(); 20 | } 21 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/ClassTransformerTee.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.ClassVisitor; 19 | import com.github.drinkjava2.asm.Opcodes; 20 | 21 | public class ClassTransformerTee extends ClassTransformer { 22 | private ClassVisitor branch; 23 | 24 | public ClassTransformerTee(ClassVisitor branch) { 25 | super(Opcodes.ASM5); 26 | this.branch = branch; 27 | } 28 | 29 | public void setTarget(ClassVisitor target) { 30 | cv = new ClassVisitorTee(branch, target); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/FieldVisitorTee.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.AnnotationVisitor; 19 | import com.github.drinkjava2.asm.Attribute; 20 | import com.github.drinkjava2.asm.FieldVisitor; 21 | import com.github.drinkjava2.asm.Opcodes; 22 | import com.github.drinkjava2.asm.TypePath; 23 | 24 | public class FieldVisitorTee extends FieldVisitor { 25 | private FieldVisitor fv1, fv2; 26 | 27 | public FieldVisitorTee(FieldVisitor fv1, FieldVisitor fv2) { 28 | super(Opcodes.ASM5); 29 | this.fv1 = fv1; 30 | this.fv2 = fv2; 31 | } 32 | 33 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { 34 | return AnnotationVisitorTee.getInstance(fv1.visitAnnotation(desc, visible), 35 | fv2.visitAnnotation(desc, visible)); 36 | } 37 | 38 | public void visitAttribute(Attribute attr) { 39 | fv1.visitAttribute(attr); 40 | fv2.visitAttribute(attr); 41 | } 42 | 43 | public void visitEnd() { 44 | fv1.visitEnd(); 45 | fv2.visitEnd(); 46 | } 47 | 48 | public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { 49 | return AnnotationVisitorTee.getInstance(fv1.visitTypeAnnotation(typeRef, typePath, desc, visible), 50 | fv2.visitTypeAnnotation(typeRef, typePath, desc, visible)); 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/MethodFilter.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | public interface MethodFilter { 19 | // TODO: pass class name too? 20 | boolean accept(int access, String name, String desc, String signature, String[] exceptions); 21 | } 22 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/MethodFilterTransformer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.ClassVisitor; 19 | import com.github.drinkjava2.asm.MethodVisitor; 20 | 21 | public class MethodFilterTransformer extends AbstractClassTransformer { 22 | private MethodFilter filter; 23 | private ClassTransformer pass; 24 | private ClassVisitor direct; 25 | 26 | public MethodFilterTransformer(MethodFilter filter, ClassTransformer pass) { 27 | this.filter = filter; 28 | this.pass = pass; 29 | super.setTarget(pass); 30 | } 31 | 32 | public MethodVisitor visitMethod(int access, 33 | String name, 34 | String desc, 35 | String signature, 36 | String[] exceptions) { 37 | return (filter.accept(access, name, desc, signature, exceptions) ? pass : direct).visitMethod(access, name, desc, signature, exceptions); 38 | } 39 | 40 | public void setTarget(ClassVisitor target) { 41 | pass.setTarget(target); 42 | direct = target; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/TransformingClassGenerator.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.ClassVisitor; 19 | import com.github.drinkjava2.cglib.core.ClassGenerator; 20 | 21 | public class TransformingClassGenerator implements ClassGenerator { 22 | private ClassGenerator gen; 23 | private ClassTransformer t; 24 | 25 | public TransformingClassGenerator(ClassGenerator gen, ClassTransformer t) { 26 | this.gen = gen; 27 | this.t = t; 28 | } 29 | 30 | public void generateClass(ClassVisitor v) throws Exception { 31 | t.setTarget(v); 32 | gen.generateClass(t); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/TransformingClassLoader.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform; 17 | 18 | import com.github.drinkjava2.asm.ClassReader; 19 | import com.github.drinkjava2.cglib.core.ClassGenerator; 20 | 21 | public class TransformingClassLoader extends AbstractClassLoader { 22 | private ClassTransformerFactory t; 23 | 24 | public TransformingClassLoader(ClassLoader parent, ClassFilter filter, ClassTransformerFactory t) { 25 | super(parent, parent, filter); 26 | this.t = t; 27 | } 28 | 29 | protected ClassGenerator getGenerator(ClassReader r) { 30 | ClassTransformer t2 = (ClassTransformer)t.newInstance(); 31 | return new TransformingClassGenerator(super.getGenerator(r), t2); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/AbstractInterceptFieldCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | /** 19 | * @author Chris Nokleberg 20 | */ 21 | public class AbstractInterceptFieldCallback implements InterceptFieldCallback { 22 | 23 | public int writeInt(Object obj, String name, int oldValue, int newValue) { return newValue; } 24 | public char writeChar(Object obj, String name, char oldValue, char newValue) { return newValue; } 25 | public byte writeByte(Object obj, String name, byte oldValue, byte newValue) { return newValue; } 26 | public boolean writeBoolean(Object obj, String name, boolean oldValue, boolean newValue) { return newValue; } 27 | public short writeShort(Object obj, String name, short oldValue, short newValue) { return newValue; } 28 | public float writeFloat(Object obj, String name, float oldValue, float newValue) { return newValue; } 29 | public double writeDouble(Object obj, String name, double oldValue, double newValue) { return newValue; } 30 | public long writeLong(Object obj, String name, long oldValue, long newValue) { return newValue; } 31 | public Object writeObject(Object obj, String name, Object oldValue, Object newValue) { return newValue; } 32 | 33 | public int readInt(Object obj, String name, int oldValue) { return oldValue; } 34 | public char readChar(Object obj, String name, char oldValue) { return oldValue; } 35 | public byte readByte(Object obj, String name, byte oldValue) { return oldValue; } 36 | public boolean readBoolean(Object obj, String name, boolean oldValue) { return oldValue; } 37 | public short readShort(Object obj, String name, short oldValue) { return oldValue; } 38 | public float readFloat(Object obj, String name, float oldValue) { return oldValue; } 39 | public double readDouble(Object obj, String name, double oldValue) { return oldValue; } 40 | public long readLong(Object obj, String name, long oldValue) { return oldValue; } 41 | public Object readObject(Object obj, String name, Object oldValue) { return oldValue; } 42 | } 43 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/AccessFieldTransformer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | import com.github.drinkjava2.asm.Type; 19 | import com.github.drinkjava2.cglib.core.CodeEmitter; 20 | import com.github.drinkjava2.cglib.core.Constants; 21 | import com.github.drinkjava2.cglib.core.Signature; 22 | import com.github.drinkjava2.cglib.core.TypeUtils; 23 | import com.github.drinkjava2.cglib.transform.ClassEmitterTransformer; 24 | 25 | public class AccessFieldTransformer extends ClassEmitterTransformer { 26 | private Callback callback; 27 | 28 | public AccessFieldTransformer(Callback callback) { 29 | this.callback = callback; 30 | } 31 | 32 | public interface Callback { 33 | String getPropertyName(Type owner, String fieldName); 34 | } 35 | 36 | public void declare_field(int access, final String name, Type type, Object value) { 37 | super.declare_field(access, name, type, value); 38 | 39 | String property = TypeUtils.upperFirst(callback.getPropertyName(getClassType(), name)); 40 | if (property != null) { 41 | CodeEmitter e; 42 | e = begin_method(Constants.ACC_PUBLIC, 43 | new Signature("get" + property, 44 | type, 45 | Constants.TYPES_EMPTY), 46 | null); 47 | e.load_this(); 48 | e.getfield(name); 49 | e.return_value(); 50 | e.end_method(); 51 | 52 | e = begin_method(Constants.ACC_PUBLIC, 53 | new Signature("set" + property, 54 | Type.VOID_TYPE, 55 | new Type[]{ type }), 56 | null); 57 | e.load_this(); 58 | e.load_arg(0); 59 | e.putfield(name); 60 | e.return_value(); 61 | e.end_method(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/AddInitTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import com.github.drinkjava2.asm.Type; 21 | import com.github.drinkjava2.cglib.core.CodeEmitter; 22 | import com.github.drinkjava2.cglib.core.Constants; 23 | import com.github.drinkjava2.cglib.core.MethodInfo; 24 | import com.github.drinkjava2.cglib.core.ReflectUtils; 25 | import com.github.drinkjava2.cglib.core.Signature; 26 | import com.github.drinkjava2.cglib.transform.ClassEmitterTransformer; 27 | 28 | /** 29 | * @author Mark Hobson 30 | */ 31 | public class AddInitTransformer extends ClassEmitterTransformer { 32 | private MethodInfo info; 33 | 34 | public AddInitTransformer(Method method) { 35 | info = ReflectUtils.getMethodInfo(method); 36 | 37 | Type[] types = info.getSignature().getArgumentTypes(); 38 | if (types.length != 1 || 39 | !types[0].equals(Constants.TYPE_OBJECT) || 40 | !info.getSignature().getReturnType().equals(Type.VOID_TYPE)) { 41 | throw new IllegalArgumentException(method + " illegal signature"); 42 | } 43 | } 44 | 45 | public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) { 46 | final CodeEmitter emitter = super.begin_method(access, sig, exceptions); 47 | if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) { 48 | return new CodeEmitter(emitter) { 49 | public void visitInsn(int opcode) { 50 | if (opcode == Constants.RETURN) { 51 | load_this(); 52 | invoke(info); 53 | } 54 | super.visitInsn(opcode); 55 | } 56 | }; 57 | } 58 | return emitter; 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/AddPropertyTransformer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | import java.util.Map; 19 | 20 | import com.github.drinkjava2.asm.Type; 21 | import com.github.drinkjava2.cglib.core.EmitUtils; 22 | import com.github.drinkjava2.cglib.core.TypeUtils; 23 | import com.github.drinkjava2.cglib.transform.ClassEmitterTransformer; 24 | @SuppressWarnings({"rawtypes" }) 25 | public class AddPropertyTransformer extends ClassEmitterTransformer { 26 | private final String[] names; 27 | private final Type[] types; 28 | 29 | public AddPropertyTransformer(Map props) { 30 | int size = props.size(); 31 | names = (String[])props.keySet().toArray(new String[size]); 32 | types = new Type[size]; 33 | for (int i = 0; i < size; i++) { 34 | types[i] = (Type)props.get(names[i]); 35 | } 36 | } 37 | 38 | public AddPropertyTransformer(String[] names, Type[] types) { 39 | this.names = names; 40 | this.types = types; 41 | } 42 | 43 | public void end_class() { 44 | if (!TypeUtils.isAbstract(getAccess())) { 45 | EmitUtils.add_properties(this, names, types); 46 | } 47 | super.end_class(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/AddStaticInitTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003,2004 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import com.github.drinkjava2.asm.Type; 21 | import com.github.drinkjava2.cglib.core.CodeEmitter; 22 | import com.github.drinkjava2.cglib.core.Constants; 23 | import com.github.drinkjava2.cglib.core.EmitUtils; 24 | import com.github.drinkjava2.cglib.core.MethodInfo; 25 | import com.github.drinkjava2.cglib.core.ReflectUtils; 26 | import com.github.drinkjava2.cglib.core.TypeUtils; 27 | import com.github.drinkjava2.cglib.transform.ClassEmitterTransformer; 28 | 29 | /** 30 | * @author Juozas Baliuka, Chris Nokleberg 31 | */ 32 | public class AddStaticInitTransformer extends ClassEmitterTransformer { 33 | private MethodInfo info; 34 | 35 | public AddStaticInitTransformer(Method classInit) { 36 | info = ReflectUtils.getMethodInfo(classInit); 37 | if (!TypeUtils.isStatic(info.getModifiers())) { 38 | throw new IllegalArgumentException(classInit + " is not static"); 39 | } 40 | Type[] types = info.getSignature().getArgumentTypes(); 41 | if (types.length != 1 || 42 | !types[0].equals(Constants.TYPE_CLASS) || 43 | !info.getSignature().getReturnType().equals(Type.VOID_TYPE)) { 44 | throw new IllegalArgumentException(classInit + " illegal signature"); 45 | } 46 | } 47 | 48 | protected void init() { 49 | if (!TypeUtils.isInterface(getAccess())) { 50 | CodeEmitter e = getStaticHook(); 51 | EmitUtils.load_class_this(e); 52 | e.invoke(info); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/FieldProvider.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform.impl; 17 | @SuppressWarnings({"rawtypes" }) 18 | public interface FieldProvider { 19 | 20 | String[] getFieldNames(); 21 | 22 | Class[] getFieldTypes(); 23 | 24 | void setField(int index, Object value); 25 | 26 | Object getField(int index); 27 | 28 | 29 | void setField(String name, Object value); 30 | 31 | Object getField(String name); 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/InterceptFieldCallback.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | /** 19 | * @author Juozas Baliuka 20 | */ 21 | public interface InterceptFieldCallback { 22 | 23 | int writeInt(Object obj, String name, int oldValue, int newValue); 24 | char writeChar(Object obj, String name, char oldValue, char newValue); 25 | byte writeByte(Object obj, String name, byte oldValue, byte newValue); 26 | boolean writeBoolean(Object obj, String name, boolean oldValue, boolean newValue); 27 | short writeShort(Object obj, String name, short oldValue, short newValue); 28 | float writeFloat(Object obj, String name, float oldValue, float newValue); 29 | double writeDouble(Object obj, String name, double oldValue, double newValue); 30 | long writeLong(Object obj, String name, long oldValue, long newValue); 31 | Object writeObject(Object obj, String name, Object oldValue, Object newValue); 32 | 33 | int readInt(Object obj, String name, int oldValue); 34 | char readChar(Object obj, String name, char oldValue); 35 | byte readByte(Object obj, String name, byte oldValue); 36 | boolean readBoolean(Object obj, String name, boolean oldValue); 37 | short readShort(Object obj, String name, short oldValue); 38 | float readFloat(Object obj, String name, float oldValue); 39 | double readDouble(Object obj, String name, double oldValue); 40 | long readLong(Object obj, String name, long oldValue); 41 | Object readObject(Object obj, String name, Object oldValue); 42 | } 43 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/InterceptFieldEnabled.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | public interface InterceptFieldEnabled { 19 | void setInterceptFieldCallback(InterceptFieldCallback callback); 20 | InterceptFieldCallback getInterceptFieldCallback(); 21 | } 22 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/InterceptFieldFilter.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | import com.github.drinkjava2.asm.Type; 19 | 20 | public interface InterceptFieldFilter { 21 | boolean acceptRead(Type owner, String name); 22 | boolean acceptWrite(Type owner, String name); 23 | } 24 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/UndeclaredThrowableStrategy.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | import com.github.drinkjava2.cglib.core.ClassGenerator; 19 | import com.github.drinkjava2.cglib.core.DefaultGeneratorStrategy; 20 | import com.github.drinkjava2.cglib.core.GeneratorStrategy; 21 | import com.github.drinkjava2.cglib.core.TypeUtils; 22 | import com.github.drinkjava2.cglib.transform.ClassTransformer; 23 | import com.github.drinkjava2.cglib.transform.MethodFilter; 24 | import com.github.drinkjava2.cglib.transform.MethodFilterTransformer; 25 | import com.github.drinkjava2.cglib.transform.TransformingClassGenerator; 26 | 27 | /** 28 | * A {@link GeneratorStrategy} suitable for use with {@link com.github.drinkjava2.cglib.proxy.Enhancer} which 29 | * causes all undeclared exceptions thrown from within a proxied method to be wrapped 30 | * in an alternative exception of your choice. 31 | */ 32 | @SuppressWarnings({"rawtypes" }) 33 | public class UndeclaredThrowableStrategy extends DefaultGeneratorStrategy { 34 | 35 | 36 | private Class wrapper; 37 | 38 | /** 39 | * Create a new instance of this strategy. 40 | * @param wrapper a class which extends either directly or 41 | * indirectly from Throwable and which has at least one 42 | * constructor that takes a single argument of type 43 | * Throwable, for example 44 | * java.lang.reflect.UndeclaredThrowableException.class 45 | */ 46 | public UndeclaredThrowableStrategy(Class wrapper) { 47 | this.wrapper = wrapper; 48 | } 49 | 50 | private static final MethodFilter TRANSFORM_FILTER = new MethodFilter() { 51 | public boolean accept(int access, String name, String desc, String signature, String[] exceptions) { 52 | return !TypeUtils.isPrivate(access) && name.indexOf('$') < 0; 53 | } 54 | }; 55 | 56 | protected ClassGenerator transform(ClassGenerator cg) throws Exception { 57 | ClassTransformer tr = new UndeclaredThrowableTransformer(wrapper); 58 | tr = new MethodFilterTransformer(TRANSFORM_FILTER, tr); 59 | return new TransformingClassGenerator(cg, tr); 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/cglib/transform/impl/UndeclaredThrowableTransformer.java: -------------------------------------------------------------------------------- 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 com.github.drinkjava2.cglib.transform.impl; 17 | 18 | import java.lang.reflect.Constructor; 19 | 20 | import com.github.drinkjava2.asm.Type; 21 | import com.github.drinkjava2.cglib.core.Block; 22 | import com.github.drinkjava2.cglib.core.CodeEmitter; 23 | import com.github.drinkjava2.cglib.core.Constants; 24 | import com.github.drinkjava2.cglib.core.EmitUtils; 25 | import com.github.drinkjava2.cglib.core.Signature; 26 | import com.github.drinkjava2.cglib.core.TypeUtils; 27 | import com.github.drinkjava2.cglib.transform.ClassEmitterTransformer; 28 | @SuppressWarnings({"rawtypes" }) 29 | public class UndeclaredThrowableTransformer extends ClassEmitterTransformer { 30 | private Type wrapper; 31 | 32 | public UndeclaredThrowableTransformer(Class wrapper) { 33 | this.wrapper = Type.getType(wrapper); 34 | boolean found = false; 35 | Constructor[] cstructs = wrapper.getConstructors(); 36 | for (int i = 0; i < cstructs.length; i++) { 37 | Class[] types = cstructs[i].getParameterTypes(); 38 | if (types.length == 1 && types[0].equals(Throwable.class)) { 39 | found = true; 40 | break; 41 | } 42 | } 43 | if (!found) 44 | throw new IllegalArgumentException(wrapper + " does not have a single-arg constructor that takes a Throwable"); 45 | } 46 | 47 | public CodeEmitter begin_method(int access, final Signature sig, final Type[] exceptions) { 48 | CodeEmitter e = super.begin_method(access, sig, exceptions); 49 | if (TypeUtils.isAbstract(access) || sig.equals(Constants.SIG_STATIC)) { 50 | return e; 51 | } 52 | return new CodeEmitter(e) { 53 | private Block handler; 54 | /* init */ { 55 | handler = begin_block(); 56 | } 57 | public void visitMaxs(int maxStack, int maxLocals) { 58 | handler.end(); 59 | EmitUtils.wrap_undeclared_throwable(this, handler, exceptions, wrapper); 60 | super.visitMaxs(maxStack, maxLocals); 61 | } 62 | }; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/AopUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox; 11 | 12 | import com.github.drinkjava2.cglib.proxy.Enhancer; 13 | 14 | /** 15 | * AopUtils create AOP proxy bean 16 | * 17 | * @author Yong Zhu 18 | * @since 2.4 19 | * 20 | */ 21 | public class AopUtils {// NOSONAR 22 | 23 | /** 24 | * Create a ProxyBean 25 | * 26 | * @param clazz 27 | * The target class 28 | * @param box 29 | * The BeanBox of target class 30 | * @param ctx 31 | * The BeanBoxContext 32 | * @return A Proxy Bean with AOP support 33 | */ 34 | public static Object createProxyBean(Class clazz, BeanBox box, BeanBoxContext ctx) { 35 | BeanBoxException.assureNotNull(clazz, "Try to create a proxy bean, but beanClass not found."); 36 | Enhancer enhancer = new Enhancer(); 37 | enhancer.setSuperclass(clazz); 38 | if (box.getConstructorParams() != null && box.getConstructorParams().length > 0) { 39 | BeanBox[] boxes = box.getConstructorParams(); 40 | Class[] argsTypes = new Class[boxes.length]; 41 | Object[] realArgsValue = new Object[boxes.length]; 42 | for (int i = 0; i < boxes.length; i++) { 43 | argsTypes[i] = boxes[i].getType(); 44 | Object realValue = ctx.getBean(boxes[i]); 45 | if (realValue instanceof String) 46 | realValue = ctx.getValueTranslator().translate((String) realValue, boxes[i].getType()); 47 | realArgsValue[i] = realValue; 48 | } 49 | enhancer.setCallback(new ProxyBean(box, ctx)); 50 | return enhancer.create(argsTypes, realArgsValue); 51 | } else { 52 | enhancer.setCallback(new ProxyBean(box, ctx)); 53 | return enhancer.create(); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/BeanBoxException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox; 11 | 12 | /** 13 | * BeanBoxException for jBeanBox 14 | * 15 | * @author Yong Zhu 16 | * @since 1.0.0 17 | */ 18 | public class BeanBoxException extends RuntimeException { 19 | private static final long serialVersionUID = 1L; 20 | 21 | public BeanBoxException() { 22 | // Default constructor 23 | } 24 | 25 | public BeanBoxException(String message) { 26 | super(message); 27 | } 28 | 29 | public BeanBoxException(Throwable cause) { 30 | super(cause); 31 | } 32 | 33 | public BeanBoxException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | public static T throwEX(String errorMsg, Throwable e) { 38 | throw new BeanBoxException(errorMsg, e); 39 | } 40 | 41 | public static T throwEX(Throwable cause) { 42 | throw new BeanBoxException(cause); 43 | } 44 | 45 | public static T throwEX(String errorMsg) { 46 | throw new BeanBoxException(errorMsg); 47 | } 48 | 49 | public static boolean assureNotNull(Object obj, String... optionMessages) { 50 | if (obj == null) 51 | throw new BeanBoxException( 52 | optionMessages.length == 0 ? "Assert error, Object parameter can not be null" : optionMessages[0]); 53 | return true; 54 | } 55 | 56 | public static boolean assureNotEmpty(String str, String... optionMessages) { 57 | if (str == null || str.length() == 0) 58 | throw new BeanBoxException( 59 | optionMessages.length == 0 ? "Assert error, String parameter can not be empty" : optionMessages[0]); 60 | return true; 61 | } 62 | 63 | public static boolean assure(boolean condition, String... optionMessages) { 64 | if (!condition) 65 | throw new BeanBoxException( 66 | optionMessages.length == 0 ? "Assert expected true but got false" : optionMessages[0]); 67 | return true; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/EMPTY.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox; 11 | 12 | /** 13 | * EMPTY used to mark a EMPTY value 14 | * 15 | * @author Yong Zhu 16 | * @since 2.4.8 17 | * 18 | */ 19 | public final class EMPTY {// NOSONAR 20 | } 21 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/NameMatchUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox; 11 | 12 | /** 13 | * A simple string matcher tool 14 | * 15 | * @author Yong Zhu 16 | * @since 2.5.0 17 | */ 18 | public class NameMatchUtil { // NOSONAR 19 | /** 20 | * A simple string matcher, only 1 * allowed, but many regex string can 21 | * seperated by "|" char, for example:
22 | * "abc.ef*|*gh|ijk*lmn" matches "abc.efxxx", "xxxgh","ijkxxxlmn" 23 | */ 24 | public static boolean nameMatch(String regex, String name) { 25 | if (regex == null || regex.length() == 0 || name == null || name.length() == 0) 26 | return false; 27 | do { 28 | int i = regex.indexOf('|'); 29 | if (i < 0) 30 | return doSingleNameMatch(regex, name); 31 | if (doSingleNameMatch(regex.substring(0, i), name)) 32 | return true; 33 | regex = regex.substring(i + 1);// NOSONAR 34 | } while (true); 35 | } 36 | 37 | /** A simple matcher, only 1 * allowed represents any string */ 38 | private static boolean doSingleNameMatch(String regex, String name) { 39 | if (regex == null || regex.length() == 0 || name == null || name.length() == 0) 40 | return false; 41 | if ('*' == (regex.charAt(0))) { 42 | return name.endsWith(regex.substring(1)); 43 | } else if (regex.endsWith("*")) { 44 | return name.startsWith(regex.substring(0, regex.length() - 1)); 45 | } else { 46 | int starPos = regex.indexOf('*'); 47 | if (-1 == starPos) 48 | return regex.equals(name); 49 | return name.startsWith(regex.substring(0, starPos)) && name.endsWith(regex.substring(starPos + 1)); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/PrototypeBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox; 11 | 12 | /** Subclass implemented this interface will create prototype bean */ 13 | public interface PrototypeBean {// NOSONAR 14 | } 15 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/ValueTranslator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox; 11 | 12 | /** 13 | * ValueTranslator translate a String to a real value, user can write other 14 | * ValueTranslator to replace the DefaultConstTranslator 15 | * 16 | * @author Yong Zhu 17 | * @since 2.4.7 18 | * 19 | */ 20 | public interface ValueTranslator { 21 | 22 | public Object translate(String s, Class type); 23 | 24 | public static class DefaultValueTranslator implements ValueTranslator { 25 | 26 | @Override 27 | public Object translate(String s, Class type) {// NOSONAR 28 | if (type == null) 29 | BeanBoxException.throwEX("ParamTranslator can not translate to 'null' type"); 30 | if (Integer.class.equals(type) || int.class.equals(type)) 31 | return Integer.parseInt(s); 32 | if (Long.class.equals(type) || long.class.equals(type)) 33 | return Long.parseLong(s); 34 | if (Character.class.equals(type) || char.class.equals(type)) 35 | return s.charAt(0); 36 | if (Byte.class.equals(type) || byte.class.equals(type)) 37 | return Byte.parseByte(s); 38 | if (Boolean.class.equals(type) || boolean.class.equals(type)) 39 | return Boolean.parseBoolean(s); 40 | if (Double.class.equals(type) || double.class.equals(type)) 41 | return Double.parseDouble(s); 42 | if (Float.class.equals(type) || float.class.equals(type)) 43 | return Float.parseFloat(s); 44 | if (Short.class.equals(type) || short.class.equals(type)) 45 | return Short.parseShort(s); 46 | if (String.class.equals(type)) 47 | return s; 48 | return BeanBoxException.throwEX("Unsupported type:" + type); 49 | } 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/AOP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import java.lang.annotation.ElementType; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.RetentionPolicy; 15 | import java.lang.annotation.Target; 16 | 17 | /** 18 | * AOP used to mark a AOP annotation, for example:
19 | * 20 | *

21 |  * @Retention(RetentionPolicy.RUNTIME)
22 |  * @Target({ ElementType.TYPE, ElementType.METHOD })
23 |  * @AOP
24 |  * public static @interface MyAop {
25 |  * 	public Class value() default Interceptor1.class;
26 |  * 
27 |  * 	public String method() default "";
28 |  * }
29 |  * 
30 |  * @MyAop
31 |  * public class User {
32 |  * 
33 |  *   @MyAop
34 |  *   public void setName(){
35 |  *   ....
36 |  *   }
37 |  * }
38 |  * 
39 |  * 
40 |  * 
41 | * 42 | * Note: for method, method field definition is not required 43 | * 44 | * 45 | * @author Yong Zhu 46 | * @since 2.4.7 47 | * 48 | */ 49 | @Target(ElementType.ANNOTATION_TYPE) 50 | @Retention(RetentionPolicy.RUNTIME) 51 | public @interface AOP { 52 | } 53 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/COMPONENT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import java.lang.annotation.ElementType; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.RetentionPolicy; 15 | import java.lang.annotation.Target; 16 | 17 | /** 18 | * @COMPONENT used to mark a component, similar like @Component 19 | * annotation in Spring 20 | * 21 | * @author Yong Zhu 22 | * @since 2.5.0 23 | */ 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target(ElementType.TYPE) 26 | public @interface COMPONENT { 27 | /** If not empty, the value is the bean name */ 28 | String value() default ""; 29 | } 30 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/INJECT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import java.lang.annotation.ElementType; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.RetentionPolicy; 15 | import java.lang.annotation.Target; 16 | 17 | import com.github.drinkjava2.jbeanbox.EMPTY; 18 | 19 | /** 20 | * INJECT used to inject BeanBox class for class, fields, method, parameter 21 | * 22 | * @author Yong Zhu 23 | * @since 2.4.7 24 | * 25 | */ 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER }) 28 | public @interface INJECT { 29 | 30 | public Class value() default EMPTY.class; // the target, default is EMPTY.class 31 | 32 | public boolean pureValue() default false; // if true mean values is a pure class value, otherwise value is a target 33 | 34 | public boolean required() default true; // if true when target not found will throw exception, if false keep silence 35 | 36 | } -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/NAMED.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import java.lang.annotation.ElementType; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.RetentionPolicy; 15 | import java.lang.annotation.Target; 16 | 17 | /** 18 | * @NAMED similar like JSR330's @Named annotation 19 | * 20 | * @author Yong Zhu 21 | * @since 2.4.7 22 | * 23 | */ 24 | @QUALIFILER 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER }) 27 | public @interface NAMED { 28 | public String value() default ""; 29 | } 30 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/POSTCONSTRUCT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import static java.lang.annotation.ElementType.METHOD; 13 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.Target; 18 | 19 | /** 20 | * The POSTCONSTRUCT annotation is used on a method that needs to be executed 21 | * after dependency injection is done to perform any initialization. 22 | */ 23 | @Documented 24 | @Retention(RUNTIME) 25 | @Target(METHOD) 26 | public @interface POSTCONSTRUCT { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/PREDESTROY.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import static java.lang.annotation.ElementType.METHOD; 13 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.Target; 18 | 19 | /** 20 | * The PREDESTROY annotation is used on methods as a callback notification to 21 | * signal that the instance is in the process of being removed by the container. 22 | * The method annotated with PreDestroy is typically used to release resources 23 | * that it has been holding. 24 | */ 25 | 26 | @Documented 27 | @Retention(RUNTIME) 28 | @Target(METHOD) 29 | public @interface PREDESTROY { 30 | } 31 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/PROTOTYPE.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import java.lang.annotation.ElementType; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.RetentionPolicy; 15 | import java.lang.annotation.Target; 16 | 17 | /** 18 | * Mark a bean is prototype, not singleton, it means each time will build a new 19 | * instance. 20 | * 21 | * @author Yong Zhu 22 | * @since 2.4 23 | * 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.TYPE }) 27 | public @interface PROTOTYPE { 28 | } 29 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/QUALIFILER.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 13 | 14 | import java.lang.annotation.ElementType; 15 | import java.lang.annotation.Retention; 16 | import java.lang.annotation.RetentionPolicy; 17 | import java.lang.annotation.Target; 18 | 19 | /** 20 | * QUALIFILER similar like jsr330's Qualifiler 21 | * 22 | * @author Yong Zhu 23 | * @since 2.4.7 24 | * 25 | */ 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target({ ANNOTATION_TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER }) 28 | public @interface QUALIFILER { 29 | } 30 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/com/github/drinkjava2/jbeanbox/annotation/VALUE.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 | * use this file except in compliance with the License. You may obtain a copy of 4 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 5 | * applicable law or agreed to in writing, software distributed under the 6 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 7 | * OF ANY KIND, either express or implied. See the License for the specific 8 | * language governing permissions and limitations under the License. 9 | */ 10 | package com.github.drinkjava2.jbeanbox.annotation; 11 | 12 | import java.lang.annotation.ElementType; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.RetentionPolicy; 15 | import java.lang.annotation.Target; 16 | 17 | /** 18 | * VALUE for inject a String String or primative value, similar like Spring's 19 | * Value annotation, current version jBeanBox does not read values from property 20 | * file, to do that need use BeanBoxContext's setValueTranslator method to 21 | * customize the value transalator 22 | * 23 | * @author Yong Zhu 24 | * @since 2.4.7 25 | * 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.FIELD, ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER }) 29 | public @interface VALUE { 30 | public String value(); 31 | } 32 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/javax/annotation/PostConstruct.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The contents of this file are subject to the terms 3 | * of the Common Development and Distribution License 4 | * (the "License"). You may not use this file except 5 | * in compliance with the License. 6 | * 7 | * You can obtain a copy of the license at 8 | * glassfish/bootstrap/legal/CDDLv1.0.txt or 9 | * https://glassfish.dev.java.net/public/CDDLv1.0.html. 10 | * See the License for the specific language governing 11 | * permissions and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL 14 | * HEADER in each file and include the License file at 15 | * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable, 16 | * add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your 18 | * own identifying information: Portions Copyright [yyyy] 19 | * [name of copyright owner] 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 25 | */ 26 | 27 | 28 | package javax.annotation; 29 | 30 | import java.lang.annotation.*; 31 | import static java.lang.annotation.ElementType.*; 32 | import static java.lang.annotation.RetentionPolicy.*; 33 | 34 | /** 35 | * The PostConstruct annotation is used on a method that needs to be executed 36 | * after dependency injection is done to perform any initialization. This 37 | * method MUST be invoked before the class is put into service. This 38 | * annotation MUST be supported on all classes that support dependency 39 | * injection. The method annotated with PostConstruct MUST be invoked even 40 | * if the class does not request any resources to be injected. Only one 41 | * method can be annotated with this annotation. The method on which the 42 | * PostConstruct annotation is applied MUST fulfill all of the following 43 | * criteria - 44 | - The method MUST NOT have any parameters except in the case of EJB 45 | * interceptors in which case it takes an InvocationC ontext object as 46 | * defined by the EJB specification. 47 | * - The return type of the method MUST be void. 48 | * - The method MUST NOT throw a checked exception. 49 | * - The method on which PostConstruct is applied MAY be public, protected, 50 | * package private or private. 51 | * - The method MUST NOT be static except for the application client. 52 | * - The method MAY be final. 53 | * - If the method throws an unchecked exception the class MUST NOT be put into 54 | * service except in the case of EJBs where the EJB can handle exceptions and 55 | * even recover from them. 56 | * @since Common Annotations 1.0 57 | * @see javax.annotation.PreDestroy 58 | * @see javax.annotation.Resource 59 | */ 60 | @Documented 61 | @Retention (RUNTIME) 62 | @Target(METHOD) 63 | public @interface PostConstruct { 64 | } 65 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/javax/annotation/PreDestroy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The contents of this file are subject to the terms 3 | * of the Common Development and Distribution License 4 | * (the "License"). You may not use this file except 5 | * in compliance with the License. 6 | * 7 | * You can obtain a copy of the license at 8 | * glassfish/bootstrap/legal/CDDLv1.0.txt or 9 | * https://glassfish.dev.java.net/public/CDDLv1.0.html. 10 | * See the License for the specific language governing 11 | * permissions and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL 14 | * HEADER in each file and include the License file at 15 | * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable, 16 | * add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your 18 | * own identifying information: Portions Copyright [yyyy] 19 | * [name of copyright owner] 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 25 | */ 26 | 27 | 28 | package javax.annotation; 29 | 30 | import java.lang.annotation.*; 31 | import static java.lang.annotation.ElementType.*; 32 | import static java.lang.annotation.RetentionPolicy.*; 33 | 34 | /** 35 | * The PreDestroy annotation is used on methods as a callback notification to 36 | * signal that the instance is in the process of being removed by the 37 | * container. The method annotated with PreDestroy is typically used to 38 | * release resources that it has been holding. This annotation MUST be 39 | * supported by all container managed objects that support PostConstruct 40 | * except the application client container in Java EE 5. The method on which 41 | * the PreDestroy annotation is applied MUST fulfill all of the following 42 | * criteria - 43 | * - The method MUST NOT have any parameters except in the case of EJB 44 | * interceptors in which case it takes an InvocationContext object as defined 45 | * by the EJB specification. 46 | * - The return type of the method MUST be void. 47 | * - The method MUST NOT throw a checked exception. 48 | * - The method on which PreDestroy is applied MAY be public, protected, 49 | * package private or private. 50 | * - The method MUST NOT be static. 51 | * - The method MAY be final. 52 | * - If the method throws an unchecked exception it is ignored except in the 53 | * case of EJBs where the EJB can handle exceptions. 54 | * 55 | * @see javax.annotation.PostConstruct 56 | * @see javax.annotation.Resource 57 | * @since Common Annotations 1.0 58 | */ 59 | 60 | @Documented 61 | @Retention (RUNTIME) 62 | @Target(METHOD) 63 | public @interface PreDestroy { 64 | } 65 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/javax/inject/Named.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The JSR-330 Expert Group 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 | 17 | package javax.inject; 18 | 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Documented; 21 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 22 | 23 | /** 24 | * String-based {@linkplain Qualifier qualifier}. 25 | * 26 | *

Example usage: 27 | * 28 | *

29 |  *   public class Car {
30 |  *     @Inject @Named("driver") Seat driverSeat;
31 |  *     @Inject @Named("passenger") Seat passengerSeat;
32 |  *     ...
33 |  *   }
34 | */ 35 | @Qualifier 36 | @Documented 37 | @Retention(RUNTIME) 38 | public @interface Named { 39 | 40 | /** The name. */ 41 | String value() default ""; 42 | } 43 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/javax/inject/Provider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The JSR-330 Expert Group 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 | 17 | package javax.inject; 18 | 19 | /** 20 | * Provides instances of {@code T}. Typically implemented by an injector. For 21 | * any type {@code T} that can be injected, you can also inject 22 | * {@code Provider}. Compared to injecting {@code T} directly, injecting 23 | * {@code Provider} enables: 24 | * 25 | * 32 | * 33 | *

For example: 34 | * 35 | *

36 |  *   class Car {
37 |  *     @Inject Car(Provider<Seat> seatProvider) {
38 |  *       Seat driver = seatProvider.get();
39 |  *       Seat passenger = seatProvider.get();
40 |  *       ...
41 |  *     }
42 |  *   }
43 | */ 44 | public interface Provider { 45 | 46 | /** 47 | * Provides a fully-constructed and injected instance of {@code T}. 48 | * 49 | * @throws RuntimeException if the injector encounters an error while 50 | * providing an instance. For example, if an injectable member on 51 | * {@code T} throws an exception, the injector may wrap the exception 52 | * and throw it to the caller of {@code get()}. Callers should not try 53 | * to handle such exceptions as the behavior may vary across injector 54 | * implementations and even different configurations of the same injector. 55 | */ 56 | T get(); 57 | } 58 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/javax/inject/Qualifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The JSR-330 Expert Group 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 | 17 | package javax.inject; 18 | 19 | import java.lang.annotation.Target; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Documented; 22 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 23 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 24 | 25 | /** 26 | * Identifies qualifier annotations. Anyone can define a new qualifier. A 27 | * qualifier annotation: 28 | * 29 | *
    30 | *
  • is annotated with {@code @Qualifier}, {@code @Retention(RUNTIME)}, 31 | * and typically {@code @Documented}.
  • 32 | *
  • can have attributes.
  • 33 | *
  • may be part of the public API, much like the dependency type, but 34 | * unlike implementation types which needn't be part of the public 35 | * API.
  • 36 | *
  • may have restricted usage if annotated with {@code @Target}. While 37 | * this specification covers applying qualifiers to fields and 38 | * parameters only, some injector configurations might use qualifier 39 | * annotations in other places (on methods or classes for example).
  • 40 | *
41 | * 42 | *

For example: 43 | * 44 | *

45 |  *   @java.lang.annotation.Documented
46 |  *   @java.lang.annotation.Retention(RUNTIME)
47 |  *   @javax.inject.Qualifier
48 |  *   public @interface Leather {
49 |  *     Color color() default Color.YELLOW;
50 |  *     public enum Color { RED, BLACK, YELLOW }
51 |  *   }
52 | * 53 | * @see javax.inject.Named @Named 54 | */ 55 | @Target(ANNOTATION_TYPE) 56 | @Retention(RUNTIME) 57 | @Documented 58 | public @interface Qualifier {} 59 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/javax/inject/Singleton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The JSR-330 Expert Group 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 | 17 | package javax.inject; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 22 | 23 | /** 24 | * Identifies a type that the injector only instantiates once. Not inherited. 25 | * 26 | * @see javax.inject.Scope @Scope 27 | */ 28 | @Scope 29 | @Documented 30 | @Retention(RUNTIME) 31 | public @interface Singleton {} 32 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/aopalliance/aop/Advice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2016 the original author or authors. 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 | 17 | package org.aopalliance.aop; 18 | 19 | /** 20 | * Tag interface for Advice. Implementations can be any type 21 | * of advice, such as Interceptors. 22 | * 23 | * @author Rod Johnson 24 | * @version $Id: Advice.java,v 1.1 2004/03/19 17:02:16 johnsonr Exp $ 25 | */ 26 | public interface Advice { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/aopalliance/aop/AspectException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2016 the original author or authors. 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 | 17 | package org.aopalliance.aop; 18 | 19 | /** 20 | * Superclass for all AOP infrastructure exceptions. 21 | * Unchecked, as such exceptions are fatal and end user 22 | * code shouldn't be forced to catch them. 23 | * 24 | * @author Rod Johnson 25 | * @author Bob Lee 26 | * @author Juergen Hoeller 27 | */ 28 | @SuppressWarnings("serial") 29 | public class AspectException extends RuntimeException { 30 | 31 | /** 32 | * Constructor for AspectException. 33 | * @param message the exception message 34 | */ 35 | public AspectException(String message) { 36 | super(message); 37 | } 38 | 39 | /** 40 | * Constructor for AspectException. 41 | * @param message the exception message 42 | * @param cause the root cause, if any 43 | */ 44 | public AspectException(String message, Throwable cause) { 45 | super(message, cause); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/aopalliance/intercept/Interceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2016 the original author or authors. 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 | 17 | package org.aopalliance.intercept; 18 | 19 | import org.aopalliance.aop.Advice; 20 | 21 | /** 22 | * This interface represents a generic interceptor. 23 | * 24 | *

A generic interceptor can intercept runtime events that occur 25 | * within a base program. Those events are materialized by (reified 26 | * in) joinpoints. Runtime joinpoints can be invocations, field 27 | * access, exceptions... 28 | * 29 | *

This interface is not used directly. Use the sub-interfaces 30 | * to intercept specific events. For instance, the following class 31 | * implements some specific interceptors in order to implement a 32 | * debugger: 33 | * 34 | *

35 |  * class DebuggingInterceptor implements MethodInterceptor, 
36 |  *     ConstructorInterceptor, FieldInterceptor {
37 |  *
38 |  *   Object invoke(MethodInvocation i) throws Throwable {
39 |  *     debug(i.getMethod(), i.getThis(), i.getArgs());
40 |  *     return i.proceed();
41 |  *   }
42 |  *
43 |  *   Object construct(ConstructorInvocation i) throws Throwable {
44 |  *     debug(i.getConstructor(), i.getThis(), i.getArgs());
45 |  *     return i.proceed();
46 |  *   }
47 |  * 
48 |  *   Object get(FieldAccess fa) throws Throwable {
49 |  *     debug(fa.getField(), fa.getThis(), null);
50 |  *     return fa.proceed();
51 |  *   }
52 |  *
53 |  *   Object set(FieldAccess fa) throws Throwable {
54 |  *     debug(fa.getField(), fa.getThis(), fa.getValueToSet());
55 |  *     return fa.proceed();
56 |  *   }
57 |  *
58 |  *   void debug(AccessibleObject ao, Object this, Object value) {
59 |  *     ...
60 |  *   }
61 |  * }
62 |  * 
63 | * 64 | * @author Rod Johnson 65 | * @see Joinpoint 66 | */ 67 | public interface Interceptor extends Advice { 68 | 69 | } 70 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/aopalliance/intercept/Invocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2016 the original author or authors. 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 | 17 | package org.aopalliance.intercept; 18 | 19 | /** 20 | * This interface represents an invocation in the program. 21 | * 22 | *

An invocation is a joinpoint and can be intercepted by an 23 | * interceptor. 24 | * 25 | * @author Rod Johnson 26 | */ 27 | public interface Invocation extends Joinpoint { 28 | 29 | /** 30 | * Get the arguments as an array object. 31 | * It is possible to change element values within this 32 | * array to change the arguments. 33 | * @return the argument of the invocation 34 | */ 35 | Object[] getArguments(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/aopalliance/intercept/Joinpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2016 the original author or authors. 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 | 17 | package org.aopalliance.intercept; 18 | 19 | import java.lang.reflect.AccessibleObject; 20 | 21 | /** 22 | * This interface represents a generic runtime joinpoint (in the AOP 23 | * terminology). 24 | * 25 | *

A runtime joinpoint is an event that occurs on a static 26 | * joinpoint (i.e. a location in a the program). For instance, an 27 | * invocation is the runtime joinpoint on a method (static joinpoint). 28 | * The static part of a given joinpoint can be generically retrieved 29 | * using the {@link #getStaticPart()} method. 30 | * 31 | *

In the context of an interception framework, a runtime joinpoint 32 | * is then the reification of an access to an accessible object (a 33 | * method, a constructor, a field), i.e. the static part of the 34 | * joinpoint. It is passed to the interceptors that are installed on 35 | * the static joinpoint. 36 | * 37 | * @author Rod Johnson 38 | * @see Interceptor 39 | */ 40 | public interface Joinpoint { 41 | 42 | /** 43 | * Proceed to the next interceptor in the chain. 44 | *

The implementation and the semantics of this method depends 45 | * on the actual joinpoint type (see the children interfaces). 46 | * @return see the children interfaces' proceed definition 47 | * @throws Throwable if the joinpoint throws an exception 48 | */ 49 | Object proceed() throws Throwable; 50 | 51 | /** 52 | * Return the object that holds the current joinpoint's static part. 53 | *

For instance, the target object for an invocation. 54 | * @return the object (can be null if the accessible object is static) 55 | */ 56 | Object getThis(); 57 | 58 | /** 59 | * Return the static part of this joinpoint. 60 | *

The static part is an accessible object on which a chain of 61 | * interceptors are installed. 62 | */ 63 | AccessibleObject getStaticPart(); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/aopalliance/intercept/MethodInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2016 the original author or authors. 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 | 17 | package org.aopalliance.intercept; 18 | 19 | /** 20 | * Intercepts calls on an interface on its way to the target. These 21 | * are nested "on top" of the target. 22 | * 23 | *

The user should implement the {@link #invoke(MethodInvocation)} 24 | * method to modify the original behavior. E.g. the following class 25 | * implements a tracing interceptor (traces all the calls on the 26 | * intercepted method(s)): 27 | * 28 | *

29 |  * class TracingInterceptor implements MethodInterceptor {
30 |  *   Object invoke(MethodInvocation i) throws Throwable {
31 |  *     System.out.println("method "+i.getMethod()+" is called on "+
32 |  *                        i.getThis()+" with args "+i.getArguments());
33 |  *     Object ret=i.proceed();
34 |  *     System.out.println("method "+i.getMethod()+" returns "+ret);
35 |  *     return ret;
36 |  *   }
37 |  * }
38 |  * 
39 | * 40 | * @author Rod Johnson 41 | */ 42 | public interface MethodInterceptor extends Interceptor { 43 | 44 | /** 45 | * Implement this method to perform extra treatments before and 46 | * after the invocation. Polite implementations would certainly 47 | * like to invoke {@link Joinpoint#proceed()}. 48 | * @param invocation the method invocation joinpoint 49 | * @return the result of the call to {@link Joinpoint#proceed()}; 50 | * might be intercepted by the interceptor 51 | * @throws Throwable if the interceptors or the target object 52 | * throws an exception 53 | */ 54 | Object invoke(MethodInvocation invocation) throws Throwable; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/aopalliance/intercept/MethodInvocation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2016 the original author or authors. 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 | 17 | package org.aopalliance.intercept; 18 | 19 | import java.lang.reflect.Method; 20 | 21 | /** 22 | * Description of an invocation to a method, given to an interceptor 23 | * upon method-call. 24 | * 25 | *

A method invocation is a joinpoint and can be intercepted by a 26 | * method interceptor. 27 | * 28 | * @author Rod Johnson 29 | * @see MethodInterceptor 30 | */ 31 | public interface MethodInvocation extends Invocation { 32 | 33 | /** 34 | * Get the method being called. 35 | *

This method is a frienly implementation of the 36 | * {@link Joinpoint#getStaticPart()} method (same result). 37 | * @return the method being called 38 | */ 39 | Method getMethod(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/springframework/beans/factory/annotation/Qualifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2011 the original author or authors. 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 | 17 | package org.springframework.beans.factory.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Inherited; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * This annotation may be used on a field or parameter as a qualifier for 28 | * candidate beans when autowiring. It may also be used to annotate other 29 | * custom annotations that can then in turn be used as qualifiers. 30 | * 31 | * @author Mark Fisher 32 | * @author Juergen Hoeller 33 | * @since 2.5 34 | * @see Autowired 35 | */ 36 | @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Inherited 39 | @Documented 40 | public @interface Qualifier { 41 | 42 | String value() default ""; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/springframework/beans/factory/annotation/Value.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 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 | 17 | package org.springframework.beans.factory.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Annotation at the field or method/constructor parameter level 27 | * that indicates a default value expression for the affected argument. 28 | * 29 | *

Typically used for expression-driven dependency injection. Also supported 30 | * for dynamic resolution of handler method parameters, e.g. in Spring MVC. 31 | * 32 | *

A common use case is to assign default field values using 33 | * "#{systemProperties.myProp}" style expressions. 34 | * 35 | *

Note that actual processing of the {@code @Value} annotation is performed 36 | * by a {@link org.springframework.beans.factory.config.BeanPostProcessor 37 | * BeanPostProcessor} which in turn means that you cannot use 38 | * {@code @Value} within 39 | * {@link org.springframework.beans.factory.config.BeanPostProcessor 40 | * BeanPostProcessor} or 41 | * {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor BeanFactoryPostProcessor} 42 | * types. Please consult the javadoc for the {@link AutowiredAnnotationBeanPostProcessor} 43 | * class (which, by default, checks for the presence of this annotation). 44 | * 45 | * @author Juergen Hoeller 46 | * @since 3.0 47 | * @see AutowiredAnnotationBeanPostProcessor 48 | * @see Autowired 49 | * @see org.springframework.beans.factory.config.BeanExpressionResolver 50 | * @see org.springframework.beans.factory.support.AutowireCandidateResolver#getSuggestedValue 51 | */ 52 | @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) 53 | @Retention(RetentionPolicy.RUNTIME) 54 | @Documented 55 | public @interface Value { 56 | 57 | /** 58 | * The actual value expression: e.g. "#{systemProperties.myProp}". 59 | */ 60 | String value(); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/springframework/stereotype/Component.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 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 | 17 | package org.springframework.stereotype; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Indicates that an annotated class is a "component". 27 | * Such classes are considered as candidates for auto-detection 28 | * when using annotation-based configuration and classpath scanning. 29 | * 30 | *

Other class-level annotations may be considered as identifying 31 | * a component as well, typically a special kind of component: 32 | * e.g. the {@link Repository @Repository} annotation or AspectJ's 33 | * {@link org.aspectj.lang.annotation.Aspect @Aspect} annotation. 34 | * 35 | * @author Mark Fisher 36 | * @since 2.5 37 | * @see Repository 38 | * @see Service 39 | * @see Controller 40 | * @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner 41 | */ 42 | @Target(ElementType.TYPE) 43 | @Retention(RetentionPolicy.RUNTIME) 44 | @Documented 45 | public @interface Component { 46 | 47 | /** 48 | * The value may indicate a suggestion for a logical component name, 49 | * to be turned into a Spring bean in case of an autodetected component. 50 | * @return the suggested component name, if any 51 | */ 52 | String value() default ""; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/springframework/stereotype/Controller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 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 | 17 | package org.springframework.stereotype; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Indicates that an annotated class is a "Controller" (e.g. a web controller). 27 | * 28 | *

This annotation serves as a specialization of {@link Component @Component}, 29 | * allowing for implementation classes to be autodetected through classpath scanning. 30 | * It is typically used in combination with annotated handler methods based on the 31 | * {@link org.springframework.web.bind.annotation.RequestMapping} annotation. 32 | * 33 | * @author Arjen Poutsma 34 | * @author Juergen Hoeller 35 | * @since 2.5 36 | * @see Component 37 | * @see org.springframework.web.bind.annotation.RequestMapping 38 | * @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner 39 | */ 40 | @Target({ElementType.TYPE}) 41 | @Retention(RetentionPolicy.RUNTIME) 42 | @Documented 43 | @Component 44 | public @interface Controller { 45 | 46 | /** 47 | * The value may indicate a suggestion for a logical component name, 48 | * to be turned into a Spring bean in case of an autodetected component. 49 | * @return the suggested component name, if any 50 | */ 51 | String value() default ""; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /jbeanbox/src/main/java/org/springframework/stereotype/Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2011 the original author or authors. 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 | 17 | package org.springframework.stereotype; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Indicates that an annotated class is a "Service", originally defined by Domain-Driven 27 | * Design (Evans, 2003) as "an operation offered as an interface that stands alone in the 28 | * model, with no encapsulated state." 29 | * 30 | *

May also indicate that a class is a "Business Service Facade" (in the Core J2EE 31 | * patterns sense), or something similar. This annotation is a general-purpose stereotype 32 | * and individual teams may narrow their semantics and use as appropriate. 33 | * 34 | *

This annotation serves as a specialization of {@link Component @Component}, 35 | * allowing for implementation classes to be autodetected through classpath scanning. 36 | * 37 | * @author Juergen Hoeller 38 | * @since 2.5 39 | * @see Component 40 | * @see Repository 41 | */ 42 | @Target({ElementType.TYPE}) 43 | @Retention(RetentionPolicy.RUNTIME) 44 | @Documented 45 | @Component 46 | public @interface Service { 47 | 48 | /** 49 | * The value may indicate a suggestion for a logical component name, 50 | * to be turned into a Spring bean in case of an autodetected component. 51 | * @return the suggested component name, if any 52 | */ 53 | String value() default ""; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/AnnotationSuperclassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jbeanbox; 13 | 14 | import javax.inject.Inject; 15 | 16 | import org.junit.Assert; 17 | import org.junit.Test; 18 | 19 | /** 20 | * @author Yong Zhu 21 | * @since 2.4.9 22 | */ 23 | public class AnnotationSuperclassTest extends BeanBoxTest { 24 | 25 | static class Parent { 26 | @Inject 27 | A field; 28 | 29 | A method; 30 | 31 | @Inject 32 | public void setField(A foo) { 33 | method = foo; 34 | } 35 | } 36 | 37 | static class Child extends Parent { 38 | } 39 | 40 | static class A { 41 | } 42 | 43 | @Test 44 | public void testSuperclassInjection() { 45 | Child c = JBEANBOX.getBean(Child.class); 46 | Assert.assertNotNull(c.field); 47 | Assert.assertNotNull(c.method); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/BeanBoxTest.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox; 2 | 3 | import org.junit.Before; 4 | 5 | /** 6 | * BeanBoxTest 7 | * 8 | * @author Yong Zhu 9 | * @since 2.4.7 10 | */ 11 | public class BeanBoxTest { 12 | @Before 13 | public void init() { 14 | JBEANBOX.reset(); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/ClassScannerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jbeanbox; 13 | 14 | import java.util.List; 15 | 16 | import org.junit.Assert; 17 | import org.junit.Test; 18 | 19 | /** 20 | * @author Yong Zhu 21 | * @since 2.5.0 22 | */ 23 | @SuppressWarnings("rawtypes") 24 | public class ClassScannerTest { 25 | 26 | @Test 27 | public void prototypeTest() { 28 | List cList1 = ClassScanner.scanPackages("com.github.drinkjava2.jbeanbox"); 29 | Assert.assertTrue(cList1.size() > 0); 30 | 31 | List cList2 = ClassScanner.scanByName("com.github.drinkjava2.jbeanbox.annotation.PR*", 32 | "com.github.drinkjava2.jbeanbox"); 33 | Assert.assertTrue(cList2.size() > 0); 34 | 35 | List cList3 = ClassScanner.scanPackages("org.junit"); 36 | Assert.assertTrue(cList3.size() > 0); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/JavaSuperclassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jbeanbox; 13 | 14 | import org.junit.Assert; 15 | import org.junit.Test; 16 | 17 | /** 18 | * @author Yong Zhu 19 | * @since 2.4.9 20 | */ 21 | public class JavaSuperclassTest extends BeanBoxTest { 22 | static class Parent { 23 | A field; 24 | 25 | A method; 26 | 27 | public void setField(A a) { 28 | method = a; 29 | } 30 | } 31 | 32 | static class Child extends Parent { 33 | } 34 | 35 | static class SubBox extends BeanBox { 36 | { 37 | this.setBeanClass(Child.class); 38 | this.injectField("field", new A()); 39 | this.injectMethod("setField", A.class, new A()); 40 | this.injectMtd("setField", new A()); // this is the shortcut usage if type same 41 | } 42 | } 43 | 44 | static class A { 45 | } 46 | 47 | @Test 48 | public void testSuperclassInjection() { 49 | Child c = JBEANBOX.getBean(SubBox.class); 50 | Assert.assertNotNull(c.field); 51 | Assert.assertNotNull(c.method); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/NameMatchUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jbeanbox; 13 | 14 | import static com.github.drinkjava2.jbeanbox.NameMatchUtil.nameMatch; 15 | 16 | import org.junit.Assert; 17 | import org.junit.Test; 18 | 19 | public class NameMatchUtilTest { 20 | @Test 21 | public void nameMatchUtilTest() { 22 | Assert.assertTrue(nameMatch("abc*", "abcx")); 23 | Assert.assertTrue(nameMatch("ghi*jkl", "ghixxjkl")); 24 | Assert.assertTrue(nameMatch("*mn", "xmn")); 25 | 26 | Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "abcd")); 27 | Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "def")); 28 | Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "ghixxjkl")); 29 | Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "ghixxjkl")); 30 | Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "mn")); 31 | 32 | Assert.assertFalse(nameMatch("abc*|def*|ghi*jkl|*mn", "abd")); 33 | Assert.assertFalse(nameMatch("abc*|def*|ghi*jkl|*mn", "de")); 34 | Assert.assertFalse(nameMatch("abc*|def*|ghi*jkl|*mn", "ghxxkl")); 35 | Assert.assertFalse(nameMatch("abc*|def*|ghi*jkl|*mn", "n")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/SingletonPrototypeTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.drinkjava2.jbeanbox; 3 | 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | import com.github.drinkjava2.jbeanbox.annotation.PROTOTYPE; 8 | 9 | public class SingletonPrototypeTest { 10 | 11 | public static class A { 12 | 13 | } 14 | 15 | public static class PrototypeBox extends BeanBox { 16 | { 17 | setBeanClass(A.class); 18 | } 19 | } 20 | 21 | @Test 22 | public void testDefaultType() { 23 | JBEANBOX.getBeanBox(PrototypeBox.class); 24 | Assert.assertTrue(!new PrototypeBox().isSingleton()); // if new beanbox, is prototype 25 | Assert.assertTrue(JBEANBOX.getBeanBox(PrototypeBox.class).isSingleton()); // if fixed class, is singleton 26 | Assert.assertTrue(JBEANBOX.getBeanBox(PrototypeBox.class) == JBEANBOX.getBeanBox(PrototypeBox.class)); 27 | 28 | BeanBox box1 = new PrototypeBox(); 29 | BeanBox box2 = new PrototypeBox(); 30 | Assert.assertTrue(box1.getBean() != box1.getBean()); 31 | Assert.assertTrue(box1.getBean() != box2.getBean()); 32 | } 33 | 34 | @Test 35 | public void testPrototype() { 36 | Assert.assertFalse(new PrototypeBox().isSingleton()); 37 | Assert.assertTrue(JBEANBOX.getBeanBox(PrototypeBox.class) == JBEANBOX.getBeanBox(PrototypeBox.class)); 38 | 39 | BeanBox box = new PrototypeBox(); 40 | Assert.assertTrue(box.getBean() != box.getBean()); 41 | } 42 | 43 | @PROTOTYPE 44 | public static class B { 45 | } 46 | 47 | public static class C implements PrototypeBean { 48 | } 49 | 50 | @Test 51 | public void testPrototypeAnno() { 52 | BeanBox boxA = JBEANBOX.getBeanBox(A.class); 53 | BeanBox boxB = JBEANBOX.getBeanBox(B.class); 54 | BeanBox boxC = JBEANBOX.getBeanBox(C.class); 55 | Assert.assertTrue(boxA.isSingleton()); 56 | Assert.assertFalse(boxB.isSingleton()); 57 | Assert.assertFalse(boxC.isSingleton()); 58 | Assert.assertTrue(boxA.getBean() == boxA.getBean()); 59 | Assert.assertTrue(boxB.getBean() != boxB.getBean()); 60 | Assert.assertTrue(boxC.getBean() != boxC.getBean()); 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/aop/AnnotationAopTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jbeanbox.aop; 13 | 14 | import java.lang.annotation.ElementType; 15 | import java.lang.annotation.Retention; 16 | import java.lang.annotation.RetentionPolicy; 17 | import java.lang.annotation.Target; 18 | 19 | import org.aopalliance.intercept.MethodInterceptor; 20 | import org.aopalliance.intercept.MethodInvocation; 21 | import org.junit.Assert; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | import com.github.drinkjava2.jbeanbox.JBEANBOX; 26 | import com.github.drinkjava2.jbeanbox.annotation.AOP; 27 | 28 | /** 29 | * Annotation configuration AOP test 30 | * 31 | * @author Yong Zhu 32 | * @since 2.4.8 33 | * 34 | */ 35 | public class AnnotationAopTest { 36 | 37 | @Before 38 | public void init() { 39 | JBEANBOX.reset(); 40 | } 41 | 42 | public static class Interceptor1 implements MethodInterceptor { 43 | public Object invoke(MethodInvocation invocation) throws Throwable { 44 | invocation.getArguments()[0] = "1"; 45 | return invocation.proceed(); 46 | } 47 | } 48 | 49 | public static class Interceptor2 implements MethodInterceptor { 50 | public Object invoke(MethodInvocation invocation) throws Throwable { 51 | invocation.getArguments()[0] = "2"; 52 | return invocation.proceed(); 53 | } 54 | } 55 | 56 | @Retention(RetentionPolicy.RUNTIME) 57 | @Target({ ElementType.TYPE }) 58 | @AOP 59 | public static @interface BeanAop { 60 | public Class value() default Interceptor1.class; 61 | 62 | public String method() default "setNa*"; 63 | } 64 | 65 | @Retention(RetentionPolicy.RUNTIME) 66 | @Target({ ElementType.METHOD }) 67 | @AOP 68 | public static @interface MethodAop { 69 | public Class value() default Interceptor2.class; 70 | } 71 | 72 | @BeanAop 73 | public static class AopDemo1 { 74 | String name; 75 | String address; 76 | 77 | public void setName(String name) { 78 | this.name = name; 79 | } 80 | 81 | @MethodAop 82 | public void setAddress(String address) { 83 | this.address = address; 84 | } 85 | } 86 | 87 | @Test 88 | public void aopTest1() { 89 | AopDemo1 demo = JBEANBOX.getBean(AopDemo1.class); 90 | demo.setName("--"); 91 | Assert.assertEquals("1", demo.name); 92 | demo.setAddress("--"); 93 | Assert.assertEquals("2", demo.address); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/aop/NameMatchingAopTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jbeanbox.aop; 13 | 14 | import org.aopalliance.intercept.MethodInterceptor; 15 | import org.aopalliance.intercept.MethodInvocation; 16 | import org.junit.Assert; 17 | import org.junit.Test; 18 | 19 | import com.github.drinkjava2.jbeanbox.JBEANBOX; 20 | 21 | /** 22 | * Annotation configuration AOP test 23 | * 24 | * @author Yong Zhu 25 | * @since 2.4.8 26 | * 27 | */ 28 | public class NameMatchingAopTest { 29 | 30 | public static class AopDemo1 { 31 | String name; 32 | String address; 33 | String email; 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public void setAddress(String address) { 40 | this.address = address; 41 | } 42 | 43 | public void setEmail(String email) { 44 | this.email = email; 45 | } 46 | } 47 | 48 | public static class ContextAOP implements MethodInterceptor { 49 | public Object invoke(MethodInvocation invocation) throws Throwable { 50 | invocation.getArguments()[0] = "bar"; 51 | return invocation.proceed(); 52 | } 53 | } 54 | 55 | @Test 56 | public void aopTest1() { 57 | JBEANBOX.reset(); 58 | // Only setName and setAddress be AOPed. 59 | JBEANBOX.ctx().addContextAop(ContextAOP.class, AopDemo1.class, "setN*|*Address"); 60 | AopDemo1 demo = JBEANBOX.getBean(AopDemo1.class); 61 | demo.setName("foo"); 62 | Assert.assertEquals("bar", demo.name); 63 | demo.setAddress("foo"); 64 | Assert.assertEquals("bar", demo.address); 65 | demo.setEmail("foo"); 66 | Assert.assertEquals("foo", demo.email); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/BoxConfig1.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark; 2 | 3 | import static com.github.drinkjava2.jbeanbox.JBEANBOX.inject; 4 | 5 | import com.github.drinkjava2.jbeanbox.BeanBox; 6 | import com.github.drinkjava2.jbeanbox.BeanBoxContext; 7 | import com.github.drinkjava2.jbeanbox.benchmark.objects.A; 8 | import com.github.drinkjava2.jbeanbox.benchmark.objects.B; 9 | import com.github.drinkjava2.jbeanbox.benchmark.objects.C; 10 | import com.github.drinkjava2.jbeanbox.benchmark.objects.D1; 11 | import com.github.drinkjava2.jbeanbox.benchmark.objects.D2; 12 | import com.github.drinkjava2.jbeanbox.benchmark.objects.E; 13 | 14 | /** 15 | * There are 3 ways to create bean:
16 | * 1. Set Constructor or set beanClass to use 0 parameter constructor
17 | * 2. Set a create method
18 | * 3. use Annotation to set constructor or create method
19 | * 20 | * This is to test Java configuration (setAllowAnnotation=false) 21 | * 22 | * 23 | * 24 | * @author Yong Zhu 25 | * @since 2.4 26 | */ 27 | public class BoxConfig1 { 28 | public static class PrototypeBox extends BeanBox { 29 | { 30 | setSingleton(false); 31 | } 32 | } 33 | 34 | public static class ABox extends PrototypeBox { 35 | { 36 | injectConstruct(A.class, B.class, inject(BBox.class)); 37 | } 38 | } 39 | 40 | public static class BBox extends PrototypeBox { 41 | { 42 | injectConstruct(B.class, C.class, inject(CBox.class)); 43 | } 44 | } 45 | 46 | public static class CBox extends PrototypeBox { 47 | { 48 | injectConstruct(C.class, D1.class, D2.class, inject(D1Box.class), inject(D2Box.class)); 49 | } 50 | } 51 | 52 | public static class D1Box extends PrototypeBox { 53 | { 54 | injectConstruct(D1.class, E.class, inject(EBox.class)); 55 | } 56 | } 57 | 58 | public static class D2Box extends PrototypeBox { 59 | { 60 | injectConstruct(D2.class, E.class, inject(EBox.class)); 61 | } 62 | } 63 | 64 | public static class EBox extends PrototypeBox { 65 | { 66 | injectConstruct(E.class); 67 | } 68 | } 69 | 70 | public static void main(String[] args) { 71 | BeanBoxContext ctx1 = new BeanBoxContext(); 72 | ctx1.setAllowAnnotation(false); 73 | A a = ctx1.getBean(ABox.class); 74 | System.out.println(a.b.c.d1.e.getname()); 75 | System.out.println(a.b.c.d2.e.getname()); 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/BoxConfig2.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark; 2 | 3 | import com.github.drinkjava2.jbeanbox.BeanBox; 4 | import com.github.drinkjava2.jbeanbox.BeanBoxContext; 5 | import com.github.drinkjava2.jbeanbox.benchmark.objects.A; 6 | import com.github.drinkjava2.jbeanbox.benchmark.objects.B; 7 | import com.github.drinkjava2.jbeanbox.benchmark.objects.C; 8 | import com.github.drinkjava2.jbeanbox.benchmark.objects.D1; 9 | import com.github.drinkjava2.jbeanbox.benchmark.objects.D2; 10 | import com.github.drinkjava2.jbeanbox.benchmark.objects.E; 11 | 12 | /** 13 | * There are 3 ways to create bean:
14 | * 1. Set Constructor or set beanClass to use 0 parameter constructor
15 | * 2. Set a create method
16 | * 3. use Annotation to set constructor or create method
17 | * 18 | * Here to test Create method (setAllowAnnotation=false) 19 | * 20 | * @author Yong Zhu 21 | * @since 2.4 22 | */ 23 | public class BoxConfig2 { 24 | public static class PrototypeBox extends BeanBox { 25 | { 26 | this.setSingleton(false); 27 | } 28 | } 29 | 30 | public static class ABox extends PrototypeBox { 31 | public Object create(BeanBoxContext caller) { 32 | return new A((B) caller.getBean(BBox.class)); 33 | } 34 | } 35 | 36 | public static class BBox extends PrototypeBox { 37 | public Object create(BeanBoxContext caller) { 38 | return new B((C) caller.getBean(CBox.class)); 39 | } 40 | } 41 | 42 | public static class CBox extends PrototypeBox { 43 | public Object create(BeanBoxContext caller) { 44 | return new C((D1) caller.getBean(D1Box.class), (D2) caller.getBean(D2Box.class)); 45 | } 46 | } 47 | 48 | public static class D1Box extends PrototypeBox { 49 | public Object create(BeanBoxContext caller) { 50 | return new D1((E) caller.getBean(EBox.class)); 51 | } 52 | } 53 | 54 | public static class D2Box extends PrototypeBox { 55 | public Object create(BeanBoxContext caller) { 56 | return new D2((E) caller.getBean(EBox.class)); 57 | } 58 | } 59 | 60 | public static class EBox extends PrototypeBox { 61 | public Object create() { 62 | return new E(); 63 | } 64 | } 65 | 66 | public static void main(String[] args) { 67 | BeanBoxContext ctx2 = new BeanBoxContext(); 68 | ctx2.setAllowAnnotation(false); 69 | ctx2.bind(A.class, ABox.class); 70 | A a = ctx2.getBean(A.class); 71 | System.out.println(a.b.c.d1.e.getname()); 72 | System.out.println(a.b.c.d2.e.getname()); 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/SimpleSpeedTest.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | 5 | import org.junit.Test; 6 | 7 | import com.github.drinkjava2.jbeanbox.BeanBox; 8 | import com.github.drinkjava2.jbeanbox.JBEANBOX; 9 | 10 | /** 11 | * A simple benchmark test 12 | * 13 | * @since 2.4 14 | */ 15 | 16 | public class SimpleSpeedTest { 17 | 18 | public static class A { 19 | } 20 | 21 | public static class myBeanBox extends BeanBox { 22 | { 23 | singleton = false; 24 | } 25 | 26 | public Object create() { 27 | return new A(); 28 | } 29 | } 30 | 31 | @Test 32 | public void speedTest() throws InstantiationException, IllegalAccessException, SecurityException, 33 | NoSuchMethodException, IllegalArgumentException, InvocationTargetException { 34 | 35 | long start = System.currentTimeMillis(); 36 | for (int i = 0; i < 5000; i++) {// change to 5000000 to do real test 37 | JBEANBOX.getBean(myBeanBox.class); 38 | } 39 | long end = System.currentTimeMillis(); 40 | String timeused = "" + ((end - start) * 1000) / 1000000.0; 41 | System.out.println(String.format("%20s: %6s s \r\n", "SimpleSpeedTest get prototype 5000 times: ", timeused)); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/objects/A.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark.objects; 2 | 3 | import javax.inject.Inject; 4 | 5 | import com.github.drinkjava2.jbeanbox.annotation.PROTOTYPE; 6 | 7 | @PROTOTYPE 8 | public class A { 9 | public B b; 10 | 11 | @Inject 12 | public A(B b) { 13 | this.b = b; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/objects/B.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark.objects; 2 | 3 | import javax.inject.Inject; 4 | 5 | import com.github.drinkjava2.jbeanbox.annotation.PROTOTYPE; 6 | 7 | @PROTOTYPE 8 | public class B { 9 | public C c; 10 | 11 | @Inject 12 | public B(C c) { 13 | this.c = c; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return getClass().getSimpleName(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/objects/C.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark.objects; 2 | 3 | import javax.inject.Inject; 4 | 5 | import com.github.drinkjava2.jbeanbox.annotation.PROTOTYPE; 6 | 7 | @PROTOTYPE 8 | public class C { 9 | public D1 d1; 10 | public D2 d2; 11 | 12 | @Inject 13 | public C(D1 d1, D2 d2) { 14 | this.d1 = d1; 15 | this.d2 = d2; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return getClass().getSimpleName(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/objects/D1.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark.objects; 2 | 3 | import javax.inject.Inject; 4 | 5 | import com.github.drinkjava2.jbeanbox.annotation.PROTOTYPE; 6 | 7 | @PROTOTYPE 8 | public class D1 { 9 | public E e; 10 | 11 | @Inject 12 | public D1(E e) { 13 | this.e = e; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return getClass().getSimpleName(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/objects/D2.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark.objects; 2 | 3 | import javax.inject.Inject; 4 | 5 | import com.github.drinkjava2.jbeanbox.annotation.PROTOTYPE; 6 | 7 | @PROTOTYPE 8 | public class D2 { 9 | public final E e; 10 | 11 | @Inject 12 | public D2(E e) { 13 | this.e = e; 14 | 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return getClass().getSimpleName(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/benchmark/objects/E.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.benchmark.objects; 2 | 3 | import com.github.drinkjava2.jbeanbox.annotation.PROTOTYPE; 4 | 5 | @PROTOTYPE 6 | public class E { 7 | 8 | public String getname() { 9 | return "" + this; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/reflection_utils/CreateMethodTest.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.drinkjava2.jbeanbox.reflection_utils; 3 | 4 | import static com.github.drinkjava2.jbeanbox.JBEANBOX.value; 5 | 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import com.github.drinkjava2.jbeanbox.BeanBox; 10 | import com.github.drinkjava2.jbeanbox.JBEANBOX; 11 | 12 | /** 13 | * This is to test a parent have a create method but child do not have 14 | * 15 | * @author Yong Zhu 16 | * 17 | * @since 2.4 18 | */ 19 | public class CreateMethodTest { 20 | 21 | public static class BaseClassBox extends BeanBox { 22 | public Object create() { 23 | Parent p = new Parent(); 24 | return p; 25 | } 26 | } 27 | 28 | public static class childClassBox extends BaseClassBox { 29 | { 30 | this.setBeanClass(Parent.class); 31 | this.injectField("userName", value("u1")); 32 | } 33 | } 34 | 35 | @Test 36 | public void test() { 37 | Parent p = JBEANBOX.getBean(childClassBox.class); 38 | Assert.assertEquals("u1", p.getUserName()); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/reflection_utils/Parent.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.reflection_utils; 2 | 3 | /** 4 | * @author Yong 5 | * @since 2.4 6 | */ 7 | @SuppressWarnings("unused") 8 | public class Parent { 9 | 10 | public String publicField = "publicField"; 11 | 12 | String defaultField = "defaultField"; 13 | 14 | protected String protectedField = "protectedField"; 15 | 16 | private String privateField = "privateField"; 17 | 18 | private String userName; 19 | private Integer age; 20 | 21 | public String publicMethod() { 22 | return "publicMethod"; 23 | } 24 | 25 | String defaultMethod() { 26 | return "defaultMethod"; 27 | } 28 | 29 | protected String protectedMethod() { 30 | return "protectedMethod"; 31 | } 32 | 33 | private String privateMethod() { 34 | return "privateMethod"; 35 | } 36 | 37 | public String getUserName() { 38 | return userName; 39 | } 40 | 41 | public void setUserName(String userName) { 42 | this.userName = userName; 43 | } 44 | 45 | public Integer getAge() { 46 | return age; 47 | } 48 | 49 | public void setAge(Integer age) { 50 | this.age = age; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /jbeanbox/src/test/java/com/github/drinkjava2/jbeanbox/reflection_utils/Son.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jbeanbox.reflection_utils; 2 | 3 | /** 4 | * @author Yong 5 | * 6 | * @since 2.4 7 | */ 8 | public class Son extends Parent { 9 | private String user; 10 | 11 | public String getUser() { 12 | return user; 13 | } 14 | 15 | public void setUser(String user) { 16 | this.user = user; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /jbeanboxdi/JumpOutSourceCode.bat: -------------------------------------------------------------------------------- 1 | XCOPY "..\jbeanbox\src\main\java\javax\*.*" ".\src\main\java\javax\" /S /D /Y 2 | XCOPY "..\jbeanbox\src\main\java\org\*.*" ".\src\main\java\org\" /S /D /Y 3 | XCOPY "..\jbeanbox\src\main\java\com\github\drinkjava2\jbeanbox\*.*" ".\src\main\java\com\github\drinkjava2\jbeanbox\" /S /D /Y 4 | XCOPY "..\jbeanbox\src\test\*.*" ".\src\test\" /S /D /Y 5 | del ".\src\test\java\com\github\drinkjava2\jbeanbox\aop\*.java" 6 | rd ".\src\test\java\com\github\drinkjava2\jbeanbox\aop" 7 | 8 | del ".\src\main\java\com\github\drinkjava2\jbeanbox\AopUtils.java" 9 | del ".\src\main\java\com\github\drinkjava2\jbeanbox\ProxyBean.java" 10 | 11 | 12 | set aop=.\src\main\java\com\github\drinkjava2\jbeanbox\AopUtils.java 13 | 14 | @echo package com.github.drinkjava2.jbeanbox; >%aop% 15 | @echo public class AopUtils { >>%aop% 16 | @echo public static Object createProxyBean(Class^<^?^> clazz, BeanBox box, BeanBoxContext ctx) { >>%aop% 17 | @echo BeanBoxException.throwEX("jBeanBoxDI does not support AOP."); >>%aop% 18 | @echo return null;>>%aop% 19 | @echo }>>%aop% 20 | @echo }>>%aop% 21 | -------------------------------------------------------------------------------- /jbeanboxdi/README.md: -------------------------------------------------------------------------------- 1 | ## jBeanBoxDI 2 | **License:** [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0) 3 | 4 | jBeanBoxDI is a pure DI (dependency inject) tool, it does not support AOP, it's lightweight only few Java source code files and ~49kb jar size. 5 | jBeanBoxDI runs on JDK1.6 and above. 6 | 7 | ## How to use jBeanBoxDI: 8 | Add below in pom.xml: 9 | ``` 10 | 11 | com.github.drinkjava2 12 | jbeanboxdi 13 | 2.4.9 14 | 15 | ``` 16 | 17 | 18 | ## Relationship of jBeanBoxDi and jBeanBox: 19 | jBeanBox = jBeanBoxDi + AOP 20 | 21 | jBeanBox support AOP, this makes it more useful but much fat(~500kbs) because it includes CGLib and ASM source code files. 22 | To use jBeanBox, add below in pom.xml: 23 | ``` 24 | 25 | com.github.drinkjava2 26 | jbeanbox 27 | 2.4.9 28 | 29 | ``` 30 | If you already added jBeanBox dependency in pom.xml, no need add jBeanBoxDI again because jBeanBoxDI is a core part of jBeanBox. 31 | 32 | ## Any user manual of jBeanBoxDI? 33 | No, jBeanBoxDI is the core fo jBeanBox, you can read jBeanBox's documents, but skip over "AOP" feature. 34 | 35 | ## Why I can not find any source code in jbeanboxdi folder? 36 | You need run "JumpOutSourceCode.bat", then source code will jump out. -------------------------------------------------------------------------------- /release_note.md: -------------------------------------------------------------------------------- 1 | 版本发布记录 2 | 2.4.1 第一版发布,仅支持Java7或以上版本 3 | 2.4.2 增加一个@AopAround注释并更正一些Bug 4 | 2.4.3 删除不常用的AspectJ支持,去除对Aop接口的依赖,将AOP接口以源码内嵌方式包含在项目内,从Java7降级到Java6发布,以支持更多开发环境。 5 | 2.4.4 改正@AopAround不支持多个方法的Bug 6 | 2.4.5 改正AOP不支持构数函数带参数的Bug 7 | 添加setConstructorTypes方法,用于明确指定构造器参数类型,消除岐义,通常用于实参为子类的情况。 8 | 改正内部类Advice失效Bug 9 | 2.4.6 添加自定义AOPAROUND注解功能 10 | 2.4.8 项目从头到尾重新写了一遍,性能提高。 11 | 2.4.9 更正不支持父类的bug 12 | 4.0.0 添加@NAMED, @QUALIFIER, @COMPONENT注解支持,添加类扫描功能 13 | 14 | 15 | 16 | Release History 17 | 2.4.1 First version, support Java7 only 18 | 2.4.2 Add a @AopAround annotation 19 | 2.4.3 Remove AspectJ support because it's not common used 20 | Direct include AOP alliance interface source code into project 21 | Downgrade from Java7 to Java6 to support older developing environment 22 | 2.4.4 Fix @AopAround does not support multiple methods bug 23 | 2.4.5 Fix AOP proxy do not support constructor parameters bug 24 | Add beanBox.setConstructorTypes() method, otherwise if constructor parameter is a subClass will have a Exception "Can not find constructor" 25 | Fix inner class advice bug 26 | 2.4.6 Add customize AOPAROUND Annotation feature 27 | 2.4.8 Re-wrote whole project,improved performance. 28 | 2.4.9 Fix superclass unsupport bug. 29 | 4.0.0 Add @NAMED, @QUALIFIER, @COMPONENT annotation support, add class scanner. --------------------------------------------------------------------------------