Repository: jena Updated Branches: refs/heads/master 085f2efb2 -> 0653392c2
Initialize functions/property functions in ARQ.init. Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/afd4ed6b Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/afd4ed6b Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/afd4ed6b Branch: refs/heads/master Commit: afd4ed6b79d0570d9786c51371c417611a2b26f1 Parents: a3b7eec Author: Andy Seaborne <[email protected]> Authored: Fri Mar 11 18:01:34 2016 +0000 Committer: Andy Seaborne <[email protected]> Committed: Sun Mar 13 17:17:30 2016 +0000 ---------------------------------------------------------------------- .../main/java/org/apache/jena/query/ARQ.java | 7 +++ .../jena/sparql/function/FunctionRegistry.java | 19 +++++--- .../pfunction/PropertyFunctionRegistry.java | 38 +++++----------- .../pfunction/StandardPropertyFunctions.java | 46 ++++++++++++++++++++ 4 files changed, 76 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/afd4ed6b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/query/ARQ.java b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java index af8439f..9391b6b 100644 --- a/jena-arq/src/main/java/org/apache/jena/query/ARQ.java +++ b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java @@ -23,11 +23,13 @@ import org.apache.jena.sparql.SystemARQ ; import org.apache.jena.sparql.algebra.optimize.TransformOrderByDistinctApplication ; import org.apache.jena.sparql.core.assembler.AssemblerUtils ; import org.apache.jena.sparql.engine.http.Service ; +import org.apache.jena.sparql.function.FunctionRegistry ; import org.apache.jena.sparql.lib.Metadata ; import org.apache.jena.sparql.mgt.ARQMgt ; import org.apache.jena.sparql.mgt.Explain ; import org.apache.jena.sparql.mgt.Explain.InfoLevel ; import org.apache.jena.sparql.mgt.SystemInfo ; +import org.apache.jena.sparql.pfunction.PropertyFunctionRegistry ; import org.apache.jena.sparql.util.Context ; import org.apache.jena.sparql.util.MappingRegistry ; import org.apache.jena.sparql.util.Symbol ; @@ -575,6 +577,11 @@ public class ARQ // Register RIOT details here, not earlier, to avoid // initialization loops with RIOT.init() called directly. RIOT.register() ; + + // Initialise + FunctionRegistry.init() ; + PropertyFunctionRegistry.init() ; + JenaSystem.logLifecycle("ARQ.init - finish") ; } } http://git-wip-us.apache.org/repos/asf/jena/blob/afd4ed6b/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionRegistry.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionRegistry.java b/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionRegistry.java index 22593ad..75a9b63 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionRegistry.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/function/FunctionRegistry.java @@ -34,22 +34,29 @@ public class FunctionRegistry //extends HashMap<String, Function> // Extract a Registry class and do casting and initialization here. Map<String, FunctionFactory> registry = new HashMap<>() ; Set<String> attemptedLoads = new HashSet<>() ; - - public synchronized static FunctionRegistry standardRegistry() + + public static FunctionRegistry standardRegistry() { + FunctionRegistry reg = get(ARQ.getContext()) ; + return reg ; + } + + public static void init() { + // Intialize if there is no registry already set FunctionRegistry reg = new FunctionRegistry() ; StandardFunctions.loadStdDefs(reg) ; - return reg ; + set(ARQ.getContext(), reg) ; } - public synchronized static FunctionRegistry get() + public static FunctionRegistry get() { // Intialize if there is no registry already set FunctionRegistry reg = get(ARQ.getContext()) ; if ( reg == null ) { - reg = standardRegistry() ; - set(ARQ.getContext(), reg) ; + Log.warn(FunctionRegistry.class, "Standard function registry should already have been initialized"); + init() ; + reg = get(ARQ.getContext()) ; } return reg ; http://git-wip-us.apache.org/repos/asf/jena/blob/afd4ed6b/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionRegistry.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionRegistry.java b/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionRegistry.java index c0f218c..d0f6fae 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionRegistry.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionRegistry.java @@ -17,19 +17,13 @@ */ package org.apache.jena.sparql.pfunction; -import java.util.HashMap ; -import java.util.HashSet ; -import java.util.Iterator ; -import java.util.Map ; -import java.util.Set ; +import java.util.* ; import org.apache.jena.atlas.logging.Log ; import org.apache.jena.query.ARQ ; import org.apache.jena.sparql.ARQConstants ; import org.apache.jena.sparql.util.Context ; import org.apache.jena.sparql.util.MappedLoader ; -import org.apache.jena.sparql.vocabulary.ListPFunction ; -import org.apache.jena.vocabulary.RDFS ; public class PropertyFunctionRegistry @@ -39,11 +33,17 @@ public class PropertyFunctionRegistry Map<String, PropertyFunctionFactory> registry = new HashMap<>() ; Set<String> attemptedLoads = new HashSet<>() ; - public synchronized static PropertyFunctionRegistry standardRegistry() + public static PropertyFunctionRegistry standardRegistry() { + PropertyFunctionRegistry reg = get(ARQ.getContext()) ; + return reg ; + } + + public static void init() { + // Intialize if there is no registry already set PropertyFunctionRegistry reg = new PropertyFunctionRegistry() ; - reg.loadStdDefs() ; - return reg ; + StandardPropertyFunctions.loadStdDefs(reg) ; + set(ARQ.getContext(), reg) ; } public static PropertyFunctionRegistry get(Context context) @@ -145,22 +145,4 @@ public class PropertyFunctionRegistry /** Iterate over URIs */ public Iterator<String> keys() { return registry.keySet().iterator() ; } - - @SuppressWarnings("deprecation") - private void loadStdDefs() - { - put(ListPFunction.member.getURI() , org.apache.jena.sparql.pfunction.library.listMember.class) ; - put(ListPFunction.index.getURI() , org.apache.jena.sparql.pfunction.library.listIndex.class) ; - put(ListPFunction.length.getURI() , org.apache.jena.sparql.pfunction.library.listLength.class) ; - put(ListPFunction.memberJ2.getURI() , org.apache.jena.sparql.pfunction.library.listMember.class) ; - put(ListPFunction.indexJ2.getURI() , org.apache.jena.sparql.pfunction.library.listIndex.class) ; - put(ListPFunction.lengthJ2.getURI() , org.apache.jena.sparql.pfunction.library.listLength.class) ; - - // (Very) old forms - put(ListPFunction.listMember.getURI() , org.apache.jena.sparql.pfunction.library.listMember.class) ; - put(ListPFunction.listIndex.getURI() , org.apache.jena.sparql.pfunction.library.listIndex.class) ; - put(ListPFunction.listLength.getURI() , org.apache.jena.sparql.pfunction.library.listLength.class) ; - - put(RDFS.member.getURI(), org.apache.jena.sparql.pfunction.library.container.class) ; - } } http://git-wip-us.apache.org/repos/asf/jena/blob/afd4ed6b/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/StandardPropertyFunctions.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/StandardPropertyFunctions.java b/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/StandardPropertyFunctions.java new file mode 100644 index 0000000..1ec7141 --- /dev/null +++ b/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/StandardPropertyFunctions.java @@ -0,0 +1,46 @@ +/* + * 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.jena.sparql.pfunction; + +import org.apache.jena.sparql.vocabulary.ListPFunction ; +import org.apache.jena.vocabulary.RDFS ; + +public class StandardPropertyFunctions { + @SuppressWarnings("deprecation") + public static void loadStdDefs(PropertyFunctionRegistry registry) { + add(registry, ListPFunction.member.getURI() , org.apache.jena.sparql.pfunction.library.listMember.class) ; + add(registry, ListPFunction.index.getURI() , org.apache.jena.sparql.pfunction.library.listIndex.class) ; + add(registry, ListPFunction.length.getURI() , org.apache.jena.sparql.pfunction.library.listLength.class) ; + add(registry, ListPFunction.memberJ2.getURI() , org.apache.jena.sparql.pfunction.library.listMember.class) ; + add(registry, ListPFunction.indexJ2.getURI() , org.apache.jena.sparql.pfunction.library.listIndex.class) ; + add(registry, ListPFunction.lengthJ2.getURI() , org.apache.jena.sparql.pfunction.library.listLength.class) ; + + // (Very) old forms + add(registry, ListPFunction.listMember.getURI() , org.apache.jena.sparql.pfunction.library.listMember.class) ; + add(registry, ListPFunction.listIndex.getURI() , org.apache.jena.sparql.pfunction.library.listIndex.class) ; + add(registry, ListPFunction.listLength.getURI() , org.apache.jena.sparql.pfunction.library.listLength.class) ; + + add(registry, RDFS.member.getURI(), org.apache.jena.sparql.pfunction.library.container.class) ; + } + + private static void add(PropertyFunctionRegistry registry, String uri, Class<?> funcClass) + { + registry.put(uri, funcClass) ; + } +}
