X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fdatarouter%2Futil%2FOxmModelLoader.java;fp=src%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fdatarouter%2Futil%2FOxmModelLoader.java;h=0000000000000000000000000000000000000000;hb=2a5ff133471c5a69b0dfd760d2743f48112da9a0;hp=a69674015578f1a31b2ef49e358e071824ff9795;hpb=e6be129e4865104321cdd6313f9729c4e7b07d22;p=aai%2Fdata-router.git diff --git a/src/main/java/org/openecomp/datarouter/util/OxmModelLoader.java b/src/main/java/org/openecomp/datarouter/util/OxmModelLoader.java deleted file mode 100644 index a696740..0000000 --- a/src/main/java/org/openecomp/datarouter/util/OxmModelLoader.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.datarouter.util; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.ws.rs.core.Response.Status; -import javax.xml.bind.JAXBException; - -import org.eclipse.persistence.jaxb.JAXBContextProperties; -import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; -import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory; -import org.onap.aai.cl.eelf.LoggerFactory; -import org.openecomp.datarouter.logging.DataRouterMsgs; - -import org.openecomp.datarouter.util.ExternalOxmModelProcessor; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; - -public class OxmModelLoader { - - private static Map versionContextMap = new ConcurrentHashMap<>(); - private static List oxmModelProcessorRegistry = new ArrayList<>(); - final static Pattern p = Pattern.compile("aai_oxm_(.*).xml"); - - - - private static org.onap.aai.cl.api.Logger logger = LoggerFactory.getInstance() - .getLogger(OxmModelLoader.class.getName()); - - public synchronized static void loadModels() throws FileNotFoundException { - - ClassLoader cl = OxmModelLoader.class.getClassLoader(); - ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl); - Resource[] resources; - try { - resources = resolver.getResources("classpath*:/oxm/aai_oxm*.xml"); - } catch (IOException ex) { - logger.error(DataRouterMsgs.LOAD_OXM_ERROR, ex.getMessage()); - throw new FileNotFoundException("Unable to load OXM models from schema path : /oxm/aai_oxm*.xml"); - } - - if (resources.length == 0) { - logger.error(DataRouterMsgs.LOAD_OXM_ERROR, "No OXM schema files found on classpath"); - throw new FileNotFoundException("Unable to load OXM models from schema path : /oxm/aai_oxm*.xml"); - } - - for (Resource resource : resources) { - Matcher matcher = p.matcher(resource.getFilename()); - - if (matcher.matches()) { - try { - OxmModelLoader.loadModel(matcher.group(1), resource.getFilename(),resource.getInputStream()); - } catch (Exception e) { - logger.error(DataRouterMsgs.LOAD_OXM_ERROR, "Failed to load " + resource.getFilename() - + ": " + e.getMessage()); - } - } - } - - - } - - - - private synchronized static void loadModel(String version,String resourceName,InputStream inputStream) throws JAXBException, FileNotFoundException { - Map properties = new HashMap<>(); - properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStream); - final DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory - .createContextFromOXM(Thread.currentThread().getContextClassLoader(), properties); - versionContextMap.put(version, jaxbContext); - if ( oxmModelProcessorRegistry != null) { - for ( ExternalOxmModelProcessor processor : oxmModelProcessorRegistry ) { - processor.onOxmVersionChange(Version.valueOf(version), jaxbContext ); - } - } - logger.info(DataRouterMsgs.LOADED_OXM_FILE, resourceName); - } - - public static DynamicJAXBContext getContextForVersion(String version) throws Exception { - if (versionContextMap == null || versionContextMap.isEmpty()) { - loadModels(); - } else if (!versionContextMap.containsKey(version)) { - throw new Exception(Status.NOT_FOUND.toString()); - - } - - return versionContextMap.get(version); - } - - public static Map getVersionContextMap() { - return versionContextMap; - } - - public static void setVersionContextMap(Map versionContextMap) { - OxmModelLoader.versionContextMap = versionContextMap; - } - - public synchronized static void registerExternalOxmModelProcessors(Collection processors) { - if(processors != null) { - for(ExternalOxmModelProcessor processor : processors) { - if(!oxmModelProcessorRegistry.contains(processor)) { - oxmModelProcessorRegistry.add(processor); - } - } - } - } - -}