Wrong createFromXML() for Projects?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Wrong createFromXML() for Projects?

Flavio Pompermaier-2
Hi to all,
in my project I extended the Project class in order to have a custom
one (in gvSIG 1.10).

Hovever, when I try to load an existing project, the method
createFromXML() always instantiate a new Project class,
regardless the className property listed in the root tag of the .gvp
file  (<xml-tag>) .

I think it would be much better if the method createFromXML() was like:

public static Project createFromXML(XMLEntity xml) throws OpenException {

                int childNumber = 0;
                String className = xml.getStringProperty("className ");
                Project p = null;
                if (projectClassName != null && !"".equals(projectClassName)) {
                        try {
                                p = (Project) Class.forName(projectClassName).newInstance();
                        }
                        catch (InstantiationException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        catch (IllegalAccessException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        catch (ClassNotFoundException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                }
                if(p==null){
                        // use default if classname not set or problems during class newInstance()
                        p = new Project();
                }
                try {
                        p.comments = xml.getStringProperty("comments");
                 etc...

In this way, my custom instance of project would be instantiated...
Don't you think..?
_______________________________________________
gvSIG-desktop-devel mailing list
[hidden email]
https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: Wrong createFromXML() for Projects?

Jorge Piera Llodrá
Hello Flavio.

Just out of curiosity: why do you need to create your own project? Yo
can extend a project adding new documents or you can extend the
documents (layouts, views or tables) but it seems that it is not enough
for you.

Regards,
Jorge

On 06/21/2011 04:53 PM, Flavio Pompermaier wrote:

> Hi to all,
> in my project I extended the Project class in order to have a custom
> one (in gvSIG 1.10).
>
> Hovever, when I try to load an existing project, the method
> createFromXML() always instantiate a new Project class,
> regardless the className property listed in the root tag of the .gvp
> file  (<xml-tag>) .
>
> I think it would be much better if the method createFromXML() was like:
>
> public static Project createFromXML(XMLEntity xml) throws OpenException {
>
> int childNumber = 0;
>                  String className = xml.getStringProperty("className ");
> Project p = null;
> if (projectClassName != null&&  !"".equals(projectClassName)) {
> try {
> p = (Project) Class.forName(projectClassName).newInstance();
> }
> catch (InstantiationException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> catch (IllegalAccessException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> catch (ClassNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> if(p==null){
> // use default if classname not set or problems during class newInstance()
> p = new Project();
> }
> try {
> p.comments = xml.getStringProperty("comments");
>                   etc...
>
> In this way, my custom instance of project would be instantiated...
> Don't you think..?
> _______________________________________________
> gvSIG-desktop-devel mailing list
> [hidden email]
> https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
>    


--
Jorge Piera Llodrá
gvSIG Development Team
PRODEVELOP
Plaza Don Juan de Villarrasa, 14 - 5
46001 Valencia
Tel: +34 963510612
Fax: +34 963510908
e-mail: [hidden email]
http://www.prodevelop.es
http://www.gvsig.org

_______________________________________________
gvSIG-desktop-devel mailing list
[hidden email]
https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: Wrong createFromXML() for Projects?

Jorge Piera Llodrá
In reply to this post by Flavio Pompermaier-2
Hello Flavio.

By the other hand, I think that the best solution for the problem is
just don't use an static method to load the project. Would be better
just removing the "static" and put the code that you propose (creating
the instance from the XML node named className) in the class that calls
to this method.

This is the standard way to create a new object using the gvSIG
persistence engine and the project could follow this mechanism.

I think also that it would be a great idea if you create a ticket with a
patch for all your proposals. Be could discuss in the ticket your bugs
or patches and would be easier to apply if the patches work fine [1].

Regards,
Jorge

[1]
http://www.gvsig.org/web/projects/gvsig-desktop/docs/devel/como-contribuir-en-gvsig/contribuciones-y-parches-al-codigo-de-gvsig/contributions-and-patches-to-the-gvsig-code/view?set_language=en

On 06/21/2011 04:53 PM, Flavio Pompermaier wrote:

> Hi to all,
> in my project I extended the Project class in order to have a custom
> one (in gvSIG 1.10).
>
> Hovever, when I try to load an existing project, the method
> createFromXML() always instantiate a new Project class,
> regardless the className property listed in the root tag of the .gvp
> file  (<xml-tag>) .
>
> I think it would be much better if the method createFromXML() was like:
>
> public static Project createFromXML(XMLEntity xml) throws OpenException {
>
> int childNumber = 0;
>                  String className = xml.getStringProperty("className ");
> Project p = null;
> if (projectClassName != null&&  !"".equals(projectClassName)) {
> try {
> p = (Project) Class.forName(projectClassName).newInstance();
> }
> catch (InstantiationException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> catch (IllegalAccessException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> catch (ClassNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> if(p==null){
> // use default if classname not set or problems during class newInstance()
> p = new Project();
> }
> try {
> p.comments = xml.getStringProperty("comments");
>                   etc...
>
> In this way, my custom instance of project would be instantiated...
> Don't you think..?
> _______________________________________________
> gvSIG-desktop-devel mailing list
> [hidden email]
> https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
>    


--
Jorge Piera Llodrá
gvSIG Development Team
PRODEVELOP
Plaza Don Juan de Villarrasa, 14 - 5
46001 Valencia
Tel: +34 963510612
Fax: +34 963510908
e-mail: [hidden email]
http://www.prodevelop.es
http://www.gvsig.org

_______________________________________________
gvSIG-desktop-devel mailing list
[hidden email]
https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: Wrong createFromXML() for Projects?

Flavio Pompermaier-2
In reply to this post by Jorge Piera Llodrá
I'd like to put some other project properties inside the gvp instead
of putting them in another file.
For example, my project could be in 4 states (NEW, VALIDATED, SENT,
CLOSED) and if I could add a custom property to the project I could
avoid the external file..

2011/6/21 Jorge Piera Llodrá <[hidden email]>:

> Hello Flavio.
>
> Just out of curiosity: why do you need to create your own project? Yo
> can extend a project adding new documents or you can extend the
> documents (layouts, views or tables) but it seems that it is not enough
> for you.
>
> Regards,
> Jorge
>
> On 06/21/2011 04:53 PM, Flavio Pompermaier wrote:
>> Hi to all,
>> in my project I extended the Project class in order to have a custom
>> one (in gvSIG 1.10).
>>
>> Hovever, when I try to load an existing project, the method
>> createFromXML() always instantiate a new Project class,
>> regardless the className property listed in the root tag of the .gvp
>> file  (<xml-tag>) .
>>
>> I think it would be much better if the method createFromXML() was like:
>>
>> public static Project createFromXML(XMLEntity xml) throws OpenException {
>>
>>               int childNumber = 0;
>>                  String className = xml.getStringProperty("className ");
>>               Project p = null;
>>               if (projectClassName != null&&  !"".equals(projectClassName)) {
>>                       try {
>>                               p = (Project) Class.forName(projectClassName).newInstance();
>>                       }
>>                       catch (InstantiationException e) {
>>                               // TODO Auto-generated catch block
>>                               e.printStackTrace();
>>                       }
>>                       catch (IllegalAccessException e) {
>>                               // TODO Auto-generated catch block
>>                               e.printStackTrace();
>>                       }
>>                       catch (ClassNotFoundException e) {
>>                               // TODO Auto-generated catch block
>>                               e.printStackTrace();
>>                       }
>>               }
>>               if(p==null){
>>                       // use default if classname not set or problems during class newInstance()
>>                       p = new Project();
>>               }
>>               try {
>>                       p.comments = xml.getStringProperty("comments");
>>                   etc...
>>
>> In this way, my custom instance of project would be instantiated...
>> Don't you think..?
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> [hidden email]
>> https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
>>
>
>
> --
> Jorge Piera Llodrá
> gvSIG Development Team
> PRODEVELOP
> Plaza Don Juan de Villarrasa, 14 - 5
> 46001 Valencia
> Tel: +34 963510612
> Fax: +34 963510908
> e-mail: [hidden email]
> http://www.prodevelop.es
> http://www.gvsig.org
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> [hidden email]
> https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
>
_______________________________________________
gvSIG-desktop-devel mailing list
[hidden email]
https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel