You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by th...@kodak.com on 2006/11/28 12:10:37 UTC
Re: svn commit: r479562 - /xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGGraphicsElement.java
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();
}
dvholten@apache.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-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org
Re: svn commit: r479562 - /xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGGraphicsElement.java
Posted by th...@kodak.com.
Hi Dieter,
"Dieter von Holten" <in...@dvholten.de> wrote on 11/28/2006 07:02:52 AM:
> no, the map-thing is correct. The map shall replace the lengthy if-else
if -
> statement in the getAttributeType-methods. The map only returns the same
> mappings as the if-statement.
> Anything not in the map is handled by the last statement in the method:
> super.getAttributeType().
> So the map is local only for this ( each ) class. Sub-classes would have
> their own maps.
Right, I wasn't implying that your code would produce errors.
I was simply pointing out that simply extending the single static
map for each subclass would lead to the need to do at least three
in some cases more lookups into a hash table, which is a bit of
a waste if it can be done with just one lookup.
> All these lookup maps are read-only and fixed after creation.
I was also wondering if we wouldn't want a "simple" extension
mechanism.
> However, cameron send me a message, that he is going to do a major
rework in
> that package,
> so any further work on the map-thing (to add these to the other classes)
> might be obsolete soon.
Ok, so the point may be moot.
> ----- Original Message -----
> From: <th...@kodak.com>
> To: <ba...@xmlgraphics.apache.org>
> Cc: <ba...@xmlgraphics.apache.org>
> Sent: Tuesday, November 28, 2006 12:10 PM
> Subject: Re: svn commit: r479562 -
>
/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGGraphicsElement
> .java
>
>
> > 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();
> > }
> >
> > dvholten@apache.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-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org
Re: svn commit: r479562 - /xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGGraphicsElement.java
Posted by Dieter von Holten <in...@dvholten.de>.
Hi thomas,
no, the map-thing is correct. The map shall replace the lengthy if-else if -
statement in the getAttributeType-methods. The map only returns the same
mappings as the if-statement.
Anything not in the map is handled by the last statement in the method:
super.getAttributeType().
So the map is local only for this ( each ) class. Sub-classes would have
their own maps.
All these lookup maps are read-only and fixed after creation.
However, cameron send me a message, that he is going to do a major rework in
that package,
so any further work on the map-thing (to add these to the other classes)
might be obsolete soon.
greetings
dieter
----- Original Message -----
From: <th...@kodak.com>
To: <ba...@xmlgraphics.apache.org>
Cc: <ba...@xmlgraphics.apache.org>
Sent: Tuesday, November 28, 2006 12:10 PM
Subject: Re: svn commit: r479562 -
/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGGraphicsElement
.java
> 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();
> }
>
> dvholten@apache.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-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org