Skip to content

Instantly share code, notes, and snippets.

@splatch
Created June 25, 2012 16:38
Show Gist options
  • Select an option

  • Save splatch/2989650 to your computer and use it in GitHub Desktop.

Select an option

Save splatch/2989650 to your computer and use it in GitHub Desktop.
/**
* 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.apache.camel.component.cdi.spi.bean;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.InjectionTarget;
import org.apache.camel.CamelContext;
import org.apache.camel.component.cdi.CdiCamelContext;
import org.apache.deltaspike.core.api.literal.AnyLiteral;
import org.apache.deltaspike.core.api.literal.DefaultLiteral;
public class CamelContextBean extends AbstractImmutableBean<CdiCamelContext> {
public static final String CONTEXT_BEAN_NAME = "camelContext";
@SuppressWarnings("unchecked")
private static final Set<Annotation> QUALIFIERS = new HashSet<Annotation>(Arrays.asList(
new DefaultLiteral(), new AnyLiteral()));
private static final Set<Type> TYPES = new HashSet<Type>(Arrays.asList(
CamelContext.class));
private final InjectionTarget<CdiCamelContext> injectionTarget;
public CamelContextBean(InjectionTarget<CdiCamelContext> injectionTarget) {
super(CdiCamelContext.class, CONTEXT_BEAN_NAME, QUALIFIERS, ApplicationScoped.class, null, TYPES, false,
false, injectionTarget.getInjectionPoints(), CONTEXT_BEAN_NAME);
this.injectionTarget = injectionTarget;
}
@Override
public CdiCamelContext create(CreationalContext<CdiCamelContext> context) {
CdiCamelContext camelContext = injectionTarget.produce(context);
injectionTarget.inject(camelContext, context);
injectionTarget.postConstruct(camelContext);
return camelContext;
}
@Override
public void destroy(CdiCamelContext instance, CreationalContext<CdiCamelContext> context) {
injectionTarget.preDestroy(instance);
injectionTarget.dispose(instance);
context.release();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment