+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cssa.rserv;\r
-\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import javax.servlet.ServletException;\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.onap.aaf.inno.env.Trans;\r
-\r
-\r
-public class Routes<TRANS extends Trans> {\r
- // Since this must be very, very fast, and only needs one creation, we'll use just an array.\r
- private Route<TRANS>[] routes;\r
- private int end;\r
- \r
-\r
- @SuppressWarnings("unchecked")\r
- public Routes() {\r
- routes = new Route[10];\r
- end = 0;\r
- }\r
- \r
- // This method for setup of Routes only...\r
- // Package on purpose\r
- synchronized Route<TRANS> findOrCreate(HttpMethods meth, String path) {\r
- Route<TRANS> rv = null;\r
- for(int i=0;i<end;++i) {\r
- if(routes[i].resolvesTo(meth,path))rv = routes[i];\r
- }\r
- \r
- if(rv==null) {\r
- if(end>=routes.length) {\r
- @SuppressWarnings("unchecked")\r
- Route<TRANS>[] temp = new Route[end+10];\r
- System.arraycopy(routes, 0, temp, 0, routes.length);\r
- routes = temp;\r
- }\r
- \r
- routes[end++]=rv=new Route<TRANS>(meth,path);\r
- }\r
- return rv;\r
- }\r
- \r
- public Route<TRANS> derive(HttpServletRequest req, CodeSetter<TRANS> codeSetter) throws IOException, ServletException {\r
- Route<TRANS> rv = null;\r
- String path = req.getPathInfo();\r
- String meth = req.getMethod();\r
- //TODO a TREE would be better\r
- for(int i=0;rv==null && i<end; ++i) {\r
- rv = routes[i].matches(meth,path);\r
- if(rv!=null && !codeSetter.matches(rv)) { // potential match, check if has Code \r
- rv = null; // not quite, keep going\r
- }\r
- }\r
- //TODO a Default?\r
- return rv;\r
- }\r
- \r
- public List<RouteReport> routeReport() {\r
- ArrayList<RouteReport> ltr = new ArrayList<RouteReport>();\r
- for(int i=0;i<end;++i) {\r
- ltr.add(routes[i].api());\r
- }\r
- return ltr;\r
- }\r
-}\r