X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fdatarouter%2Futil%2FOxmModelLoader.java;h=345bc48bbe2537f120236d06297c1560e38047c9;hb=72da66902a3efaff3068ed2b3f4f7eb3bb5fe43f;hp=37713c4f16c86fc0b1662733fcdca50c1288ca07;hpb=7af00564f04e1b8f441536fce5bdf31d59fe722c;p=aai%2Fdata-router.git diff --git a/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java b/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java index 37713c4..345bc48 100644 --- a/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java +++ b/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ * 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.onap.aai.datarouter.util; @@ -26,10 +24,11 @@ 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.Collection; +import java.util.NoSuchElementException; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -42,23 +41,20 @@ import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.datarouter.logging.DataRouterMsgs; -import org.onap.aai.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 Map versionContextMap = new ConcurrentHashMap<>(); private static List oxmModelProcessorRegistry = new ArrayList<>(); - final static Pattern p = Pattern.compile("aai_oxm_(.*).xml"); - - + static final 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 { + public static synchronized void loadModels() throws FileNotFoundException { ClassLoader cl = OxmModelLoader.class.getClassLoader(); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl); @@ -91,9 +87,8 @@ public class OxmModelLoader { } - - private synchronized static void loadModel(String version,String resourceName,InputStream inputStream) throws JAXBException, FileNotFoundException { + private static synchronized void loadModel(String version,String resourceName,InputStream inputStream) throws JAXBException { Map properties = new HashMap<>(); properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStream); final DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory @@ -107,11 +102,11 @@ public class OxmModelLoader { logger.info(DataRouterMsgs.LOADED_OXM_FILE, resourceName); } - public static DynamicJAXBContext getContextForVersion(String version) throws Exception { + public static DynamicJAXBContext getContextForVersion(String version) throws NoSuchElementException, FileNotFoundException { if (versionContextMap == null || versionContextMap.isEmpty()) { loadModels(); } else if (!versionContextMap.containsKey(version)) { - throw new Exception(Status.NOT_FOUND.toString()); + throw new NoSuchElementException(Status.NOT_FOUND.toString()); } @@ -126,7 +121,7 @@ public class OxmModelLoader { OxmModelLoader.versionContextMap = versionContextMap; } - public synchronized static void registerExternalOxmModelProcessors(Collection processors) { + public static synchronized void registerExternalOxmModelProcessors(Collection processors) { if(processors != null) { for(ExternalOxmModelProcessor processor : processors) { if(!oxmModelProcessorRegistry.contains(processor)) {