Anaxa Gore ha scritto:
> Hi!
> 
> I am currently writing a wrapper; to "convert" java beans to features, 
> throw the SimpleFeature interface...
> But there are choices to do, and i would be happy to have your suggestions !

Sorry for the late response...

> The idea is this :
> 
> In an application, we have a model (MVC pattern for instance), described 
> by some classes observing the bean norme.
> We manage this model trow the wrapper, which allow us to consider this 
> model as features for the geotools.
> 
> The SimpleFeatureWrapper is built like this :
> 
> public class SimpleFeatureWrapper implements SimpleFeature{
>     /** The bean to wrap. */
>     Object bean = null;
>     /** The list of bean properties. */
>     Map<String,Object> props = null;
>    
>     public SimpleFeatureWrapper(Object bean) throws
>                                              IllegalAccessException,
>                                              InvocationTargetException,
>                                              NoSuchMethodException{
>         this.bean = bean;
>         props = PropertyUtils.describe(this.bean);
>        
>         /* Here, we remove the property "class", given for all
>          * beans, describing the class of bean. (not needed as an 
> attribute ?)
>          */
>         for(Iterator<String> it = props.keySet().iterator(); it.hasNext();){
>             String key = it.next();
>             if(key.compareTo("class") == 0)
>                 it.remove();
>         }
>     }
> }
> 
> Problems appear when implementing functions of SimpleFeature, and 
> especially methods of Property, Attribute, ComplexAttribute and Feature.
> 
> My questions are :
> 
>     * What is exactly the interface Name (getAttribute(Name name),
>       setAttribute(Name name)...). Is there an implementation of this ?
>       How can i do a link between the "Name", and the String describing
>       my property in the Map ?

SimpleFeature is basically a generic Feature plus all the methods the 
old gt2 feature provided. You can safely assume nothing in the current 
api is using getAttribute(Name). Anyways, Name is a qualified name, that 
is, a straight name + namespace, which is used in complex features 
because it's unfortunately very possible that a feature has attributes
coming from different namespaces (in fact, even a simple feature has,
there are a few like "name" that should come from the gml namespace).

>     * What can I return in the getDefaultGeometry() ? A very simple idea
>       is to scan the Map, trying to find an object instance of Geometry,
>       and return the first found... any other idea ?

That's what the current simple feature do. Return the first geometry
in the schema.

>     * What can I return in the getFeatureType() ? An idea is to create
>       dynamically a SimpleFeatureType from the bean, after getting its
>       properties. Is it really a good idea ? I am not sure. Another way
>       could be forcing the user to create a SimpleFeatureType for its
>       bean, and pass it throw the construcor. Any other idea ?

FeatureType is static information, so I'd suggest you create a class
that has the ability to turn a Class into a FeatureType and that caches 
the result. And then you can use the feature type to drive your
simple feature implementation as well (since the Class -> featureType
converter will already had to

>     * Is there a way to create a BoundingBox ? I could not find any
>       information about how to do it ?

The current simple feature implementation scans over the geometry 
attributes and grabs their aggregated bbox. It basically uses JTS.
You can then wrap it into a ReferencedEnvelope.

>     * setAttributes(List or Object[]). It s too bad this methods can't
>       throw any exception... We could test each elements of list or tab,
>       compare their type with properties type in the Map and throw an
>       exception is the instanceof is false ! Actually, I can't see how
>       to do this without exception...

You're free to thorw an unckecked exception like RuntimeException or
InvalidAttributeException or something like that.

Cheers
Andrea

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to