forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r693454 - in /forrest/trunk/whiteboard/dispatcher: ./ java/org/apache/forrest/dispatcher/api/ java/org/apache/forrest/dispatcher/helper/ java/org/apache/forrest/dispatcher/impl/ lib/
Date Tue, 09 Sep 2008 13:06:26 GMT
Author: thorsten
Date: Tue Sep  9 06:06:25 2008
New Revision: 693454

URL: http://svn.apache.org/viewvc?rev=693454&view=rev
Log:
Starting the rewrite with the contracts

Added:
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java
  (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/Loggable.java
  (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAX.java
  (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/XSLContractHelper.java
  (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XSLContract.java
  (with props)
    forrest/trunk/whiteboard/dispatcher/lib/commons-logging-1.1.1.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/lib/log4j-1.2.14.jar   (with props)
Modified:
    forrest/trunk/whiteboard/dispatcher/build.xml

Modified: forrest/trunk/whiteboard/dispatcher/build.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/build.xml?rev=693454&r1=693453&r2=693454&view=diff
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/build.xml (original)
+++ forrest/trunk/whiteboard/dispatcher/build.xml Tue Sep  9 06:06:25 2008
@@ -37,7 +37,7 @@
     <property name="dispatcher.build.compiler.type"        value="classic"/>
     <property name="dispatcher.build.compiler.vm"          value="1.5"/>
     <property name="name" value="apache-dispatcher"/>
-    <property name="dispatcher.version" value="0.0.1-dev"/>
+    <property name="dispatcher.version" value="0.0.2-dev"/>
     <property name="dispatcher.home" location="."/>
     <property file="${dispatcher.home}/local.build.properties" />
     <property file="${dispatcher.home}/build.properties" />

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java?rev=693454&view=auto
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java
(added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java
Tue Sep  9 06:06:25 2008
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.api;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+
+public interface Contract {
+  /**
+   * Some contracts are based on text based files. Best known example are the
+   * xsl contracts as the first implementation.
+   * 
+   * @param stream
+   *          that contains all information of the contract as description,
+   *          name, usage, ...
+   */
+  void initializeFromStream(InputStream stream);
+
+  /**
+   * Execute the contract with the given DataStream. The dataStream serves as
+   * base to do a transformation (in xsl based contracts) or invocation of
+   * business logic if used in java based contracts.
+   * 
+   * @param dataStream
+   *          base to do the transformation or invoked business logic
+   * @param properties
+   *          the parameter that configure the contract (customizing it)
+   * @return the resulting transformation of the dataStream with the given
+   *         properties.
+   */
+  OutputStream execute(InputStream dataStream, HashMap properties);
+
+  /**
+   * @return the name of the contract
+   */
+  String getName();
+
+  /**
+   * @param contractName
+   *          - the name of the contract
+   */
+  void setName(String contractName);
+
+  /**
+   * @return the description of the contract
+   */
+  String getDescription();
+
+  /**
+   * @param Description
+   *          - the description of the contract
+   */
+  void setDescription(String contractDescription);
+
+  /**
+   * @return how to use the contract
+   */
+  String getUsage();
+
+  /**
+   * @param contractUsage
+   *          - how to use the contract
+   */
+  void setUsage(String contractUsage);
+
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/Loggable.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/Loggable.java?rev=693454&view=auto
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/Loggable.java
(added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/Loggable.java
Tue Sep  9 06:06:25 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Simple wrapper class to easier debug/log.
+ * 
+ * @author thorsten
+ * @version 1.0
+ */
+public class Loggable {
+
+  protected final Log log = LogFactory.getLog(this.getClass()
+      .getCanonicalName());
+
+  protected Loggable() {
+  }
+
+}
\ No newline at end of file

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/Loggable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAX.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAX.java?rev=693454&view=auto
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAX.java
(added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAX.java
Tue Sep  9 06:06:25 2008
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Helper class that eases the usage of StAX in your plugins.
+ * 
+ * @author thorsten
+ * @version 1.0
+ * 
+ */
+public class StAX extends Loggable {
+  private XMLOutputFactory outputFactory = null;
+
+  private XMLEventFactory eventFactory = null;
+
+  private XMLInputFactory inputFactory = null;
+
+  /**
+   * Easy helper to get StAX based parser and writer.
+   */
+  public StAX() {
+    inputFactory = XMLInputFactory.newInstance();
+    outputFactory = XMLOutputFactory.newInstance();
+    eventFactory = XMLEventFactory.newInstance();
+  }
+
+  /**
+   * Get an event writer based on the incoming stream
+   * 
+   * @param stream
+   *                the stream we want to write to
+   * @return ready to use event writer
+   * @throws XMLStreamException
+   */
+  public XMLEventWriter getWriter(OutputStream stream)
+      throws XMLStreamException {
+    XMLEventWriter writer = outputFactory.createXMLEventWriter(stream);
+    return writer;
+  }
+
+  /**
+   * Get a stream writer based on the incoming stream
+   * 
+   * @param stream
+   *                the stream we want to write to
+   * @return ready to use stream writer
+   * @throws XMLStreamException
+   */
+  public XMLStreamWriter getStreamWriter(OutputStream stream)
+      throws XMLStreamException {
+    XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stream);
+    return writer;
+  }
+
+  /**
+   * Get an event Parser based on the incoming stream
+   * 
+   * @param in
+   *                the stream we want to read from
+   * @return ready to use event parser
+   * @throws XMLStreamException
+   */
+  public XMLEventReader getEventParser(InputStream in)
+      throws XMLStreamException {
+    XMLEventReader parser = inputFactory.createXMLEventReader(in);
+    return parser;
+  }
+
+  /**
+   * Get a stream Parser based on the incoming stream
+   * 
+   * @param in
+   *                the stream we want to read from
+   * @return ready to use stream parser
+   * @throws XMLStreamException
+   */
+  public XMLStreamReader getParser(InputStream in) throws XMLStreamException {
+    XMLStreamReader parser = inputFactory.createXMLStreamReader(in);
+    return parser;
+  }
+
+  /**
+   * Get the ready to used EventFactory
+   * 
+   * @return ready to used EventFactory
+   */
+  public XMLEventFactory getEventFactory() {
+    return eventFactory;
+  }
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAX.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/XSLContractHelper.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/XSLContractHelper.java?rev=693454&view=auto
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/XSLContractHelper.java
(added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/XSLContractHelper.java
Tue Sep  9 06:06:25 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.forrest.dispatcher.helper.StAX;
+
+public class XSLContractHelper extends StAX {
+  public ByteArrayOutputStream createEmptyXmlOutput() throws XMLStreamException {
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    XMLStreamWriter writer = getStreamWriter(out);
+    writer.writeStartDocument("UTF-8", "1.0");
+    writer.writeStartElement("foo");
+    writer.writeEndDocument();
+    writer.flush();
+    writer.close();
+    return out;
+  }
+
+  public InputStream createEmptyXml() throws XMLStreamException {
+    ByteArrayOutputStream out = createEmptyXmlOutput();
+    return new BufferedInputStream(new ByteArrayInputStream(out.toByteArray()));
+  }
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/XSLContractHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XSLContract.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XSLContract.java?rev=693454&view=auto
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XSLContract.java
(added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XSLContract.java
Tue Sep  9 06:06:25 2008
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.impl;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+
+import javax.xml.stream.XMLStreamException;
+
+
+import org.apache.forrest.dispatcher.api.Contract;
+
+import org.apache.forrest.dispatcher.helper.Loggable;
+import org.apache.forrest.dispatcher.helper.XSLContractHelper;
+
+public class XSLContract extends Loggable implements Contract {
+
+  private String name="", usage="", description="";
+  private XSLContractHelper helper=null;
+
+  public OutputStream execute(InputStream dataStream, HashMap properties) {
+    /* 
+     * get a new instance of the corresponding helper class since the helper
+     * is doing the actual work
+     */
+     helper = new XSLContractHelper();
+    /*
+     *  If no dataStream is present we need to create an empty xml doc
+     *  to be able to invoke the xsl transformation.
+     */
+    if (null == dataStream) {
+      try {
+        dataStream = helper.createEmptyXml();
+      } catch (XMLStreamException e) {
+        log.fatal(e);
+      }
+    }
+
+    return null;
+  }
+
+  public void initializeFromStream(InputStream stream) {
+    // TODO Auto-generated method stub
+
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public void setDescription(String description) {
+    this.description = description;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getUsage() {
+    return usage;
+  }
+
+  public void setUsage(String usage) {
+    this.usage = usage;
+  }
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XSLContract.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/lib/commons-logging-1.1.1.jar
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/lib/commons-logging-1.1.1.jar?rev=693454&view=auto
==============================================================================
Binary file - no diff available.

Propchange: forrest/trunk/whiteboard/dispatcher/lib/commons-logging-1.1.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: forrest/trunk/whiteboard/dispatcher/lib/log4j-1.2.14.jar
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/lib/log4j-1.2.14.jar?rev=693454&view=auto
==============================================================================
Binary file - no diff available.

Propchange: forrest/trunk/whiteboard/dispatcher/lib/log4j-1.2.14.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message