Package org.dbwiki.exception.data

Examples of org.dbwiki.exception.data.WikiDataException


        targetElement = targetNode.parent();
      } else {
        targetElement = (DatabaseElementNode)targetNode;
      }
    } else if (!pasteNode.isElement()) {
      throw new WikiDataException(WikiDataException.InvalidPasteTarget, target.toParameterString());
    }
   
    if (pasteNode.isElement()) {
      if (targetElement != null) {
        if (!targetElement.isGroup()) {
          throw new WikiDataException(WikiDataException.InvalidPasteTarget, target.toParameterString());
        }
      }
      Connection con = _connector.getConnection();     
      try {
        SQLDatabaseSchema schema = new SQLDatabaseSchema(con, _versionIndex, _wiki.name());
        DocumentNode insertNode = null;
        if (targetElement != null) {
          // FIXME #copypaste: This code looks unnecessarily complicated
          // Isn't:
          //
          //   (GroupSchemaNode)schema.get(targetElement.schema().id())
          //
          // entirely equivalent to:
          //
          //   (GroupSchemaNode)targetElement.schema()
          //
          // ?
          insertNode = getPasteInsertNode((GroupSchemaNode)schema.get(targetElement.schema().id()), (PasteElementNode)pasteNode, schema);
        } else {
          insertNode = getPasteInsertNode(null, (PasteElementNode)pasteNode, schema);
        }
        if (insertNode != null) {
          Version version = _versionIndex.getNextVersion(new ProvenanceCopy(user, target, sourceURL));
          try {
            con.setAutoCommit(false);
            try {
              if (target.isRootIdentifier()) {
                new DatabaseWriter(con, this).insertRootNode((DocumentGroupNode)insertNode, version);     
              } else {
                new DatabaseWriter(con, this).insertNode((NodeIdentifier)target, insertNode, version);
              }
              for (int i = schema().size(); i < schema.size(); i++) {
                new DatabaseWriter(con, this).insertSchemaNode(schema.get(i), version);
              }
              _versionIndex.add(version);
              _versionIndex.store(con);
            } catch (org.dbwiki.exception.WikiException wikiException) {
              con.rollback();
              con.close();
              throw wikiException;
            }
            con.commit();
            con.close();
          } catch (java.sql.SQLException sqlException) {
            throw new WikiFatalException(sqlException);
          }
          _schema = schema;
        }
      } catch (java.sql.SQLException sqlException) {
        throw new WikiFatalException(sqlException);
      }
    } else {
      // targetElement should be nonnull
      assert(targetElement != null);
      if (!targetElement.isAttribute()) {
        throw new WikiDataException(WikiDataException.InvalidPasteTarget, target.toParameterString());
      }
      Update update = new Update();
      update.add(new NodeUpdate(targetElement.identifier(), ((PasteTextNode)pasteNode).getValue()));
      updateNodeWrapped(targetElement, update, _versionIndex.getNextVersion(new ProvenanceCopy(user, targetElement.identifier(), sourceURL)));
    }
View Full Code Here


          } else {
            schemaNode = new GroupSchemaNode(schema.size(), sourceNode.label(), parentSchemaNode, null);
          }
          schema.add(schemaNode);
        } else if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesNever) {
          throw new WikiDataException(WikiDataException.UnknownSchemaNode, sourceNode.label() + " not allowed under " + parentSchemaNode.label());
        }
      }
    } else if (schema.root() != null) {
      schemaNode = schema.root();
      if (!schemaNode.label().equals(sourceNode.label())) {
        throw new WikiDataException(WikiDataException.InvalidPasteTarget, "Node label does not match root label");
      }
    } else {
      if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesAllow) {
        schemaNode = new GroupSchemaNode(schema.size(), sourceNode.label(), null, null);
        schema.add(schemaNode);
      } else if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesNever) {
        throw new WikiDataException(WikiDataException.UnknownSchemaNode, sourceNode.label() + " not allowed as schema root");
      }
    }
   
    if (schemaNode != null) {
      if (schemaNode.isAttribute()) {
View Full Code Here

      int pos = entryIdentifier.indexOf(':');
      if (pos != -1) {
        if (entryIdentifier.substring(0, pos).equals(root.label())) {
          entryIdentifier = entryIdentifier.substring(pos + 1);
        } else {
          throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
        }
      }
      DatabaseEntry entry = database.content().get(entryIdentifier);
      if (entry != null) {
        if (url.size() > 1) {
          return this.decode(database, (DatabaseGroupNode)database.get(entry.identifier()), versionParameter, url, 1);
        } else {
          return entry.identifier();
        }
      } else {
        throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
      }
    } else {
      throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
    }
  }
View Full Code Here

        SchemaNode childSchema = schemaNode.children().get(iChild);
        if ((childSchema.label().equals(nodeIdentifier)) && (childSchema.isAttribute())) {
          // Make sure that there is only one child
          DatabaseElementList nodes = node.find(childSchema.path().substring(node.schema().path().length() + 1));
          if (nodes.size() > 1) {
            throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
          } else if (nodes.size() == 1) {
            if (pathIndex == (url.size() - 1)) {
              return nodes.get(0).identifier();
            } else {
              return this.decode(database, (DatabaseGroupNode)nodes.get(0), versionParameter, url, pathIndex + 1);
            }
          } else {
            throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
          }
        }
      }
      // This part of the code is only reached if the nodeIdentifier does not point
      // to an attribute node. There should only be one schema node child with a rule defined
      // for that node.
      for (int iChild = 0; iChild < schemaNode.children().size(); iChild++) {
        URLDecodingRule childRule = this.get(schemaNode.children().get(iChild));
        if (childRule != null) {
          if (rule == null) {
            rule = childRule;
          } else {
            throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
          }
        }
      }
    }

    if (rule != null) {
      DatabaseElementList nodes = node.find(rule.node().path().substring(node.schema().path().length() + 1));
      DatabaseGroupNode nextNode = null;
      for (int iNode = 0; iNode < nodes.size(); iNode++) {
        DatabaseGroupNode childNode = (DatabaseGroupNode)nodes.get(iNode);
        if (versionParameter.matches(childNode)) {
          int matches = 0;
          DatabaseElementList valueNodes = childNode.find(rule.value().path().substring(childNode.schema().path().length() + 1));
          for (int iValueNode = 0; iValueNode < valueNodes.size(); iValueNode++) {
            DatabaseAttributeNode attributeNode = (DatabaseAttributeNode)valueNodes.get(iValueNode);
            for (int iAttrValue = 0; iAttrValue < attributeNode.value().size(); iAttrValue++) {
              DatabaseTextNode textNode = attributeNode.value().get(iAttrValue);
              if ((versionParameter.matches(textNode)) && (textNode.value().equals(keyValue))) {
                matches++;
                break;
              }
            }
          }
          if (matches == 1) {
            if (nextNode == null) {
              nextNode = childNode;
            } else {
              throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
            }
          }
        }
      }
      if (nextNode != null) {
        if (pathIndex == (url.size() - 1)) {
          return nextNode.identifier();
        } else {
          return this.decode(database, nextNode, versionParameter, url, pathIndex + 1);
        }
      } else {
        throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
      }
    } else {
      throw new WikiDataException(WikiDataException.UnknownResource, url.toString());
    }
   
  }
View Full Code Here

TOP

Related Classes of org.dbwiki.exception.data.WikiDataException

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.