001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.dataformat.bindy;
018
019 import java.util.Locale;
020
021 import org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat;
022 import org.apache.camel.spi.DataFormat;
023 import org.apache.camel.spi.PackageScanClassResolver;
024 import org.slf4j.Logger;
025 import org.slf4j.LoggerFactory;
026
027 public abstract class BindyAbstractDataFormat implements DataFormat {
028 private String[] packages;
029 private String locale;
030 private BindyAbstractFactory modelFactory;
031
032 public BindyAbstractDataFormat() {
033 }
034
035 public BindyAbstractDataFormat(String... packages) {
036 this.packages = packages;
037 }
038
039 public String[] getPackages() {
040 return packages;
041 }
042
043 public void setPackages(String... packages) {
044 this.packages = packages;
045 }
046
047 public String getLocale() {
048 return locale;
049 }
050
051 public void setLocale(String locale) {
052 this.locale = locale;
053 }
054
055 public BindyAbstractFactory getFactory(PackageScanClassResolver resolver) throws Exception {
056 if (modelFactory == null) {
057 modelFactory = createModelFactory(resolver);
058 modelFactory.setLocale(locale);
059 }
060 return modelFactory;
061 }
062
063 public void setModelFactory(BindyAbstractFactory modelFactory) {
064 this.modelFactory = modelFactory;
065 }
066
067 protected abstract BindyAbstractFactory createModelFactory(PackageScanClassResolver resolver) throws Exception;
068 }