forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
26 changed files
with
1,306 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[[dozer]] | ||
= Dozer Extension | ||
|
||
*Since Camel Quarkus 0.5.0* | ||
|
||
The Dozer component provides the ability to map between Java beans using the http://camel.apache.org/dozer-type-conversion.html[Dozer] mapping framework. | ||
|
||
Maven users will need to add the following dependency to their `pom.xml` for this extension. | ||
|
||
[source,xml] | ||
------------------------------------------------------------ | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-dozer</artifactId> | ||
</dependency> | ||
------------------------------------------------------------ | ||
|
||
== Usage | ||
|
||
The extension provides support for the Camel https://camel.apache.org/components/latest/dozer-component.html[Dozer Component]. | ||
|
||
=== Configuration | ||
|
||
The Dozer extension can automatically register a `DozerBeanMapperConfiguration` bean with the Camel registry which references your mapping files. | ||
|
||
Use the following configuration property to specify the location(s) of your Dozer mapping configuration files. | ||
|
||
[source,properties] | ||
---- | ||
quarkus.camel.dozer.mapping-files = dozerMappings.xml,file:foo/bar/custom-mappings.xml,http://foo/bar/mapping.xml | ||
---- |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-dozer-parent</artifactId> | ||
<version>0.4.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>camel-quarkus-dozer-deployment</artifactId> | ||
<name>Camel Quarkus :: Dozer :: Deployment</name> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-bom-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jaxb-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-core-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-dozer</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
179 changes: 179 additions & 0 deletions
179
...ent/src/main/java/org/apache/camel/quarkus/component/dozer/deployment/DozerProcessor.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,179 @@ | ||
/* | ||
* 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.quarkus.component.dozer.deployment; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
|
||
import java.io.File; | ||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.sql.Time; | ||
import java.sql.Timestamp; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import com.github.dozermapper.core.builder.model.jaxb.AllowedExceptionsDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.ClassDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.ConfigurationDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.ConverterTypeDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.CopyByReferencesDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.CustomConvertersDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.FieldDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.FieldDefinitionDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.FieldExcludeDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.FieldType; | ||
import com.github.dozermapper.core.builder.model.jaxb.MappingDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.MappingsDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.Relationship; | ||
import com.github.dozermapper.core.builder.model.jaxb.Type; | ||
import com.github.dozermapper.core.builder.model.jaxb.VariableDefinition; | ||
import com.github.dozermapper.core.builder.model.jaxb.VariablesDefinition; | ||
import com.sun.el.ExpressionFactoryImpl; | ||
|
||
import org.apache.camel.component.dozer.CustomMapper; | ||
import org.apache.camel.component.dozer.DozerConfiguration; | ||
import org.apache.camel.component.dozer.ExpressionMapper; | ||
import org.apache.camel.component.dozer.VariableMapper; | ||
import org.apache.camel.converter.dozer.DozerBeanMapperConfiguration; | ||
import org.apache.camel.converter.dozer.DozerThreadContextClassLoader; | ||
import org.apache.camel.quarkus.component.dozer.CamelDozerConfig; | ||
import org.apache.camel.quarkus.component.dozer.CamelDozerRecorder; | ||
import org.apache.camel.quarkus.core.deployment.CamelBeanBuildItem; | ||
|
||
class DozerProcessor { | ||
|
||
private static final String FEATURE = "camel-dozer"; | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep | ||
void configureCamelDozer(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, | ||
BuildProducer<NativeImageResourceBuildItem> nativeImage, | ||
CamelDozerConfig camelDozerConfig) { | ||
|
||
// Add user Dozer mapping files to the image | ||
camelDozerConfig.mappingFiles | ||
.stream() | ||
.map(this::mappingPathToURI) | ||
// No scheme means classpath URI | ||
.filter(uri -> uri.getScheme() == null) | ||
.map(uri -> new NativeImageResourceBuildItem(uri.getPath())) | ||
.forEach(nativeImage::produce); | ||
|
||
// Add Dozer JAXB resources to the image | ||
nativeImage.produce(new NativeImageResourceBuildItem( | ||
"dtd/bean-mapping.dtd", | ||
"dtd/bean-mapping-6.0.0.dtd", | ||
"dtd/bean-mapping-6.2.0.dtd", | ||
"schema/bean-mapping.xsd", | ||
"schema/bean-mapping-6.0.0.xsd", | ||
"schema/bean-mapping-6.2.0.xsd", | ||
"com/github/dozermapper/core/builder/model/jaxb/jaxb.index")); | ||
|
||
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, | ||
BigDecimal[].class, | ||
BigInteger[].class, | ||
Boolean[].class, | ||
Byte[].class, | ||
Calendar[].class, | ||
Character[].class, | ||
Class[].class, | ||
Date[].class, | ||
java.sql.Date[].class, | ||
Double[].class, | ||
File[].class, | ||
Float[].class, | ||
Integer[].class, | ||
Long[].class, | ||
Object[].class, | ||
Short[].class, | ||
String[].class, | ||
Time[].class, | ||
Timestamp[].class, | ||
URL[].class, | ||
DozerThreadContextClassLoader.class, | ||
ExpressionFactoryImpl.class)); | ||
|
||
reflectiveClass.produce( | ||
new ReflectiveClassBuildItem(false, false, | ||
"com.github.dozermapper.core.builder.model.jaxb.package-info", | ||
"com.sun.org.apache.xerces.internal.impl.dv.xs.SchemaDVFactoryImpl")); | ||
|
||
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, | ||
CustomMapper.class, | ||
DozerConfiguration.class, | ||
ExpressionMapper.class, | ||
VariableMapper.class)); | ||
|
||
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, | ||
AllowedExceptionsDefinition.class, | ||
ClassDefinition.class, | ||
ConfigurationDefinition.class, | ||
ConverterTypeDefinition.class, | ||
CopyByReferencesDefinition.class, | ||
CustomConvertersDefinition.class, | ||
FieldDefinition.class, | ||
FieldDefinitionDefinition.class, | ||
FieldExcludeDefinition.class, | ||
FieldType.class, | ||
MappingDefinition.class, | ||
MappingsDefinition.class, | ||
Relationship.class, | ||
Type.class, | ||
VariableDefinition.class, | ||
VariablesDefinition.class)); | ||
} | ||
|
||
@Record(ExecutionTime.STATIC_INIT) | ||
@BuildStep | ||
CamelBeanBuildItem configureCamelDozerBeanMappings(BuildProducer<CamelBeanBuildItem> camelBeanBuildItemBuildProducer, | ||
CamelDozerConfig camelDozerConfig, | ||
CamelDozerRecorder camelDozerRecorder) { | ||
|
||
CamelBeanBuildItem camelBeanBuildItem = null; | ||
|
||
if (!camelDozerConfig.mappingFiles.isEmpty()) { | ||
// Bind DozerBeanMapperConfiguration to the Camel registry for the user provided Dozer mapping files | ||
camelBeanBuildItem = new CamelBeanBuildItem( | ||
"dozerBeanMappingConfiguration", | ||
DozerBeanMapperConfiguration.class.getName(), | ||
camelDozerRecorder.createDozerBeanMapperConfiguration(camelDozerConfig.mappingFiles)); | ||
} | ||
|
||
return camelBeanBuildItem; | ||
} | ||
|
||
private URI mappingPathToURI(String mappingPath) { | ||
try { | ||
return new URI(mappingPath); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-build-parent</artifactId> | ||
<version>0.4.1-SNAPSHOT</version> | ||
<relativePath>../../poms/build-parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>camel-quarkus-dozer-parent</artifactId> | ||
<name>Camel Quarkus :: Dozer</name> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
Oops, something went wrong.