blob: 6e9de147d4da8cbc67a115e484794b6ca9d10397 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.runtime.jsr303.validation;
import java.util.ArrayList;
import java.util.List;
import javax.validation.Validation;
import javax.validation.ValidationProviderResolver;
import javax.validation.ValidatorFactory;
import javax.validation.spi.ValidationProvider;
import org.apache.bval.jsr303.ApacheValidationProvider;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
public class Activator implements BundleActivator, ValidationProviderResolver {
private ServiceRegistration<ValidatorFactory> registry;
@Override
public void start(BundleContext context) throws Exception {
// provide the bean validation factory
ValidatorFactory avf = Validation
.byProvider(ApacheValidationProvider.class)
.providerResolver(this).configure()
.messageInterpolator(new OSGiMessageInterpolator())
.buildValidatorFactory();
registry = context.registerService(ValidatorFactory.class, avf, null);
}
@Override
public void stop(BundleContext context) throws Exception {
if (registry != null) {
registry.unregister();
registry = null;
}
}
@Override
public List<ValidationProvider<?>> getValidationProviders() {
List<ValidationProvider<?>> result = new ArrayList<ValidationProvider<?>>();
result.add(new ApacheValidationProvider());
return result;
}
}