You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Christofer Dutz <du...@c-ware.de> on 2002/02/16 20:23:17 UTC

Create Components ?

Hi again.

 

I hope this is the right newsgroup for this kind of question, but I
couldn’t see any similar threads in Cocoon-User.

 

I have tried looking through several sources, but I couldn’t find some
sort of HowTo for writing own components. I have tried creating one by
having a look at the hsqldb Classes, but I can’t get the thing to work.
Every time I add the attribute for a user-role in the cocoon.xconf file,
but I always get a “java.lang.NullPointerException” in the
/WEB-INF/cocoon.log.000001 file

 

Here the soure for my roles file :

 

<?xml version="1.0"?>

<role-list>

       <role name="org.apache.cocoon.components.exist.Exist"
shorthand="exist-server"
default-class="org.apache.cocoon.components.exist.ExistImpl"/>

</role-list>

 

And the config-part of my cocoon.xconf :

...

       <exist-server class="org.apache.cocoon.components.ExistImpl"
pool-max="1" pool-min="1">

             <parameter name="http-port" value="8010"/>

             <parameter name="rpc-port" value="8011"/>

       </exist-server>

…

 

I have created two classes :

1. org.apache.cocoon.components.exist.Exist : 

 

package org.apache.cocoon.components.exist;

import org.apache.avalon.framework.component.Component;

public interface Exist extends Component {

    String ROLE = "org.apache.cocoon.components.exist.Exist";

}

 

2. org.apache.cocoon.components.exist.ExistImpl :

 

package org.apache.cocoon.components.exist;

 

import org.apache.avalon.framework.activity.Startable;

import org.apache.avalon.framework.context.Context;

import org.apache.avalon.framework.context.ContextException;

import org.apache.avalon.framework.context.Contextualizable;

import org.apache.avalon.framework.logger.AbstractLoggable;

import org.apache.avalon.framework.parameters.Parameters;

import org.apache.avalon.framework.parameters.Parameterizable;

import org.apache.avalon.framework.thread.ThreadSafe;

import org.apache.cocoon.Constants;

 

import java.io.File;

import java.io.IOException;

import java.net.MalformedURLException;

import java.sql.SQLException;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

import java.util.Enumeration;

 

import org.exist.ServerBean;

 

/**

 *  Überschrift: eXist XML-Datenbankerweitrung um Lokle Interfaces
Beschreibung:

 *  Copyright: Copyright (c) 2002 Organisation: C-Ware IT-Service

 *

 *@author     Christofer Dutz

 *@created    14. Februar 2002

 *@version    1.0

 */

 

public class ExistImpl extends AbstractLoggable implements Exist,

        Parameterizable,

        Contextualizable,

        ThreadSafe,

        Runnable,

        Startable {

 

    private ServerBean server = null;

 

 

    /**

     *  Initialize the ServerImpl. A few options can be used :

     *  <UL>

     *    <LI> http-port = port where the http-server is listening</LI>

     *    <LI> rpc-port = port where the rpc-server is listening</LI>

     *  </UL>

     *

     *

     *@param  params  Description of the Parameter

     */

    public void parameterize(Parameters params) {

        if (this.getLogger().isDebugEnabled()) {

            this.getLogger().debug("Parameterize ServerImpl");

        }

        this.server = ServerBean.getInstance();

 
this.server.setHttpPort(params.getParameterAsInteger("http-port", 0));

        this.server.setRpcPort(params.getParameterAsInteger("rpc-port",
0));

        if (this.getLogger().isDebugEnabled()) {

            this.getLogger().debug("Configure ServerImpl" +

                    ((params.getParameterAsInteger("with http-port", 0)
== 0) ? " http-port : " + params.getParameter("http-port", "0") : "") +

                    ((params.getParameterAsInteger("with rpc-port", 0)
== 0) ? " rpc-port : " + params.getParameter("rpc-port", "0") : ""));

        }

    }

 

 

    /**

     *  Contextualize this class

     *

     *@param  context               Description of the Parameter

     *@exception  ContextException  Description of the Exception

     */

    public void contextualize(Context context) throws ContextException {

        org.apache.cocoon.environment.Context ctx =

                (org.apache.cocoon.environment.Context)
context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);

 

        try {

            String dbPath = new
File(ctx.getRealPath("/WEB-INF/xmldb")).getCanonicalPath();

            this.server.setHome(dbPath);

            if (this.getLogger().isDebugEnabled()) {

                this.getLogger().debug("database is : " + dbPath);

            }

        } catch (MalformedURLException mue) {

            getLogger().error("MalformedURLException - Could not get
database directory ", mue);

        } catch (IOException ioe) {

            this.getLogger().error("IOException - Could not get database
directory ", ioe);

        }

    }

 

 

    /**

     *  Start the server

     */

    public void start() {

        if (!this.server.isActive()) {

            this.server.startup();

        }

    }

 

 

    /**

     *  Stop the server

     */

    public void stop() {

        if (this.server.isActive()) {

            this.server.shutdown();

        }

    }

 

 

    /**

     *  Main processing method for the ServerImpl object

     */

    public void run() {

        if (!this.server.isActive()) {

            this.server.startup();

        }

    }

}

 

The result I get in the log-file is : 

 

DEBUG   (2002-02-15) 17:44.22:287   [cocoon  ] (Unknown-URI)
Unknown-thread/Cocoon: Root configuration: cocoon

DEBUG   (2002-02-15) 17:44.22:287   [cocoon  ] (Unknown-URI)
Unknown-thread/Cocoon: Configuration version: 2.0

DEBUG   (2002-02-15) 17:44.22:297   [cocoon  ] (Unknown-URI)
Unknown-thread/DefaultComponentFactory: ComponentFactory creating new
instance of org.apache.cocoon.components.parser.JaxpParser.

DEBUG   (2002-02-15) 17:44.22:297   [cocoon  ] (Unknown-URI)
Unknown-thread/JaxpParser: Looking up
org.apache.cocoon.components.resolver.Resolver

DEBUG   (2002-02-15) 17:44.22:297   [cocoon  ] (Unknown-URI)
Unknown-thread/ExcaliburComponentManager: Could not find
ComponentHandler, attempting to create one for role:
org.apache.cocoon.components.resolver.Resolver

DEBUG   (2002-02-15) 17:44.22:297   [cocoon  ] (Unknown-URI)
Unknown-thread/JaxpParser: JaxpParser: Could not yet find
org.apache.cocoon.components.resolver.Resolver

ERROR   (2002-02-15) 17:44.22:297   [cocoon  ] (Unknown-URI)
Unknown-thread/Cocoon: Could not configure Cocoon environment

java.lang.NullPointerException

      at org.apache.cocoon.Cocoon.configure(Cocoon.java:341)

      at org.apache.cocoon.Cocoon.initialize(Cocoon.java:197)

      at
org.apache.cocoon.servlet.CocoonServlet.createCocoon(CocoonServlet.java:
864)

      at
org.apache.cocoon.servlet.CocoonServlet.init(CocoonServlet.java:220)

      at
org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:852)

      at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.j
ava:3267)

      at
org.apache.catalina.core.StandardContext.start(StandardContext.java:3384
)

      at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:785)

      at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:454)

      at
org.apache.catalina.core.StandardHost.install(StandardHost.java:712)

      at
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:599)

      at
org.apache.catalina.startup.HostConfig.start(HostConfig.java:777)

      at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:46
3)

      at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSu
pport.java:155)

      at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1131)

      at
org.apache.catalina.core.StandardHost.start(StandardHost.java:612)

      at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1123)

      at
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:307)

      at
org.apache.catalina.core.StandardService.start(StandardService.java:388)

      at
org.apache.catalina.core.StandardServer.start(StandardServer.java:505)

      at org.apache.catalina.startup.Catalina.start(Catalina.java:776)

      at org.apache.catalina.startup.Catalina.execute(Catalina.java:681)

      at org.apache.catalina.startup.Catalina.process(Catalina.java:179)

      at java.lang.reflect.Method.invoke(Native Method)

      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:243)

DEBUG   (2002-02-15) 17:44.22:297   [cocoon  ] (Unknown-URI)
Unknown-thread/DefaultComponentFactory: ComponentFactory decommissioning
instance of org.apache.cocoon.components.parser.JaxpParser.

 

Have I missed configuring anything ? Or have I done something wrong ? I
simply can’t get any usefull information from the log :-(

 

Plese help me ( or redirect me if this doesn’t belong here )

 

Thanx in advance,

     Christofer Dutz

 

 

 

Christofer Dutz

C-Ware IT-Service

Inh. Christofer Dutz

Goethestr. 18

64372 Ober-Ramstadt

www.c-ware.de