@Override protected void computeRelatedMetaBean(MetaProperty prop, String beanRef) { if (beanRef != null) { prop.setMetaBean(findForId(beanRef)); } else { super.computeRelatedMetaBean(prop, beanRef); } } }
/** * Create a {@link MetaBeanManager} using the specified builders. * * @param builders * {@link MetaBeanFactory} {@link List} * @return {@link MetaBeanManager} */ @SuppressWarnings("deprecation") protected MetaBeanFinder createMetaBeanManager(List<MetaBeanFactory> builders) { // as long as we support both: jsr303 (in the builders list) and xstream-xml metabeans: if (Boolean.parseBoolean(factory.getProperties().get( ApacheValidatorConfiguration.Properties.ENABLE_METABEANS_XML))) { return XMLMetaBeanManagerCreator.createXMLMetaBeanManager(builders); } return new MetaBeanManager(new MetaBeanBuilder(builders.toArray(new MetaBeanFactory[builders.size()]))); }
/** * {@inheritDoc} */ @Override public MetaBean findForClass(final Class<?> clazz) { if (clazz == null) { return null; } MetaBean beanInfo = cache.findForClass(clazz); if (beanInfo != null) { return beanInfo; } try { beanInfo = builder.buildForClass(clazz); cache.cache(beanInfo); computeRelationships(beanInfo); return beanInfo; } catch (final RuntimeException e) { throw e; // do not wrap runtime exceptions } catch (final Exception e) { throw new IllegalArgumentException("error creating beanInfo for " + clazz, e); } }
/** * Compute a single related {@link MetaBean}. * * @param prop meta property * @param beanRef bean reference */ protected void computeRelatedMetaBean(MetaProperty prop, String beanRef) { Class<?> beanType = prop.getFeature(REF_BEAN_TYPE); if (beanType == null) { if (prop.getFeature(REF_CASCADE) != null) { // dynamic type resolution: prop.setMetaBean(new DynamicMetaBean(this)); } } else { prop.setMetaBean(findForClass(beanType)); } }
/** * {@inheritDoc} */ @Override public MetaBean findForId(final String beanInfoId) { MetaBean beanInfo = cache.findForId(beanInfoId); if (beanInfo != null) { return beanInfo; } try { beanInfo = builder.buildForId(beanInfoId); cache.cache(beanInfo); computeRelationships(beanInfo); return beanInfo; } catch (final RuntimeException e) { throw e; // do not wrap runtime exceptions } catch (final Exception e) { throw new IllegalArgumentException("error creating beanInfo with id: " + beanInfoId, e); } }
/** * Compute all known relationships for <code>beanInfo</code>. must be called * AFTER cache.cache() to avoid endless loop * * @param beanInfo * - the bean for which to compute relationships */ protected void computeRelationships(MetaBean beanInfo) { for (final MetaProperty prop : beanInfo.getProperties()) { final String beanRef = prop.getFeature(REF_BEAN_ID); computeRelatedMetaBean(prop, beanRef); } }