List Info

Thread: svn commit: r479562 - /xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGGraphicsElement.j




svn commit: r479562 - /xmlgraphics/batik/trunk/sources/org/apa che/batik/dom/svg/SVGGraphicsElement.j
user name
2006-11-28 11:10:37
Hi Dieter

    I'm a little nervous about the map being static.  The
direction seems 
right
but it seems that most subclasses of SVGGraphicsElement
override this 
method 
with additional attribute types. 

    I would suggest that we either have a method that
returns the 
attribute Type 
map, then we do  something like (note pseudo code, we also
need to deal 
with namespaces here):

        // Start with parents type mapping...
        protected static final classTypeMap = new 
HashMap(super.classTypeMap);

        // Every class provides a version of this...
        protected Map getTypeMap() { return classTypeMap; }

        static {
             Map  map = classTypeMap;
             SVGOMAttributeInfo svgType;
             svgType = new
SVOMAttributeInfo(SVGTypes.TYPE_LENGTH, true);
             map.put( SVG_X_ATTRIBUTE, svgType);
             map.put( SVG_Y_ATTRIBUTE, svgType);
             map.put( SVG_RX_ATTRIBUTE, svgType);
             /* etc */
        }


    public int getAttributeType(String ns, String ln) {
        if (ns != null) 
           return SVGTypes.TYPE_UNKNOWN;
          SVGOMAttributeInfo typeCode = 
(SVGOMAttributeInfo)getTypeMap().get( ln );

        if ( typeCode == null )
           return SVGTypes.TYPE_UNKNOWN;
        return typeCode.getSVGType();
      }

dvholtenapache.org wrote on 11/27/2006 04:49:01 AM:

> +    /**
> +     * this map supports a fast lookup from
svg-attribute-name string 
to
> +     * svgType-integer. It is faster than doing
string-equals in a
> +     * lengthy if-else-statement.
> +     * This map is used only by {link
#getAttributeType }
> +     */
> +    private static final Map typeMap = new HashMap();
> +
> +    static {
> +        Map map = typeMap;
> +
> +        SVGOMAttributeInfo svgType = new
SVGOMAttributeInfo( SVGTypes.
> TYPE_TRANSFORM_LIST, true );
> +        map.put(  SVG_TRANSFORM_ATTRIBUTE, svgType );
> +
> +        svgType = new SVGOMAttributeInfo(
SVGTypes.TYPE_IDENT, true );
> +        map.put( 
SVG_EXTERNAL_RESOURCES_REQUIRED_ATTRIBUTE, svgType );
> +
> +        svgType = new SVGOMAttributeInfo(
SVGTypes.TYPE_URI_LIST, false 
);
> +        map.put(  SVG_REQUIRED_EXTENSIONS_ATTRIBUTE,
svgType );
> +        map.put(  SVG_REQUIRED_FEATURES_ATTRIBUTE,
svgType );
> +
> +        svgType = new SVGOMAttributeInfo(
SVGTypes.TYPE_LANG_LIST, 
false );
> +        map.put(  SVG_SYSTEM_LANGUAGE_ATTRIBUTE,
svgType );
> +
> +    }
> +
> +
> +
>      /**
>       * Supplemental transformation due to motion
animation.
>       */
>  -227,8 +261,9 
> 
>      /**
>       * Returns the type of the given attribute.
> +     * to be removed
>       */
> -    public int getAttributeType(String ns, String ln)
{
> +    public int OLDgetAttributeType(String ns, String
ln) {
>          if (ns == null) {
>              if (ln.equals(SVG_TRANSFORM_ATTRIBUTE)) {
>                  return SVGTypes.TYPE_TRANSFORM_LIST;
>  -239,6 +274,21 
>                  return SVGTypes.TYPE_URI_LIST;
>              } else if
(ln.equals(SVG_SYSTEM_LANGUAGE_ATTRIBUTE)) {
>                  return SVGTypes.TYPE_LANG_LIST;
> +            }
> +        }
> +        return super.getAttributeType(ns, ln);
> +    }
> +
> +    /**
> +     * Returns the type of the given attribute.
> +     */
> +    public int getAttributeType(String ns, String ln)
{
> +
> +        if (ns == null) {
> +            SVGOMAttributeInfo typeCode = 
(SVGOMAttributeInfo)typeMap.get( ln );
> +            if ( typeCode != null ){
> +                // it is one of 'my' mappings..
> +                return typeCode.getSVGType();
>              }
>          }
>          return super.getAttributeType(ns, ln);
> 
> 


------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-dev-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-dev-helpxmlgraphics.apache.org

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )