cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Mao <james....@iona.com>
Subject Re: ListUtils? WAS: svn commit: r475168 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ common/common/src/test/java/org/apache/cxf/common/util/ tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/
Date Thu, 16 Nov 2006 02:03:05 GMT
Will change soon.

Thanks,
James.

Daniel Kulp 写道:
> I'm -1 on this commit unless someone can come up with a very good reason 
> why we cannot just use:
> void Collections.sort(List<T>, Comparator<? super T> c) 
>
> We shouldn't be duplicating stuff that's available in the JDK.
>
> Dan
>
>
> On Wednesday November 15 2006 4:21 am, mmao@apache.org wrote:
>   
>> Author: mmao
>> Date: Wed Nov 15 01:21:08 2006
>> New Revision: 475168
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=475168
>> Log:
>> Fixed a potential bug in schema validator.
>> schema validator failed on same specific platform due to the jar entry
>> order. the work around solution is sort the jar entry of the
>> common/schema
>>
>> Added:
>>    
>> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/u
>> til/ListUtils.java   (with props)
>> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/u
>> til/ListUtilsTest.java   (with props) Modified:
>>    
>> incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/
>> validator/internal/WSDL11Validator.java
>>
>> Added:
>> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/u
>> til/ListUtils.java URL:
>> http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main
>> /java/org/apache/cxf/common/util/ListUtils.java?view=auto&rev=475168
>> =======================================================================
>> ======= ---
>> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/u
>> til/ListUtils.java (added) +++
>> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/u
>> til/ListUtils.java Wed Nov 15 01:21:08 2006 @@ -0,0 +1,37 @@
>> +/**
>> + * 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.common.util;
>> +
>> +import java.util.*;
>> +
>> +public final class ListUtils {
>> +
>> +    private ListUtils() {
>> +    }
>> +
>> +    public static <T> List<T> sort(List<T> list, Comparator<?
super T>
>> c) { +        if (c == null) {
>> +            return list;
>> +        }
>> +        T[] listArray = (T[]) list.toArray();
>> +        Arrays.sort(listArray, c);
>> +        return Arrays.asList(listArray);
>> +    }
>> +}
>>
>> Propchange:
>> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/u
>> til/ListUtils.java
>> -----------------------------------------------------------------------
>> ------- svn:eol-style = native
>>
>> Propchange:
>> incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/u
>> til/ListUtils.java
>> -----------------------------------------------------------------------
>> ------- svn:keywords = Rev Date
>>
>> Added:
>> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/u
>> til/ListUtilsTest.java URL:
>> http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test
>> /java/org/apache/cxf/common/util/ListUtilsTest.java?view=auto&rev=475168
>> =======================================================================
>> ======= ---
>> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/u
>> til/ListUtilsTest.java (added) +++
>> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/u
>> til/ListUtilsTest.java Wed Nov 15 01:21:08 2006 @@ -0,0 +1,39 @@
>> +/**
>> + * 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.common.util;
>> +
>> +import java.util.*;
>> +
>> +import junit.framework.TestCase;
>> +
>> +public class ListUtilsTest extends TestCase {
>> +    public void testSort() throws Exception {
>> +        List<String> aList = Arrays.asList(new String[]{"soap", "xml",
>> "apache"}); +        assertEquals("soap", aList.get(0));
>> +        assertEquals("apache", aList.get(2));
>> +        aList = ListUtils.sort(aList, new Comparator<String>() {
>> +            public int compare(String o1, String o2) {
>> +                return o1.compareTo(o2);
>> +            }
>> +        });
>> +        assertEquals("apache", aList.get(0));
>> +        assertEquals("xml", aList.get(2));
>> +    }
>> +}
>>
>> Propchange:
>> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/u
>> til/ListUtilsTest.java
>> -----------------------------------------------------------------------
>> ------- svn:eol-style = native
>>
>> Propchange:
>> incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/u
>> til/ListUtilsTest.java
>> -----------------------------------------------------------------------
>> ------- svn:keywords = Rev Date
>>
>> Modified:
>> incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/
>> validator/internal/WSDL11Validator.java URL:
>> http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/ma
>> in/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java?vie
>> w=diff&rev=475168&r1=475167&r2=475168
>> =======================================================================
>> ======= ---
>> incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/
>> validator/internal/WSDL11Validator.java (original) +++
>> incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/
>> validator/internal/WSDL11Validator.java Wed Nov 15 01:21:08 2006 @@
>> -22,9 +22,7 @@
>>  import java.io.IOException;
>>  import java.net.JarURLConnection;
>>  import java.net.URL;
>> -import java.util.ArrayList;
>> -import java.util.Enumeration;
>> -import java.util.List;
>> +import java.util.*;
>>  import java.util.jar.JarEntry;
>>  import java.util.jar.JarFile;
>>
>> @@ -32,14 +30,13 @@
>>
>>  import org.xml.sax.InputSource;
>>
>> +import org.apache.cxf.common.util.ListUtils;
>>  import org.apache.cxf.common.util.StringUtils;
>>  import org.apache.cxf.resource.URIResolver;
>>  import org.apache.cxf.tools.common.ToolConstants;
>>  import org.apache.cxf.tools.common.ToolContext;
>>  import org.apache.cxf.tools.common.ToolException;
>>
>> -
>> -
>>  public class WSDL11Validator extends AbstractValidator {
>>
>>      private final List<AbstractValidator> validators = new
>> ArrayList<AbstractValidator>(); @@ -63,7 +60,6 @@
>>          //3.If 1 and 2 is null , then load these schema files from jar
>> file
>>
>>          if (!StringUtils.isEmpty(schemaDir)) {
>> -
>>              schemaValidator = new SchemaValidator(schemaDir,
>> (String)env.get(ToolConstants.CFG_WSDLURL), schemas);
>>          } else {
>> @@ -115,7 +111,6 @@
>>          List<InputSource> xsdList = new ArrayList<InputSource>();
>>          ClassLoader clzLoader =
>> Thread.currentThread().getContextClassLoader(); URL url =
>> clzLoader.getResource(ToolConstants.CXF_SCHEMAS_DIR_INJAR); -
>>          JarURLConnection jarConnection =
>> (JarURLConnection)url.openConnection();
>>
>>          JarFile jarFile = jarConnection.getJarFile();
>> @@ -126,15 +121,27 @@
>>              JarEntry ele =  (JarEntry)entry.nextElement();
>>              if (ele.getName().endsWith(".xsd")
>>                  &&
>> ele.getName().indexOf(ToolConstants.CXF_SCHEMAS_DIR_INJAR) > -1) { +
>>                  URIResolver resolver =  new
>> URIResolver(ele.getName()); if (resolver.isResolved()) {
>>                      InputSource is = new
>> InputSource(resolver.getInputStream()); is.setSystemId(ele.getName());
>> -                    xsdList.add(new
>> InputSource(resolver.getInputStream())); +                   
>> xsdList.add(is);
>>                  }
>>              }
>>          }
>>
>> -        return xsdList;
>> -    }
>> +        return sort(xsdList);
>> +    }
>> +
>> +    private List<InputSource> sort(List<InputSource> list) {
>> +        return ListUtils.sort(list, new Comparator<InputSource>() {
>> +            public int compare(InputSource i1, InputSource i2) {
>> +                if (i1 == null && i2 == null) {
>> +                    return -1;
>> +                }
>> +                return i1.getSystemId().compareTo(i2.getSystemId());
>> +            }
>> +        });
>> +    }
>>  }
>>     
>
>   


Mime
View raw message