blob: 6c478920f91fe972cc27812edc77f5146f912bf8 [file] [log] [blame]
/*
* 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.bean.validator;
import java.util.Map;
import javax.validation.ValidatorFactory;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.Endpoint;
import org.apache.camel.Producer;
import org.apache.camel.component.bean.validator.BeanValidatorComponent;
import org.apache.camel.component.bean.validator.BeanValidatorEndpoint;
import org.apache.camel.component.bean.validator.BeanValidatorProducer;
import org.apache.camel.support.CamelContextHelper;
@Recorder
public class BeanValidatorRecorder {
/*
* TODO: remove when rebasing on Camel > 3.0.0-RC3 as camel-main engine
* should automatically bind the ValidatorFactory set-up by Quarkus
* to the component
*/
public RuntimeValue<BeanValidatorComponent> createBeanValidatorComponent() {
return new RuntimeValue<>(new QuarkusBeanValidatorComponent());
}
static class QuarkusBeanValidatorComponent extends BeanValidatorComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
BeanValidatorEndpoint endpoint = new QuarkusBeanValidatorEndpoint(uri, this);
endpoint.setLabel(remaining);
setProperties(endpoint, parameters);
return endpoint;
}
}
static class QuarkusBeanValidatorEndpoint extends BeanValidatorEndpoint {
public QuarkusBeanValidatorEndpoint(String endpointUri, Component component) {
super(endpointUri, component);
}
@Override
public Producer createProducer() throws Exception {
final CamelContext camelContext = getCamelContext();
final BeanValidatorProducer producer = new BeanValidatorProducer(this);
final String group = getGroup();
if (group != null) {
producer.setGroup(camelContext.getClassResolver().resolveMandatoryClass(group));
}
ValidatorFactory validatorFactory = CamelContextHelper.mandatoryLookup(
camelContext,
"quarkus-hibernate-validator-factory",
ValidatorFactory.class);
producer.setValidatorFactory(validatorFactory);
return producer;
}
}
}