/** * Adds a field, _serviceExtensionPoint, whose type matches this class, and a constructor which * sets the field. */ private static void addConstructor(ClassFab classFab, ServiceModel model) { Class modelClass = model.getClass(); classFab.addField("_serviceModel", modelClass); classFab.addConstructor(new Class[] { modelClass }, null, "{ super(); _serviceModel = $1; }"); }
void finalizeEnhancedClass() { finalizeIncompleteMethods(); if (_constructorBuilder != null) { _constructorBuilder.end(); Class[] types = (Class[]) _constructorTypes.toArray(new Class[_constructorTypes.size()]); _classFab.addConstructor(types, null, _constructorBuilder.toString()); } if (_log != null && _log.isDebugEnabled()) _log.debug("Creating class:\n\n" + _classFab); }
void finalizeEnhancedClass() { finalizeIncompleteMethods(); if (_constructorBuilder != null) { _constructorBuilder.end(); Class[] types = (Class[]) _constructorTypes.toArray(new Class[_constructorTypes.size()]); _classFab.addConstructor(types, null, _constructorBuilder.toString()); } if (_log != null && _log.isDebugEnabled()) _log.debug("Creating class:\n\n" + _classFab); }
/** * Assumes that the factory will keep cranking out instances of the same class. * * @since 1.1 */ private Class constructBridgeProxyClass(Object service) { ProxyBuilder builder = new ProxyBuilder("BridgeProxy", getServicePoint()); ClassFab cf = builder.getClassFab(); Class serviceType = service.getClass(); cf.addField("_service", serviceType); cf.addConstructor(new Class[] { serviceType }, null, "{ super(); _service = $1; }"); builder.addServiceMethods("_service"); return cf.createClass(); }
private void createInfrastructure(InterceptorStack stack, ClassFab classFab) { Class topClass = ClassFabUtils.getInstanceClass(stack.peek(), stack.getServiceInterface()); classFab.addField("_log", Log.class); // This is very important: since we know the instance of the top object (the next // object in the pipeline for this service), we can build the instance variable // and constructor to use the exact class rather than the service interface. // That's more efficient at runtime, lowering the cost of using interceptors. // One of the reasons I prefer Javassist over JDK Proxies. classFab.addField("_delegate", topClass); classFab.addConstructor( new Class[] { Log.class, topClass }, null, "{ _log = $1; _delegate = $2; }"); }
classFab.addMethod(Modifier.PUBLIC, valueSetter, generateOgnlSetter(classFab, valueSetter)); classFab.addConstructor(new Class[0], new Class[0], "{}");
classFab.addMethod(Modifier.PUBLIC, valueSetter, generateOgnlSetter(classFab, valueSetter)); classFab.addConstructor(new Class[0], new Class[0], "{}");
generateClassFab(compiled).addMethod(Modifier.PUBLIC, valueSetter, setBody); generateClassFab(compiled).addConstructor(new Class[0], new Class[0], "{}");
generateClassFab(compiled).addMethod(Modifier.PUBLIC, valueSetter, setBody); generateClassFab(compiled).addConstructor(new Class[0], new Class[0], "{}");
/** @since 1.1 */ private static void addDelegateAccessor(ClassFab classFab, ServicePoint servicePoint, Object delegate) { classFab.addField("_shutdown", boolean.class); Class delegateClass = ClassFabUtils.getInstanceClass(delegate, servicePoint .getServiceInterface()); classFab.addField("_delegate", delegateClass); classFab.addConstructor(new Class[] { delegateClass }, null, "{ super(); _delegate = $1; }"); classFab.addInterface(RegistryShutdownListener.class); if( RegistryShutdownListener.class.isAssignableFrom( delegateClass ) ) { classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class, "registryDidShutdown", null, null), "{ _delegate.registryDidShutdown(); _delegate = null; _shutdown = true; }"); } else { classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class, "registryDidShutdown", null, null), "{ _delegate = null; _shutdown = true; }"); } BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.addln("if (_shutdown)"); builder.addln(" throw org.apache.hivemind.HiveMind#createRegistryShutdownException();"); builder.add("return _delegate;"); builder.end(); classFab.addMethod(Modifier.FINAL | Modifier.PRIVATE, new MethodSignature(delegateClass, DELEGATE_ACCESSOR_METHOD_NAME, null, null), builder.toString()); }
classFab.addConstructor(new Class[] { deferredProxyClass, getClass() }, null, body.toString());