基本工作原理:
上面的静态类图表现了注册结构的静态分析,类org.apache.tuscany.sca.core. DefaultExtensionPointRegistry的getExtensionPoint流程图体现了在如何从注册中心获取需要的对象的过程。从本质上分析ExtensionPointRegistry就类似于Collection,其功能无外乎可添加,可删除,可获取,这儿用HashMap<Class<?>,Object>来实现,HashMap也就是put,get,remove方法。可以把DefaultExtensionPointRegistry理解为HashMap的特殊封装,其中<Class<?>,Object>是非常重要的。
换句话说,META-INF/services下面的文件相当于插件板组,其中包含着若干个插件板,每个插件板的插件孔是可以预先调配的。另外,类似于树的概念,有些插件板的插孔也可以插入子插件板,下面显示一个简单插件板的例子,插件板的名称是“org.apache.tuscany.sca.contribution.resolver. ModelResolverExtensionPoint” ,插件板的名称一般是Java接口的名称,而插孔的名称一般为实现类的名称,该例子仅仅声明了一个插孔,插孔名称为“org.apache.tuscany.sca.contribution.resolver.DefaultModelResolverExtensionPoint”,另外我告诉你一秘密,凡是以“ExtensionPoin”结尾的,一般是子插件板,呵呵!一般人我不告诉他。
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
org.apache.tuscany.sca.contribution.resolver.DefaultModelResolverExtensionPoint
从而,我们就可以非常方便地对插件板进行修改,或增加插件板来满足系统不断新增需求,不断新增模块,修改模块的需求。并且DefaultExtensionPointRegistry是系统中的根插件板,是其他所有插件板或者插件的根(root)。