protected void updateNodeType()

in src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java [160:192]


    protected void updateNodeType(final ResourceResolver resolver,
                    final String path,
                    final Map<String, RequestProperty> reqProperties,
                    final List<Modification> changes,
                    final VersioningConfiguration versioningConfiguration)
    throws PersistenceException {
        final String nodeType = getPrimaryType(reqProperties, path);
        if (nodeType != null) {
            final Resource rsrc = resolver.getResource(path);
            final ModifiableValueMap mvm = rsrc.adaptTo(ModifiableValueMap.class);
            if ( mvm != null ) {
                final Object node = this.jcrSupport.getNode(rsrc);
                final boolean wasVersionable = (node == null ? false : this.jcrSupport.isVersionable(rsrc));

                if ( node != null ) {
                    this.jcrSupport.checkoutIfNecessary(rsrc, changes, versioningConfiguration);
                    this.jcrSupport.setPrimaryNodeType(node, nodeType);
                } else {
                    mvm.put(JcrConstants.JCR_PRIMARYTYPE, nodeType);
                }

                if ( node != null ) {
                    // this is a bit of a cheat; there isn't a formal checkout, but assigning
                    // the mix:versionable mixin does an implicit checkout
                    if (!wasVersionable &&
                            versioningConfiguration.isCheckinOnNewVersionableNode() &&
                            this.jcrSupport.isVersionable(rsrc)) {
                        changes.add(Modification.onCheckout(path));
                    }
                }
            }
        }
    }