private void initClassConstraints( Class<?> clazz, AnnotationIgnores annotationIgnores, BeanMetaDataCache beanMetaDataCache) { if (annotationIgnores.isIgnoreAnnotations(clazz)) { return; } // HV-262 BeanMetaDataImpl<?> cachedMetaData = beanMetaDataCache.getBeanMetaData(clazz); List<ConstraintDescriptorImpl<?>> classMetaData; if (cachedMetaData != null && cachedMetaData.getMetaConstraintsAsMap().get(clazz) != null) { classMetaData = new ArrayList<ConstraintDescriptorImpl<?>>(); for (MetaConstraint<?> metaConstraint : cachedMetaData.getMetaConstraintsAsMap().get(clazz)) { ConstraintDescriptorImpl<?> descriptor = metaConstraint.getDescriptor(); if (descriptor.getElementType() == ElementType.TYPE) { classMetaData.add(descriptor); } } } else { classMetaData = findClassLevelConstraints(clazz); } for (ConstraintDescriptorImpl<?> constraintDescription : classMetaData) { BeanMetaConstraint<?> metaConstraint = createBeanMetaConstraint(clazz, null, constraintDescription); addMetaConstraint(clazz, metaConstraint); } }
protected MetaVariable getConflict() { if (this.metaConstraints == null) return null; for (MetaConstraint df : this.metaConstraints) { ConstraintNetwork cn = df.getMetaVariable(); if (cn != null) return new MetaVariable(df, cn); } return null; }
/** * Method to add a {@link MetaConstraint} to this meta-CSP solver. * * @param metaConstraint The {@link MetaConstraint} to add. */ public void addMetaConstraint(MetaConstraint metaConstraint) { if (this.metaConstraints == null) this.metaConstraints = new Vector<MetaConstraint>(); // here the metaConstraint is added this.metaConstraints.add(metaConstraint); // the meta constraint now refers to the MetaConstraintSolver metaConstraint.setMetaSolver(this); boolean found = false; // Here I simply check if the type of the metaConstraint is already taken into account, // otherwise the array of types is extended for (Class<?> cl : this.constraintTypes) if (cl.equals(metaConstraint.getClass())) found = true; if (!found) { Class<?>[] newConstraintTypes = new Class<?>[this.constraintTypes.length + 1]; for (int i = 0; i < this.constraintTypes.length; i++) newConstraintTypes[i] = this.constraintTypes[i]; newConstraintTypes[this.constraintTypes.length] = metaConstraint.getClass(); this.constraintTypes = newConstraintTypes; } }