/*
 * Copyright 2014 the original author or authors.
 *
 * 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 net.kuujo.vertigo.component;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Verticle;
import io.vertx.core.VertxException;
import io.vertx.core.spi.VerticleFactory;

/**
 * Component verticle factory.
 *
 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
 */
public class ComponentFactory implements VerticleFactory {

  @Override
  public boolean requiresResolve() {
    return true;
  }

  @Override
  public String resolve(String identifier, DeploymentOptions options, ClassLoader classLoader) throws Exception {
    identifier = VerticleFactory.removePrefix(identifier);
    Config config = ConfigFactory.load(classLoader, identifier);
    String main = config.getString("main");
    if (main == null) {
      throw new VertxException(identifier + " does not contain a main field");
    }

    Config deployment = config.getConfig("deployment");
    if (deployment != null) {
      if (deployment.hasPath("worker")) {
        options.setWorker(deployment.getBoolean("worker"));
      }
      if (deployment.hasPath("multi-threaded")) {
        options.setMultiThreaded(deployment.getBoolean("multi-threaded"));
      }
    }
    return main;
  }

  @Override
  public String prefix() {
    return "component";
  }

  @Override
  public Verticle createVerticle(String verticle, ClassLoader classLoader) throws Exception {
    throw new IllegalStateException();
  }

}

@@ -646,85 +646,8 @@
 t;%0A%0A
-import com.typesafe.config.Config;%0Aimport com.typesafe.config.ConfigFactory;%0A
 impo
@@ -750,16 +750,54 @@
 eption;%0A
+import io.vertx.core.json.JsonObject;%0A
 import i
@@ -829,16 +829,55 @@
 Factory;
+%0Aimport net.kuujo.vertigo.util.Configs;
 %0A%0A/**%0A *
@@ -1298,22 +1298,26 @@
 r);%0A    
-Config
+JsonObject
  config 
@@ -1328,34 +1328,15 @@
 nfig
-Factory.load(classLoader, 
+s.load(
 iden
@@ -1502,22 +1502,26 @@
  %7D%0A%0A    
-Config
+JsonObject
  deploym
@@ -1536,22 +1536,26 @@
 nfig.get
-Config
+JsonObject
 (%22deploy
@@ -1613,23 +1613,27 @@
 loyment.
-hasPath
+containsKey
 (%22worker
@@ -1731,15 +1731,19 @@
 ent.
-hasPath
+containsKey
 (%22mu

Fix bad codez in ComponentFactory.