2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.introspection;
23 import org.eclipse.persistence.jaxb.JAXBContextFactory;
24 import org.openecomp.aai.db.props.AAIProperties;
26 import javax.xml.bind.JAXBContext;
27 import javax.xml.bind.JAXBException;
28 import java.util.regex.Matcher;
29 import java.util.regex.Pattern;
31 public class PojoInjestor {
33 private String POJO_CLASSPATH = "org.openecomp.aai.domain.yang";
34 private final Pattern classNamePattern = Pattern.compile("\\.(v\\d+)\\.");
36 public PojoInjestor() {
39 public JAXBContext getContextForVersion(Version v) {
40 JAXBContext context = null;
42 if (!v.equals(AAIProperties.LATEST)) {
43 POJO_CLASSPATH += "." + v;
45 context = JAXBContextFactory.createContext(POJO_CLASSPATH, this.getClass().getClassLoader());
46 } catch (JAXBException e) {
47 // TODO Auto-generated catch block
53 public Version getVersion (String classname) {
54 Matcher m = classNamePattern.matcher(classname);
59 //only POJOs of old versions have the version number in their classnames
60 //so if we can't find a version, default to the latest
61 version = AAIProperties.LATEST.toString();
64 return Version.valueOf(version);