我们继续分析当前这个类型中的InternalContextUtil.internalEnter(Constants.CONTEXT_DEFAULT_NAME);方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 private final static class InternalContextUtil extends ContextUtil { static Context internalEnter (String name) { return trueEnter(name, "" ); } static Context internalEnter (String name, String origin) { return trueEnter(name, origin); } }
首先这里要明确一下,一个Context的组成实际上需要name(名称)和origin(来源),所以方法上传入这两个参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 protected static Context trueEnter (String name, String origin) { Context context = contextHolder.get(); if (context == null ) { Map<String, DefaultNode> localCacheNameMap = contextNameNodeMap; DefaultNode node = localCacheNameMap.get(name); if (node == null ) { if (localCacheNameMap.size() > Constants.MAX_CONTEXT_NAME_SIZE) { setNullContext(); return NULL_CONTEXT; } else { LOCK.lock(); try { node = contextNameNodeMap.get(name); if (node == null ) { if (contextNameNodeMap.size() > Constants.MAX_CONTEXT_NAME_SIZE) { setNullContext(); return NULL_CONTEXT; } else { node = new EntranceNode (new StringResourceWrapper (name, EntryType.IN), null ); Constants.ROOT.addChild(node); Map<String, DefaultNode> newMap = new HashMap <>(contextNameNodeMap.size() + 1 ); newMap.putAll(contextNameNodeMap); newMap.put(name, node); contextNameNodeMap = newMap; } } } finally { LOCK.unlock(); } } } context = new Context (node, name); context.setOrigin(origin); contextHolder.set(context); } return context; }