Package com.dbxml.db.core.query

Examples of com.dbxml.db.core.query.CompilationException


         boolean hasDocName = docName != null && docName.length() > 0;
         boolean hasXpath = xpath != null && xpath.length() > 0;

         if ( hasDocName && hasXpath )
            throw new CompilationException("'document' and 'xpath' attributes are mutually exclusive");
         else if ( hasDocName ) {
            Document doc = null;
            try {
               doc = domAdapter.getDocument(tx, docName);
            }
            catch ( DBException e ) {
               // Null is ok
            }

            if ( doc != null ) {
               try {
                  String path = context.getCanonicalDocumentName(new Key(docName));
                  String systemID = XSLTQueryResolver.URL_PREFIX + path;
                  src = new DOMSource(doc, systemID);
               }
               catch ( Exception e ) {
                  // This shouldn't happen
               }
            }
            else
               throw new CompilationException("Document '" + docName + "' not found");
         }
         else if ( hasXpath ) {
            ResultSet rs;
            if ( keys != null )
               rs = context.queryDocument(tx, XPathQueryResolver.STYLE_XPATH, xpath, nsMap, keys);
            else
               rs = context.queryCollection(tx, XPathQueryResolver.STYLE_XPATH, xpath, nsMap);

            Document doc = ResultSetWrapper.toDocument(rs);
            String path = context.getCanonicalName();
            String systemID = XSLTQueryResolver.URL_PREFIX+path+"/";
            src = new DOMSource(doc, systemID);
         }
         else {
            NodeList nl = sourceElem.getChildNodes();
            Element e = null;
            for ( int i = 0; i < nl.getLength(); i++ ) {
               Node n = nl.item(i);
               if ( n.getNodeType() == Node.ELEMENT_NODE ) {
                  if ( e == null )
                     e = (Element)n;
                  else
                     throw new CompilationException("Only a single Element is allowed for inline source");
               }
            }
            String path = context.getCanonicalName();
            String systemID = XSLTQueryResolver.URL_PREFIX+path+"/";
            src = new DOMSource(e, systemID);
         }
      }
      catch ( DBException e ) {
         try {
            tx.cancel();
         }
         catch ( DBException ex ) {
            ex.printStackTrace(System.err);
         }

         if ( e instanceof QueryException )
            throw (QueryException)e;
         else
            throw new CompilationException(e);
      }
      finally {
         if ( tx.getStatus() == Transaction.ACTIVE ) {
            try {
               tx.commit();
View Full Code Here


               String name = p.getAttribute(NAME);
               String value = p.getAttribute(VALUE);
               params.put(name, value);
            }
            else
               throw new CompilationException("Unknown Tag '" + tagName + "'");
         }
         else
            throw new CompilationException("Invalid Namespace '" + p.getNamespaceURI() + "'");
      }
   }
View Full Code Here

            Node n = nl.item(i);
            if ( n.getNodeType() == Node.ELEMENT_NODE ) {
               if ( elem == null )
                  elem = (Element)n;
               else
                  throw new CompilationException("Only a single Element is allowed for inline styles");
            }
         }

         if ( elem != null ) {
            String path = context.getCanonicalName();
            String systemID = XSLTQueryResolver.URL_PREFIX+path+"/";
            Source ds = new DOMSource(elem, systemID);
            transformer = resolver.getTransformer(ds);
         }
         else
            throw new CompilationException("'document' attribute or inline styles required");
      }
   }
View Full Code Here

      }
      catch ( Exception e ) {
         if ( e instanceof QueryException )
            throw (QueryException)e;
         else
            throw new CompilationException("Couldn't compile XSLT Query", e);
      }
   }
View Full Code Here

      String docName = path.substring(idx + 1);

      try {
         CollectionClientImpl col = (CollectionClientImpl)client.getCollection(colName);
         if ( col == null )
            throw new CompilationException("Template Collection '" + colName + "' not found");

         RecordMetaData meta = col.getInternalCollection().getRecordMetaData(tx, new Key(docName));
         long lastModified = System.currentTimeMillis();
         if ( meta != null ) {
            Long lm = (Long)meta.getValue(RecordMetaData.MODIFIED);
            if ( lm != null )
               lastModified = lm.longValue();
         }

         TemplatesInfo info = (TemplatesInfo)cache.get(path);
         if ( info == null || info.lastModified != lastModified ) {
            Document doc = col.getDocument(docName);
            String systemID = URL_PREFIX+colName+"/"+docName;
            Source src = new DOMSource(doc, systemID);
            Templates t = tf.newTemplates(src);

            info = new TemplatesInfo(path, lastModified, t);
            cache.put(path, info);
         }

         Transformer transformer = info.tmp.newTransformer();
         transformer.setURIResolver(uriResolver);
         return transformer;
      }
      catch ( Exception e ) {
         try {
            tx.cancel();
         }
         catch ( DBException ex ) {
            ex.printStackTrace(System.err);
         }

         if ( e instanceof QueryException )
            throw (QueryException)e;
         else
            throw new CompilationException("Couldn't compile XSLT Query", e);
      }
      finally {
         if ( tx.getStatus() == Transaction.ACTIVE ) {
            try {
               tx.commit();
View Full Code Here

                  else if ( tagName.equals(PARAMS) )
                     processParams(e);
                  else if ( tagName.equals(STYLESHEET) )
                     processStyles(e);
                  else
                     throw new CompilationException("Unknown Tag '" + tagName + "'");
               }
               else
                  throw new CompilationException("Invalid Namespace '" + e.getNamespaceURI() + "'");
            }
         }
      }
      catch ( Exception e ) {
         throw new CompilationException("Error Parsing XSLT Query", e);
      }

      if ( transformer == null || src == null )
         throw new CompilationException("Unknown Error Compiling XSLT Templates");

      Iterator iter = params.entrySet().iterator();
      while ( iter.hasNext() ) {
         Map.Entry entry = (Map.Entry)iter.next();
         String name = (String)entry.getKey();
View Full Code Here

      try {
         xu = new XUpdateImpl();
         xu.setQString(query);
      }
      catch ( Exception e ) {
         throw new CompilationException("Error Compiling XUpdate Query", e);
      }
   }
View Full Code Here

TOP

Related Classes of com.dbxml.db.core.query.CompilationException

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.