/******************************************************************************* | |
* Copyright (C) 2018 ANSYS medini Technologies AG | |
* | |
* This program and the accompanying materials are made | |
* available under the terms of the Eclipse Public License 2.0 | |
* which is available at https://www.eclipse.org/legal/epl-2.0/ | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* ANSYS medini Technologies AG - initial API and implementation | |
******************************************************************************/ | |
package org.eclipse.opencert.elastic.cdo; | |
import java.util.Iterator; | |
import org.eclipse.emf.cdo.CDOObject; | |
import org.eclipse.emf.cdo.eresource.CDOResource; | |
import org.eclipse.opencert.elastic.search.ObjectResolver; | |
public class CDOObjectResolver implements ObjectResolver<CDOObject> { | |
@Override | |
public CDOObject resolve(String objectId, Object context) { | |
if (context instanceof CDOResource) { | |
context = ((CDOResource) context).eAllContents(); | |
} | |
if (context instanceof Iterator) { | |
@SuppressWarnings("unchecked") | |
Iterator<Object> it = (Iterator<Object>) context; | |
while (it.hasNext()) { | |
Object next = (Object) it.next(); | |
if (next instanceof CDOObject) { | |
CDOObject object = (CDOObject) next; | |
if (objectId.equals(object.cdoID().toString())) { | |
return object; | |
} | |
} | |
} | |
} else if (context instanceof Iterable) { | |
for (Object next : (Iterable<?>) context) { | |
if (next instanceof CDOObject) { | |
CDOObject object = (CDOObject) next; | |
if (objectId.equals(object.cdoID().toString())) { | |
return object; | |
} | |
} | |
} | |
} | |
return null; | |
} | |
} |