Пример #1
0
  /**
   * Adds the specified resource to the protection space specified by the given realm. All resources
   * at or deeper than the depth of the last symbolic element in the path of the given resource URL
   * are assumed to be in the same protection space.
   *
   * @param resourceUrl the URL identifying the resources to be added to the specified protection
   *     space. For example, "http://www.hostname.com/folder/".
   * @param realm the name of the protection space. For example, "*****@*****.**"
   */
  public void addProtectionSpace(URL resourceUrl, String realm) {
    Assert.isNotNull(resourceUrl);
    Assert.isNotNull(realm);

    if (!resourceUrl.getFile().endsWith("/")) { // $NON-NLS-1$
      resourceUrl = URLTool.getParent(resourceUrl);
    }

    String oldRealm = getProtectionSpace(resourceUrl);
    if (oldRealm != null && oldRealm.equals(realm)) {
      return;
    }

    String url1 = resourceUrl.toString();
    Enumeration urls = protectionSpace.keys();
    while (urls.hasMoreElements()) {
      String url2 = (String) urls.nextElement();
      if (url1.startsWith(url2) || url2.startsWith(url1)) {
        protectionSpace.remove(url2);
        break;
      }
    }

    protectionSpace.put(url1, realm);
    needsSaving = true;
  }
Пример #2
0
 /**
  * Creates a new authorization database, or opens an existing one, whose data is, or can be, saved
  * to a file with the given filename. A password must be given to create a new database and an
  * existing database is opened by supplying the password that was given to create it.
  *
  * @param filename the location of the database on disk. For example, "c:/temp/database"
  * @param password the password to access the database. For example, "secret"
  * @exception CoreException if there are problems creating the database. Reasons include:
  *     <ul>
  *       <li>The database could not be opened because the wrong password was given.
  *       <li>The database could not be opened because the specified file is corrupt.
  *     </ul>
  */
 public AuthorizationDatabase(String filename, String password) throws CoreException {
   Assert.isNotNull(filename);
   Assert.isNotNull(password);
   this.password = password;
   file = new File(filename);
   load();
 }
  /**
   * Create a job to refresh the specified resources with the subscriber.
   *
   * @param participant the subscriber participant
   * @param jobName
   * @param taskName
   * @param listener
   */
  public RefreshParticipantJob(
      ISynchronizeParticipant participant,
      String jobName,
      String taskName,
      IRefreshSubscriberListener listener) {
    super(jobName);
    Assert.isNotNull(participant);
    this.participant = participant;
    this.taskName = taskName;
    setPriority(Job.DECORATE);
    setRefreshInterval(3600 /* 1 hour */);

    // Handle restarting of job if it is configured as a scheduled refresh job.
    addJobChangeListener(
        new JobChangeAdapter() {
          @Override
          public void done(IJobChangeEvent event) {
            if (shouldReschedule()) {
              IStatus result = event.getResult();
              if (result.getSeverity() == IStatus.CANCEL && !restartOnCancel) {
                return;
              }
              long delay = scheduleDelay;
              if (result == POSTPONED) {
                // Restart in 5 seconds
                delay = 5000;
              }
              RefreshParticipantJob.this.schedule(delay);
              restartOnCancel = true;
            }
          }
        });
    if (listener != null) initialize(listener);
  }
Пример #4
0
 @Override
 public void appendContents(InputStream content, int updateFlags, IProgressMonitor monitor)
     throws CoreException {
   monitor = Policy.monitorFor(monitor);
   try {
     String message = NLS.bind(Messages.resources_settingContents, getFullPath());
     monitor.beginTask(message, Policy.totalWork);
     Assert.isNotNull(content, "Content cannot be null."); // $NON-NLS-1$
     if (workspace.shouldValidate) workspace.validateSave(this);
     final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
     try {
       workspace.prepareOperation(rule, monitor);
       ResourceInfo info = getResourceInfo(false, false);
       checkAccessible(getFlags(info));
       workspace.beginOperation(true);
       IFileInfo fileInfo = getStore().fetchInfo();
       internalSetContents(
           content, fileInfo, updateFlags, true, Policy.subMonitorFor(monitor, Policy.opWork));
     } catch (OperationCanceledException e) {
       workspace.getWorkManager().operationCanceled();
       throw e;
     } finally {
       workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
     }
   } finally {
     monitor.done();
     FileUtil.safeClose(content);
   }
 }
  protected void assertRetrievedItem(Object obj) throws Exception {
    ArrayList item = (ArrayList) obj;
    IntItem intItem = (IntItem) item.get(0);
    TAIntItem taIntItem = (TAIntItem) item.get(1);

    Assert.isNotNull(intItem);
    Assert.isNotNull(taIntItem);

    Assert.areEqual(100, intItem.value);
    Assert.areEqual(new Integer(200), intItem.i);
    Assert.areEqual(new Integer(300), intItem.obj);

    Assert.areEqual(0, taIntItem.value);
    isPrimitiveNull(taIntItem.i);
    Assert.isNull(taIntItem.obj);
  }
Пример #6
0
  private void assertHandlerComparison(Comparable4 handler, Object smaller, Object greater) {
    PreparedComparison comparable = handler.prepareComparison(context(), smaller);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(smaller));
    Assert.isSmaller(0, comparable.compareTo(greater));
    Assert.isGreater(0, comparable.compareTo(null));

    comparable = handler.prepareComparison(context(), greater);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(greater));
    Assert.isGreater(0, comparable.compareTo(smaller));
    Assert.isGreater(0, comparable.compareTo(null));

    comparable = handler.prepareComparison(context(), null);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(null));
    Assert.isSmaller(0, comparable.compareTo(smaller));
  }
Пример #7
0
 public static void waitForImage(Component component, Image image) {
   MediaTracker tracker = new MediaTracker(component);
   try {
     tracker.addImage(image, 0);
     tracker.waitForID(0);
   } catch (InterruptedException e) {
     Assert.isNotNull(null);
   }
 }
Пример #8
0
 private void peek(Item original, int depth) {
   Item peeked = (Item) db().peekPersisted(original, depth, true);
   for (int i = 0; i <= depth; i++) {
     Assert.isNotNull(peeked, "Failed to peek at child " + i + " at depth " + depth);
     Assert.isFalse(db().isStored(peeked));
     peeked = peeked.child;
   }
   Assert.isNull(peeked);
 }
Пример #9
0
  public void testDeactivateDepth() throws Exception {
    TALinkedListItem item = (TALinkedListItem) retrieveOnlyInstance();
    TALinkedList list = item.list();
    TALinkedList next3 = list.nextN(3);
    TALinkedList next5 = list.nextN(5);

    Assert.isNotNull(next3.next());
    Assert.isNotNull(next5.next());

    db().deactivate(list, 4);

    Assert.isNull(list.next);
    Assert.areEqual(0, list.value);

    // FIXME: test fails if uncomenting the following assertion.
    //	    	Assert.isNull(next3.next);
    Assert.isNotNull(next5.next);
  }
Пример #10
0
  void internalSetContentDescription(String description) {
    Assert.isNotNull(description);

    // Do not send changes if they are the same
    if (Util.equals(contentDescription, description)) {
      return;
    }
    this.contentDescription = description;

    firePropertyChange(IWorkbenchPartConstants.PROP_CONTENT_DESCRIPTION);
  }
  public void setRules(IndentationRule[] rules) {
    Assert.isNotNull(rules);

    clear();
    for (int index = 0; index < rules.length; index++) {
      IndentationRule scheme = rules[index];
      if (scheme != null) {
        addIndentationRule(scheme);
      }
    }
  }
Пример #12
0
 public static void areEqual(Iterator expected, Iterator actual) {
   if (null == expected) {
     Assert.isNull(actual);
     return;
   }
   Assert.isNotNull(actual);
   while (expected.hasNext()) {
     Assert.isTrue(actual.hasNext());
     Assert.areEqual(expected.next(), actual.next());
   }
   Assert.isFalse(actual.hasNext());
 }
Пример #13
0
 public void testQuery() {
   ExtObjectContainer oc = fixture().db();
   initGenericObjects();
   ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
   Assert.isNotNull(rc);
   // now query to make sure there are none left
   Query q = oc.query();
   q.constrain(rc);
   q.descend("surname").constrain("John");
   ObjectSet results = q.execute();
   Assert.isTrue(results.size() == 1);
 }
Пример #14
0
 public void testUpdate() {
   ExtObjectContainer oc = fixture().db();
   initGenericObjects();
   // Db4oUtil.dump(oc);
   ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
   Assert.isNotNull(rc);
   Query q = oc.query();
   q.constrain(rc);
   ObjectSet results = q.execute();
   // Db4oUtil.dumpResults(oc, results);
   Assert.isTrue(results.size() == 1);
 }
Пример #15
0
  void internalSetPartName(String partName) {
    partName = Util.safeString(partName);

    Assert.isNotNull(partName);

    // Do not send changes if they are the same
    if (Util.equals(this.partName, partName)) {
      return;
    }
    this.partName = partName;

    firePropertyChange(IWorkbenchPartConstants.PROP_PART_NAME);
  }
Пример #16
0
  /**
   * Adds the given authorization information to the database. The information is relevant for the
   * specified protection space and the given authorization scheme. The protection space is defined
   * by the combination of the given server URL and realm. The authorization scheme determines what
   * the authorization information contains and how it should be used. The authorization information
   * is a <code>Map</code> of <code>String</code> to <code>String</code> and typically contain
   * information such as usernames and passwords.
   *
   * @param serverUrl the URL identifying the server for this authorization information. For
   *     example, "http://www.hostname.com/".
   * @param realm the subsection of the given server to which this authorization information
   *     applies. For example, "*****@*****.**" or "" for no realm.
   * @param authScheme the scheme for which this authorization information applies. For example,
   *     "Basic" or "" for no authorization scheme
   * @param info a <code>Map</code> containing authorization information such as usernames and
   *     passwords
   */
  public void addAuthorizationInfo(URL serverUrl, String realm, String authScheme, Map info) {
    Assert.isNotNull(serverUrl);
    Assert.isNotNull(realm);
    Assert.isNotNull(authScheme);
    Assert.isNotNull(info);

    String url = serverUrl.toString();
    Hashtable realmToAuthScheme = (Hashtable) authorizationInfo.get(url);
    if (realmToAuthScheme == null) {
      realmToAuthScheme = new Hashtable(5);
      authorizationInfo.put(url, realmToAuthScheme);
    }

    Hashtable authSchemeToInfo = (Hashtable) realmToAuthScheme.get(realm);
    if (authSchemeToInfo == null) {
      authSchemeToInfo = new Hashtable(5);
      realmToAuthScheme.put(realm, authSchemeToInfo);
    }

    authSchemeToInfo.put(authScheme.toLowerCase(), info);
    needsSaving = true;
  }
Пример #17
0
  public void testCreate() throws Exception {

    initGenericObjects();
    // fixture().reopen();
    ExtObjectContainer oc = fixture().db();
    // now check to see if person was saved
    ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
    Assert.isNotNull(rc);
    Query q = oc.query();
    q.constrain(rc);
    ObjectSet results = q.execute();
    Assert.isTrue(results.size() == 1);
    // Db4oUtil.dumpResults(fixture().db(), results);

  }
Пример #18
0
  /**
   * Checks whether the given move included is vaild
   *
   * @param destination
   * @return a staus indicating whether the included is valid or not
   */
  public RefactoringStatus verifyDestination(IResource destination) {
    RefactoringStatus status = new RefactoringStatus();

    Assert.isNotNull(destination);
    if (!destination.exists() || destination.isPhantom())
      return RefactoringStatus.createFatalErrorStatus(
          PhpRefactoringCoreMessages.getString("MoveDelegate.2")); // $NON-NLS-1$
    if (!destination.isAccessible())
      return RefactoringStatus.createFatalErrorStatus(
          PhpRefactoringCoreMessages.getString("MoveDelegate.3")); // $NON-NLS-1$
    Assert.isTrue(destination.getType() != IResource.ROOT);

    IResource[] sourceResources = fProcessor.getSourceSelection();
    for (IResource element : sourceResources) {
      if (destination.equals(element.getParent()))
        return RefactoringStatus.createFatalErrorStatus(
            PhpRefactoringCoreMessages.getString("MoveDelegate.4")); // $NON-NLS-1$
      if (destination.equals(element)) {
        return RefactoringStatus.createFatalErrorStatus(
            PhpRefactoringCoreMessages.getString("MoveDelegate.5")); // $NON-NLS-1$
      }
    }
    return status;
  }
Пример #19
0
 private void assertData() {
   Holder holder = (Holder) retrieveOnlyInstance(Holder.class);
   Assert.isNotNull(holder._item);
   Assert.areEqual(NAME, holder._item._name);
 }
 /* (non-Javadoc)
  * @see Job#setProgressGroup(IProgressMonitor, int)
  */
 protected void setProgressGroup(IProgressMonitor group, int ticks) {
   Assert.isNotNull(group);
   IProgressMonitor pm = manager.createMonitor(this, group, ticks);
   if (pm != null) setProgressMonitor(pm);
 }
 /* (non-Javadoc)
  * @see Job#setName(String)
  */
 protected void setName(String name) {
   Assert.isNotNull(name);
   this.name = name;
 }
 protected InternalJob(String name) {
   Assert.isNotNull(name);
   this.name = name;
 }
Пример #23
0
 public void testAccessingBTree() throws Exception {
   BTree bTree = storedField().getIndex(trans());
   Assert.isNotNull(bTree);
   expectKeysSearch(bTree, FOOS);
 }
 public void test() {
   Assert.isNotNull(db());
   Assert.isNotNull(values);
 }