org.glassfish.pfl.basic.facet.FacetAccessorImpl Maven / Gradle / Ivy
/*
* Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.glassfish.pfl.basic.facet;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.pfl.basic.algorithm.ClassAnalyzer;
import org.glassfish.pfl.basic.contain.Holder;
import org.glassfish.pfl.basic.func.UnaryPredicate;
/**
*
* @author ken
*/
public class FacetAccessorImpl implements FacetAccessor {
private Object delegate ;
private Map,Object> facetMap =
new HashMap,Object>() ;
public FacetAccessorImpl( Object delegate ) {
this.delegate = delegate ;
}
@Override
public T facet(Class cls ) {
Object result = null ;
if (cls.isInstance(delegate)) {
result = delegate ;
} else {
result = facetMap.get( cls ) ;
}
if (result == null) {
return null ;
} else {
return cls.cast( result ) ;
}
}
@Override
public Collection
© 2015 - 2024 Weber Informatics LLC | Privacy Policy