2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.introspection;
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
26 import org.eclipse.persistence.jaxb.JAXBContextFactory;
27 import org.onap.aai.db.props.AAIProperties;
29 import javax.xml.bind.JAXBContext;
30 import javax.xml.bind.JAXBException;
31 import java.util.regex.Matcher;
32 import java.util.regex.Pattern;
34 public class PojoInjestor {
35 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(PojoInjestor.class);
37 private String POJO_CLASSPATH = "org.onap.aai.domain.yang";
38 private final Pattern classNamePattern = Pattern.compile("\\.(v\\d+)\\.");
40 public PojoInjestor() {
43 public JAXBContext getContextForVersion(Version v) {
44 JAXBContext context = null;
46 if (!v.equals(AAIProperties.LATEST)) {
47 POJO_CLASSPATH += "." + v;
49 context = JAXBContextFactory.createContext(POJO_CLASSPATH, this.getClass().getClassLoader());
50 } catch (JAXBException e) {
51 LOGGER.error(e.getMessage(),e);
56 public Version getVersion (String classname) {
57 Matcher m = classNamePattern.matcher(classname);
62 //only POJOs of old versions have the version number in their classnames
63 //so if we can't find a version, default to the latest
64 version = AAIProperties.LATEST.toString();
67 return Version.valueOf(version);