Hi Paolo,
P.Rizzi Ag.Mobilità Ambiente wrote:
I read the IRC of yesterday and I'd like to add a few opinion about
containers and factories.
They are, obviously, plain IMHOs.
Bye
Paolo Rizzi
1) Constructors should _only_ take immutable parameters. That is values that
cannot change
after the object has been constructed, hence there should be no setter for
them.
If a value has an associated setter, it means it _can_ change during the
life of the object,
so the object has to be prepared for it to change and also for it to become
null or invalid.
So if an object has some parameters it _needs_ to function but those params
have a setter,
than they shouldn't go in the constructor, but the object has to be prepared
to be in a state
of "not ready", or something like that, until all needed params are set.
2) IoC containers like Spring have _no_ problems working with factories.
They're able to construct
objects in whatever style: constructor injection, property injection, static
factories, etc.
So I really see no need to modify anything to prepare GeoTools objects to be
instantiated from
a container. You can even call DataStoreFinder.getDataStore(Map) from a IoC.
For example in Spring you can do something like this:
<bean id="mainDataStore"
class="org.geotools.data.DataStoreFinder"
factory-method="getDataStore">
<constructor-arg>
<map>
<entry
key="dbtype"><value>postgis</value></entry>
<entry
key="host"><value>localhost</value></entry>
<entry key="port">
<bean class="java.lang.Integer">
<constructor-arg>
<value>5432</value>
</constructor-arg>
</bean>
</entry>
<entry
key="database"><value>test</value></entry>
<entry
key="user"><value>uuuuuuu</value></entry>
<entry
key="passwd"><value>ppppppp</value></entry>
</map>
</constructor-arg>
</bean>
And more or less the same you can do with JBoss Microcontainer:
<bean name="mainDataStore" class="java.lang.Object">
<constructor
factoryClass="org.geotools.data.DataStoreFinder"
factoryMethod="getDataStore">
<parameter class="java.util.Map">
<value class="java.util.Properties">
dbtype=postgis
host=localhost
port=5432
database=test
user=uuuuuuu
passwd=ppppppp
</value>
</parameter>
</constructor>
</bean>
Having objects injectible is only half the battle. And as you say with
most containers you can provide enough metadata to be able to so do.
However, the problem is that many of the factories dont allow
dependencies to be set via a setter or a constructor. The dependency is
in essence hardcoded inside the class. Or the dependency is pulled out
of a hashmap based on some key. It may be tricky to get spring to inject
a dependency in this manner, although probably possible.
Also, not all containers support the addition of xml to describe the
objects living in the container. PicoContainer for instance doesn't
really have this and is one of the more popular containers (its close
relative nanocontainer does but that is besides the point).
I think what we are shooting for is to allow clients to use any
container they wish, and because the geotools factories are "good
citizens", everything should gel.
Justin
AVVERTENZE AI SENSI DEL D. LGS. 196/2003
Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i
file/s allegato/i, sono da considerarsi strettamente riservate. Il loro
utilizzo è consentito esclusivamente al destinatario del messaggio, per le
finalità indicate nel messaggio stesso. Qualora riceveste questo messaggio
senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia
via e-mail e di procedere alla distruzione del messaggio stesso,
cancellandolo dal Vostro sistema; costituisce comportamento contrario ai
principi dettati dal D. Lgs. 196/2003 il trattenere il messaggio stesso,
divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
utilizzarlo per finalità diverse.
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_idv28&alloc_id845&op=click
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel
--
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel