/*
 * Copyright 2012-2013 Cooma Team.
 *
 * Licensed 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.
 */

package com.metaframe.demo.cooma;

import com.metaframe.cooma.Config;
import com.metaframe.cooma.ExtensionLoader;
import com.metaframe.demo.cooma.car.Car;

import java.util.Arrays;

/**
 * @author Jerry Lee(oldratlee AT gmail DOT com)
 */
public class CarDemo {
    public static void main(String[] args) {
        ExtensionLoader<Car> extensionLoader = ExtensionLoader.getExtensionLoader(Car.class);

        // 演示 扩展的获得、关联扩展点的注入（Car扩展点引用了Wheel）

        Car racingCar = extensionLoader.getExtension("racing");
        racingCar.run(Config.fromKv("wheel", "wood")); // 通过Key指定要哪种轮子

        System.out.println("=================================");

        Car sportCar = extensionLoader.getExtension("sport");
        sportCar.run(Config.fromKv("k1", "v1")); // 缺省使用RubberWheel

        // 演示 Adaptive Instance的使用

        System.out.println("=================================");

        Car adaptiveInstance = extensionLoader.getAdaptiveInstance();
        adaptiveInstance.run(Config.fromKv("car", "racing")); // 通过car key指定的Car本身使用哪个实现。

        // 演示 Wrapper的使用

        System.out.println("=================================");

        Car countedSportCar = extensionLoader.getExtension("sport", Arrays.asList("run_counter"));
        countedSportCar.run(Config.fromKv("k1", "v1"));
    }
}

@@ -1934,24 +1934,364 @@
 k1%22, %22v1%22));
+ // %E7%BC%BA%E7%9C%81%E4%BD%BF%E7%94%A8RubberWheel%0D%0A%0D%0A        // %E6%BC%94%E7%A4%BA %E5%9C%A8Adaptive Instance%E4%B8%8AWrapper%E7%9A%84%E4%BD%BF%E7%94%A8%0D%0A%0D%0A        System.out.println(%22=================================%22);%0D%0A%0D%0A        Car countedAdaptiveInstance = extensionLoader.getAdaptiveInstance(Arrays.asList(%22run_counter%22));%0D%0A        countedAdaptiveInstance.run(Config.fromKv(%22car%22, %22racing%22)); // %E9%80%9A%E8%BF%87car key%E6%8C%87%E5%AE%9A%E7%9A%84Car%E6%9C%AC%E8%BA%AB%E4%BD%BF%E7%94%A8%E5%93%AA%E4%B8%AA%E5%AE%9E%E7%8E%B0%E3%80%82
 %0D%0A    %7D%0D%0A%7D%0D%0A

update wrapper usage demo #47