/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * 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.
 */

package org.rapidpm.microservice.rest;


import org.rapidpm.ddi.DI;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import java.util.Collections;
import java.util.Set;

import static java.util.stream.Collectors.toSet;

@ApplicationPath("/rest")
public class JaxRsActivator extends Application {

  public boolean somethingToDeploy() {
    final Set<Class<?>> jaxRsActivatorClasses = getClasses();
    final Set<Object> jaxRsActivatorSingletons = getSingletons();
    return !(jaxRsActivatorClasses.isEmpty() && jaxRsActivatorSingletons.isEmpty());
  }

  @Override
  public Set<Class<?>> getClasses() {
    return DI.getTypesAnnotatedWith(Path.class, true)
        .stream()
        .filter(aClass -> !aClass.getCanonicalName().contains("org.jboss"))
        .collect(toSet());
  }

  /**
   * Hier kann man dann die Proxies holen ?
   *
   * @return
   */
  public Set<Object> getSingletons() {
    //TODO DDI aktivieren
    return Collections.emptySet();
  }
}

@@ -852,28 +852,120 @@
 ort 
-org.rapidpm.ddi.DI;%0A
+java.util.Collections;%0Aimport java.util.Set;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.Stream;
 %0Aimp
@@ -1074,97 +1074,55 @@
 java
-.util.Collections;%0Aimport java.util.Set;%0A%0Aimport static java.util.stream.Collectors.toSet
+x.ws.rs.ext.Provider;%0Aimport org.rapidpm.ddi.DI
 ;%0A%0A@
@@ -1508,22 +1508,45 @@
 ) %7B%0A    
-return
+Stream%3CClass%3C?%3E%3E pathStream =
  DI.getT
@@ -1678,26 +1678,179 @@
 s%22))
+;%0A
 %0A    
-    .collect(
+Stream%3CClass%3C?%3E%3E providerStream = DI.getTypesAnnotatedWith(Provider.class, true).stream();%0A%0A    return Stream.concat(pathStream, providerStream).collect(Collectors.
 toSe
@@ -1934,16 +1934,28 @@
 n%0A   */%0A
+  @Override%0A
   public

Load @Provider classes for JAX-RS