org.backsource.xindice
Class AmsterdamXindicePublisher

java.lang.Object
  extended byorg.backsource.amsterdam.service.HandlerSupport
      extended byorg.backsource.amsterdam.service.filter.ServiceFilterSupport
          extended byorg.backsource.xindice.AmsterdamXindiceBase
              extended byorg.backsource.xindice.AmsterdamXindicePublisher
All Implemented Interfaces:
org.backsource.amsterdam.service.Handler, org.backsource.amsterdam.service.HandlerSupportMBean, org.backsource.amsterdam.service.publisher.Publisher, org.backsource.amsterdam.service.Servable, org.backsource.amsterdam.service.filter.ServiceFilter, org.backsource.amsterdam.service.filter.ServiceFilterSupportMBean, org.backsource.amsterdam.metadata.XmlConfigurable

public class AmsterdamXindicePublisher
extends AmsterdamXindiceBase
implements org.backsource.amsterdam.service.publisher.Publisher, org.backsource.amsterdam.metadata.XmlConfigurable

Amsterdam publisher for Xindice.

This class publishes the incomming document to the configured collections. It overrides the validateCollection(java.lang.String, boolean) method to create any collection that it can not find if the create-collections flag is true. It is also possible to set a key-xpath expression so that it can lookup the key to save as from the incomming document. There is currently no way to just use a subset of the collections fethched from the xpath; to make collections name or skip certain collections, sublcass this class and override the getCollectionName(java.lang.String) and/or validateCollection(java.lang.String, boolean)

Here is a configuration that goes agains a single collections.

     
     <filter className="org.backsource.xindice.AmsterdamXindicePublisher">
        <filter-conf>
          <url>xmldb:xindice:///db/test</url>
          <collection>senasteNytt</collection>
          <create-collections>true</create-collections>
          <key-xpath>/NewsML/NewsEnvelope/TransmissionId</key-xpath>
        </filter-conf>
      </filter>

And here is a publisher config that dynalically selects the collections to save the document to (and creates them if they do not exist).

    
    <publisher className="org.backsource.xindice.AmsterdamXindicePublisher">
      <url>xmldb:xindice:///db/test</url>
      <!--<collection>test</collection>-->
      <collection-xpath>//Subject[@Scheme="EdrumCategory"]/@FormalName</collection-xpath>
      <create-collections>true</create-collections>
      <key-xpath>/NewsML/NewsEnvelope/TransmissionId</key-xpath>
    </publisher>

Possible bugs

1. Have seen situations when loading of thow parallell messages with same category and where the category did not exist prior: seems as if the second one does not allways see that the collection was created by the first thread.

Version:
$Revision: 1.1.1.1 $
Author:
Peter Antman

Field Summary
protected  boolean createCols
           
protected  java.lang.String keyXpath
           
 
Fields inherited from class org.backsource.xindice.AmsterdamXindiceBase
col, existingCollections, pool, url, xpath
 
Fields inherited from class org.backsource.amsterdam.service.HandlerSupport
name, objectName, service, useBean
 
Constructor Summary
AmsterdamXindicePublisher()
           
 
Method Summary
protected  java.lang.String getCollectionName(java.lang.String colName)
          Template method to use in sublclasses that wants to map incomming collection name to another, this version just returns the name.
protected  java.lang.String[] getCollections(org.w3c.dom.Document doc, boolean create)
          Get the collection(s) this message should be saved in.
 void handleMessage(org.backsource.amsterdam.service.ServiceMessage message)
          Publish the xml message to the collections this service was configured to i use.
 void importXml(org.w3c.dom.Element element)
          Takes argument as AmsterdamXindiceBase.
 void start()
          Start the component, get a list of all existing child collections.
 java.lang.String toString()
           
protected  boolean validateCollection(java.lang.String colName, boolean create)
          Validate that the collection exists, if create is true try create one.
 
Methods inherited from class org.backsource.xindice.AmsterdamXindiceBase
getDocument, stop, updateExistingCollections
 
Methods inherited from class org.backsource.amsterdam.service.filter.ServiceFilterSupport
getFilterName, getFilterObjectName, getNext, getObjectNameProperty, setFilterName, setFilterObjectName, setNext
 
Methods inherited from class org.backsource.amsterdam.service.HandlerSupport
constructObjectName, destroy, getName, getObjectName, getService, init, isUseBean, setName, setObjectName, setService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.backsource.amsterdam.service.Handler
getName, getObjectName, getService, isUseBean, setService
 
Methods inherited from interface org.backsource.amsterdam.service.Servable
destroy, init, stop
 
Methods inherited from interface org.backsource.amsterdam.service.HandlerSupportMBean
getName, getObjectName, isUseBean
 

Field Detail

createCols

protected boolean createCols

keyXpath

protected java.lang.String keyXpath
Constructor Detail

AmsterdamXindicePublisher

public AmsterdamXindicePublisher()
Method Detail

start

public void start()
           throws java.lang.Exception
Description copied from class: AmsterdamXindiceBase
Start the component, get a list of all existing child collections.

Specified by:
start in interface org.backsource.amsterdam.service.Servable
Overrides:
start in class AmsterdamXindiceBase
Throws:
java.lang.Exception

handleMessage

public void handleMessage(org.backsource.amsterdam.service.ServiceMessage message)
                   throws org.backsource.amsterdam.service.ServiceException
Publish the xml message to the collections this service was configured to i use. if getNext() returns null, we are a publisher, othervise we are a filter.

Specified by:
handleMessage in interface org.backsource.amsterdam.service.Handler
Throws:
org.backsource.amsterdam.service.ServiceException

importXml

public void importXml(org.w3c.dom.Element element)
               throws org.backsource.amsterdam.deployment.DeploymentException
Takes argument as AmsterdamXindiceBase. Also takes the optional create-collections and key-xpath.

Specified by:
importXml in interface org.backsource.amsterdam.metadata.XmlConfigurable
Overrides:
importXml in class AmsterdamXindiceBase
Throws:
org.backsource.amsterdam.deployment.DeploymentException

toString

public java.lang.String toString()
Overrides:
toString in class AmsterdamXindiceBase

getCollections

protected java.lang.String[] getCollections(org.w3c.dom.Document doc,
                                            boolean create)
                                     throws XindiceException,
                                            org.backsource.utils.xml.XmlException
Get the collection(s) this message should be saved in.

if col is set, that will be used, if xpath i set, the names of the collections will fetched from the document.if create is set to true, we will try to create the collection if it does not exist, otherwise an XindiceExceptiob will be thrown if the collections does not exist.

Overrides:
getCollections in class AmsterdamXindiceBase
Parameters:
doc - document to save.
Throws:
XindiceException - if collection is not correct
org.backsource.utils.xml.XmlException - if getting of collection with xpath failes.

getCollectionName

protected java.lang.String getCollectionName(java.lang.String colName)
                                      throws XindiceException
Template method to use in sublclasses that wants to map incomming collection name to another, this version just returns the name.

Overrides:
getCollectionName in class AmsterdamXindiceBase
Returns:
a collections name, wich may be a mapped name, or null if the collection is not a valid/allowed collection.
Throws:
XindiceException

validateCollection

protected boolean validateCollection(java.lang.String colName,
                                     boolean create)
                              throws XindiceException
Validate that the collection exists, if create is true try create one.

Overrides:
validateCollection in class AmsterdamXindiceBase
Parameters:
colName - the collection to check.
create - create collection if it does not exists if set to true.
Throws:
XindiceException - if collection did not exist and create was false or if creation did not work.


Copyright © 2003-2004 Backsource. All Rights Reserved.