You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2014/09/18 11:30:36 UTC

svn commit: r1625925 - in /jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql: modify/request/ serializer/

Author: rvesse
Date: Thu Sep 18 09:30:35 2014
New Revision: 1625925

URL: http://svn.apache.org/r1625925
Log:
Add missing license headers and improve javadoc on new SerializerRegistry classes

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/UpdateSerializer.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializerFactory.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/SerializerRegistry.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/UpdateSerializerFactory.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/UpdateSerializer.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/UpdateSerializer.java?rev=1625925&r1=1625924&r2=1625925&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/UpdateSerializer.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/UpdateSerializer.java Thu Sep 18 09:30:35 2014
@@ -1,11 +1,37 @@
+/*
+ * 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 com.hp.hpl.jena.sparql.modify.request;
 
 import java.util.Iterator;
 
 import org.apache.jena.atlas.lib.Closeable;
 
+import com.hp.hpl.jena.sparql.serializer.SerializerRegistry;
+import com.hp.hpl.jena.sparql.serializer.UpdateSerializerFactory;
 import com.hp.hpl.jena.update.Update;
 
+/**
+ * Interface for update serializers which may be registered indirectly with the
+ * {@link SerializerRegistry} via a {@link UpdateSerializerFactory} thus
+ * allowing the customisation of update serialization.
+ * 
+ */
 public interface UpdateSerializer extends Closeable {
 
     /**

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java?rev=1625925&r1=1625924&r2=1625925&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java Thu Sep 18 09:30:35 2014
@@ -36,8 +36,9 @@ import com.hp.hpl.jena.sparql.syntax.Ele
 import com.hp.hpl.jena.sparql.syntax.Template ;
 import com.hp.hpl.jena.sparql.util.FmtUtils ;
 
-/** Serialize a query into SPARQL or ARQ formats */
-
+/** 
+ * Serialize a query into SPARQL or ARQ formats 
+ */
 public class QuerySerializer implements QueryVisitor
 {
     static final int BLOCK_INDENT = 2 ;

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializerFactory.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializerFactory.java?rev=1625925&r1=1625924&r2=1625925&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializerFactory.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializerFactory.java Thu Sep 18 09:30:35 2014
@@ -1,3 +1,21 @@
+/*
+ * 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 com.hp.hpl.jena.sparql.serializer;
 
 import org.apache.jena.atlas.io.IndentedWriter;
@@ -7,8 +25,10 @@ import com.hp.hpl.jena.query.Syntax;
 import com.hp.hpl.jena.sparql.core.Prologue;
 
 /**
- * Interface for query serializer factories
- *
+ * Interface for query serializer factories, these may be registered with the
+ * {@link SerializerRegistry} thus allowing the serialization of queries to be
+ * customised
+ * 
  */
 public interface QuerySerializerFactory {
 

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/SerializerRegistry.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/SerializerRegistry.java?rev=1625925&r1=1625924&r2=1625925&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/SerializerRegistry.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/SerializerRegistry.java Thu Sep 18 09:30:35 2014
@@ -1,3 +1,21 @@
+/*
+ * 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 com.hp.hpl.jena.sparql.serializer;
 
 import java.util.HashMap;
@@ -15,6 +33,19 @@ import com.hp.hpl.jena.sparql.util.NodeT
 
 /**
  * Provides a registry of serializers for queries and updates
+ * <p>
+ * By registering custom {@link QuerySerializerFactory} or
+ * {@link UpdateSerializerFactory} instances the mapping of a syntax to a
+ * serialization can be customised and this allows the serialization of queries
+ * and updates to be customised if desired.
+ * </p>
+ * <p>
+ * This feature is primarily intended for system programmers as changing how
+ * queries and updates are serialized could have knock on effects particularly
+ * if you use ARQ to interact with remote systems. The default registered
+ * serializers produce standards compliant SPARQL syntax and should be more than
+ * sufficient in most cases
+ * </p>
  * 
  */
 public class SerializerRegistry {
@@ -60,9 +91,9 @@ public class SerializerRegistry {
 
             @Override
             public UpdateSerializer create(Syntax syntax, Prologue prologue, IndentedWriter writer) {
-                if ( ! prologue.explicitlySetBaseURI() )
-                    prologue = new Prologue(prologue.getPrefixMapping(), (IRIResolver)null) ;
-                
+                if (!prologue.explicitlySetBaseURI())
+                    prologue = new Prologue(prologue.getPrefixMapping(), (IRIResolver) null);
+
                 SerializationContext context = new SerializationContext(prologue);
                 return new UpdateWriter(writer, context);
             }
@@ -82,6 +113,12 @@ public class SerializerRegistry {
         registry = reg;
     }
 
+    /**
+     * Gets the serializer registry which is a singleton lazily instantiating it
+     * if this is the first time this method has been called
+     * 
+     * @return Registry
+     */
     public static SerializerRegistry get() {
         if (registry == null)
             init();
@@ -89,38 +126,104 @@ public class SerializerRegistry {
         return registry;
     }
 
+    /**
+     * Adds a query serializer factory for the given syntax
+     * 
+     * @param syntax
+     *            Syntax
+     * @param factory
+     *            Serializer factory
+     * @throws IllegalArgumentException
+     *             Thrown if the given factory does not accept the given syntax
+     */
     public void addQuerySerializer(Syntax syntax, QuerySerializerFactory factory) {
         if (!factory.accept(syntax))
             throw new IllegalArgumentException("Factory does not accept the specified syntax");
         querySerializers.put(syntax, factory);
     }
 
+    /**
+     * Adds an update serializer factory for the given syntax
+     * 
+     * @param syntax
+     *            Syntax
+     * @param factory
+     *            Serializer factory
+     * @throws IllegalArgumentException
+     *             Thrown if the given factory does not accept the given syntax
+     */
     public void addUpdateSerializer(Syntax syntax, UpdateSerializerFactory factory) {
         if (!factory.accept(syntax))
             throw new IllegalArgumentException("Factory does not accept the specified syntax");
         updateSerializers.put(syntax, factory);
     }
 
+    /**
+     * Gets whether a query serializer factory is registered for the given
+     * syntax
+     * 
+     * @param syntax
+     *            Syntax
+     * @return True if registered, false otherwise
+     */
     public boolean containsQuerySerializer(Syntax syntax) {
-        return querySerializers.containsKey(syntax);
+        return querySerializers.containsKey(syntax) && querySerializers.get(syntax) != null;
     }
 
+    /**
+     * Gets whether an update serializer factory is registered for the given
+     * syntax
+     * 
+     * @param syntax
+     *            Syntax
+     * @return True if registered, false otherwise
+     */
     public boolean containsUpdateSerializer(Syntax syntax) {
-        return updateSerializers.containsKey(syntax);
+        return updateSerializers.containsKey(syntax) && updateSerializers.get(syntax) != null;
     }
 
+    /**
+     * Gets the query serializer factory for the given syntax which may be null
+     * if there is none registered
+     * 
+     * @param syntax
+     *            Syntax
+     * @return Query Serializer Factory or null if none registered for the given
+     *         syntax
+     */
     public QuerySerializerFactory getQuerySerializerFactory(Syntax syntax) {
         return querySerializers.get(syntax);
     }
 
+    /**
+     * Gets the update serializer factory for the given syntax which may be null
+     * if there is none registered
+     * 
+     * @param syntax
+     *            Syntax
+     * @return Update Serializer Factory or null if none registered for the
+     *         given syntax
+     */
     public UpdateSerializerFactory getUpdateSerializerFactory(Syntax syntax) {
         return updateSerializers.get(syntax);
     }
 
+    /**
+     * Removes the query serializer factory for the given syntax
+     * 
+     * @param syntax
+     *            Syntax
+     */
     public void removeQuerySerializer(Syntax syntax) {
         querySerializers.remove(syntax);
     }
 
+    /**
+     * Removes the update serializer factory for the given syntax
+     * 
+     * @param syntax
+     *            Syntax
+     */
     public void removeUpdateSerializer(Syntax syntax) {
         updateSerializers.remove(syntax);
     }

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/UpdateSerializerFactory.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/UpdateSerializerFactory.java?rev=1625925&r1=1625924&r2=1625925&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/UpdateSerializerFactory.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/UpdateSerializerFactory.java Thu Sep 18 09:30:35 2014
@@ -1,3 +1,21 @@
+/*
+ * 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 com.hp.hpl.jena.sparql.serializer;
 
 import org.apache.jena.atlas.io.IndentedWriter;
@@ -7,8 +25,10 @@ import com.hp.hpl.jena.sparql.core.Prolo
 import com.hp.hpl.jena.sparql.modify.request.UpdateSerializer;
 
 /**
- * Interface for update serializer factories
- *
+ * Interface for update serializer factories, these may be registered with the
+ * {@link SerializerRegistry} thus allowing update serialization to be
+ * customised
+ * 
  */
 public interface UpdateSerializerFactory {