You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Danilo Graziano (JIRA)" <xm...@xml.apache.org> on 2007/04/10 09:14:32 UTC

[jira] Created: (XMLBEANS-322) Class Loader

Class Loader
------------

                 Key: XMLBEANS-322
                 URL: https://issues.apache.org/jira/browse/XMLBEANS-322
             Project: XMLBeans
          Issue Type: Bug
          Components: Binding
    Affects Versions: Version 2.2
            Reporter: Danilo Graziano


I have two jar files that contains two 'RispostaDocument'  classes. The first one 'it.visura.assi.xmlbeans.navigazione.imprese.risposta.RispostaDocument'
is the class that i want to use. There is another class 'it.visura.assi.xmlbeans.navigazione.assettiproprietari.risposta.soci.impl.RispostaDocument' that is the class that is actually used. 

When the findDocumentTypeRef(QName ) is called the class founded in the 'documentCache' is a ''it.visura.assi.xmlbeans.navigazione.assettiproprietari.risposta.soci.impl.RispostaDocument' ' while i had instantiate the first one

'it.visura.assi.xmlbeans.navigazione.imprese.risposta-RispostaDocument rispostaDocument = 'it.visura.assi.xmlbeans.navigazione.imprese.risposta.RispostaDocument.Factory.parse(messaggio2)";


 public SchemaType.Ref findDocumentTypeRef(QName name)
    {
        Object cached = _documentCache.get(name);
        if (cached == CACHED_NOT_FOUND)
            return null;
        SchemaType.Ref result = (SchemaType.Ref) cached;
        if (result == null)
        {
            for (int i = 0; i < _searchPath.length; i++)
                if (null != (result = _searchPath[i].findDocumentTypeRef(name)))
                    break;
            if (result == null)
            {
                SchemaTypeSystem ts = typeSystemForComponent("schema" + METADATA_PACKAGE_LOAD + "/element/", name);
                if (ts != null)
                {
                    result = ts.findDocumentTypeRef(name);
                    assert(result != null) : "Type system registered element " + QNameHelper.pretty(name) + " but does not contain document type";
                }
            }
            _documentCache.put(name, result == null ? CACHED_NOT_FOUND : result);
        }
        return result;
    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Commented: (XMLBEANS-322) Class Loader

Posted by "Radu Preotiuc-Pietro (JIRA)" <xm...@xml.apache.org>.
    [ https://issues.apache.org/jira/browse/XMLBEANS-322?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12492135 ] 

Radu Preotiuc-Pietro commented on XMLBEANS-322:
-----------------------------------------------

So you have two classes corresponding to the same element/type QName at the same time on your classpath. I am afraid that by default, the SchemaTypeLoader used by all the Factory.parse() methods is the context SchemaTypeLoader and the QName that is going to be used is the first QName found on the classpath and the class associated to it.

This is "by design". Now, the main problem with this design is that you run into situations like in your case where the type that's found is not the one you want. The advantage of the design is that when you use "xsi:type" and have nothing but the QName of the type to go by, the result is consistent with the rule that components that are found first on the classpath take precedence. I don't want to go too much into details, it's just that this behavior is not unexpected if I understand correctly your use case and there are reasons for it working like that (whether these reasons are good enough is debatable).

How about if instead of doing 

    it.visura.assi.xmlbeans.navigazione.imprese.risposta.RispostaDocument.Factory.parse(messaggio2)

you do

   it.visura.assi.xmlbeans.navigazione.imprese.risposta.RispostaDocument.type.getSchemaTypeSystem().parse(mesaggio2)

This will force it to use only the types in the same "TypeSystem" with the one that you want and I think will get you the result you want.


> Class Loader
> ------------
>
>                 Key: XMLBEANS-322
>                 URL: https://issues.apache.org/jira/browse/XMLBEANS-322
>             Project: XMLBeans
>          Issue Type: Bug
>          Components: Binding
>    Affects Versions: Version 2.2
>            Reporter: Danilo Graziano
>
> I have two jar files that contains two 'RispostaDocument'  classes. The first one 'it.visura.assi.xmlbeans.navigazione.imprese.risposta.RispostaDocument'
> is the class that i want to use. There is another class 'it.visura.assi.xmlbeans.navigazione.assettiproprietari.risposta.soci.impl.RispostaDocument' that is the class that is actually used. 
> When the findDocumentTypeRef(QName ) is called the class founded in the 'documentCache' is a ''it.visura.assi.xmlbeans.navigazione.assettiproprietari.risposta.soci.impl.RispostaDocument' ' while i had instantiate the first one
> 'it.visura.assi.xmlbeans.navigazione.imprese.risposta-RispostaDocument rispostaDocument = 'it.visura.assi.xmlbeans.navigazione.imprese.risposta.RispostaDocument.Factory.parse(messaggio2)";
>  public SchemaType.Ref findDocumentTypeRef(QName name)
>     {
>         Object cached = _documentCache.get(name);
>         if (cached == CACHED_NOT_FOUND)
>             return null;
>         SchemaType.Ref result = (SchemaType.Ref) cached;
>         if (result == null)
>         {
>             for (int i = 0; i < _searchPath.length; i++)
>                 if (null != (result = _searchPath[i].findDocumentTypeRef(name)))
>                     break;
>             if (result == null)
>             {
>                 SchemaTypeSystem ts = typeSystemForComponent("schema" + METADATA_PACKAGE_LOAD + "/element/", name);
>                 if (ts != null)
>                 {
>                     result = ts.findDocumentTypeRef(name);
>                     assert(result != null) : "Type system registered element " + QNameHelper.pretty(name) + " but does not contain document type";
>                 }
>             }
>             _documentCache.put(name, result == null ? CACHED_NOT_FOUND : result);
>         }
>         return result;
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org