1 5 6 package org.joseki.server; 7 8 import java.util.* ; 9 10 import org.joseki.vocabulary.*; 11 12 import com.hp.hpl.jena.rdf.model.* ; 13 14 19 20 public class ProcessorRegistry 21 { 22 QueryOperationRegistry queryRegistry = new QueryOperationRegistry() ; 23 OperationRegistry operationRegistry = new OperationRegistry() ; 24 25 Set processorURIs = new HashSet() ; 26 Set queryLanguageURIs = new HashSet() ; 27 28 public boolean hasProcessor(String opName) 29 { 30 return findProcessor( opName) != null ; 31 } 32 33 public boolean hasQueryProcessor(String queryLanguageName) 34 { 35 return findQueryProcessor(queryLanguageName) != null ; 36 } 37 38 39 public Processor findProcessor(String opName) 40 { 41 return operationRegistry.findProcessor(opName) ; 42 } 43 44 45 public QueryProcessor findQueryProcessor(String queryLanguageName) 46 { 47 return queryRegistry.findProcessor(queryLanguageName) ; 48 } 49 50 51 public void registerProcessor(String shortName, Processor processor) 52 { 53 operationRegistry.register(shortName, processor) ; 54 processorURIs.add(processor.getInterfaceURI()) ; 55 } 56 57 public void registerQueryProcessor(String langName, QueryProcessor queryProcessor) 58 { 59 queryRegistry.register(langName, queryProcessor) ; 60 queryLanguageURIs.add(queryProcessor.getInterfaceURI()) ; 61 } 62 63 public void remove(Processor processor) 64 { 65 operationRegistry.remove(processor) ; 66 } 67 68 public void remove(QueryProcessor queryProcessor) 69 { 70 queryRegistry.remove(queryProcessor) ; 71 } 72 73 76 78 79 public void toRDF(Model optModel, Resource optionRes) throws RDFException 80 { 81 Map processors = operationRegistry.procRegistry ; 82 for ( Iterator iter = processors.keySet().iterator() ; iter.hasNext() ; ) 83 { 84 String name = (String )iter.next() ; 85 Processor proc = (Processor)processors.get(name) ; 86 Resource r = optModel.createResource() ; 87 r.addProperty(JosekiVocab.operationName, name) ; 88 Resource opRes = optModel.createResource(proc.getInterfaceURI()) ; 89 r.addProperty(JosekiVocab.operation, opRes) ; 90 optModel.add(optionRes, JosekiVocab.hasOperation, r) ; 91 } 92 93 Map queryLanguages = queryRegistry.procRegistry ; 95 for ( Iterator iter = queryLanguages.keySet().iterator() ; iter.hasNext() ; ) 96 { 97 String qlName = (String )iter.next() ; 98 QueryProcessor qproc = (QueryProcessor)queryLanguages.get(qlName) ; 99 Resource r = optModel.createResource() ; 100 r.addProperty(JosekiVocab.queryOperationName, qlName) ; 101 Resource qRes = optModel.createResource(qproc.getInterfaceURI()) ; 102 r.addProperty(JosekiVocab.queryOperation, qRes) ; 103 optModel.add(optionRes, JosekiVocab.hasQueryOperation, r) ; 104 } 105 106 } 107 108 112 static class OperationRegistry 113 { 114 Map procRegistry = new HashMap() ; 116 117 void register(String shortName, Processor processor) 118 { 119 procRegistry.put(shortName, processor) ; 120 } 121 122 Processor findProcessor(String opName) 123 { 124 Processor proc = (Processor)procRegistry.get(opName) ; 125 return proc ; 126 } 127 128 129 130 void remove(Processor processor) 131 { 132 for ( Iterator iter = procRegistry.entrySet().iterator() ; iter.hasNext() ; ) 133 { 134 Map.Entry entry = (Map.Entry)iter.next() ; 135 Processor proc = (Processor)entry.getValue() ; 136 137 if ( processor.equals(proc) ) 138 iter.remove() ; 139 } 140 } 141 } 142 143 static class QueryOperationRegistry 144 { 145 Map procRegistry = new HashMap() ; 147 148 void register(String languageName, QueryProcessor queryPprocessor) 149 { 150 procRegistry.put(languageName, queryPprocessor) ; 151 } 152 153 QueryProcessor findProcessor(String languageName) 154 { 155 QueryProcessor proc = (QueryProcessor)procRegistry.get(languageName) ; 156 return proc ; 157 } 158 159 160 161 void remove(QueryProcessor queryProcessor) 162 { 163 for ( Iterator iter = procRegistry.entrySet().iterator() ; iter.hasNext() ; ) 164 { 165 Map.Entry entry = (Map.Entry)iter.next() ; 166 QueryProcessor qProc = (QueryProcessor)entry.getValue() ; 167 168 if ( queryProcessor.equals(qProc) ) 169 iter.remove() ; 170 } 171 } 172 } 173 } 174 175 201 | Popular Tags |