/** * Creates a new {@linkplain TypeEditor} instance * * @param callback the callback to use when a constraint violation is found. The client must * check the results of the callback invocations if the specified callback does not * immediately propagate constraint violations as checked exceptions. * @param typesToCheck the types to check for. If {@code null}, this node is checked. Otherwise * it is checked if its primary type or one of it's mixin types is contained in this parameters * @param types the {@code /jcr:system/jcr:nodeTypes} node * @param primary the node's primary type * @param mixins the node's mixins * @param builder a builder containing the current state of the node to check. May be used to set * a default primary type if none is set * @return a new TypeEditor instance * @throws CommitFailedException when the primary type of mixin definition is incorrect */ public static TypeEditor create(@NotNull ConstraintViolationCallback callback, Set<String> typesToCheck, @NotNull NodeState types, String primary, Iterable<String> mixins, @NotNull NodeBuilder builder) throws CommitFailedException { return new TypeEditor(callback, typesToCheck, types, primary, mixins, builder); }
/** * Creates a new <tt>TypeEditor</tt> instance * * @param callback the callback to use when a constraint violation is found. The client must * check the results of the callback invocations if the specified callback does not * immediately propagate constraint violations as checked exceptions. * @param typesToCheck the types to check for. If <tt>null</tt>, this node is checked. Otherwise * it is checked if its primary type or one of it's mixin types is contained in this parameters * @param types the <tt>/jcr:system/jcr:nodeTypes</tt> node * @param primary the node's primary type * @param mixins the node's mixins * @param builder a builder containing the current state of the node to check. May be used to set * a default primary type if none is set * @return a new TypeEditor instance * @throws CommitFailedException when the primary type of mixin definition is incorrect */ public static TypeEditor create(@Nonnull ConstraintViolationCallback callback, Set<String> typesToCheck, @Nonnull NodeState types, String primary, Iterable<String> mixins, @Nonnull NodeBuilder builder) throws CommitFailedException { return new TypeEditor(callback, typesToCheck, types, primary, mixins, builder); }
@Controller public class MyController { @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Type.class, new TypeEditor()); } }
/** * Creates a new {@linkplain TypeEditor} instance * * @param callback the callback to use when a constraint violation is found. The client must * check the results of the callback invocations if the specified callback does not * immediately propagate constraint violations as checked exceptions. * @param typesToCheck the types to check for. If {@code null}, this node is checked. Otherwise * it is checked if its primary type or one of it's mixin types is contained in this parameters * @param types the {@code /jcr:system/jcr:nodeTypes} node * @param primary the node's primary type * @param mixins the node's mixins * @param builder a builder containing the current state of the node to check. May be used to set * a default primary type if none is set * @return a new TypeEditor instance * @throws CommitFailedException when the primary type of mixin definition is incorrect */ public static TypeEditor create(@NotNull ConstraintViolationCallback callback, Set<String> typesToCheck, @NotNull NodeState types, String primary, Iterable<String> mixins, @NotNull NodeBuilder builder) throws CommitFailedException { return new TypeEditor(callback, typesToCheck, types, primary, mixins, builder); }
@Test(expected = CommitFailedException.class) public void removeMandatoryChildNode() throws CommitFailedException { EffectiveType effective = createControl().createMock(EffectiveType.class); expect(effective.isMandatoryChildNode("mandatory")).andReturn(true); expect(effective.getDirectTypeNames()).andReturn(Collections.emptyList()); replay(effective); TypeEditor editor = new TypeEditor(effective); editor.childNodeDeleted("mandatory", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void removeMandatoryProperty() throws CommitFailedException { EffectiveType effective = createControl().createMock(EffectiveType.class); expect(effective.isMandatoryProperty("mandatory")).andReturn(true); expect(effective.getDirectTypeNames()).andReturn(Collections.emptyList()); replay(effective); TypeEditor editor = new TypeEditor(effective); editor.propertyDeleted(PropertyStates.createProperty("mandatory", "")); }
@Test public void removeNonMandatoryChildNode() throws CommitFailedException { EffectiveType effective = createControl().createMock(EffectiveType.class); expect(effective.isMandatoryChildNode("mandatory")).andReturn(false); replay(effective); TypeEditor editor = new TypeEditor(effective); editor.childNodeDeleted("mandatory", EMPTY_NODE); }
Editor editor = new VisibleEditor(new TypeEditor( callback, modifiedTypes, afterTypes, primary, mixins, builder)); return new VisibleEditor(new TypeEditor( callback, null, afterTypes, primary, mixins, builder));
Editor editor = new VisibleEditor(new TypeEditor( callback, modifiedTypes, afterTypes, primary, mixins, builder)); return new VisibleEditor(new TypeEditor( callback, null, afterTypes, primary, mixins, builder));
Editor editor = new VisibleEditor(new TypeEditor( callback, modifiedTypes, afterTypes, primary, mixins, builder)); return new VisibleEditor(new TypeEditor( callback, null, afterTypes, primary, mixins, builder));
private void checkNodeTypeConstraints(NodeState after) throws CommitFailedException { EffectiveType effective = getEffective(); Set<String> properties = effective.getMandatoryProperties(); for (PropertyState ps : after.getProperties()) { properties.remove(ps.getName()); checkPropertyTypeConstraints(ps); } // verify the presence of all mandatory items if (!properties.isEmpty()) { constraintViolation(21, "Mandatory property " + properties.iterator().next() + " not found in a new node"); } List<String> names = Lists.newArrayList(after.getChildNodeNames()); for (String child : effective.getMandatoryChildNodes()) { if (!names.remove(child)) { constraintViolation(25, "Mandatory child node " + child + " not found in a new node"); } } if (!names.isEmpty()) { for (String name : names) { NodeState child = after.getChildNode(name); String primary = child.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = child.getNames(JCR_MIXINTYPES); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, false); if (!effective.isValidChildNode(name, editor.getEffective())) { constraintViolation(25, "Unexpected child node " + name + " found in a new node"); } } } }
private void checkNodeTypeConstraints(NodeState after) throws CommitFailedException { EffectiveType effective = getEffective(); Set<String> properties = effective.getMandatoryProperties(); for (PropertyState ps : after.getProperties()) { properties.remove(ps.getName()); checkPropertyTypeConstraints(ps); } // verify the presence of all mandatory items if (!properties.isEmpty()) { constraintViolation(21, "Mandatory property " + properties.iterator().next() + " not found in a new node"); } List<String> names = Lists.newArrayList(after.getChildNodeNames()); for (String child : effective.getMandatoryChildNodes()) { if (!names.remove(child)) { constraintViolation(25, "Mandatory child node " + child + " not found in a new node"); } } if (!names.isEmpty()) { for (String name : names) { NodeState child = after.getChildNode(name); String primary = child.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = child.getNames(JCR_MIXINTYPES); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, false); if (!effective.isValidChildNode(name, editor.getEffective())) { constraintViolation(25, "Unexpected child node " + name + " found in a new node"); } } } }
private void checkNodeTypeConstraints(NodeState after) throws CommitFailedException { EffectiveType effective = getEffective(); Set<String> properties = effective.getMandatoryProperties(); for (PropertyState ps : after.getProperties()) { properties.remove(ps.getName()); checkPropertyTypeConstraints(ps); } // verify the presence of all mandatory items if (!properties.isEmpty()) { constraintViolation(21, "Mandatory property " + properties.iterator().next() + " not found in a new node"); } List<String> names = Lists.newArrayList(after.getChildNodeNames()); for (String child : effective.getMandatoryChildNodes()) { if (!names.remove(child)) { constraintViolation(25, "Mandatory child node " + child + " not found in a new node"); } } if (!names.isEmpty()) { for (String name : names) { NodeState child = after.getChildNode(name); String primary = child.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = child.getNames(JCR_MIXINTYPES); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, false); if (!effective.isValidChildNode(name, editor.getEffective())) { constraintViolation(25, "Unexpected child node " + name + " found in a new node"); } } } }
@Test public void removeNonMandatoryProperty() throws CommitFailedException { EffectiveType effective = createControl().createMock(EffectiveType.class); expect(effective.isMandatoryProperty("mandatory")).andReturn(false); replay(effective); TypeEditor editor = new TypeEditor(effective); editor.propertyDeleted(PropertyStates.createProperty("mandatory", "")); }
@Override public TypeEditor childNodeChanged( String name, NodeState before, NodeState after) throws CommitFailedException { String primary = after.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = after.getNames(JCR_MIXINTYPES); if (primary == null && effective != null) { // no primary type defined, find and apply a default type primary = effective.getDefaultType(name); if (primary != null) { builder.setProperty(JCR_PRIMARYTYPE, primary, NAME); } else { constraintViolation( 4, "No default primary type available " + " for child node " + name); } } // if node type didn't change no need to validate child node boolean validate = primaryChanged(before, primary) || mixinsChanged(before, mixins); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, validate); if (checkThisNode && validate && !effective.isValidChildNode(name, editor.getEffective())) { constraintViolation( 1, "No matching definition found for child node " + name + " with effective type " + editor.getEffective()); } return editor; }
@Override public TypeEditor childNodeChanged( String name, NodeState before, NodeState after) throws CommitFailedException { String primary = after.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = after.getNames(JCR_MIXINTYPES); if (primary == null && effective != null) { // no primary type defined, find and apply a default type primary = effective.getDefaultType(name); if (primary != null) { builder.setProperty(JCR_PRIMARYTYPE, primary, NAME); } else { constraintViolation( 4, "No default primary type available " + " for child node " + name); } } // if node type didn't change no need to validate child node boolean validate = primaryChanged(before, primary) || mixinsChanged(before, mixins); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, validate); if (checkThisNode && validate && !effective.isValidChildNode(name, editor.getEffective())) { constraintViolation( 1, "No matching definition found for child node " + name + " with effective type " + editor.getEffective()); } return editor; }
@Override public TypeEditor childNodeChanged( String name, NodeState before, NodeState after) throws CommitFailedException { String primary = after.getName(JCR_PRIMARYTYPE); Iterable<String> mixins = after.getNames(JCR_MIXINTYPES); if (primary == null && effective != null) { // no primary type defined, find and apply a default type primary = effective.getDefaultType(name); if (primary != null) { builder.setProperty(JCR_PRIMARYTYPE, primary, NAME); } else { constraintViolation( 4, "No default primary type available " + " for child node " + name); } } // if node type didn't change no need to validate child node boolean validate = primaryChanged(before, primary) || mixinsChanged(before, mixins); NodeBuilder childBuilder = builder.getChildNode(name); TypeEditor editor = new TypeEditor(this, name, primary, mixins, childBuilder, validate); if (checkThisNode && validate && !effective.isValidChildNode(name, editor.getEffective())) { constraintViolation( 1, "No matching definition found for child node " + name + " with effective type " + editor.getEffective()); } return editor; }