Re: [Digester] addFactoryCreate problem (I think)

2007-07-17 Thread simon
Hi Robert,

Sorry you didn't get any feedback from the list. When I saw it involved
hashmaps of hashmaps I decided I'd punt and let someone else figure it
out. I guess everyone else did too :-). 

Actually, having re-read your email several times now I'm still not
clear what datastructure you really want to end up with. Just as a
suggestion, if you created real classes (eg TypeRegistry, FieldType,
AnalyserType) rather than using hashmaps for everything then this might
be easier to understand. However as you've got something working now
there's probably no point in revisiting it.

However I did see this in your code:
  analyzer type=index class=index_analyzer; /
which I assume means that you allow many different analyser classes to
be configured (plugged in) here, maybe even ones written by third
parties or which don't exist yet. If analyzer classes need no
configuration of any sort, then this is fine. However if you find at
some point that different analyser classes do need data that would most
naturally be put inline in the input xml file then you might like to
look at the plugins feature of Digester.


By the way, there are extensive examples on using and extending
Digester. These examples are included in the source download bundle,
and can also be browsed directly in the svn repository:
http://svn.apache.org/repos/asf/jakarta/commons/proper/digester/trunk/src/examples/


Regards,

Simon


On Fri, 2007-06-29 at 11:30 -0400, Robert Watkins wrote:
 In the final analysis, I suspect the problem had to do with the order
 and way in which Digester is pushing and popping to/from the stack,
 and not with ObjectCreationFactory.
 
 The solution I eventually came up with (my this is a quiet list!) was a
 refactoring of my approach, using a single Rule at the /schema/types
 element and at each of its possible child elements in order to gather
 the appropriate data. Here's the code, in case anyone out there is
 listening (or for the sake of anyone who ends up with a similar problem
 and finds this in the mailing list archive):
 
   FieldTypeAnalyzerMappingRule ftamRule = \
   new FieldTypeAnalyzerMappingRule();
   digester.addObjectCreate( prefix + /types, HashMap.class );
   digester.addRule(prefix + /types, ftamRule);
   digester.addRule(prefix + /types/fieldtype, ftamRule);
   digester.addRule(prefix + /types/fieldtype/analyzer, ftamRule);
   digester.addSetNext( prefix + /types, setFieldTypeAnalyzerMap );
 
 public class FieldTypeAnalyzerMappingRule extends Rule
 {
   protected static HashMapString, HashMapString, String \
   fieldTypeAnalyzerMap;
   protected static String fieldType;
   protected static HashMapString, String analyzerClassMap;
 
   public FieldTypeAnalyzerMappingRule()
   {
   // empty
   }
 
   @Override
   @SuppressWarnings(unchecked)
   public void begin(String namespace, String name, Attributes attrs)
   {
   if (name.equals(types)) {
   fieldTypeAnalyzerMap = \
   (HashMapString, HashMapString, 
 String)digester.pop();
   }
   else if (name.equals(fieldtype)) {
   fieldType = attrs.getValue(name);
   analyzerClassMap = new HashMapString, String();
   }
   else if (name.equals(analyzer)) {
   if (attrs != null) {
   String type = null, className = null;
   type = attrs.getValue(type);
   className = attrs.getValue(class);
   if (type == null) {
   analyzerClassMap.put(index, 
 className);
   analyzerClassMap.put(query, 
 className);
   }
   else {
   analyzerClassMap.put(type, className);
   }
   }
   }
   // push the fieldTypeAnalyzerMap back onto the stack:
   // this is the only way I can think of to make sure it's
   // available (and populated) when we leave the types
   // element (see the end() method for more detail)
   digester.push(fieldTypeAnalyzerMap);
   }
 
   @Override
   public void end(String namespace, String name)
   {
   if (name.equals(fieldtype)) {
   fieldTypeAnalyzerMap.put(fieldType, analyzerClassMap);
   }
   // remove the fieldTypeAnalyzerMap from the Digester stack
   // unless we are leaving the types element:
   // in that case we want it to remain on the stack so that it can
   // be used by ContentMeta.setFieldTypeAnalyzerMap
   // when we call digester.addSetNext
   if 

Re: [Digester] addFactoryCreate problem (I think)

2007-07-17 Thread Robert Watkins

Thanks, Simon, for taking the time to respond even though this posting
is no longer fresh.

For the sake of completeness, the data structure I want (and now have)
is indeed a HashMap of HashMaps:

  HashMapString, HashMapString, String

Having written the code myself, this of course does not seem all that
complicated to me, but then I see not just the abstract maps but the
concept underlying them. I never bothered to create a custom class
because what I need is already there in the API.

Thanks for the tip about the plugins feature of Digester. Fortunately,
Analyzer classes do not need configuration, so what I've got does all
that it needs to.

Thanks again,
-- Robert

On Tue, 17 Jul 2007, simon wrote:


Hi Robert,

Sorry you didn't get any feedback from the list. When I saw it involved
hashmaps of hashmaps I decided I'd punt and let someone else figure it
out. I guess everyone else did too :-).

Actually, having re-read your email several times now I'm still not
clear what datastructure you really want to end up with. Just as a
suggestion, if you created real classes (eg TypeRegistry, FieldType,
AnalyserType) rather than using hashmaps for everything then this might
be easier to understand. However as you've got something working now
there's probably no point in revisiting it.

However I did see this in your code:
 analyzer type=index class=index_analyzer; /
which I assume means that you allow many different analyser classes to
be configured (plugged in) here, maybe even ones written by third
parties or which don't exist yet. If analyzer classes need no
configuration of any sort, then this is fine. However if you find at
some point that different analyser classes do need data that would most
naturally be put inline in the input xml file then you might like to
look at the plugins feature of Digester.


By the way, there are extensive examples on using and extending
Digester. These examples are included in the source download bundle,
and can also be browsed directly in the svn repository:
http://svn.apache.org/repos/asf/jakarta/commons/proper/digester/trunk/src/examples/


Regards,

Simon


On Fri, 2007-06-29 at 11:30 -0400, Robert Watkins wrote:

In the final analysis, I suspect the problem had to do with the order
and way in which Digester is pushing and popping to/from the stack,
and not with ObjectCreationFactory.

The solution I eventually came up with (my this is a quiet list!) was a
refactoring of my approach, using a single Rule at the /schema/types
element and at each of its possible child elements in order to gather
the appropriate data. Here's the code, in case anyone out there is
listening (or for the sake of anyone who ends up with a similar problem
and finds this in the mailing list archive):

FieldTypeAnalyzerMappingRule ftamRule = \
new FieldTypeAnalyzerMappingRule();
digester.addObjectCreate( prefix + /types, HashMap.class );
digester.addRule(prefix + /types, ftamRule);
digester.addRule(prefix + /types/fieldtype, ftamRule);
digester.addRule(prefix + /types/fieldtype/analyzer, ftamRule);
digester.addSetNext( prefix + /types, setFieldTypeAnalyzerMap );

public class FieldTypeAnalyzerMappingRule extends Rule
{
protected static HashMapString, HashMapString, String \
fieldTypeAnalyzerMap;
protected static String fieldType;
protected static HashMapString, String analyzerClassMap;

public FieldTypeAnalyzerMappingRule()
{
// empty
}

@Override
@SuppressWarnings(unchecked)
public void begin(String namespace, String name, Attributes attrs)
{
if (name.equals(types)) {
fieldTypeAnalyzerMap = \
(HashMapString, HashMapString, 
String)digester.pop();
}
else if (name.equals(fieldtype)) {
fieldType = attrs.getValue(name);
analyzerClassMap = new HashMapString, String();
}
else if (name.equals(analyzer)) {
if (attrs != null) {
String type = null, className = null;
type = attrs.getValue(type);
className = attrs.getValue(class);
if (type == null) {
analyzerClassMap.put(index, 
className);
analyzerClassMap.put(query, 
className);
}
else {
analyzerClassMap.put(type, className);
}
}
}
// push the fieldTypeAnalyzerMap back onto the stack:
// this is the only way I can think of to make sure it's
// available (and 

Re: [Digester] addFactoryCreate problem (I think)

2007-06-29 Thread Robert Watkins

In the final analysis, I suspect the problem had to do with the order
and way in which Digester is pushing and popping to/from the stack,
and not with ObjectCreationFactory.

The solution I eventually came up with (my this is a quiet list!) was a
refactoring of my approach, using a single Rule at the /schema/types
element and at each of its possible child elements in order to gather
the appropriate data. Here's the code, in case anyone out there is
listening (or for the sake of anyone who ends up with a similar problem
and finds this in the mailing list archive):

FieldTypeAnalyzerMappingRule ftamRule = \
new FieldTypeAnalyzerMappingRule();
digester.addObjectCreate( prefix + /types, HashMap.class );
digester.addRule(prefix + /types, ftamRule);
digester.addRule(prefix + /types/fieldtype, ftamRule);
digester.addRule(prefix + /types/fieldtype/analyzer, ftamRule);
digester.addSetNext( prefix + /types, setFieldTypeAnalyzerMap );

public class FieldTypeAnalyzerMappingRule extends Rule
{
protected static HashMapString, HashMapString, String \
fieldTypeAnalyzerMap;
protected static String fieldType;
protected static HashMapString, String analyzerClassMap;

public FieldTypeAnalyzerMappingRule()
{
// empty
}

@Override
@SuppressWarnings(unchecked)
public void begin(String namespace, String name, Attributes attrs)
{
if (name.equals(types)) {
fieldTypeAnalyzerMap = \
(HashMapString, HashMapString, 
String)digester.pop();
}
else if (name.equals(fieldtype)) {
fieldType = attrs.getValue(name);
analyzerClassMap = new HashMapString, String();
}
else if (name.equals(analyzer)) {
if (attrs != null) {
String type = null, className = null;
type = attrs.getValue(type);
className = attrs.getValue(class);
if (type == null) {
analyzerClassMap.put(index, 
className);
analyzerClassMap.put(query, 
className);
}
else {
analyzerClassMap.put(type, className);
}
}
}
// push the fieldTypeAnalyzerMap back onto the stack:
// this is the only way I can think of to make sure it's
// available (and populated) when we leave the types
// element (see the end() method for more detail)
digester.push(fieldTypeAnalyzerMap);
}

@Override
public void end(String namespace, String name)
{
if (name.equals(fieldtype)) {
fieldTypeAnalyzerMap.put(fieldType, analyzerClassMap);
}
// remove the fieldTypeAnalyzerMap from the Digester stack
// unless we are leaving the types element:
// in that case we want it to remain on the stack so that it can
// be used by ContentMeta.setFieldTypeAnalyzerMap
// when we call digester.addSetNext
if (!name.equals(types)) {
digester.pop();
}
}

Ciao!
-- RW

On Tue, 26 Jun 2007, Robert Watkins wrote:


This one's been dogging me for hours, and as I've been unable to find an
answer on the web, it's to the community I go!

A relevant XML fragment is as follows:

types
fieldtype name=analyzedField class=solr.TextField
analyzer type=index class=index_analyzer; /
analyzer type=query class=query_analyzer; /
/fieldtype
fieldtype name=verbatimField class=solr.StrField
/types

In my code I've got:

digester.addObjectCreate(/schema/types, HashMap.class);
digester.addCallMethod(/schema/types/fieldtype, put, 2);
digester.addCallParam(/schema/types/fieldtype, 0, name);
digester.addCallParam(/schema/types/fieldtype, 1, class);
digester.addSetNext(/schema/types, setFieldClasses);

So far, this works fine, passing the created HashMap to the
setFieldClasses() method of the top-level object.

What I want to do is also create a HashMap which has the name attribute
of the fieldtype element as its key, and as its value another HashMap,
this time with the type and class of the analyzer element as key and
value.

As the XML fragment shows, not all fieldtype elements have child
elements of the type analyzer (and another possibility is a 

Re: [Digester] addFactoryCreate problem (I think)

2007-06-28 Thread Robert Watkins

Given the lack of response, I fear it may be due to the improper subject
line, lacking the [Digester] string. I've thus added it in hopes that it
will garner a response (and at the risk of being considered pushy).
-- RW

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Digester] addFactoryCreate problem (I think)

2007-06-28 Thread Rahul Akolkar

Can you please include the original question? Not that it will
guarantee an answer, but it may be easier on anyone looking at this.

-Rahul

On 6/28/07, Robert Watkins [EMAIL PROTECTED] wrote:

Given the lack of response, I fear it may be due to the improper subject
line, lacking the [Digester] string. I've thus added it in hopes that it
will garner a response (and at the risk of being considered pushy).
-- RW



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Digester] addFactoryCreate problem (I think)

2007-06-28 Thread Robert Watkins

Sorry, thought it would remain part of the original thread. Here goes:

 original question 

This one's been dogging me for hours, and as I've been unable to find an
answer on the web, it's to the community I go!

A relevant XML fragment is as follows:

types
fieldtype name=analyzedField class=solr.TextField
analyzer type=index class=index_analyzer; /
analyzer type=query class=query_analyzer; /
/fieldtype
fieldtype name=verbatimField class=solr.StrField
/types

In my code I've got:

digester.addObjectCreate(/schema/types, HashMap.class);
digester.addCallMethod(/schema/types/fieldtype, put, 2);
digester.addCallParam(/schema/types/fieldtype, 0, name);
digester.addCallParam(/schema/types/fieldtype, 1, class);
digester.addSetNext(/schema/types, setFieldClasses);

So far, this works fine, passing the created HashMap to the
setFieldClasses() method of the top-level object.

What I want to do is also create a HashMap which has the name attribute
of the fieldtype element as its key, and as its value another HashMap,
this time with the type and class of the analyzer element as key and
value.

As the XML fragment shows, not all fieldtype elements have child
elements of the type analyzer (and another possibility is a single
analyzer child with no type attribute, just class). As such, I attempted
to use Digester.addFactoryCreate() to generate the data:

ObjectCreationFactory analyzerClassMapCreationFactory = \
new AnalyzerClassMapCreationFactory();
digester.addFactoryCreate(/schema/types/fieldtype/analyzer, \
analyzerClassMapCreationFactory);
digester.addSetNext(/schema/types/fieldtype, \
setFieldTypeAnalyzerMap);

These lines were placed just before the digester.addSetNext() line from
the previous block. As well, the code for the ObjectCreationFactory
implementation is as follows:

public class AnalyzerClassMapCreationFactory \
extends AbstractObjectCreationFactory
{
public AnalyzerClassMapCreationFactory()
{
}
public String getFieldTypeName()
{
HashMap fieldClassMap = (HashMap)digester.peek(0);
String fieldTypeName = \
(String)fieldClassMap.keySet().iterator().next();
return fieldTypeName;
}
@Override
public Object createObject(Attributes attributes)
throws Exception
{
HashMapString, String analyzerClassMap = \
new HashMapString, String();
String type = null, className = null;
if (attributes != null) {
type = attributes.getValue(type);
className = attributes.getValue(class);
if (type == null) {
analyzerClassMap.put(index, className);
analyzerClassMap.put(query, className);
}
else {
analyzerClassMap.put(type, className);
}
}
String fieldTypeName = this.getFieldTypeName();
HashMapString, HashMapString, String fieldTypeAnalyzerMap = \
new HashMapString, HashMapString, String();
fieldTypeAnalyzerMap.put(fieldTypeName, analyzerClassMap);
return fieldTypeAnalyzerMap;
}
}

I realize one of the problems may have to do with the digester.peek()
call, but even if I don't use that and use a debug String in its place,
I get the same problem.

The problem is that the previously created HashMap (from the
setFieldClasses() call) is no longer created. Indeed, it appears that
the createObject() method of my ObjectCreationFactory implementation is
never called, and certainly the setFieldTypeAnalyzerMap() method is
never
called.

Any guidance would be appreciated. Thanks,
-- Robert


Robert Watkins
[EMAIL PROTECTED]



On Thu, 28 Jun 2007, Rahul Akolkar wrote:


Can you please include the original question? Not that it will
guarantee an answer, but it may be easier on anyone looking at this.

-Rahul

On 6/28/07, Robert Watkins [EMAIL PROTECTED] wrote:

Given the lack of response, I fear it may be due to the improper subject
line, lacking the [Digester] string. I've thus added it in hopes that it
will garner a response (and at the risk of being considered pushy).
-- RW



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



addFactoryCreate problem (I think)

2007-06-26 Thread Robert Watkins

This one's been dogging me for hours, and as I've been unable to find an
answer on the web, it's to the community I go!

A relevant XML fragment is as follows:

types
fieldtype name=analyzedField class=solr.TextField
analyzer type=index class=index_analyzer; /
analyzer type=query class=query_analyzer; /
/fieldtype
fieldtype name=verbatimField class=solr.StrField
/types

In my code I've got:

digester.addObjectCreate(/schema/types, HashMap.class);
digester.addCallMethod(/schema/types/fieldtype, put, 2);
digester.addCallParam(/schema/types/fieldtype, 0, name);
digester.addCallParam(/schema/types/fieldtype, 1, class);
digester.addSetNext(/schema/types, setFieldClasses);

So far, this works fine, passing the created HashMap to the
setFieldClasses() method of the top-level object.

What I want to do is also create a HashMap which has the name attribute
of the fieldtype element as its key, and as its value another HashMap,
this time with the type and class of the analyzer element as key and
value.

As the XML fragment shows, not all fieldtype elements have child
elements of the type analyzer (and another possibility is a single
analyzer child with no type attribute, just class). As such, I attempted
to use Digester.addFactoryCreate() to generate the data:

ObjectCreationFactory analyzerClassMapCreationFactory = \
new AnalyzerClassMapCreationFactory();
digester.addFactoryCreate(/schema/types/fieldtype/analyzer, \
analyzerClassMapCreationFactory);
digester.addSetNext(/schema/types/fieldtype, \
setFieldTypeAnalyzerMap);

These lines were placed just before the digester.addSetNext() line from
the previous block. As well, the code for the ObjectCreationFactory
implementation is as follows:

public class AnalyzerClassMapCreationFactory \
extends AbstractObjectCreationFactory
{
public AnalyzerClassMapCreationFactory()
{
}
public String getFieldTypeName()
{
HashMap fieldClassMap = (HashMap)digester.peek(0);
String fieldTypeName = \

(String)fieldClassMap.keySet().iterator().next();
return fieldTypeName;
}
@Override
public Object createObject(Attributes attributes)
throws Exception
{
HashMapString, String analyzerClassMap = \
new HashMapString, String();
String type = null, className = null;
if (attributes != null) {
type = attributes.getValue(type);
className = attributes.getValue(class);
if (type == null) {
analyzerClassMap.put(index, 
className);
analyzerClassMap.put(query, 
className);
}
else {
analyzerClassMap.put(type, className);
}
}
String fieldTypeName = this.getFieldTypeName();
HashMapString, HashMapString, String 
fieldTypeAnalyzerMap = \
new HashMapString, HashMapString, String();
fieldTypeAnalyzerMap.put(fieldTypeName, 
analyzerClassMap);
return fieldTypeAnalyzerMap;
}
}

I realize one of the problems may have to do with the digester.peek()
call, but even if I don't use that and use a debug String in its place,
I get the same problem.

The problem is that the previously created HashMap (from the
setFieldClasses() call) is no longer created. Indeed, it appears that
the createObject() method of my ObjectCreationFactory implementation is
never called, and certainly the setFieldTypeAnalyzerMap() method is never
called.

Any guidance would be appreciated. Thanks,
-- Robert


Robert Watkins
[EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]