On Wed, Oct 19, 2011 at 2:18 AM, Andreas Veithen
<andreas.veit...@gmail.com> wrote:
> The functionality of the isSuperClass method is actually already
> provided by the JRE:
>
> http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html#isAssignableFrom(java.lang.Class)

I also used above method several places in adb module, I can't recall
exactly how I get this idea to implement isSuperClass method :)
It seems isAssignableFrom method smart enough for TypeTable's
requirement too will change this.

Thanks !

>
> Andreas
>
> On Thu, Sep 29, 2011 at 13:19,  <sag...@apache.org> wrote:
>> Author: sagara
>> Date: Thu Sep 29 11:19:01 2011
>> New Revision: 1177265
>>
>> URL: http://svn.apache.org/viewvc?rev=1177265&view=rev
>> Log:
>> Changed getSchemaTypeNameByClass(String name) method to use Class as the 
>> comparison basis instead of String comparison.
>>
>> Modified:
>>    
>> axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java
>>    
>> axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java
>>
>> Modified: 
>> axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java
>> URL: 
>> http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java?rev=1177265&r1=1177264&r2=1177265&view=diff
>> ==============================================================================
>> --- 
>> axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java
>>  (original)
>> +++ 
>> axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java
>>  Thu Sep 29 11:19:01 2011
>> @@ -28,6 +28,7 @@ import javax.xml.datatype.Duration;
>>  import javax.xml.datatype.XMLGregorianCalendar;
>>  import javax.xml.namespace.QName;
>>  import java.util.ArrayList;
>> +import java.util.Calendar;
>>  import java.util.HashMap;
>>  import java.util.List;
>>  import java.util.Map;
>> @@ -114,9 +115,7 @@ public class TypeTable {
>>         simpleTypetoxsd.put("java.util.Date",
>>                 new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD, "date", 
>> "xs"));
>>         simpleTypetoxsd.put("java.util.Calendar",
>> -                new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD, 
>> "dateTime", "xs"));
>> -        simpleTypetoxsd.put("java.util.GregorianCalendar",
>> -                new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD, 
>> "dateTime", "xs"));
>> +                new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD, 
>> "dateTime", "xs"));
>>
>>         // SQL date time
>>          simpleTypetoxsd.put("java.sql.Date",
>> @@ -334,19 +333,52 @@ public class TypeTable {
>>      */
>>     private QName getSchemaTypeNameByClass(String name) {
>>         /*
>> +         * e.g
>>          * XMLGregorianCalendar can be found as following classes.
>>          * 
>> 1.)com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl
>>          * 2.)org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl
>>          */
>> -        if 
>> ("com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl"
>> -                .equals(name)
>> -                || 
>> "org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl"
>> -                        .equals(name)) {
>> -            return (QName) simpleTypetoxsd.get(XMLGregorianCalendar.class
>> -                    .getName());
>> +        try {
>> +            Class thisClass = Class.forName(name);
>> +            if(isSuperClass(thisClass, XMLGregorianCalendar.class)) {
>> +                return (QName) 
>> simpleTypetoxsd.get(XMLGregorianCalendar.class
>> +                        .getName());
>> +
>> +            } else if(isSuperClass(thisClass, Calendar.class)) {
>> +                return (QName) simpleTypetoxsd.get(Calendar.class
>> +                        .getName());
>> +            }
>> +        } catch (ClassNotFoundException e) {
>> +            e.printStackTrace();
>>         }
>> +
>>         return null;
>>     }
>> +
>> +    /**
>> +     * This method check whether given child class in a extended class of 
>> given
>> +     * parent class.
>> +     * TODO - may be need to come up with a better name for this method .
>> +     *
>> +     * @param child
>> +     *            the child
>> +     * @param parent
>> +     *            the parent
>> +     * @return true, if is super class
>> +     */
>> +    public static boolean isSuperClass(Class child, Class parent) {
>> +        if (child == null || parent == null) {
>> +            return false;
>> +        }
>> +        Class superclass = child.getSuperclass();
>> +        while (superclass != null) {
>> +            if (superclass.getName().equals(parent.getName())) {
>> +                return true;
>> +            }
>> +            superclass = superclass.getSuperclass();
>> +        }
>> +        return false;
>> +    }
>>  }
>>
>>
>>
>> Modified: 
>> axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java
>> URL: 
>> http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java?rev=1177265&r1=1177264&r2=1177265&view=diff
>> ==============================================================================
>> --- 
>> axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java
>>  (original)
>> +++ 
>> axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java
>>  Thu Sep 29 11:19:01 2011
>> @@ -19,15 +19,23 @@
>>
>>  package org.apache.axis2.description.java2wsdl;
>>
>> +import java.math.BigDecimal;
>>  import java.math.BigInteger;
>> +import java.util.GregorianCalendar;
>> +import java.util.Locale;
>> +import java.util.TimeZone;
>>
>>  import javax.activation.DataHandler;
>> +import javax.xml.datatype.Duration;
>> +import javax.xml.datatype.XMLGregorianCalendar;
>>  import javax.xml.namespace.QName;
>>
>>  import junit.framework.TestCase;
>>
>>  import org.apache.ws.commons.schema.constants.Constants;
>>
>> +
>> +
>>  /**
>>  * The Class TypeTableTest is used to test
>>  * {@link org.apache.axis2.description.java2wsdl.TypeTable TypeTable} class.
>> @@ -80,5 +88,217 @@ public class TypeTableTest extends TestC
>>                assertNull("NULl value expected",
>>                                
>> typeTable.getClassNameForQName(Constants.XSD_LANGUAGE));
>>        }
>> +
>> +
>> +    public void testGetSchemaTypeName() {
>> +        String className = null;
>> +        QName dateType = new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD,
>> +                "date", "xs");
>> +        TypeTable typeTable = new TypeTable();
>> +
>> +        className = 
>> "com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl";
>> +        assertEquals("Not the expected value", dateType,
>> +                typeTable.getSchemaTypeName(className));
>> +
>> +        className = TestXMLGregorianCalendarImpl.class.getName();
>> +        assertEquals("Not the expected value", dateType,
>> +                typeTable.getSchemaTypeName(className));
>> +
>> +        className = GregorianCalendar.class.getName();
>> +        dateType = new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD,
>> +                "dateTime", "xs");
>> +        System.out.println( typeTable.getSchemaTypeName(className));
>> +        assertEquals("Not the expected value", dateType,
>> +                typeTable.getSchemaTypeName(className));
>> +
>> +        className = TestCalendarImpl.class.getName();
>> +        assertNull("Not the expected value",
>> +                typeTable.getSchemaTypeName(className));
>> +    }
>> +
>> +    class TestXMLGregorianCalendarImpl extends XMLGregorianCalendar {
>> +        @Override
>> +        public void clear() {
>> +        }
>> +
>> +        @Override
>> +        public void reset() {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setYear(BigInteger year) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setYear(int year) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setMonth(int month) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setDay(int day) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setTimezone(int offset) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setHour(int hour) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setMinute(int minute) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setSecond(int second) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setMillisecond(int millisecond) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public void setFractionalSecond(BigDecimal fractional) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public BigInteger getEon() {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public int getYear() {
>> +
>> +            return 0;
>> +        }
>> +
>> +        @Override
>> +        public BigInteger getEonAndYear() {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public int getMonth() {
>> +
>> +            return 0;
>> +        }
>> +
>> +        @Override
>> +        public int getDay() {
>> +
>> +            return 0;
>> +        }
>> +
>> +        @Override
>> +        public int getTimezone() {
>> +
>> +            return 0;
>> +        }
>> +
>> +        @Override
>> +        public int getHour() {
>> +
>> +            return 0;
>> +        }
>> +
>> +        @Override
>> +        public int getMinute() {
>> +
>> +            return 0;
>> +        }
>> +
>> +        @Override
>> +        public int getSecond() {
>> +
>> +            return 0;
>> +        }
>> +
>> +        @Override
>> +        public BigDecimal getFractionalSecond() {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public int compare(XMLGregorianCalendar xmlGregorianCalendar) {
>> +
>> +            return 0;
>> +        }
>> +
>> +        @Override
>> +        public XMLGregorianCalendar normalize() {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public String toXMLFormat() {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public QName getXMLSchemaType() {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public boolean isValid() {
>> +            return false;
>> +        }
>> +
>> +        @Override
>> +        public void add(Duration duration) {
>> +
>> +        }
>> +
>> +        @Override
>> +        public GregorianCalendar toGregorianCalendar() {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public GregorianCalendar toGregorianCalendar(TimeZone timezone,
>> +                Locale aLocale, XMLGregorianCalendar defaults) {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public TimeZone getTimeZone(int defaultZoneoffset) {
>> +
>> +            return null;
>> +        }
>> +
>> +        @Override
>> +        public Object clone() {
>> +
>> +            return null;
>> +        }
>> +
>> +    }
>> +
>> +    class TestCalendarImpl {
>> +
>> +    }
>>
>>  }
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscr...@axis.apache.org
> For additional commands, e-mail: java-dev-h...@axis.apache.org
>
>



-- 
Sagara Gunathunga

Blog      - http://ssagara.blogspot.com
Web      - http://people.apache.org/~sagara/
LinkedIn - http://www.linkedin.com/in/ssagara

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscr...@axis.apache.org
For additional commands, e-mail: java-dev-h...@axis.apache.org

Reply via email to