/** * Applies a state change on the given metadata object. */ static void applyTo(final ModifiableMetadata.State target, final ModifiableMetadata metadata) { final StateChanger changer = VISITORS.get(); final ModifiableMetadata.State previous = changer.target; changer.target = target; changer.walk(metadata.getStandard(), null, metadata, true); changer.target = previous; }
/** * Merges the data from the given source into the given target. * See class javadoc for a description of the merge process. * * @param source the source metadata to merge into the target. Will never be modified. * @param target the target metadata where to merge values. Will be modified as a result of this call. * @throws ClassCastException if the source and target are not instances of the same metadata standard. * @throws InvalidMetadataException if the {@code target} metadata can not hold all {@code source} properties, * for example because the source class is a more specialized type than the target class. * @throws IllegalArgumentException if this method detects a cross-reference between source and target metadata. */ public final void copy(final Object source, final ModifiableMetadata target) { if (!copy(source, target, false)) { throw new InvalidMetadataException(errors().getString(Errors.Keys.IllegalArgumentClass_3, "target", target.getStandard().getInterface(source.getClass()), Classes.getClass(target))); } }
/** * Merges the data from the given source into the given target. * See class javadoc for a description of the merge process. * * @param source the source metadata to merge into the target. Will never be modified. * @param target the target metadata where to merge values. Will be modified as a result of this call. * @throws ClassCastException if the source and target are not instances of the same metadata standard. * @throws InvalidMetadataException if the {@code target} metadata can not hold all {@code source} properties, * for example because the source class is a more specialized type than the target class. * @throws IllegalArgumentException if this method detects a cross-reference between source and target metadata. */ public final void copy(final Object source, final ModifiableMetadata target) { if (!copy(source, target, false)) { throw new InvalidMetadataException(errors().getString(Errors.Keys.IllegalArgumentClass_3, "target", target.getStandard().getInterface(source.getClass()), Classes.getClass(target))); } }
final MetadataStandard standard = target.getStandard(); if (!standard.getInterface(source.getClass()).isInstance(target)) { return false;
final MetadataStandard standard = target.getStandard(); if (!standard.getInterface(source.getClass()).isInstance(target)) { return false;
try { unmodifiable = FREEZING; getStandard().freeze(this); success = this; } finally {
/** * Checks if changes in the metadata are allowed. All {@code setFoo(…)} methods in subclasses * shall invoke this method (directly or indirectly) before to apply any change. * The current property value should be specified in argument. * * @param current the current value, or {@code null} if none. * @throws UnmodifiableMetadataException if this metadata is unmodifiable. * * @see #state() * * @since 1.0 */ protected void checkWritePermission(Object current) throws UnmodifiableMetadataException { if (state != COMPLETABLE) { checkWritePermission(); } else if (current != null) { final MetadataStandard standard; if (current instanceof AbstractMetadata) { standard = ((AbstractMetadata) current).getStandard(); } else { standard = getStandard(); } final Object c = standard.getTitle(current); if (c != null) current = c; throw new UnmodifiableMetadataException(Resources.format(Resources.Keys.ElementAlreadyInitialized_1, current)); } }
final ModifiableMetadata candidate = (ModifiableMetadata) MetadataCopier.forModifiable(getStandard()).copy(this); candidate.freeze();