public Object put()

in src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java [52:81]


    public Object put(final String aKey, final Object value) {
        final String key = checkKey(aKey);
        if (key.indexOf('/') != -1) {
            throw new IllegalArgumentException("Invalid key: " + key);
        }
        if (value == null) {
            throw new NullPointerException("Value should not be null (key = " + key + ")");
        }
        readFully();
        final Object oldValue = this.get(key);
        try {
            final JcrPropertyMapCacheEntry entry = new JcrPropertyMapCacheEntry(value, this.node);
            this.cache.put(key, entry);
            final String name = escapeKeyName(key);
            if (JcrConstants.JCR_MIXINTYPES.equals(name)) {
                NodeUtil.handleMixinTypes(node, entry.convertToType(String[].class, node, this.helper.getDynamicClassLoader()));
            } else if ("jcr:primaryType".equals(name)) {
                node.setPrimaryType(entry.convertToType(String.class, node, this.helper.getDynamicClassLoader()));
            } else if (entry.isArray()) {
                node.setProperty(name, entry.convertToType(Value[].class, node, this.helper.getDynamicClassLoader()));
            } else {
                node.setProperty(name, entry.convertToType(Value.class, node, this.helper.getDynamicClassLoader()));
            }
        } catch (final RepositoryException re) {
            throw new IllegalArgumentException("Value '" + value + "' for property '" + key + "' can't be put into node '" + getPath() + "'.", re);
        }
        this.valueCache.put(key, value);

        return oldValue;
    }