-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support CDI Camel context customization
- Loading branch information
1 parent
db5caac
commit 120cd46
Showing
12 changed files
with
301 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/java/io/astefanutti/camel/cdi/CdiCamelContextBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com) | ||
* | ||
* 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 io.astefanutti.camel.cdi; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.spi.AnnotatedType; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
import javax.enterprise.inject.spi.InjectionTarget; | ||
import javax.enterprise.inject.spi.PassivationCapable; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
final class CdiCamelContextBean implements Bean<CdiCamelContext>, PassivationCapable { | ||
|
||
private final Set<Type> types; | ||
|
||
private final InjectionTarget<CdiCamelContext> target; | ||
|
||
CdiCamelContextBean(BeanManager manager) { | ||
AnnotatedType<CdiCamelContext> annotatedType = manager.createAnnotatedType(CdiCamelContext.class); | ||
this.types = annotatedType.getTypeClosure(); | ||
this.target = manager.createInjectionTarget(annotatedType); | ||
} | ||
|
||
@Override | ||
public Class<? extends Annotation> getScope() { | ||
return ApplicationScoped.class; | ||
} | ||
|
||
@Override | ||
public Set<Annotation> getQualifiers() { | ||
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(DefaultLiteral.INSTANCE, AnyLiteral.INSTANCE))); | ||
} | ||
|
||
@Override | ||
public CdiCamelContext create(CreationalContext<CdiCamelContext> creational) { | ||
CdiCamelContext context = target.produce(creational); | ||
target.postConstruct(context); | ||
creational.push(context); | ||
return context; | ||
} | ||
|
||
@Override | ||
public void destroy(CdiCamelContext instance, CreationalContext<CdiCamelContext> creational) { | ||
target.preDestroy(instance); | ||
target.dispose(instance); | ||
creational.release(); | ||
} | ||
|
||
@Override | ||
public Class<CdiCamelContext> getBeanClass() { | ||
return CdiCamelContext.class; | ||
} | ||
|
||
@Override | ||
public Set<InjectionPoint> getInjectionPoints() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "cdi-camel-context"; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Default CdiCamelContext Bean"; | ||
} | ||
|
||
@Override | ||
public Set<Class<? extends Annotation>> getStereotypes() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public Set<Type> getTypes() { | ||
return Collections.unmodifiableSet(types); | ||
} | ||
|
||
@Override | ||
public boolean isAlternative() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isNullable() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return getClass().getName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/io/astefanutti/camel/cdi/DefaultLiteral.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com) | ||
* | ||
* 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 io.astefanutti.camel.cdi; | ||
|
||
import javax.enterprise.inject.Default; | ||
import javax.enterprise.util.AnnotationLiteral; | ||
|
||
final class DefaultLiteral extends AnnotationLiteral<Default> implements Default { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
static final Default INSTANCE = new DefaultLiteral(); | ||
|
||
private DefaultLiteral() { | ||
} | ||
} |
Oops, something went wrong.