/*******************************************************************************
* Copyright (c) 2012 Google, Inc.
* 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:
* Google, Inc. - initial API and implementation
*******************************************************************************/
package com.windowtester.runtime.gef.internal.reflect;
import com.windowtester.internal.runtime.reflect.Reflector;
/**
* Id accessor service.
*/
public class IdIntrospector {
private final String idKey;
public IdIntrospector(String id) {
this.idKey = id;
}
public static IdIntrospector forName(String id) {
return new IdIntrospector(id);
}
public String getId(Object o) {
if (o == null)
return null;
Reflector reflector = Reflector.forObject(o);
if (!reflector.supports(idKey))
return null;
return (String) reflector.invoke(idKey);
}
}