cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r725348 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: model/ClassResourceInfoComparator.java model/OperationResourceInfoComparator.java model/URITemplate.java utils/JAXRSUtils.java
Date Wed, 10 Dec 2008 17:21:28 GMT
Author: sergeyb
Date: Wed Dec 10 09:21:27 2008
New Revision: 725348

URL: http://svn.apache.org/viewvc?rev=725348&view=rev
Log:
JAXRS : minor updates to class and operation resource info comparators

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java?rev=725348&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
Wed Dec 10 09:21:27 2008
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.cxf.jaxrs.model;
+
+import java.util.Comparator;
+
+public class ClassResourceInfoComparator implements Comparator<ClassResourceInfo> {
+
+    public int compare(ClassResourceInfo cr1, ClassResourceInfo cr2) {
+        
+        return URITemplate.compareTemplates(
+               cr1.getURITemplate(), 
+               cr2.getURITemplate());
+    }
+}
+    
+

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java?rev=725348&r1=725347&r2=725348&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
Wed Dec 10 09:21:27 2008
@@ -34,30 +34,17 @@
         }
 
             
-        String l1 = e1.getURITemplate().getLiteralChars();
-        String l2 = e2.getURITemplate().getLiteralChars();
-        if (!l1.equals(l2)) {
-            // descending order 
-            return l1.length() < l2.length() ? 1 : -1; 
-        }
-        
-        int g1 = e1.getURITemplate().getNumberOfGroups();
-        int g2 = e2.getURITemplate().getNumberOfGroups();
-        if (g1 != g2) {
-            // descending order 
-            return g1 < g2 ? 1 : -1;
-        }
+        int result = URITemplate.compareTemplates(
+                          e1.getURITemplate(),
+                          e2.getURITemplate());
         
-        int gCustom1 = e1.getURITemplate().getNumberOfGroupsWithCustomExpression();
-        int gCustom2 = e2.getURITemplate().getNumberOfGroupsWithCustomExpression();
-        if (gCustom1 != gCustom2) {
-            // descending order 
-            return gCustom1 < gCustom2 ? 1 : -1;
-        }
+        if (result == 0) {
         
-        int result = JAXRSUtils.compareSortedMediaTypes(
+            result = JAXRSUtils.compareSortedMediaTypes(
                           e1.getConsumeTypes(), 
                           e2.getConsumeTypes());
+        }
+        
         if (result == 0) {
             //use the media type of output data as the secondary key.
             result = JAXRSUtils.compareSortedMediaTypes(e1.getProduceTypes(), 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=725348&r1=725347&r2=725348&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
Wed Dec 10 09:21:27 2008
@@ -35,7 +35,6 @@
 public final class URITemplate {
     
     public static final String TEMPLATE_PARAMETERS = "jaxrs.template.parameters";
-    
     public static final String LIMITED_REGEX_SUFFIX = "(/.*)?";
     public static final String FINAL_MATCH_GROUP = "FINAL_MATCH_GROUP";
     
@@ -46,6 +45,7 @@
         Pattern.compile("\\{(\\w[-\\w\\.]*)(\\:(.+?))?\\}");
 
     private static final String DEFAULT_PATH_VARIABLE_REGEX = "([^/]+?)";
+    private static final String CHARACTERS_TO_ESCAPE = ".";
     
     private final String template;
     private final List<String> templateVariables = new ArrayList<String>();
@@ -123,9 +123,9 @@
     }
     
     private static boolean isReservedCharater(char ch) {
-        return '.' == ch;
+        return CHARACTERS_TO_ESCAPE.indexOf(ch) != -1;
     }
-
+    
     public boolean match(String uri, MultivaluedMap<String, String> templateVariableToValue)
{
 
         if (uri == null) {
@@ -192,4 +192,27 @@
         
         return new URITemplate(pathValue);
     }
+    
+    public static int compareTemplates(URITemplate t1, URITemplate t2) {
+        String l1 = t1.getLiteralChars();
+        String l2 = t2.getLiteralChars();
+        if (!l1.equals(l2)) {
+            // descending order 
+            return l1.length() < l2.length() ? 1 : -1; 
+        }
+        
+        int g1 = t1.getNumberOfGroups();
+        int g2 = t2.getNumberOfGroups();
+        // descending order 
+        int result = g1 < g2 ? 1 : g1 > g2 ? -1 : 0;
+        if (result == 0) {
+            int gCustom1 = t1.getNumberOfGroupsWithCustomExpression();
+            int gCustom2 = t2.getNumberOfGroupsWithCustomExpression();
+            if (gCustom1 != gCustom2) {
+                // descending order 
+                return gCustom1 < gCustom2 ? 1 : -1;
+            }
+        }
+        return result;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=725348&r1=725347&r2=725348&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Wed
Dec 10 09:21:27 2008
@@ -82,6 +82,7 @@
 import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.ClassResourceInfoComparator;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfoComparator;
 import org.apache.cxf.jaxrs.model.URITemplate;
@@ -218,24 +219,7 @@
         
         SortedMap<ClassResourceInfo, MultivaluedMap<String, String>> candidateList
= 
             new TreeMap<ClassResourceInfo, MultivaluedMap<String, String>>(
-                new Comparator<ClassResourceInfo>() {
-
-                    public int compare(ClassResourceInfo cr1, ClassResourceInfo cr2) {
-                        
-                        String l1 = cr1.getURITemplate().getLiteralChars();
-                        String l2 = cr2.getURITemplate().getLiteralChars();
-                        if (!l1.equals(l2)) {
-                            // descending order 
-                            return l1.length() < l2.length() ? 1 : -1; 
-                        }
-                        
-                        int g1 = cr1.getURITemplate().getNumberOfGroups();
-                        int g2 = cr2.getURITemplate().getNumberOfGroups();
-                        // descending order 
-                        return g1 < g2 ? 1 : g1 > g2 ? -1 : 0;
-                    }
-                    
-                });
+                new ClassResourceInfoComparator());
         
         for (ClassResourceInfo resource : resources) {
             MultivaluedMap<String, String> map = new MetadataMap<String, String>();



Mime
View raw message