nodepropbundle.java

来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 698 行 · 第 1/2 页

JAVA
698
字号
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.jackrabbit.core.persistence.bundle.util;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Set;import javax.jcr.PropertyType;import org.apache.jackrabbit.core.NodeId;import org.apache.jackrabbit.core.PropertyId;import org.apache.jackrabbit.core.persistence.PersistenceManager;import org.apache.jackrabbit.core.value.InternalValue;import org.apache.jackrabbit.core.value.BLOBFileValue;import org.apache.jackrabbit.core.state.PropertyState;import org.apache.jackrabbit.core.state.NodeState;import org.apache.jackrabbit.core.nodetype.NodeDefId;import org.apache.jackrabbit.core.nodetype.PropDefId;import org.apache.jackrabbit.name.QName;/** * This Class provides a simple structure to hold the nodestate and related * propertystate data. */public class NodePropBundle {    /** the cvs/svn id */    static final String CVS_ID = "$URL: http://svn.apache.org/repos/asf/jackrabbit/tags/1.3.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NodePropBundle.java $ $Rev: 517150 $ $Date: 2007-03-12 11:42:12 +0200 (Mon, 12 Mar 2007) $";    /**     * the node id     */    private final NodeId id;    /**     * the parent node id     */    private NodeId parentId;    /**     * the nodetype name     */    private QName nodeTypeName;    /**     * the mixintype names     */    private Set mixinTypeNames;    /**     * the nodedef id     */    private NodeDefId nodeDefId;    /**     * the child node entries     */    private LinkedList childNodeEntries = new LinkedList();    /**     * the properties     */    private HashMap properties = new HashMap();    /**     * flag that indicates if this bundle is new     */    private boolean isNew = true;    /**     * flag that indicates if this bundle is referenceable     */    private boolean isReferenceable = false;    /**     * the mod count     */    private short modCount = 0;    /**     * the size     */    private long size = 0;    /**     * Creates a "new" bundle with the given id     * @param id the node id     */    public NodePropBundle(NodeId id) {        this.id = id;    }    /**     * Creates a bundle from the given state     * @param state the node state     */    public NodePropBundle(NodeState state) {        this((NodeId) state.getId());        update(state);    }    /**     * Updates this bundle with values from the given state.     * @param state the node state     */    public void update(NodeState state) {        if (!id.equals(state.getNodeId())) {            // sanity check            throw new IllegalArgumentException("Not allowed to update forgein state.");        }        parentId = state.getParentId();        nodeTypeName = state.getNodeTypeName();        mixinTypeNames = state.getMixinTypeNames();        nodeDefId = state.getDefinitionId();        isReferenceable = state.hasPropertyName(QName.JCR_UUID);        modCount = state.getModCount();        List list = state.getChildNodeEntries();        Iterator iter = list.iterator();        childNodeEntries.clear();        while (iter.hasNext()) {            NodeState.ChildNodeEntry cne = (NodeState.ChildNodeEntry) iter.next();            addChildNodeEntry(cne.getName(), cne.getId());        }    }    /**     * Creates a node state from the values of this bundle     * @param pMgr the persistence manager     * @return the new nodestate     */    public NodeState createNodeState(PersistenceManager pMgr) {        NodeState state = pMgr.createNew(id);        state.setParentId(parentId);        state.setNodeTypeName(nodeTypeName);        state.setMixinTypeNames(mixinTypeNames);        state.setDefinitionId(nodeDefId);        state.setModCount(modCount);        Iterator iter = childNodeEntries.iterator();        while (iter.hasNext()) {            ChildNodeEntry e = (ChildNodeEntry) iter.next();            state.addChildNodeEntry(e.getName(), e.getId());        }        state.setPropertyNames(properties.keySet());        // add fake property entries        state.addPropertyName(QName.JCR_PRIMARYTYPE);        if (mixinTypeNames.size()>0) {            state.addPropertyName(QName.JCR_MIXINTYPES);        }        // uuid is special...only if 'referenceable'        if (isReferenceable) {            state.addPropertyName(QName.JCR_UUID);        }        return state;    }    /**     * Creates a property state from the values of this bundle     * @param pMgr the persistence manager     * @param name the name of the new property     * @return the new property state     */    public PropertyState createPropertyState(PersistenceManager pMgr, QName name) {        PropertyEntry p = getPropertyEntry(name);        if (p == null) {            return null;        }        PropertyState ps = pMgr.createNew(new PropertyId(id, name));        ps.setDefinitionId(p.getPropDefId());        ps.setMultiValued(p.isMultiValued());        ps.setType(p.getType());        ps.setValues(p.getValues());        ps.setModCount(p.getModCount());        return ps;    }    /**     * Checks if this bundle is new.     * @return <code>true</code> if this bundle is new;     *         <code>false</code> otherwise.     */    public boolean isNew() {        return isNew;    }    /**     * Marks this bunlde as 'not new'.     */    public void markOld() {        isNew = false;    }    /**     * Returns the node id of this bundle     * @return the node id of this bundle     */    public NodeId getId() {        return id;    }    /**     * Returns the parent id of this bundle     * @return the parent id of this bundle     */    public NodeId getParentId() {        return parentId;    }    /**     * Sets the parent id     * @param parentId the parent id     */    public void setParentId(NodeId parentId) {        this.parentId = parentId;    }    /**     * Returns the nodetype name of this bundle     * @return the nodetype name of this bundle     */    public QName getNodeTypeName() {        return nodeTypeName;    }    /**     * Sets the node type name     * @param nodeTypeName the nodetype name     */    public void setNodeTypeName(QName nodeTypeName) {        this.nodeTypeName = nodeTypeName;    }    /**     * Returns the mixin type names of this bundle.     * @return the mixin type names of this bundle.     */    public Set getMixinTypeNames() {        return mixinTypeNames;    }    /**     * Sets the mixin type names     * @param mixinTypeNames the mixin type names     */    public void setMixinTypeNames(Set mixinTypeNames) {        this.mixinTypeNames = mixinTypeNames;    }    /**     * Returns the node def id of this bundle.     * @return the node def id.     */    public NodeDefId getNodeDefId() {        return nodeDefId;    }    /**     * Sets the node def id.     * @param nodeDefId the node def id.     */    public void setNodeDefId(NodeDefId nodeDefId) {        this.nodeDefId = nodeDefId;    }    /**     * Checks if this bundle is referenceable.     * @return <code>true</code> if this bundle is referenceable;     *         <code>false</code> otherwise.     */    public boolean isReferenceable() {        return isReferenceable;    }    /**     * Sets the is referenceable flag on this bundle     * @param referenceable the ref. flag     */    public void setReferenceable(boolean referenceable) {        isReferenceable = referenceable;    }    /**     * Retrusn the mod clount.     * @return the mod clount.     */    public short getModCount() {        return modCount;    }    /**     * Sets the mod count     * @param modCount the mod count     */    public void setModCount(short modCount) {        this.modCount = modCount;    }    /**     * Returns the list of the child node entries.     * @return the list of the child node entries.     */    public List getChildNodeEntries() {        return childNodeEntries;    }    /**     * Adds a child node entry.     * @param name the name of the entry.     * @param id the id of the entry     */    public void addChildNodeEntry(QName name, NodeId id) {        childNodeEntries.add(new ChildNodeEntry(name, id));    }    /**     * Adds a new property entry     * @param entry the enrty to add     */    public void addProperty(PropertyEntry entry) {        properties.put(entry.getName(), entry);    }    /**     * Creates a property entry from the given state and adds it.     * @param state the property state     */    public void addProperty(PropertyState state) {        PropertyEntry old = (PropertyEntry) properties.put(state.getName(), new PropertyEntry(state));        if (old != null) {            old.destroy();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?