Here is a snippet ... this is a method from an object
"ThesaurusBrowser". The method searches a number of terms from the
thesaurus, that, say, start with a given substring: 

public void searchTerms(ContentHandler ch, byte[] nb, String language,
String smode, boolean nonpreferred)
{
AttributesImpl attr = new AttributesImpl();
int hits = 0;
ResultSet rs = null;
// here we are going to form a query and execute it. 
rs = p.executeQuery();
        ResultSetMetaData rsmd = rs.getMetaData();

        while (rs.next()) {
                hits++;

attr.addAttribute("","id","id","CDATA",rs.getString("id"));
                if (nonpreferred)
attr.addAttribute("","npt","npt","CDATA","1");
                ch.startElement("","term","term",attr);
                attr.clear();
                for (int i=1; i <= rsmd.getColumnCount(); i++) {
                        String tagname = rsmd.getColumnName(i);
                        ch.startElement("",tagname,tagname,attr);
                        String value = rs.getString(i);
                        if (value != null)
ch.characters(value.toCharArray(),0,value.length());
                        ch.endElement("",tagname,tagname);
                        }
                ch.endElement("","term","term");
                }

        rs.close();
        p.close();
}
------------------------------------------------
I just display the relevant part: This code produces XML
<term id="234" term="someterm" context="somecontext" nonPreferred="0"/>
...
Change it to an alternative that returns an array of Term
------------------------------------------------------
public Concept[] searchTerms(byte[]nb, String language, String smode,
boolean nonPreferred) {
int hits = 0;

ResultSet rs = null;
// here we are going to form a query and execute it. 
rs = p.executeQuery();
        ResultSetMetaData rsmd = rs.getMetaData();
        Vector<Concept> VTerms = new Vector<Concept>();
        while (rs.next()) {
                hits++;
                Concept T = new Concept T();
                T.setId(rs.getInt(1));
                T.setTerm(rs.getString(2));
                T.setContext(rs.getString(3));
                T.setNonPreferred(rs.getString(4));
                VTerms.addElement(T);
                }
        
        rs.close();
        p.close();

Concept[] concepts = new Concept[C.size()];
                for (int j=0; j<C.size();j++) concepts[j] = (Concept)
VTerms.elementAt(j);
                return concepts;
                }

}



}

And you could then modify your Cocoon method to:

public void searchTerms(ContentHandler ch, byte[] nb, String language,
String smode, boolean nonpreferred)
{
Concept[] hits = searchTerms(nb, language,  smode, nonpreferred);
AttributesImpl attr = new AttributesImpl();

for (hit : hits) {
        attr.addAttribute( ... );

        ...
        ch.startElement("" 
        attr.clear();   
        }

that way extending the use and insulating the SAX interface. One step
further is creating separate cocoon classes, that only do the SAX
production thus universalizing your business model.





On Tue, 2009-09-29 at 09:31 -0400, Paul Joseph wrote:
> Thank Jos...I follow the general concept...would you know of any example 
> that I could take a look at?
> 
> thx.
> Paul
> 
> Jos Snellings wrote:
> > Hi Paul,
> >
> > Classes that live in a Cocoon environment will typically send their
> > output via SAX events. They would take a "ContentHandler" or
> > "XMLConsumer" as a parameter and call
> > startElement/endElement/characters. 
> > There might exist an insulation layer between the SAX-world and the
> > objects properly.
> >
> > If you extend these classes with methods that return objects, and arrays
> > of objects, they become available to other "Views".
> >
> > Does this answer make sense to you?
> >
> > Best,
> > Jos
> >
> > On Tue, 2009-09-29 at 06:33 -0400, Paul Joseph wrote:
> >   
> >> Hi there,
> >>
> >> What is the best way to make business functionality available in the 
> >> Java tier of my Cocoon application available available to another 
> >> application written in say ASP?
> >>
> >> Is sharing Cocoon applications java tier functionality with other apps. 
> >> possible and are there any "easy" ways to do this?
> >>
> >> thx.
> >> Paul
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
> >> For additional commands, e-mail: users-h...@cocoon.apache.org
> >>
> >>
> >>     
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
> > For additional commands, e-mail: users-h...@cocoon.apache.org
> >
> >
> >   
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
> For additional commands, e-mail: users-h...@cocoon.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org

Reply via email to