Package org.exist.xquery

Examples of org.exist.xquery.Module


     */
    private Module getModule(String name, String namespace, XQueryContext ctxt)
            throws XPathException {
        try {
            final Class clazz = Class.forName(name);
            final Module module = instantiateModule(clazz);
            final String ns = module.getNamespaceURI();
            if (!ns.equals(namespace)) {
                throw new XPathException("The namespace in the Java module " +
                    "does not match the namespace in the package descriptor: " +
                    namespace + " - " + ns);
            }
View Full Code Here


        Set<String> depSet = dependencies.get(xqueryUri);
        if(depSet == null) {
       
            final Iterator<Module> itModule = xqyCtx.getModules();
            while(itModule.hasNext()) {
                final Module module = itModule.next();
                if(module instanceof ExternalModule) {
                    final ExternalModule extModule = (ExternalModule)module;
                    final Source source = extModule.getSource();
                    if(source instanceof DBSource) {
                        final String moduleUri = getDbUri(source);
View Full Code Here

                // Get URI and class
                String        namespaceURI = entry.getKey();
                Class<Module> moduleClass  = entry.getValue();
               
                // first check if the module has already been loaded in the parent context
                Module        module       = getModule( namespaceURI );

                if( module == null ) {
                    // Module does not exist yet, instantiate
                    instantiateModule( namespaceURI, moduleClass,
                        (Map<String, Map<String, List<? extends Object>>>)
                        getBroker().getConfiguration().getProperty(PROPERTY_MODULE_PARAMETERS));

                } else if( ( getPrefixForURI( module.getNamespaceURI() ) == null )
                           && ( module.getDefaultPrefix().length() > 0 ) ) {

                    // make sure the namespaces of default modules are known,
                    // even if they were imported in a parent context
                    try {
                        declareNamespace( module.getDefaultPrefix(), module.getNamespaceURI() );
                       
                    } catch( XPathException e ) {
                        LOG.warn( "Internal error while loading default modules: " + e.getMessage(), e );
                    }
                }
View Full Code Here

    attribs.addAttribute("", "name", "name", "CDATA", qname.getStringValue());
    attribs.addAttribute("", "module", "module", "CDATA", uri);
    final int nodeNr = builder.startElement("", "function", "function", attribs);
   
    FunctionSignature signature;
    final Module module = context.getModule(uri);
    if(module != null) {
      final Iterator<FunctionSignature> i = module.getSignaturesForFunction(qname);
      while(i.hasNext()) {
        signature = i.next();
        writeSignature(signature, builder);
      }
    } else {
View Full Code Here

  public Sequence eval(Sequence[] args, Sequence contextSequence)
      throws XPathException {
   
    if("get-module-description".equals(getSignature().getName().getLocalName())) {
      final String uri = args[0].getStringValue();
      final Module module = context.getModule(uri);
      if(module == null)
        {throw new XPathException(this, "No module found matching namespace URI: " + uri);}
      return new StringValue(module.getDescription());
    } else if ("is-module-registered".equals(getSignature().getName().getLocalName())) {
      final String uri = args[0].getStringValue();
      final Module module = context.getModule(uri);
      return new BooleanValue(module != null);
        } else if ("mapped-modules".equals(getSignature().getName().getLocalName())) {
            final ValueSequence resultSeq = new ValueSequence();
            for (final Iterator<String> i = context.getMappedModuleURIs(); i.hasNext();) {
                resultSeq.add(new StringValue(i.next().toString()));
            }
            return resultSeq;
    } else if ("is-module-mapped".equals(getSignature().getName().getLocalName())) {
      final String uri = args[0].getStringValue();
      return new BooleanValue(((Map<String, String>)context.getBroker().getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP)).get(uri) != null);
    } else if ("map-module".equals(getSignature().getName().getLocalName())) {
      if (!context.getSubject().hasDbaRole()) {
        final XPathException xPathException = new XPathException(this, "Permission denied, calling user '" + context.getSubject().getName() + "' must be a DBA to call this function.");
        logger.error("Invalid user", xPathException);
        throw xPathException;
      }     
      final String namespace = args[0].getStringValue();
      final String location = args[1].getStringValue();
      final Map <String, String> moduleMap = (Map<String, String>)context.getBroker().getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP);
      moduleMap.put(namespace, location);
      return Sequence.EMPTY_SEQUENCE;
    } else if ("unmap-module".equals(getSignature().getName().getLocalName())) {
      if (!context.getSubject().hasDbaRole()) {
        final XPathException xPathException = new XPathException(this, "Permission denied, calling user '" + context.getSubject().getName() + "' must be a DBA to call this function.");
        logger.error("Invalid user", xPathException);
        throw xPathException;
      }     
      final String namespace = args[0].getStringValue();
      final Map <String, String> moduleMap = (Map<String, String>)context.getBroker().getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP);
      moduleMap.remove(namespace);
      return Sequence.EMPTY_SEQUENCE;
    } else if ("get-module-info".equals(getSignature().getName().getLocalName())) {
      context.pushDocumentContext();
     
      try {
        final MemTreeBuilder builder = context.getDocumentBuilder();
        builder.startElement(MODULES_QNAME, null);
       
        if (getArgumentCount() == 1) {
          final Module module = context.getModule(args[0].getStringValue());
          if (module != null)
            {outputModule(builder, module);}
        } else {
          for(final Iterator<Module> i = context.getRootModules(); i.hasNext(); ) {
            final Module module = i.next();
            outputModule(builder, module);
          }
        }
        return builder.getDocument().getNode(1);
      } finally {
        context.popDocumentContext();
      }
    } else {
      final ValueSequence resultSeq = new ValueSequence();
            final XQueryContext tempContext = new XQueryContext(context.getBroker().getBrokerPool(), AccessContext.XMLDB);
      for(final Iterator<Module> i = tempContext.getRootModules(); i.hasNext(); ) {
        final Module module = i.next();
        resultSeq.add(new StringValue(module.getNamespaceURI()));
      }
            for (final URI uri : tempContext.getRepository().getJavaModules()) {
                resultSeq.add(new StringValue(uri.toString()));
            }
      return resultSeq;
View Full Code Here

    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
       
        final QName functionName = ((QNameValue)args[0].itemAt(0)).getQName();
        final int arity = ((IntegerValue)args[1].itemAt(0)).getInt();
       
        final Module module = context.getModule(functionName.getNamespaceURI());
        boolean found = false;
        if(module == null) {
            found = context.resolveFunction(functionName, arity) != null;
        } else {
            if(module instanceof InternalModule) {
View Full Code Here

            }
            funcName = funcName.substring(0, p);
        }
        try {
            final QName fqn = QName.parse(context, funcName);
            final Module module = context.getModule(fqn.getNamespaceURI());
            UserDefinedFunction func = null;
            if (module != null)
                {func = ((ExternalModule)module).getFunction(fqn, arity, context);}
            else
                {func = context.resolveFunction(fqn, arity);}
View Full Code Here

    context.saveState();
   
    final String uri = args[0].getStringValue();
    final String prefix = args[1].getStringValue();
    final String location = args[2].getStringValue();
    final Module module = context.importModule(uri, prefix, location);

    context.getRootContext().resolveForwardReferences();

    if( !module.isInternalModule() ) {
          ((ExternalModule)module).getRootExpression().analyze( new AnalyzeContextInfo() );
        }
   
//    context.getRootContext().analyzeAndOptimizeIfModulesChanged((PathExpr) context.getRootExpression());
  }
View Full Code Here

  *  not a library module.
  */
  public RequestCtx createFunctionRequest(XQueryContext context, Module contextModule, QName functionName)
  {
    final String namespaceURI = functionName.getNamespaceURI();
    final Module functionModule = context.getModule(namespaceURI);
    if(functionModule == null)
    {
      //main module, not a library module, so access to function is always allowed
      return null;
    }
View Full Code Here

TOP

Related Classes of org.exist.xquery.Module

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.