You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Ricky Panaglucci <hi...@yahoo.co.uk> on 2003/10/20 23:02:57 UTC

[digester] why private XXXRule in DigesterRuleParser?

hello,
why do classes like PatternRule have private access?

now, for adding my own rules which may use surrounding
"pattern", i just copied the PatternRule source [very
brown imho]

why not make them protected or public?


ricardo

________________________________________________________________________
Want to chat instantly with your online friends?  Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] why private XXXRule in DigesterRuleParser?

Posted by Ricky Panaglucci <hi...@yahoo.co.uk>.
simon,
nevermind, i don't remember what i did, but 
 <pattern value="child">
   <object-create-rule classname="xxx"/>
     <set-generic-properties-rule/>
     <set-next-rule methodname="addChild"/>
 </pattern>

now works with [d instanceof Digester]
  d.addFactoryCreate("*/set-generic-properties-rule",
new SetGenericPropertiesRuleFactory());
//      d.addRule("*/set-generic-properties-rule", new
XPatternRule("pattern")); <--- thought i need this
      d.addSetNext("*/set-generic-properties-rule",
"add", Rule.class.getName());
(XXGenericXX some Castor related stuff)


i've been using Digester for 3 days now and haven't
digged the push/pop stuff completely yet...
your arguments regarding private use have been
absorbed though

thanks
ricardo

 --- Simon Kitching <si...@ecnetwork.co.nz> wrote: >
Hi Ricky,
> 
> You must be referring to
>   xmlrules/DigesterRuleParser.java
> 
> I'm no expert on the xmlrules package.
> 
> However it is normal practice for classes created
> solely for the purpose
> of implementing function X to be declared private.
> 
> The PatternRule class appears to have been created
> *not* with the
> intention of providing additional services to users
> of Digester, but
> solely as an implementation detail of the xmlrules
> functionality. As
> such, private seems the appropriate scope to me.
> 
> If you feel that the functionality of the
> PatternRule is useful outside
> of the xmlrules package, then consideration could be
> given to
> "promoting" the class to public. 
> 
> Note however that any class or method declared
> public (or protected) is
> part of the "public interface" to a package, and
> must:
> (a) be documented much more thoroughly than
> private/package classes
> (b) be backwards-compatible in future releases
> (c) be deprecated before removal
> 
> So a class really should only be public if it needs
> to be.
> 
> 
> Regards,
> 
> Simon
> 
> On Tue, 2003-10-21 at 10:02, Ricky Panaglucci wrote:
> > hello,
> > why do classes like PatternRule have private
> access?
> > 
> > now, for adding my own rules which may use
> surrounding
> > "pattern", i just copied the PatternRule source
> [very
> > brown imho]
> > 
> > why not make them protected or public?
> > 
> > 
> > ricardo
> > 
> >
>
________________________________________________________________________
> > Want to chat instantly with your online friends? 
> Get the FREE Yahoo!
> > Messenger http://mail.messenger.yahoo.co.uk
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
> > 
> > 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
>  

________________________________________________________________________
Want to chat instantly with your online friends?  Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] why private XXXRule in DigesterRuleParser?

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi ricardo

i think i understand what you code is doing (in general terms). the idea 
is that you're adding your own rules to the existing xml-rules so that 
they can be used for parsing, right?

i've taken a look at the code in DigesterRuleParser i'm not too sure that 
your plan would work. the inner classes cannot simply be extracted to 
public scope without some refactoring.

i was wondering:

1. whether anyone would really need to subclass PatternRule - or whether a 
factory method would be good enough.

2. whether it's only PatternRule that really needs more public scope.

answers anyone?

- robert

On Tuesday, October 21, 2003, at 11:23 PM, Ricky Panaglucci wrote:

> hello,
> below is a case, where the existing PatternRule would
> be usefull
>
> ricardo
>
> myrules.xml:
> <digester-rules>
>     <pattern value="*/MyObject">
>       <object-create-rule classname="MyObject"/>
>       <set-generic-property-rule pattern="attr"
> name="name" value="value"/>
>     </pattern>
> </digester-rules>
>
> myobject.xml:
> <?xml version="1.0"?>
> <jLab>
>   <MyObject">
>      <attr name="att1" value="val1"/>
>      <attr name="att2" value="val2"/>
>   </MyObject>
> </jLab>
>
>       Digester d=new Digester()
>       DigesterRuleParser drp=new
> DigesterRuleParser(d);
>
> d.addFactoryCreate("*/set-generic-property-rule", new
> SetGenericPropertyRuleFactory());
> //*** would like to write
> d.addRule("*/set-generic-property-rule", drp.new
> PatternRule("pattern"));
>       d.addRule("*/set-generic-property-rule", new
> XPatternRule("pattern"));
>       d.addSetNext("*/set-generic-property-rule",
> "add", Rule.class.getName());
>
>       RuleSet ruleSet = new FromXmlRuleSet(new
> Files("myrules").toURL(), drp, d);
>       d.addRuleSet(ruleSet);
>       MyObject obj = (MyObject)d.parse(new
> File("myobject.xml");
>
>
>   public class SetGenericPropertyRuleFactory extends
> AbstractObjectCreationFactory {
>         public SetGenericPropertyRuleFactory() {
>
>         }
>         public Object createObject(Attributes
> attributes) {
>           String name = attributes.getValue("name");
>           String value = attributes.getValue("value");
>           return new GenericPropertyRule( name,
> value);
>         }
>     }
>
>
>   public class GenericPropertiesRule extends Rule {
> //***source copied from SetPropertyRule with some
>
>   }
>
>   public class XPatternRule {
> //***source copied from PatternRule
>   }
>
>  --- robert burrell donkin
> <ro...@blueyonder.co.uk> wrote: > +1
>>
>> i'd be happy to see the nested classed in the
>> xmlrules made public if a
>> need could be demonstrated.
>>
>> - robert
>>
>> On Monday, October 20, 2003, at 10:12 PM, Simon
>> Kitching wrote:
>>
>>> Hi Ricky,
>>>
>>> You must be referring to
>>>   xmlrules/DigesterRuleParser.java
>>>
>>> I'm no expert on the xmlrules package.
>>>
>>> However it is normal practice for classes created
>> solely for the purpose
>>> of implementing function X to be declared private.
>>>
>>> The PatternRule class appears to have been created
>> *not* with the
>>> intention of providing additional services to
>> users of Digester, but
>>> solely as an implementation detail of the xmlrules
>> functionality. As
>>> such, private seems the appropriate scope to me.
>>>
>>> If you feel that the functionality of the
>> PatternRule is useful outside
>>> of the xmlrules package, then consideration could
>> be given to
>>> "promoting" the class to public.
>>>
>>> Note however that any class or method declared
>> public (or protected) is
>>> part of the "public interface" to a package, and
>> must:
>>> (a) be documented much more thoroughly than
>> private/package classes
>>> (b) be backwards-compatible in future releases
>>> (c) be deprecated before removal
>>>
>>> So a class really should only be public if it
>> needs to be.
>>>
>>>
>>> Regards,
>>>
>>> Simon
>>>
>>> On Tue, 2003-10-21 at 10:02, Ricky Panaglucci
>> wrote:
>>>> hello,
>>>> why do classes like PatternRule have private
>> access?
>>>>
>>>> now, for adding my own rules which may use
>> surrounding
>>>> "pattern", i just copied the PatternRule source
>> [very
>>>> brown imho]
>>>>
>>>> why not make them protected or public?
>>>>
>>>>
>>>> ricardo
>>>>
>>>>
>>
> ________________________________________________________________________
>>>> Want to chat instantly with your online friends?
>> Get the FREE Yahoo!
>>>> Messenger http://mail.messenger.yahoo.co.uk
>>>>
>>>>
>>
> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>> commons-dev-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:
>> commons-dev-help@jakarta.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>
> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> commons-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:
>> commons-dev-help@jakarta.apache.org
>>>
>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> commons-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> commons-dev-help@jakarta.apache.org
>>
>
> ________________________________________________________________________
> Want to chat instantly with your online friends?  Get the FREE Yahoo!
> Messenger http://mail.messenger.yahoo.co.uk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] why private XXXRule in DigesterRuleParser?

Posted by Ricky Panaglucci <hi...@yahoo.co.uk>.
hello,
below is a case, where the existing PatternRule would
be usefull

ricardo

myrules.xml:
<digester-rules>
    <pattern value="*/MyObject">
      <object-create-rule classname="MyObject"/>
      <set-generic-property-rule pattern="attr"
name="name" value="value"/>
    </pattern>
</digester-rules> 

myobject.xml:
<?xml version="1.0"?>
<jLab>
  <MyObject">
     <attr name="att1" value="val1"/>
     <attr name="att2" value="val2"/>
  </MyObject>
</jLab>

      Digester d=new Digester()
      DigesterRuleParser drp=new
DigesterRuleParser(d);
     
d.addFactoryCreate("*/set-generic-property-rule", new
SetGenericPropertyRuleFactory());
//*** would like to write      
d.addRule("*/set-generic-property-rule", drp.new
PatternRule("pattern"));
      d.addRule("*/set-generic-property-rule", new
XPatternRule("pattern"));
      d.addSetNext("*/set-generic-property-rule",
"add", Rule.class.getName());

      RuleSet ruleSet = new FromXmlRuleSet(new
Files("myrules").toURL(), drp, d);
      d.addRuleSet(ruleSet);
      MyObject obj = (MyObject)d.parse(new
File("myobject.xml");


  public class SetGenericPropertyRuleFactory extends
AbstractObjectCreationFactory {
        public SetGenericPropertyRuleFactory() {

        }
        public Object createObject(Attributes
attributes) {
          String name = attributes.getValue("name");
          String value = attributes.getValue("value");
          return new GenericPropertyRule( name,
value);
        }
    }


  public class GenericPropertiesRule extends Rule {
//***source copied from SetPropertyRule with some 

  }

  public class XPatternRule {
//***source copied from PatternRule 
  }

 --- robert burrell donkin
<ro...@blueyonder.co.uk> wrote: > +1
> 
> i'd be happy to see the nested classed in the
> xmlrules made public if a 
> need could be demonstrated.
> 
> - robert
> 
> On Monday, October 20, 2003, at 10:12 PM, Simon
> Kitching wrote:
> 
> > Hi Ricky,
> >
> > You must be referring to
> >   xmlrules/DigesterRuleParser.java
> >
> > I'm no expert on the xmlrules package.
> >
> > However it is normal practice for classes created
> solely for the purpose
> > of implementing function X to be declared private.
> >
> > The PatternRule class appears to have been created
> *not* with the
> > intention of providing additional services to
> users of Digester, but
> > solely as an implementation detail of the xmlrules
> functionality. As
> > such, private seems the appropriate scope to me.
> >
> > If you feel that the functionality of the
> PatternRule is useful outside
> > of the xmlrules package, then consideration could
> be given to
> > "promoting" the class to public.
> >
> > Note however that any class or method declared
> public (or protected) is
> > part of the "public interface" to a package, and
> must:
> > (a) be documented much more thoroughly than
> private/package classes
> > (b) be backwards-compatible in future releases
> > (c) be deprecated before removal
> >
> > So a class really should only be public if it
> needs to be.
> >
> >
> > Regards,
> >
> > Simon
> >
> > On Tue, 2003-10-21 at 10:02, Ricky Panaglucci
> wrote:
> >> hello,
> >> why do classes like PatternRule have private
> access?
> >>
> >> now, for adding my own rules which may use
> surrounding
> >> "pattern", i just copied the PatternRule source
> [very
> >> brown imho]
> >>
> >> why not make them protected or public?
> >>
> >>
> >> ricardo
> >>
> >>
>
________________________________________________________________________
> >> Want to chat instantly with your online friends? 
> Get the FREE Yahoo!
> >> Messenger http://mail.messenger.yahoo.co.uk
> >>
> >>
>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
> >>
> >>
> >
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
> >
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
>  

________________________________________________________________________
Want to chat instantly with your online friends?  Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] why private XXXRule in DigesterRuleParser?

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
+1

i'd be happy to see the nested classed in the xmlrules made public if a 
need could be demonstrated.

- robert

On Monday, October 20, 2003, at 10:12 PM, Simon Kitching wrote:

> Hi Ricky,
>
> You must be referring to
>   xmlrules/DigesterRuleParser.java
>
> I'm no expert on the xmlrules package.
>
> However it is normal practice for classes created solely for the purpose
> of implementing function X to be declared private.
>
> The PatternRule class appears to have been created *not* with the
> intention of providing additional services to users of Digester, but
> solely as an implementation detail of the xmlrules functionality. As
> such, private seems the appropriate scope to me.
>
> If you feel that the functionality of the PatternRule is useful outside
> of the xmlrules package, then consideration could be given to
> "promoting" the class to public.
>
> Note however that any class or method declared public (or protected) is
> part of the "public interface" to a package, and must:
> (a) be documented much more thoroughly than private/package classes
> (b) be backwards-compatible in future releases
> (c) be deprecated before removal
>
> So a class really should only be public if it needs to be.
>
>
> Regards,
>
> Simon
>
> On Tue, 2003-10-21 at 10:02, Ricky Panaglucci wrote:
>> hello,
>> why do classes like PatternRule have private access?
>>
>> now, for adding my own rules which may use surrounding
>> "pattern", i just copied the PatternRule source [very
>> brown imho]
>>
>> why not make them protected or public?
>>
>>
>> ricardo
>>
>> ________________________________________________________________________
>> Want to chat instantly with your online friends?  Get the FREE Yahoo!
>> Messenger http://mail.messenger.yahoo.co.uk
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] why private XXXRule in DigesterRuleParser?

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
Hi Ricky,

You must be referring to
  xmlrules/DigesterRuleParser.java

I'm no expert on the xmlrules package.

However it is normal practice for classes created solely for the purpose
of implementing function X to be declared private.

The PatternRule class appears to have been created *not* with the
intention of providing additional services to users of Digester, but
solely as an implementation detail of the xmlrules functionality. As
such, private seems the appropriate scope to me.

If you feel that the functionality of the PatternRule is useful outside
of the xmlrules package, then consideration could be given to
"promoting" the class to public. 

Note however that any class or method declared public (or protected) is
part of the "public interface" to a package, and must:
(a) be documented much more thoroughly than private/package classes
(b) be backwards-compatible in future releases
(c) be deprecated before removal

So a class really should only be public if it needs to be.


Regards,

Simon

On Tue, 2003-10-21 at 10:02, Ricky Panaglucci wrote:
> hello,
> why do classes like PatternRule have private access?
> 
> now, for adding my own rules which may use surrounding
> "pattern", i just copied the PatternRule source [very
> brown imho]
> 
> why not make them protected or public?
> 
> 
> ricardo
> 
> ________________________________________________________________________
> Want to chat instantly with your online friends?  Get the FREE Yahoo!
> Messenger http://mail.messenger.yahoo.co.uk
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org