*/existingResults) {
+ if (existingResults == null)
+ return;
+ synchronized (results) {
+ for (Iterator i = existingResults.iterator(); i.hasNext();) {
+ add((IResult) i.next());
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.ui.presence.search.IResultList#getEntries()
+ */
+ public Collection geResults() {
+ return results;
+ }
+
+ public boolean remove(IResult item) {
+ return results.remove(item);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.ui.presence.search.IResultList#getResult
+ */
+ public IResult getResult(String field, String value) {
+ // TODO
+ return null;
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (adapter.isInstance(this)) {
+ return this;
+ }
+ IAdapterManager adapterManager = PresencePlugin.getDefault().getAdapterManager();
+ if (adapterManager == null)
+ return null;
+ return adapterManager.loadAdapter(this, adapter.getName());
+ }
+
+}
Index: src/org/eclipse/ecf/presence/search/ICriteria.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/ICriteria.java
diff -N src/org/eclipse/ecf/presence/search/ICriteria.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/ICriteria.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+
+package org.eclipse.ecf.presence.search;
+
+import java.util.List;
+
+/**
+ * Criteria helps for retrieving results from the provider search by composing Criterion objects.
+ * The {@link IUserSearchManager} is a factory for Criteria. Criterion instances are obtained via ISelection methods.
+ * Criteria can deal with different kind of criterion, as logical or just simple expression.
+ *
+ * The typical usage of the Criteria is as
+ * follows:
+ *
+ *
+ * ISelection selection = ...
+ * ICriterion name = selection.eq("name", "value");
+ * ICriterion host = selection.eq("host", "value");
+ * ICriterion and = selection.and(name, host);
+ * ICriteria criteria = ...
+ * criteria.add(and);
+ *
+ *
+ * @since 3.0
+ */
+public interface ICriteria {
+
+ /**
+ * Add a criterion that composes the criteria
+ * @param criterion
+ */
+ public void add(ICriterion criterion);
+
+ /**
+ * A list of all criterion added to the criteria
+ * @return List of {@link ICriterion}
+ */
+ public List getCriterions();
+
+ /**
+ * Notify if there is or not criterion added for this criteria
+ * @return indicate if there are or not criterion
+ */
+ public boolean isEmpty();
+
+}
Index: src/org/eclipse/ecf/presence/search/LogicalCriterion.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/LogicalCriterion.java
diff -N src/org/eclipse/ecf/presence/search/LogicalCriterion.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/LogicalCriterion.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+/**
+ * Base class implementation of {@link ICriterion} for logical criterion.
+ * Subclasses may be created as appropriate. It is just a simple
+ * implementation that can be considered for some provider or even used
+ * as base for some implementation.
+ * @since 3.0
+ */
+public class LogicalCriterion implements ICriterion {
+
+ final ICriterion left;
+ final ICriterion right;
+ final String operator;
+
+ /**
+ * Creates a logic operation for compose a {@link ICrteria}
+ * @param left Criterion on the left side of the expression
+ * @param right Criterion on the right side of the expression
+ * @param operator Operator considered on the logical. Ex: And
+ */
+ public LogicalCriterion(ICriterion left, ICriterion right, String operator) {
+ this.left = left;
+ this.right = right;
+ this.operator = operator;
+ }
+
+ public String toExpression() {
+ return left.toExpression() + ' ' + operator + ' ' + right.toExpression();
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("LogicalCriterion["); //$NON-NLS-1$
+ sb.append("left=").append(left).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append("right=").append(right).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append("operator=").append(operator).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return sb.toString();
+ }
+
+}
Index: src/org/eclipse/ecf/presence/search/IUserSearchManager.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/IUserSearchManager.java
diff -N src/org/eclipse/ecf/presence/search/IUserSearchManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/IUserSearchManager.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+
+package org.eclipse.ecf.presence.search;
+
+import org.eclipse.ecf.core.ContainerConnectException;
+
+/**
+ * Get a search mechanism for an account.
+ * @since 3.0
+ */
+public interface IUserSearchManager {
+
+ /**
+ * Execute the search for a specific criteria, blocking until the search returns.
+ * This method can apply search to math the specific criteria in case if the
+ * provider is not able to do it completely
+ * @param criteria
+ * @return ISearch Contain the search results
+ * @throws UserSearchException
+ */
+ public ISearch search(ICriteria criteria) throws UserSearchException;
+
+ /**
+ * Execute the search for a specific criteria, not blocking until the search returns.
+ * This method can apply search to math the specific criteria in case if the
+ * provider is not able to do it completely
+ * @param criteria
+ * @param listener the listener {@link IUserSearchListener} to search. Must not be null
.
+ */
+ public void search(ICriteria criteria, IUserSearchListener listener);
+
+ /**
+ * Create a specific criteria for the provider. Each provider must
+ * implement a specific Criteria in a convenient approach for keep,
+ * organize and deal with the {@link ICriterion}.
+ * @return {@link ICriteria}
+ */
+ public ICriteria createCriteria();
+
+ /**
+ * Create a specific {@link IRestriction} implementation for the provider.
+ * This implementation will provide the methods to created and organize
+ * the {@link ICriterion} that composes the search. The {@link Restriction}
+ * is a simple implementation of this, but subclasses or new implementation
+ * may be created as appropriate.
+ *
+ * @return {@link IRestriction}
+ */
+ public IRestriction createSelection();
+
+ /**
+ * Each provider can inform the user properties fields
+ * to be considered on the user search, allowing the
+ * dynamically user interface for the search.
+ * @return String[] user properties provides by server
+ * @throws ContainerConnectException
+ */
+ public String[] getUserPropertiesFields() throws ContainerConnectException;
+
+ /**
+ * Whether this handler is capable of executing at this time.
+ * @return boolean
+ */
+ public boolean isEnabled();
+}
Index: src/org/eclipse/ecf/presence/search/ICriterion.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/ICriterion.java
diff -N src/org/eclipse/ecf/presence/search/ICriterion.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/ICriterion.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+
+package org.eclipse.ecf.presence.search;
+
+/**
+ * A representation of a query criterion for a restriction in a Criteria.
+ * A Criteria is formed by one or several criterion,
+ * that together are able to compose an entire expression to project
+ * a result that match the criteria. The instances of this should be
+ * created for {@link IRestriction} implementations.
+ * @since 3.0
+ */
+public interface ICriterion {
+
+ /**
+ * Returns a expression composed for the search.
+ * The String can be something like 'field' + 'operator' + value,
+ * that it will be interpreted for each specific provider.
+ * @return String
+ */
+ public String toExpression();
+}
Index: src/org/eclipse/ecf/presence/search/IUserSearchEvent.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/IUserSearchEvent.java
diff -N src/org/eclipse/ecf/presence/search/IUserSearchEvent.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/IUserSearchEvent.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+/**
+ * An event received by a user search. This interface address the events
+ * that happens on user search API. There be different sub-interfaces of IUserSearchEvent to
+ * represent different types of events.
+ * @since 3.0
+ */
+public interface IUserSearchEvent {
+ //
+}
Index: src/org/eclipse/ecf/presence/search/UserSearchCompleteEvent.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/UserSearchCompleteEvent.java
diff -N src/org/eclipse/ecf/presence/search/UserSearchCompleteEvent.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/UserSearchCompleteEvent.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+/**
+ *
+ * @since 3.0
+ */
+public class UserSearchCompleteEvent implements IUserSearchCompleteEvent {
+
+ private ISearch search;
+
+ public UserSearchCompleteEvent(ISearch search) {
+ this.search = search;
+ }
+
+ public ISearch getSearch() {
+ return search;
+ }
+
+}
Index: src/org/eclipse/ecf/presence/search/Restriction.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/Restriction.java
diff -N src/org/eclipse/ecf/presence/search/Restriction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/Restriction.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+/**
+ * This Class implements {@link IRestriction}. Subclasses may be created as
+ * appropriate. It is just a simple implementation that can be considered
+ * for some provider or even used as base for some implementation.
+ * @since 3.0
+ */
+public class Restriction implements IRestriction {
+
+ /** Operator Equal */
+ public static final String OPERATOR_EQ = "="; //$NON-NLS-1$
+
+ /** Operator Not Equal */
+ public static final String OPERATOR_NE = "!="; //$NON-NLS-1$
+
+ /** Operator AND */
+ public static final String OPERATOR_AND = "&&"; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ecf.presence.search.ISelection#and(org.eclipse.ecf.presence.search.ICriterion, org.eclipse.ecf.presence.search.ICriterion)
+ */
+ public ICriterion and(ICriterion left, ICriterion right) {
+ return new LogicalCriterion(left, right, OPERATOR_AND);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ecf.presence.search.ISelection#eq(java.lang.String, java.lang.String)
+ */
+ public ICriterion eq(String field, String value) {
+ return new SimpleCriterion(field, value, OPERATOR_EQ);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ecf.presence.search.ISelection#ne(java.lang.String, java.lang.String)
+ */
+ public ICriterion ne(String field, String value) {
+ return new SimpleCriterion(field, value, OPERATOR_NE);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ecf.presence.search.ISelection#eq(java.lang.String, java.lang.String, boolean)
+ */
+ public ICriterion eq(String field, String value, boolean ignoreCase) {
+ //TODO implement a criterion that supports ignore case approach
+ return new SimpleCriterion(field, value, OPERATOR_EQ);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ecf.presence.search.ISelection#ne(java.lang.String, java.lang.String, boolean)
+ */
+ public ICriterion ne(String field, String value, boolean ignoreCase) {
+ //TODO implement a criterion that supports ignore case approach
+ return new SimpleCriterion(field, value, OPERATOR_NE);
+ }
+
+}
Index: src/org/eclipse/ecf/presence/search/UserSearchException.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/UserSearchException.java
diff -N src/org/eclipse/ecf/presence/search/UserSearchException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/UserSearchException.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.ecf.core.util.ECFException;
+
+/**
+ *
+ * @since 3.0
+ */
+public class UserSearchException extends ECFException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -896845055593390010L;
+
+ private ICriteria criteria = null;
+
+ /**
+ *
+ */
+ public UserSearchException(ICriteria criteria) {
+ super();
+ this.criteria = criteria;
+ }
+
+ /**
+ * @param status
+ */
+ public UserSearchException(IStatus status, ICriteria criteria) {
+ super(status);
+ this.criteria = criteria;
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public UserSearchException(String message, Throwable cause, ICriteria criteria) {
+ super(message, cause);
+ this.criteria = criteria;
+ }
+
+ /**
+ * @param message
+ */
+ public UserSearchException(String message, ICriteria criteria) {
+ super(message);
+ this.criteria = criteria;
+ }
+
+ /**
+ * @param cause
+ */
+ public UserSearchException(Throwable cause, ICriteria criteria) {
+ super(cause);
+ this.criteria = criteria;
+ }
+
+ public ICriteria getSearchCriteria() {
+ return this.criteria;
+ }
+}
Index: src/org/eclipse/ecf/presence/search/ISearch.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/ISearch.java
diff -N src/org/eclipse/ecf/presence/search/ISearch.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/ISearch.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+
+package org.eclipse.ecf.presence.search;
+
+/**
+ * Provide access for the list of matched query results. This interface can be
+ * extended to supply more features around the result list.
+ * @since 3.0
+ */
+public interface ISearch {
+
+ /**
+ * Gets a result list.
+ * Will not return null
.
+ * @return IResultList list of {@link IResult}
+ */
+ IResultList getResultList();
+
+ /**
+ *
+ * @param IResultList
+ */
+ public void setResultList(IResultList resultList);
+
+}
Index: src/org/eclipse/ecf/presence/search/IRestriction.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/IRestriction.java
diff -N src/org/eclipse/ecf/presence/search/IRestriction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/IRestriction.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+/**
+ * Instances implementing this interface provide methods to compose the corrects operations for each
+ * provide
+ * @since 3.0
+ */
+public interface IRestriction {
+
+ /**
+ * Apply an "add" constraint to the two criterion
+ * @param left
+ * @param right
+ * @return ICriterion
+ */
+ public ICriterion and(ICriterion left, ICriterion right);
+
+ /**
+ * Apply an "equal" constraint to the field, ignoring case
+ * @param field
+ * @param value
+ * @return ICriterion
+ */
+ public ICriterion eq(String field, String value);
+
+ /**
+ * Apply an "not equal" constraint to the field ignoring case
+ * @param field
+ * @param value
+ * @return ICriterion
+ */
+ public ICriterion ne(String field, String value);
+
+ /**
+ * Apply an "equal" constraint to the field, taking into consideration ignore case
+ * @param field
+ * @param value
+ * @param ignoreCase
+ * @return ICriterion
+ */
+ public ICriterion eq(String field, String value, boolean ignoreCase);
+
+ /**
+ * Apply an "not equal" constraint to the field, taking into consideration ignore case
+ * @param field
+ * @param value
+ * @param ignoreCase
+ * @return ICriterion
+ */
+ public ICriterion ne(String field, String value, boolean ignoreCase);
+
+}
Index: src/org/eclipse/ecf/presence/search/IResult.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/IResult.java
diff -N src/org/eclipse/ecf/presence/search/IResult.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/IResult.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ecf.core.user.IUser;
+
+/**
+ * Each result returned for the search will be reach through this interface.
+ * The result contain the user that match the search.
+ * @since 3.0
+ */
+public interface IResult extends IAdaptable {
+
+ /**
+ * Get user for the search. This is the user that comes from the search.
+ *
+ * @return IUser user associated with the search.
+ */
+ public IUser getUser();
+}
Index: src/org/eclipse/ecf/presence/search/IUserSearchListener.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/IUserSearchListener.java
diff -N src/org/eclipse/ecf/presence/search/IUserSearchListener.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/IUserSearchListener.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+/**
+ * This Interface allows for implementing classes to execute the search
+ * for users in a non block way.
+ * Note these methods will be called asynchronously not blocking a search action.
+ * The provider is free to call the methods below with an arbitrary thread, so the
+ * implementation of these methods must be appropriately prepared.
+ * @since 3.0
+ */
+public interface IUserSearchListener {
+
+ /**
+ * Catch the event fired and proceed to complete the search.
+ * Handle the search asynchronously. Notify that the search was completed
+ * for the specific criteria.
+ * @param event the object that contains the composition of {@link ICriteria}
+ * and deal with the results in a non-blocking way
+ */
+ public void handleUserSearchEvent(IUserSearchEvent event);
+
+}
Index: src/org/eclipse/ecf/presence/search/SimpleCriterion.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/SimpleCriterion.java
diff -N src/org/eclipse/ecf/presence/search/SimpleCriterion.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/SimpleCriterion.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+/**
+ *
+ * Base class implementation of {@link ICriterion} for simple comparisons. Subclasses may be created as
+ * appropriate.
+ * @since 3.0
+ */
+public class SimpleCriterion implements ICriterion {
+
+ protected final String field;
+ protected final String value;
+ protected final String operator;
+ protected final boolean ignoreCase;
+
+ /**
+ * Constructor for a instance of {@link ICriterion}
+ * @param field Name of the field
+ * @param value Value that match the search
+ * @param operator Operator opportune for the search
+ * @param ignoreCase Consider case or not
+ */
+ public SimpleCriterion(String field, String value, String operator, boolean ignoreCase) {
+ this.field = field;
+ this.value = value;
+ this.operator = operator;
+ this.ignoreCase = ignoreCase;
+ }
+
+ /**
+ * Constructor for a instance of {@link ICriterion}. This is
+ * ignore case
+ * @param field Name of the field
+ * @param value Value that match the search
+ * @param operator Operator opportune for the search
+ */
+ public SimpleCriterion(String field, String value, String operator) {
+ this.field = field;
+ this.value = value;
+ this.operator = operator;
+ this.ignoreCase = false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ecf.presence.search.ICriterion#toExpression()
+ */
+ public String toExpression() {
+ return field + ' ' + operator + ' ' + value;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("SimpleCriterion["); //$NON-NLS-1$
+ sb.append("field=").append(field).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append("value=").append(value).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append("operator=").append(operator).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append("ignoreCase=").append(ignoreCase).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return sb.toString();
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o instanceof String) {
+ return o.equals(field);
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ return (field != null ? field.hashCode() : 0);
+ }
+}
Index: src/org/eclipse/ecf/presence/search/AbstractUserSearchManager.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/AbstractUserSearchManager.java
diff -N src/org/eclipse/ecf/presence/search/AbstractUserSearchManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/AbstractUserSearchManager.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.presence.search;
+
+import java.util.*;
+
+/**
+ * Abstract implementation of IUserSearchManager. Provides implementations of listener
+ * methods that subsclasses may use to avoid having to implement them
+ * themselves. This class may be subclassed as needed.
+ * @since 3.0
+ */
+public abstract class AbstractUserSearchManager implements IUserSearchManager {
+
+ private final List userSearchListeners = new ArrayList(5);
+ protected ICriteria criteria;
+
+ /**
+ * Add the listener to be notify by events
+ * @param listener
+ */
+ public void addListener(IUserSearchListener l) {
+ synchronized (userSearchListeners) {
+ userSearchListeners.add(l);
+ }
+ }
+
+ public void removeListener(IUserSearchListener l) {
+ synchronized (userSearchListeners) {
+ userSearchListeners.remove(l);
+ }
+ }
+
+ /**
+ * Fires a user search event
+ *
+ * @param event
+ */
+ public void fireUserSearchEvent(IUserSearchEvent event) {
+ List toNotify = null;
+ // Copy array
+ synchronized (userSearchListeners) {
+ toNotify = new ArrayList(userSearchListeners);
+ }
+ // Notify all in toNotify
+ for (Iterator i = toNotify.iterator(); i.hasNext();) {
+ IUserSearchListener l = (IUserSearchListener) i.next();
+ l.handleUserSearchEvent(event);
+ }
+ }
+
+ /**
+ * Returns a default implementation for IUserSearchListner
+ * @return IUserSearchListener
+ */
+ public IUserSearchListener getUserSearchListner() {
+ return new UserListener();
+ }
+
+ public class UserListener implements IUserSearchListener {
+
+ public void handleUserSearchEvent(IUserSearchEvent event) {
+ try {
+ if (event instanceof IUserSearchCompleteEvent) {
+ //ISearch searchResult = ((IUserSearchCompleteEvent) event).getSearch();
+ } else if (event instanceof IUserSearchEvent) {
+ ISearch searchResult = search(criteria);
+ fireUserSearchEvent(new UserSearchCompleteEvent(searchResult));
+ }
+
+ } catch (UserSearchException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ }
+
+}
Index: src/org/eclipse/ecf/presence/search/IResultList.java
===================================================================
RCS file: src/org/eclipse/ecf/presence/search/IResultList.java
diff -N src/org/eclipse/ecf/presence/search/IResultList.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/presence/search/IResultList.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+
+package org.eclipse.ecf.presence.search;
+
+import java.util.Collection;
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * This interface provides methods to handle the result list that match the search.
+ * @since 3.0
+ */
+public interface IResultList extends IAdaptable {
+
+ /**
+ * Get results that match the search. Instances of list are of type
+ * {@link IResult}
+ *
+ * @return Collection of IResult. Will not return null
.
+ * May return an empty Collection.
+ */
+ public Collection geResults();
+
+ /**
+ * Get the result that math the specific field and value
+ * @param field field's name used as argument to try to match the search
+ * @param value value for the respective field used as argument to try to match the search
+ * @return IResult will be null case it doesn't exist
+ */
+ public IResult getResult(String field, String value);
+}
#P org.eclipse.ecf.provider.msn
Index: src/org/eclipse/ecf/internal/provider/msn/MSNContainer.java
===================================================================
RCS file: /cvsroot/rt/org.eclipse.ecf/providers/bundles/org.eclipse.ecf.provider.msn/src/org/eclipse/ecf/internal/provider/msn/MSNContainer.java,v
retrieving revision 1.31
diff -u -r1.31 MSNContainer.java
--- src/org/eclipse/ecf/internal/provider/msn/MSNContainer.java 3 Nov 2007 12:58:41 -0000 1.31
+++ src/org/eclipse/ecf/internal/provider/msn/MSNContainer.java 21 Jan 2009 23:42:37 -0000
@@ -63,6 +63,12 @@
import org.eclipse.ecf.presence.roster.IRosterManager;
import org.eclipse.ecf.presence.roster.IRosterSubscriptionListener;
import org.eclipse.ecf.presence.roster.IRosterSubscriptionSender;
+import org.eclipse.ecf.presence.search.ICriteria;
+import org.eclipse.ecf.presence.search.ISearch;
+import org.eclipse.ecf.presence.search.IRestriction;
+import org.eclipse.ecf.presence.search.IUserSearchListener;
+import org.eclipse.ecf.presence.search.IUserSearchManager;
+import org.eclipse.ecf.presence.search.UserSearchException;
import org.eclipse.ecf.presence.service.IPresenceService;
import org.eclipse.ecf.protocol.msn.ChatSession;
import org.eclipse.ecf.protocol.msn.Contact;
@@ -758,4 +764,48 @@
return null;
}
+ /**
+ * TODO Implement a User Search Manager for MSN
+ * for while it just returns a manger
+ * to inform that user search is not allow
+ * for this provider see {@link IUserSearchManager#isEnabled()}
+ */
+ public IUserSearchManager getUserSearchManager() {
+ return new IUserSearchManager(){
+
+ public ICriteria createCriteria() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public IRestriction createSelection() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String[] getUserPropertiesFields()
+ throws ContainerConnectException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isEnabled() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public ISearch search(ICriteria criteria)
+ throws UserSearchException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void search(ICriteria criteria, IUserSearchListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ };
+ }
+
}
#P org.eclipse.ecf.tests.presence
Index: src/org/eclipse/ecf/tests/presence/AbstractSearchTest.java
===================================================================
RCS file: src/org/eclipse/ecf/tests/presence/AbstractSearchTest.java
diff -N src/org/eclipse/ecf/tests/presence/AbstractSearchTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/tests/presence/AbstractSearchTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Marcelo Mayworm. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Marcelo Mayworm - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.ecf.tests.presence;
+
+
+public abstract class AbstractSearchTest extends AbstractPresenceTestCase {
+
+ public static final int CLIENT_COUNT = 1;
+ public static final int WAITTIME = 3000;
+
+ protected void setUp() throws Exception {
+ setClientCount(CLIENT_COUNT);
+ clients = createClients();
+ }
+
+}