abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r565408 - in /incubator/abdera/java/trunk: build/ protocol/src/main/java/org/apache/abdera/protocol/error/ protocol/src/main/resources/ protocol/src/main/resources/META-INF/ protocol/src/main/resources/META-INF/services/ server/src/main/jav...
Date Mon, 13 Aug 2007 16:43:15 GMT
Author: jmsnell
Date: Mon Aug 13 09:43:14 2007
New Revision: 565408

URL: http://svn.apache.org/viewvc?view=rev&rev=565408
Log:
Provide an Error extension element and factory for use with the protocol code as suggested
on the user list by Chris Berry. Thx!

Added:
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ErrorExtensionFactory.java
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java
    incubator/abdera/java/trunk/protocol/src/main/resources/
    incubator/abdera/java/trunk/protocol/src/main/resources/META-INF/
    incubator/abdera/java/trunk/protocol/src/main/resources/META-INF/services/
    incubator/abdera/java/trunk/protocol/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
Modified:
    incubator/abdera/java/trunk/build/build.xml
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java

Modified: incubator/abdera/java/trunk/build/build.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/build.xml?view=diff&rev=565408&r1=565407&r2=565408
==============================================================================
--- incubator/abdera/java/trunk/build/build.xml (original)
+++ incubator/abdera/java/trunk/build/build.xml Mon Aug 13 09:43:14 2007
@@ -44,6 +44,7 @@
   <property name="core.jar" value="${dist}/${ant.project.name}.core.${version}.jar" />
   <property name="protocol" value="${basedir}/protocol" />
   <property name="protocol.src" value="${protocol}/src/main/java" />
+  <property name="parser.resources" value="${protocol}/src/main/resources" />
   <property name="protocol.work" value="${work}/protocol" />
   <property name="protocol.jar" value="${dist}/${ant.project.name}.protocol.${version}.jar"
/>
   <property name="parser" value="${basedir}/parser" />
@@ -212,10 +213,13 @@
     </copy>
   </target>
 
-  <target name="compile.protocol" depends="init">
+  <target name="compile.protocol" depends="init,compile.core">
     <mkdir dir="${protocol.work}" />
     <javac srcdir="${protocol.src}" destdir="${protocol.work}" classpathref="jar.dependencies"
classpath="${core.work}" debug="${debug}" />
     <mkdir dir="${protocol.work}/META-INF" />
+    <copy todir="${protocol.work}">
+      <fileset dir="${protocol.resources}" includes="**/*" />
+    </copy>
     <copy todir="${protocol.work}/META-INF">
       <fileset dir="${basedir}">
         <include name="LICENSE" />

Added: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java?view=auto&rev=565408
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java
(added)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java
Mon Aug 13 09:43:14 2007
@@ -0,0 +1,95 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.error;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ExtensibleElementWrapper;
+
+/**
+ * Abdera protocol error element
+ */
+public class Error
+  extends ExtensibleElementWrapper {
+
+  public static final String NS        = "http://incubator.apache.org/abdera";
+  public static final QName ERROR         = new QName(NS, "error");
+  public static final QName CODE          = new QName(NS, "code");
+  public static final QName MESSAGE       = new QName(NS, "message");
+  
+  public Error(Element internal) {
+    super(internal);
+  }
+
+  public Error(Factory factory, QName qname) {
+    super(factory, qname);
+  }
+  
+  public int getCode() {
+    String code = getSimpleExtension(CODE);
+    return code != null ? Integer.parseInt(code) : -1;
+  }
+  
+  public void setCode(int code) {
+    if (code > -1) {
+      Element element = getExtension(CODE);
+      if (element != null) {
+        element.setText(Integer.toString(code));
+      } else {
+        addSimpleExtension(CODE,Integer.toString(code));
+      }
+    } else {
+      Element element = getExtension(CODE);
+      if (element != null) element.discard();
+    }
+  }
+ 
+  public String getMessage() {
+    return getSimpleExtension(MESSAGE);
+  }
+  
+  public void setMessage(String message) {
+    if (message != null) {
+      Element element = getExtension(MESSAGE);
+      if (element != null) {
+        element.setText(message);
+      } else {
+        addSimpleExtension(MESSAGE,message);
+      }
+    } else {
+      Element element = getExtension(MESSAGE);
+      if (element != null) element.discard();
+    }
+  }
+  
+  public void throwException() {
+    throw new ProtocolException(this);
+  }
+  
+  public static Error create(Abdera abdera, int code, String message) {
+    Document<Error> doc = abdera.getFactory().newDocument();
+    Error error = abdera.getFactory().newElement(ERROR,doc);
+    error.setCode(code);
+    error.setMessage(message);
+    return error;
+  }
+}

Added: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ErrorExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ErrorExtensionFactory.java?view=auto&rev=565408
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ErrorExtensionFactory.java
(added)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ErrorExtensionFactory.java
Mon Aug 13 09:43:14 2007
@@ -0,0 +1,30 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.error;
+
+import org.apache.abdera.util.AbstractExtensionFactory;
+
+public class ErrorExtensionFactory
+    extends AbstractExtensionFactory {
+
+  public ErrorExtensionFactory() {
+    super(Error.NS);
+    addImpl(Error.ERROR, Error.class);
+  }
+  
+}

Added: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java?view=auto&rev=565408
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java
(added)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java
Mon Aug 13 09:43:14 2007
@@ -0,0 +1,62 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.error;
+
+import org.apache.abdera.Abdera;
+
+public class ProtocolException
+    extends RuntimeException {
+
+  private static final long serialVersionUID = 1017447143200419489L;
+  protected final Error error;
+  
+  public ProtocolException(Error error) {
+    super(error.getCode() + "::" + error.getMessage());
+    this.error = error;
+  }
+  
+  public ProtocolException(Abdera abdera, int code, String message) {
+    super(code + "::" + message);
+    this.error = Error.create(abdera, code, message);
+  }
+  
+  public Error getError() {
+    return error;
+  }
+
+  @Override
+  public int hashCode() {
+    final int PRIME = 31;
+    int result = 1;
+    result = PRIME * result + ((error == null) ? 0 : error.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj) return true;
+    if (obj == null) return false;
+    if (getClass() != obj.getClass()) return false;
+    final ProtocolException other = (ProtocolException) obj;
+    if (error == null) {
+      if (other.error != null) return false;
+    } else if (!error.equals(other.error)) return false;
+    return true;
+  }
+  
+}

Added: incubator/abdera/java/trunk/protocol/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory?view=auto&rev=565408
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
(added)
+++ incubator/abdera/java/trunk/protocol/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
Mon Aug 13 09:43:14 2007
@@ -0,0 +1,5 @@
+org.apache.abdera.ext.thread.ThreadExtensionFactory
+org.apache.abdera.ext.opensearch.OpenSearchExtensionFactory
+org.apache.abdera.ext.media.MediaExtensionFactory
+org.apache.abdera.ext.features.FeaturesExtensionFactory
+org.apache.abdera.ext.sse.SharingExtensionFactory
\ No newline at end of file

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java?view=diff&rev=565408&r1=565407&r2=565408
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
Mon Aug 13 09:43:14 2007
@@ -31,6 +31,7 @@
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.ExtensibleElement;
+import org.apache.abdera.protocol.error.Error;
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
@@ -47,13 +48,6 @@
 
   private final static Log log = LogFactory.getLog(AbstractProvider.class);
   
-  private static final String NS        = "http://incubator.apache.org/abdera";
-  private static final String PFX       = "a";
-  private static final QName ERROR         = new QName(NS, "error", PFX);
-  private static final QName CODE          = new QName(NS, "code", PFX);
-  private static final QName MESSAGE       = new QName(NS, "message", PFX);
-
-  
   protected int defaultpagesize = 10;
   
   protected AbstractProvider() {}
@@ -62,19 +56,13 @@
     this.defaultpagesize = defaultpagesize;
   }
   
-  protected Document createErrorDocument(
+  protected Document<Error> createErrorDocument(
     Abdera abdera, 
     int code, 
     String message, 
     Throwable e) {
-      if (e != null) log.debug(Messages.format("CREATING.ERROR.DOC",code,message), e);
-      else log.debug("Creating error document - " + code + ", " + message);
-      Document doc = abdera.getFactory().newDocument();
-      ExtensibleElement root = 
-        (ExtensibleElement) abdera.getFactory().newElement(ERROR, doc);
-      root.addSimpleExtension(CODE, (code != -1) ? String.valueOf(code) : "");
-      root.addSimpleExtension(MESSAGE, (message != null) ? message : "");
-      return doc;
+      Error error = Error.create(abdera,code,message);
+      return error.getDocument();
   }
 
   /**



Mime
View raw message