/*
 * 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.alibaba.demo.cooma;

import com.alibaba.cooma.ExtensionLoader;
import com.alibaba.demo.cooma.car.Car;
import com.alibaba.demo.cooma.wheel.Wheel;
import com.alibaba.util.Utils;

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 defaultCar = extensionLoader.getDefaultExtension();
        defaultCar.run();

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

        Car racingCar = extensionLoader.getExtension("racing");
        racingCar.run();

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

        Car sportCar = extensionLoader.getExtension("sport", Utils.kv2Map(Wheel.class.getName(), "wood"));
        sportCar.run(); // 缺省使用RubberWheel

        // 演示 Wrapper的使用

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

        Car countedSportCar1 = extensionLoader.getExtension("sport", Arrays.asList("run_counter"));
        Car countedSportCar2 = extensionLoader.getExtension("sport", Arrays.asList("run_counter"));

        countedSportCar1.run();
        countedSportCar2.run();
        countedSportCar1.run();
    }
}

@@ -1284,25 +1284,20 @@
     Car 
-racingC
+c
 ar
+1
  = exten
@@ -1344,17 +1344,12 @@
     
-racingC
+c
 ar
+1
 .run
@@ -1435,24 +1435,20 @@
     Car 
-sportC
+c
 ar
+2
  = exten
@@ -1539,16 +1539,248 @@
     
-sportCar
+car2.run(); // %E7%BC%BA%E7%9C%81%E4%BD%BF%E7%94%A8RubberWheel%0D%0A%0D%0A        System.out.println(%22=================================%22);%0D%0A%0D%0A        Car car3 = extensionLoader.getExtension(Utils.kv2Map(Car.class.getName(), %22racing%22, Wheel.class.getName(), %22wood%22));%0D%0A        car3
 .run

update demo