Introspects a Java bean to learn about all its properties,
exposed methods, and events.  Returns null if the BeanInfo
could not be created.
342184
public BeanInfo getBeanInfo() {
        if (mBeanInfo == null) {
            try { 
                mBeanInfo = getTeaToolsUtils().getBeanInfo(mType);
            }
            catch (Exception e) {
                return null;
            }
        }

        return mBeanInfo;
    }
1118947
@Override
    public T create(final CreationalContext<T> creationalContext) {
        if (proxyInstantiator == null) {
            // initializeAfterBeanDiscovery wasn't yet invoked
            // this can happen if you attempt to create bean prior to fully booting container
            throw BeanLogger.LOG.initABDnotInvoked(annotatedType);
        }
        return proxyInstantiator.newInstance(creationalContext, beanManager);
    }
461951
@Override
    public void introspect(PrintWriter writer) {
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();

        introspectUptime(runtime, writer);
        introspectVendorVersion(runtime, writer);
        introspectInputArguments(runtime, writer);
        Map<String, String> props = introspectSystemProperties(runtime, writer);
        //introspectPaths(runtime, writer);
        introspectDirsFromSystemProperties(runtime, writer, "java.ext.dirs", props);
        introspectDirsFromSystemProperties(runtime, writer, "java.endorsed.dirs", props);
    }
1063820
private void processBeanInterceptors() // d630717
    throws EJBConfigurationException
    {
        ivBeanInterceptorProxyMap = createInterceptorProxyMap(ivEjbClass, -1);

        // F743-1751 - Not all bean types collect bean methods.  For those
        // that do, find the methods that are declared on the bean.
        if (ivBeanLifecycleMethods != null)
        {
            for (InterceptorMethodKind kind : InterceptorMethodKind.values())
            {
                int mid = kind.getMethodID();
                if (mid != -1)
                {
                    List<InterceptorProxy> proxyList = ivBeanInterceptorProxyMap.get(kind);
                    if (proxyList != null)
                    {
                        for (InterceptorProxy proxy : proxyList)
                        {
                            Method m = proxy.ivInterceptorMethod;
                            if (m.getDeclaringClass() == ivEjbClass)
                            {
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                                    Tr.debug(tc, "found bean " + LifecycleInterceptorWrapper.TRACE_NAMES[mid] + " method: " + m);

                                ivBeanLifecycleMethods[mid] = m;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
168666
@Bean
    public Reflections reflections() {
        return new Reflections(new ConfigurationBuilder()
                                    .setUrls(ClasspathHelper.forPackage(scanPackage))
                                    .setScanners(new MethodAnnotationsScanner()));
    }
1311995
private BeanDefinition findBeanDefinition(ConfigurableListableBeanFactory beanFactory, String serviceBeanName) {
		if (beanFactory.containsLocalBean(serviceBeanName)) return beanFactory.getBeanDefinition(serviceBeanName);
		BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory();
		if (parentBeanFactory != null && ConfigurableListableBeanFactory.class.isInstance(parentBeanFactory))
			return findBeanDefinition((ConfigurableListableBeanFactory) parentBeanFactory, serviceBeanName);
		throw new RuntimeException(format("Bean with name '%s' can no longer be found.", serviceBeanName));
	}
987106
private static Object fillBean(final OptionVisitor visitor, final Type type, final Object bean, final List<ParameterMetadata> metadatas) {
        if (!Class.class.isInstance(type)) { // can't do anything
            return null;
        }

        List<Object> constructorParam = bean == null ? new ArrayList<>() : null;
        try {
            final Constructor constructor = Class.class.cast(type).getConstructors()[0];
            final BeanInfo descriptor = Introspector.getBeanInfo(Class.class.cast(type));
            final Map<String, PropertyDescriptor> descriptorMap = new HashMap<>();
            for (final PropertyDescriptor d : descriptor.getPropertyDescriptors()) {
                descriptorMap.put(d.getName(), d);
            }
            Object value = bean;
            int consIdx = -1;
            for (final ParameterMetadata metadata : metadatas) {
                consIdx++;
                if (metadata.getType() != ParameterMetadata.ParamType.OPTION) { // we support only 1 level for now
                    continue;
                }


                final String name = metadata.getName().substring(metadata.getName().lastIndexOf('.') + 1);
                if (!descriptorMap.containsKey(name)) {
                    continue;
                }

                final PropertyDescriptor propertyDescriptor = descriptorMap.get(name);
                if (propertyDescriptor == null) {
                    continue;
                }

                if (bean != null) { // check it is not already set
                    final Method readMethod = propertyDescriptor.getReadMethod();
                    if (readMethod == null) {
                        continue;
                    }
                    try {
                        final Object val = readMethod.invoke(bean);
                        if (val != null) {
                            continue;
                        }
                    } catch (final IllegalAccessException e) {
                        throw new IllegalStateException(e);
                    } catch (InvocationTargetException e) {
                        throw new IllegalStateException(e.getCause());
                    }
                }

                final Method write = propertyDescriptor.getWriteMethod();
                if (write != null) {
                    final Object val = visitor.onOption(consIdx, metadata, new AnnotatedElementImpl(write.getParameterAnnotations()[0]));
                    if (val != null) {
                        try {
                            if (value == null) {
                                constructorParam.add(val);
                            } else {
                                write.invoke(value, val);
                            }
                        } catch (final IllegalAccessException e) {
                            throw new IllegalStateException(e);
                        } catch (final InvocationTargetException e) {
                            throw new IllegalStateException(e.getCause());
                        }
                    }

                }
            }
            if (value == null) {
                try {
                    value = constructor.newInstance(constructorParam.toArray(new Object[constructorParam.size()]));
                } catch (final IllegalAccessException e) {
                    throw new IllegalStateException(e);
                } catch (final InstantiationException e) {
                    throw new IllegalStateException(e);
                } catch (final InvocationTargetException e) {
                    throw new IllegalStateException(e.getCause());
                }
            }
            return value;
        } catch (final IntrospectionException e) {
            throw new IllegalStateException(e);
        }
    }
720354
@SuppressWarnings("unchecked")
    protected void initialise() {
        if (getBean() == null) {
            return;
        }

        this.beanClass = (Class<T>) bean.getClass();
        if (!(getBean() instanceof Map)) {
            Class currentClass = beanClass;

            List<Class> classes = Lists.newLinkedList();

            while (currentClass != null) {
                classes.add(0, currentClass);
                currentClass = currentClass.getSuperclass();
            }

            for (Class clazz : classes) {
                for (Method m : clazz.getMethods()) {
                    String name = m.getName();
                    Class rtype = m.getReturnType();
                    if (void.class != rtype && !name.equals("getClass")) {
                        boolean getType = name.startsWith(HandleType.GET.name().toLowerCase());
                        boolean isType = false;
                        if (!getType) {
                            isType = name.startsWith(HandleType.IS.name().toLowerCase())
                                    && (Boolean.class.isAssignableFrom(rtype) || rtype == boolean.class);
                        }
                        if (getType || isType) {
                            String fn = transformPropertyName(StringUtils.uncapitalize(name.substring(isType ? 2 : 3)));
                            if (StringUtils.isNotBlank(fn)) {
                                types.put(fn, rtype);
                                readHandleType.put(fn, isType ? HandleType.IS : HandleType.GET);
                            }
                        }
                    }
                }
            }
        } else {
            if (getBean() instanceof BeanMap) {
                types = ((BeanMap) getBean()).types;
                readInvokers = ((BeanMap) getBean()).readInvokers;
                writeInvokers = ((BeanMap) getBean()).writeInvokers;
                beanClass = (Class<T>) bean.getClass();
                bean = (T) ((BeanMap) bean).getBean();
            } else {
                Set<Map.Entry> entries = ((Map) getBean()).entrySet();
                for (Map.Entry entry : entries) {
                    String name = transformPropertyName((String) entry.getKey());
                    if (StringUtils.isNotBlank(name) && entry.getValue() != null) {
                        types.put(name, entry.getValue().getClass());
                    }
                }
            }
        }
    }
1077893
private static DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory() {
            {
                final InstantiationStrategy is = getInstantiationStrategy();
                setInstantiationStrategy(new InstantiationStrategy() {
                    @Override
                    public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner) throws BeansException {
                        return is.instantiate(beanDefinition, beanName, owner);
                    }

                    @Override
                    public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner, Constructor<?> ctor, Object[] args) throws BeansException {
                        final Object bean = is.instantiate(beanDefinition, beanName, owner, ctor, args);
                        addDependencies(bean, args);
                        return bean;
                    }

                    @Override
                    public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner, Object factoryBean, Method factoryMethod, Object[] args) throws BeansException {
                        final Object bean = is.instantiate(beanDefinition, beanName, owner, factoryBean, factoryMethod, args);
                        addDependencies(bean, args);
                        return bean;
                    }
                });
            }

            private void addDependencies(Object bean, Object[] args) {
                if (bean instanceof Service) {
                    for (Object arg : args) {
                        if (arg instanceof Service) {
                            ((Service) arg).addDependedBy((Service) bean);
                            ((Service) bean).addDependsOn((Service) arg);
                        }
                    }
                }
            }
        };
    }
347520
private Method findAddRemoveListenerMethod(Class<?> sourceClass, String methodName) throws IntrospectionException
	{
		try
		{
			return sourceClass.getMethod(methodName, listenerType);
		}
		catch (NoSuchMethodException e)
		{
			return findAddRemoveListnerMethodWithLessCheck(sourceClass, methodName);
		}
		catch (Exception e)
		{
			throw new IntrospectionException(Messages.getString("beans.31", //$NON-NLS-1$
					methodName, listenerType.getName()));
		}
	}
171808
private List<PropertyDescriptor> getPropertyDescriptorsForClass(Class<?> clasz) {
        try {
            BeanInfo beanInfo = Introspector.getBeanInfo(clasz);
            return Arrays.asList(beanInfo.getPropertyDescriptors());
        } catch (IntrospectionException e) {
            LOGGER.error("instantiation exception while trying to create instance of class {}", clasz.getName());
        }
        return Lists.newArrayList();
    }
909572
void introspectThisClassOnly(com.ibm.ws.rsadapter.FFDCLogger info) {
        info.createFFDCHeader(this);

        info.append("ManagedConnection:", ivManagedConnection);
        info.append("Underlying XAResource Object: " + AdapterUtil.toString(ivXaRes), ivXaRes);
        info.append("Xid: ", AdapterUtil.toString(ivXid)); 
    }
36117
public static <T> T createInternal(Config config, Class<T> clazz) {
        if (((SimpleConfig)config).root().resolveStatus() != ResolveStatus.RESOLVED)
            throw new ConfigException.NotResolved(
                    "need to Config#resolve() a config before using it to initialize a bean, see the API docs for Config#resolve()");

        Map<String, AbstractConfigValue> configProps = new HashMap<String, AbstractConfigValue>();
        Map<String, String> originalNames = new HashMap<String, String>();
        for (Map.Entry<String, ConfigValue> configProp : config.root().entrySet()) {
            String originalName = configProp.getKey();
            String camelName = ConfigImplUtil.toCamelCase(originalName);
            // if a setting is in there both as some hyphen name and the camel name,
            // the camel one wins
            if (originalNames.containsKey(camelName) && !originalName.equals(camelName)) {
                // if we aren't a camel name to start with, we lose.
                // if we are or we are the first matching key, we win.
            } else {
                configProps.put(camelName, (AbstractConfigValue) configProp.getValue());
                originalNames.put(camelName, originalName);
            }
        }

        BeanInfo beanInfo = null;
        try {
            beanInfo = Introspector.getBeanInfo(clazz);
        } catch (IntrospectionException e) {
            throw new ConfigException.BadBean("Could not get bean information for class " + clazz.getName(), e);
        }

        try {
            List<PropertyDescriptor> beanProps = new ArrayList<PropertyDescriptor>();
            for (PropertyDescriptor beanProp : beanInfo.getPropertyDescriptors()) {
                if (beanProp.getReadMethod() == null || beanProp.getWriteMethod() == null) {
                    continue;
                }
                beanProps.add(beanProp);
            }

            // Try to throw all validation issues at once (this does not comprehensively
            // find every issue, but it should find common ones).
            List<ConfigException.ValidationProblem> problems = new ArrayList<ConfigException.ValidationProblem>();
            for (PropertyDescriptor beanProp : beanProps) {
                Method setter = beanProp.getWriteMethod();
                Class<?> parameterClass = setter.getParameterTypes()[0];

                ConfigValueType expectedType = getValueTypeOrNull(parameterClass);
                if (expectedType != null) {
                    String name = originalNames.get(beanProp.getName());
                    if (name == null)
                        name = beanProp.getName();
                    Path path = Path.newKey(name);
                    AbstractConfigValue configValue = configProps.get(beanProp.getName());
                    if (configValue != null) {
                        SimpleConfig.checkValid(path, expectedType, configValue, problems);
                    } else {
                        if (!isOptionalProperty(clazz, beanProp)) {
                            SimpleConfig.addMissing(problems, expectedType, path, config.origin());
                        }
                    }
                }
            }

            if (!problems.isEmpty()) {
                throw new ConfigException.ValidationFailed(problems);
            }

            // Fill in the bean instance
            T bean = clazz.newInstance();
            for (PropertyDescriptor beanProp : beanProps) {
                Method setter = beanProp.getWriteMethod();
                Type parameterType = setter.getGenericParameterTypes()[0];
                Class<?> parameterClass = setter.getParameterTypes()[0];
                String configPropName = originalNames.get(beanProp.getName());
                // Is the property key missing in the config?
                if (configPropName == null) {
                    // If so, continue if the field is marked as @{link Optional}
                    if (isOptionalProperty(clazz, beanProp)) {
                        continue;
                    }
                    // Otherwise, raise a {@link Missing} exception right here
                    throw new ConfigException.Missing(beanProp.getName());
                }
                Object unwrapped = getValue(clazz, parameterType, parameterClass, config, configPropName);
                setter.invoke(bean, unwrapped);
            }
            return bean;
        } catch (InstantiationException e) {
            throw new ConfigException.BadBean(clazz.getName() + " needs a public no-args constructor to be used as a bean", e);
        } catch (IllegalAccessException e) {
            throw new ConfigException.BadBean(clazz.getName() + " getters and setters are not accessible, they must be for use as a bean", e);
        } catch (InvocationTargetException e) {
            throw new ConfigException.BadBean("Calling bean method on " + clazz.getName() + " caused an exception", e);
        }
    }
824873
public BeanDefinition toInternal(BeanDefinitionInfo beanDefinitionInfo) {
		if (beanDefinitionInfo instanceof GenericBeanDefinitionInfo) {
			GenericBeanDefinitionInfo genericInfo = (GenericBeanDefinitionInfo) beanDefinitionInfo;
			GenericBeanDefinition def = new GenericBeanDefinition();
			def.setBeanClassName(genericInfo.getClassName());
			if (genericInfo.getPropertyValues() != null) {
				MutablePropertyValues propertyValues = new MutablePropertyValues();
				for (Entry<String, BeanMetadataElementInfo> entry : genericInfo.getPropertyValues().entrySet()) {
					BeanMetadataElementInfo info = entry.getValue();
					propertyValues.add(entry.getKey(), toInternal(info));
				}
				def.setPropertyValues(propertyValues);
			}
			return def;
		} else if (beanDefinitionInfo instanceof ObjectBeanDefinitionInfo) {
			ObjectBeanDefinitionInfo objectInfo = (ObjectBeanDefinitionInfo) beanDefinitionInfo;
			return createBeanDefinitionByIntrospection(objectInfo.getObject());
		} else {
			throw new IllegalArgumentException("Conversion to internal of " + beanDefinitionInfo.getClass().getName()
					+ " not implemented");
		}
	}
617393
@Override
    public String[] introspectSelf() {
        String[] debugInfo = new String[6];
        debugInfo[0] = "JSMessageData:";

        // Include the basic toString info so we know who we are
        StringBuilder sb = new StringBuilder("Self: ");
        sb.append(toString());
        debugInfo[1] = new String(sb);

        // Include the cache information
        sb.setLength(0);
        sb.append("Cache: size=");
        sb.append(cacheSize);
        sb.append(" cache=");
        sb.append(cache); // Yes we really do just want [Ljava.lang.Object;@xxxxxx here
        debugInfo[2] = new String(sb);

        // Include the cache information
        sb.setLength(0);
        sb.append("Contents: ");
        if (contents == null) {
            sb.append("null");
        }
        else {
            sb.append("size=");
            sb.append(contents.length);
            sb.append(" contents=");
            sb.append(contents); // Yes we really do just want [B@xxxxxxx here
        }
        debugInfo[3] = new String(sb);

        // Include sharing information
        sb.setLength(0);
        sb.append("Sharing: sharedCache=");
        sb.append(sharedCache);
        sb.append(" sharedContents=");
        sb.append(sharedContents);
        debugInfo[4] = new String(sb);

        // Include all the stuff abot how it fits in to the heirarchy
        sb.setLength(0);
        sb.append("Context: parentMessage=");
        sb.append(parentMessage);
        sb.append(" containingMessage=");
        sb.append(containingMessage);
        sb.append(" master=");
        if (master == this) {
            sb.append("self");
        }
        else {
            sb.append(master);
        }
        sb.append(" compatibilityWrapperOrSelf=");
        if (compatibilityWrapperOrSelf == this) {
            sb.append("self");
        }
        else {
            sb.append(compatibilityWrapperOrSelf);
        }
        debugInfo[5] = new String(sb);

        // Now return it all
        return debugInfo;
    }
525094
@Override
  public void introspect(ContextH3 context)
  {
    if (_infoRef.get() != null) {
      return;
    }

    _ctor = introspectConstructor();

    introspectFields();

    FieldInfoH3[] fieldInfo = new FieldInfoH3[1];

    fieldInfo[0] = _item.info();

    ClassInfoH3 classInfo
      = new ClassInfoH3(_type.getName(),
                        ClassTypeH3.LIST,
                        fieldInfo);

    _infoRef.compareAndSet(null, classInfo);
  }
1255696
@Override
    @SuppressWarnings("ConstantConditions")
    @Nonnull
    public <T> Set<ConstraintViolation<T>> validate(@Nonnull BeanIntrospection<T> introspection, @Nonnull T object, @Nullable Class<?>... groups) {
        if (introspection == null) {
            throw new ValidationException("Passed object [" + object + "] cannot be introspected. Please annotate with @Introspected");
        }
        @SuppressWarnings("unchecked")
        final Collection<? extends BeanProperty<Object, Object>> constrainedProperties =
                ((BeanIntrospection<Object>) introspection).getIndexedProperties(Constraint.class);
        @SuppressWarnings("unchecked")
        final Collection<BeanProperty<Object, Object>> cascadeProperties =
                ((BeanIntrospection<Object>) introspection).getIndexedProperties(Valid.class);

        if (CollectionUtils.isNotEmpty(constrainedProperties) || CollectionUtils.isNotEmpty(cascadeProperties)) {
            DefaultConstraintValidatorContext context = new DefaultConstraintValidatorContext(object, groups);
            Set<ConstraintViolation<T>> overallViolations = new HashSet<>(5);
            return doValidate(
                    object,
                    object,
                    constrainedProperties,
                    cascadeProperties,
                    context,
                    overallViolations
            );
        }
        return Collections.emptySet();
    }