找到现成的的或创建一个。
<p>
Finds the existing one or create a new one.

@param environment
@return the context found or created
@throws NamingException
329189
public static InitialContext findOrCreate(Hashtable<?,?> environment) throws NamingException{
		if (found){
			return findDefault(environment);
		}
		
		InitialContext ctx = null;
		NamingException lastE = null;
		
		synchronized (InitialContextFinder.class){
			// get and test if the initial context is usable
			try {
				ctx = findDefault(environment);
			} catch (NamingException e) {
				lastE = e;
			}
			if (ctx != null){
				try {
					@SuppressWarnings("unused")
					Object o = ctx.lookup(InitialContextFinder.class.getName());
				} catch (NoInitialContextException e) {
					ctx = null;
				} catch (NamingException e) {
					lastE = e;
				}
			}
			
			// create one if needed
			if (ctx == null){
				try {
					ctx = createFSContext();
				} catch (NamingException e) {
					lastE = e;
				}
			}
			
			if (ctx != null){
				found = true;
				return ctx;
			}else{
				if (lastE != null){
					throw lastE;
				}else{
					throw new NamingException("Can't find InitialContext.");
				}
			}
		}
		
	}
985799
public static Log instance(Context context) {
        Log instance = context.get(logKey);
        if (instance == null)
            instance = new Log(context);
        return instance;
    }
729069
@Override
    @SuppressFBWarnings(value = "UL_UNRELEASED_LOCK", justification = "False positive from FindBugs")
    public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
        if (!isActive()) {
            throw new ContextNotActiveException();
        }
        checkContextInitialized();
        final BeanStore beanStore = getBeanStore();
        if (beanStore == null) {
            return null;
        }
        if (contextual == null) {
            throw ContextLogger.LOG.contextualIsNull();
        }
        BeanIdentifier id = getId(contextual);
        ContextualInstance<T> beanInstance = beanStore.get(id);
        if (beanInstance != null) {
            return beanInstance.getInstance();
        } else if (creationalContext != null) {
            LockedBean lock = null;
            try {
                if (multithreaded) {
                    lock = beanStore.lock(id);
                    beanInstance = beanStore.get(id);
                    if (beanInstance != null) {
                        return beanInstance.getInstance();
                    }
                }
                T instance = contextual.create(creationalContext);
                if (instance != null) {
                    beanInstance = new SerializableContextualInstanceImpl<Contextual<T>, T>(contextual, instance, creationalContext, serviceRegistry.get(ContextualStore.class));
                    beanStore.put(id, beanInstance);
                }
                return instance;
            } finally {
                if (lock != null) {
                    lock.unlock();
                }
            }
        } else {
            return null;
        }
    }
976686
public ScriptEnvironment getEnvironment(String environmentName) {
      Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName),
                                  "Environment name cannot be null or empty"
                                 );
      ScriptEngine engine = engineManager.getEngineByName(environmentName);
      Preconditions.checkArgument(engine != null, environmentName + " is an unknown.");
      environmentName = engine.getFactory().getEngineName();
      if (!environments.containsKey(environmentName)) {
         environments.put(environmentName, new ScriptEnvironment(engine));
      }
      return environments.get(environmentName);
   }
468036
@Override
    public Namespace createNamespace(Namespace namespace) {
        requireNotDisposed();
        requireArgument(namespace != null, "null namespace cannot be created.");
        
        if (!_validateQualifier(namespace.getQualifier())) {
            throw new SystemException(new IllegalArgumentException(
                    "Illegal characters found while generating namespace. Cannot generate a namespace with this qualifier."));
        }
        
        if (Namespace.findByQualifier(emf.get(), namespace.getQualifier()) != null) {
            throw new SystemException(new IllegalArgumentException("Namespace already exists. Please try a different namespace."));
        }
        
        namespace = updateNamespace(namespace);
        _logger.debug("Generated namespace {}.", namespace);
        return namespace;
    }
992021
public static ScriptEnvironment getTemporaryEnvironment(String environmentName) {
      Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName),
                                  "Environment name cannot be null or empty"
                                 );
      ScriptEngine engine = ScriptEnvironmentManager.getInstance().engineManager.getEngineByName(environmentName);
      Preconditions.checkArgument(engine != null, environmentName + " is an unknown.");
      return new ScriptEnvironment(engine);
   }
1271472
public static Environment getEnvironment(Map<String,Object> properties)
    {
        if (gEnv == null)	// TODO(don) Possible concurrency issue
            gEnv = new Environment(properties); // Create the Environment (using defalt database(s))
        //+else
        //+	Utility.getLogger().warning("getEnvironmentCalled");
        return gEnv;
    }
227156
public static ClassWriter instance(Context context) {
        ClassWriter instance = context.get(classWriterKey);
        if (instance == null)
            instance = new ClassWriter(context);
        return instance;
    }
734048
private Context createContext(String name) {
		Context context = new Context(this, this.nextContextIndex++);
		context.setName(name);
		return context;
	}
219343
public static HierarchicalConfiguration findForName(final HierarchicalConfiguration config, final String subKey, final String nameKey,
		final String nameValue)
			throws ConfigurationException {
		for (HierarchicalConfiguration subConfig : config.configurationsAt(subKey)) {
			String name = subConfig.getString(nameKey);
			if (name.equals(nameValue)) {
				return subConfig;
			}
		}
		// 没有找到
		throw new ConfigurationException(MessageFormats.format(ResourceBundles.getBundle(RESOURCE_BASENAME), "subnodeNotFound", nameKey, nameValue, subKey));
	}
724525
@Override
    protected EnvironmentConfig createEnvConfig() {
        EnvironmentConfig envConf = new EnvironmentConfig();
        envConf.setAllowCreate(true);
        envConf.setTransactional(true);

        LOGGER.log(Level.FINE, "Calculating cache size");
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage();
        long max = memoryUsage.getMax();
        long used = memoryUsage.getUsed();
        long available = max - used;
        long cacheSize = Math.round(available / 6.0);
        envConf.setCacheSize(cacheSize);
        LOGGER.log(Level.FINE, "Cache size set to {0}", cacheSize);
        return envConf;
    }
937423
@SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public WSContext getInitialContext(Hashtable env) throws NamingException {
        return new WSContext(userContext, JNDIServiceBinderHolder.HELPER.root, env);
    }
951920
public RuntimeEnvironmentBuilder addConfiguration(String name, String value) {
        if (name == null || value == null) {
            return this;
        }
        _runtimeEnvironment.addToConfiguration(name, value);

        return this;
    }
937789
public RuntimeEnvironmentBuilder addEnvironmentEntry(String name, Object value) {
        if (name == null || value == null) {
            return this;
        }
        _runtimeEnvironment.addToEnvironment(name, value);

        return this;
    }
1323243
public static Context getContext( String jdniInitialContextFactoryName , String providerURL , Hashtable<String,Object> extraEnv ) throws NamingException
    {
    	Hashtable<String,Object> env = new Hashtable<>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, jdniInitialContextFactoryName);
        env.put(Context.PROVIDER_URL, providerURL);
        if (extraEnv != null)
            env.putAll(extraEnv);
        return createJndiContext(env);
    }
670174
public static SoaFeatures getFeatures(Environment environment)
    {
        SoaFeaturesImpl features = (SoaFeaturesImpl)environment.getApplicationContext().getAttribute(SoaFeatures.class.getName());
        if ( features == null )
        {
            features = new SoaFeaturesImpl();   // temp version so that named values can be set
            environment.getApplicationContext().setAttribute(SoaFeatures.class.getName(), features);
        }

        if ( !features.hasDynamicAttributes() )
        {
            DynamicAttributes dynamicAttributes = (DynamicAttributes)environment.getApplicationContext().getAttribute(DynamicAttributes.class.getName());
            features.setDynamicAttributes(dynamicAttributes);
        }

        return features;
    }
837535
public ContextAwareMeter contextAwareMeter(String name, ContextAwareMetricFactory<ContextAwareMeter> factory) {
    return this.innerMetricContext.getOrCreate(name, factory);
  }