📄 jk_env.c
字号:
/* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999-2002 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation <http://www.apache.org/>." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Jk", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact <apache@apache.org>. * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see <http://www.apache.org/>. * * * * ========================================================================= */ #include "jk_global.h"#include "jk_env.h"#include "jk_objCache.h"#ifdef HAS_APR#include "apr_general.h"#endifjk_env_t *jk_env_globalEnv;void *jkGlobalAprPool=NULL;/* Private methods */static void jk2_env_initEnv( jk_env_t *env, char *id );/* We should have one env per thread to avoid sync problems. The env provides access to tmp pools, exception *//* -------------------- Env management -------------------- */static void * JK_METHOD jk2_env_getAprPool( jk_env_t *env ) {#ifdef HAS_APR /* We don't want to have to recreate the scoreboard after * restarts, so we'll create a global pool and never clean it. */ if( jkGlobalAprPool==NULL ) { int rc; rc = apr_pool_create(( apr_pool_t **)&jkGlobalAprPool, NULL); if (rc != APR_SUCCESS || jkGlobalAprPool==NULL ) { env->l->jkLog(env, env->l, JK_LOG_ERROR, "Unable to create global apr pool\n"); return NULL; } } return jkGlobalAprPool;#else return NULL;#endif}void JK_METHOD jk2_env_setAprPool( jk_env_t *env, void *aprPool ) { jkGlobalAprPool=aprPool;}/** Public method, creates/get the global env */jk_env_t* JK_METHOD jk2_env_getEnv( char *id, jk_pool_t *pool ) { if( jk_env_globalEnv == NULL ) { if( pool == NULL ) return NULL; jk_env_globalEnv=(jk_env_t *)pool->calloc( NULL, pool, sizeof( jk_env_t )); jk_env_globalEnv->globalPool = pool; jk2_env_initEnv( (jk_env_t *)jk_env_globalEnv, id ); /* fprintf( stderr, "env: top level env %#lx\n", jk_env_globalEnv); */ } return jk_env_globalEnv;}/** Get a local env - either a new one or a recycled one * XXX Try TLD too */static jk_env_t * JK_METHOD jk2_env_get( jk_env_t *parentEnv ){ jk_env_t *env=(jk_env_t *)parentEnv->envCache->get( parentEnv, parentEnv->envCache); if( env == NULL ) { jk_pool_t *parentPool=parentEnv->globalPool; env=(jk_env_t *)parentPool->calloc( parentEnv, parentPool, sizeof( jk_env_t )); env->tmpPool=parentPool->create(parentEnv, parentPool, HUGE_POOL_SIZE);; env->registerFactory= parentEnv->registerFactory; env->getByName= parentEnv->getByName; env->getByName2= parentEnv->getByName2; env->getBean2= parentEnv->getBean2; env->getBean= parentEnv->getBean; env->alias= parentEnv->alias; env->createBean2= parentEnv->createBean2; env->createBean= parentEnv->createBean; env->getEnv= parentEnv->getEnv; env->releaseEnv= parentEnv->releaseEnv; env->jkClearException=parentEnv->jkClearException; env->jkException=parentEnv->jkException; env->getAprPool=parentEnv->getAprPool; env->setAprPool=parentEnv->setAprPool; env->_registry=parentEnv->_registry; env->_objects=parentEnv->_objects; env->l=parentEnv->l; env->globalPool=parentEnv->globalPool; env->envCache=parentEnv->envCache; env->debug=parentEnv->debug; env->soName=parentEnv->soName; if( env->debug > 0 ) { if( env->l == NULL ) fprintf( stderr, "env:Create child env %#lx %#lx\n", parentEnv, env); else env->l->jkLog(env, env->l, JK_LOG_DEBUG, "env:Create child env %#lx %#lx\n", parentEnv, env); } } return env;}/** Release the env ( clean and recycle ) */static int JK_METHOD jk2_env_recycleEnv( jk_env_t *env ){ env->tmpPool->reset(env, env->tmpPool); env->jkClearException(env); return JK_OK;}/** Release the env ( clean and recycle ) */static int JK_METHOD jk2_env_put( jk_env_t *parent, jk_env_t *chld ){ jk2_env_recycleEnv( chld ); return parent->envCache->put( parent, parent->envCache, chld);}/* -------------------- Object management -------------------- *//** Create a jk component, using only the name. * Now things are simpler - the 'type' is the prefix, separated by ':' - no * guessing involved. */static jk_bean_t *jk2_env_createBean( jk_env_t *env, jk_pool_t *pool, char *objName ){ char *type=NULL;/* void *obj; */ char *localName; localName=strchr( objName, ':' ); if( localName==NULL ) { type=objName; } else { /* Funny pointer arithmetic. I hope I got it right */ type=env->tmpPool->calloc( env, env->tmpPool, localName - objName + 2 ); strncpy( type, objName, localName - objName ); localName++; } return env->createBean2( env, pool, type, localName );}/** Create a component using type and local part ( pre-cooked ). */static jk_bean_t *jk2_env_createBean2( jk_env_t *env, jk_pool_t *pool, char *type, char *localName ){ jk_env_objectFactory_t fac; jk_bean_t *result=NULL; jk_pool_t *workerPool; char *name; int i; if( localName!=NULL ) result=env->getBean2( env, type, localName ); if( result!=NULL ) return result; if( pool==NULL ) { pool=env->globalPool; } if( type==NULL ) { env->l->jkLog(env, env->l, JK_LOG_ERROR, "env.createBean2(): NullPointerException\n"); return NULL; } if( strcmp( "disabled", type ) == 0 ) { return NULL; } /* if( localName!=NULL && strncmp( localName, type, strlen( type )) == 0 ) { */ /* Common error, make it 'localName' */ /* if( strcmp( type, localName ) == 0 ) { */ /* localName=""; */ /* } else { */ /* localName= localName + strlen(type) + 1; */ /* } */ /* } */ if( env->debug > 0 ) { if( env->l != NULL ) { env->l->jkLog(env, env->l, JK_LOG_DEBUG, "env.createBean2(): Create [%s] %s\n", type, localName); } else { fprintf(stderr, "env.createBean2(): Create [%s] %s\n", type, localName); } } fac=(jk_env_objectFactory_t)env->_registry->get( env, env->_registry, type); if( fac==NULL ) { if( env->l ) { env->l->jkLog(env, env->l, JK_LOG_ERROR, "env.createBean2(): Error getting factory for [%s] %s\n", type, localName); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -