bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug xml/28816] New: Behavioral Difference in Java and Classpath executi


From: kulkarni dot avadhoot at gmail dot com
Subject: [Bug xml/28816] New: Behavioral Difference in Java and Classpath executions while using System property while creating SchemaFactory Instances.
Date: 23 Aug 2006 06:59:16 -0000

In Sun Java, You can set a System property to suggest the SchemaFactory class
to instantiate a perticular factory class in its NewInstance() Method.

e.g. 
System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema";,
                                     "MySchemaFactoryImpl");
SchemaFactory sf =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema";);


This code when runs under java creates instance of MySchemaFactoryImpl but when
it runs under GNU classpath library it creates instance of
"gnu.xml.validation.xmlschema.XMLSchemaSchemaFactory". It happens due to hard
coding inside the new Instance Method of "javax.xml.validation.SchemaFactory"
class.

<current implementation>
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schemaLanguage)) {
        return new gnu.xml.validation.xmlschema.XMLSchemaSchemaFactory();
 }
if (XMLConstants.RELAXNG_NS_URI.equals(schemaLanguage)) {
        return new gnu.xml.validation.relaxng.RELAXNGSchemaFactory();
 }
</current implementation>
We can change the implemantation of newInstance() Method to fix this behavioral
difference as follows. 

<suggested Implementation>
public static final SchemaFactory newInstance(String schemaLanguage)
  {
              //START
             //check which schema language is specified
       if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schemaLanguage)) {
                  //for schema language = http://www.w3.org/2001/XMLSchema
String className =
System.getProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema";);
                      // is the property set in environment variables???
                      if (className != null && className != "") {
                          try {
                 java.lang.ClassLoader cl = ClassLoader.getSystemClassLoader();
                           Class cls = cl.loadClass(className);
                           //load the class and create instance as
schemaFactory
                           SchemaFactory sf = (SchemaFactory)
cls.newInstance();
if (sf.isSchemaLanguageSupported(XMLConstants.W3C_XML_SCHEMA_NS_URI) == false){
                                /*check if the instantiated schemafactory
supports the provided schema language..*/
                                throw new IllegalArgumentException("Schema
Language Not Supported in SchemaFactory Class :"+ className);
                            }
                            return sf;
                          } catch (Exception e) {
                          // classDefinationNotFound, IllegalCastException etc.
                          throw new IllegalArgumentException(e);
                          }
                      } else {
                      //Default behaviour
              return new gnu.xml.validation.xmlschema.XMLSchemaSchemaFactory();
              }
         }
      if (XMLConstants.RELAXNG_NS_URI.equals(schemaLanguage)) {
     //for schema language =http://relaxng.org/ns/structure/1.0
          String className =
System.getProperty("javax.xml.validation.SchemaFactory:http://relaxng.org/ns/structure/1.0";);
      // does the property is set in environment variables???
     if (className != "" && className != null) {
       try {
        java.lang.ClassLoader cl = ClassLoader.getSystemClassLoader();
       Class cls = cl.loadClass(className);
      /*load the class and create instance as schemaFactory*/
       SchemaFactory sf = (SchemaFactory) cls.newInstance();
if (sf.isSchemaLanguageSupported(XMLConstants.RELAXNG_NS_URI) == false) {
/*check if the instantiated schemafactory supports the provided schema
language..*/
           throw new IllegalArgumentException("Schema Language Not Supported in
SchemaFactory Class :" + className);
                              }
                              return sf;
                          } catch (Exception e) {
                          throw new IllegalArgumentException(e);
                       }
                  } else {
                   // classDefinationNotFound, IlligleCastException etc.
                  return new gnu.xml.validation.relaxng.RELAXNGSchemaFactory();
                  }
             }else{
                  //Default behaviour
                throw new IllegalArgumentException(schemaLanguage);
         }
         //END
}
</suggested Implementation>

I have already done this change locally on my end adn partially tested it.

This bug can also seen into other factory implementations because harcoding in
newInstance() method of factories.
e.g. javax.xml.parsers.SAXParserFactory


-- 
           Summary: Behavioral Difference in Java and Classpath executions
                    while using System property while creating SchemaFactory
                    Instances.
           Product: classpath
           Version: 0.92
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: xml
        AssignedTo: dog at gnu dot org
        ReportedBy: kulkarni dot avadhoot at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28816





reply via email to

[Prev in Thread] Current Thread [Next in Thread]