nodetypemanagerimpl.java

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

JAVA
500
字号
                    throw new IOException(e.getMessage());                }            } else {                throw new UnsupportedRepositoryOperationException(                        "Unsupported content type: " + contentType);            }            Iterator iterator = namespaceMap.entrySet().iterator();            while (iterator.hasNext()) {                Map.Entry entry = (Map.Entry) iterator.next();                nsReg.safeRegisterNamespace((String) entry.getKey(),                        (String) entry.getValue());            }            if (reregisterExisting) {                // split the node types into new and already registered node types.                // this way we can register new node types together with already                // registered node types which make circular dependencies possible                List newNodeTypeDefs = new ArrayList();                List registeredNodeTypeDefs = new ArrayList();                for (Iterator iter = nodeTypeDefs.iterator(); iter.hasNext();) {                    NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next();                    if (ntReg.isRegistered(nodeTypeDef.getName())) {                        registeredNodeTypeDefs.add(nodeTypeDef);                    } else {                        newNodeTypeDefs.add(nodeTypeDef);                    }                }                ArrayList nodeTypes = new ArrayList();                // register new node types                nodeTypes.addAll(Arrays.asList(registerNodeTypes(newNodeTypeDefs)));                // reregister already existing node types                for (Iterator iter = registeredNodeTypeDefs.iterator(); iter.hasNext();) {                    NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next();                    ntReg.reregisterNodeType(nodeTypeDef);                    nodeTypes.add(getNodeType(nodeTypeDef.getName()));                }                return (NodeType[]) nodeTypes.toArray(new NodeType[nodeTypes.size()]);            } else {                return registerNodeTypes(nodeTypeDefs);            }        } catch (InvalidNodeTypeDefException e) {            throw new RepositoryException("Invalid node type definition", e);        }    }    //---------------------------------------------< NodeTypeRegistryListener >    /**     * {@inheritDoc}     */    public void nodeTypeRegistered(QName ntName) {        // not interested, ignore    }    /**     * {@inheritDoc}     */    public void nodeTypeReRegistered(QName ntName) {        // flush all affected cache entries        ntCache.remove(ntName);        synchronized (pdCache) {            Iterator iter = pdCache.values().iterator();            while (iter.hasNext()) {                PropertyDefinitionImpl pd = (PropertyDefinitionImpl) iter.next();                if (ntName.equals(pd.unwrap().getDeclaringNodeType())) {                    iter.remove();                }            }        }        synchronized (ndCache) {            Iterator iter = ndCache.values().iterator();            while (iter.hasNext()) {                NodeDefinitionImpl nd = (NodeDefinitionImpl) iter.next();                if (ntName.equals(nd.unwrap().getDeclaringNodeType())) {                    iter.remove();                }            }        }    }    /**     * {@inheritDoc}     */    public void nodeTypeUnregistered(QName ntName) {        // flush all affected cache entries        ntCache.remove(ntName);        synchronized (pdCache) {            Iterator iter = pdCache.values().iterator();            while (iter.hasNext()) {                PropertyDefinitionImpl pd = (PropertyDefinitionImpl) iter.next();                if (ntName.equals(pd.unwrap().getDeclaringNodeType())) {                    iter.remove();                }            }        }        synchronized (ndCache) {            Iterator iter = ndCache.values().iterator();            while (iter.hasNext()) {                NodeDefinitionImpl nd = (NodeDefinitionImpl) iter.next();                if (ntName.equals(nd.unwrap().getDeclaringNodeType())) {                    iter.remove();                }            }        }    }    //------------------------------------------------------< NodeTypeManager >    /**     * {@inheritDoc}     */    public NodeTypeIterator getAllNodeTypes() throws RepositoryException {        QName[] ntNames = ntReg.getRegisteredNodeTypes();        ArrayList list = new ArrayList(ntNames.length);        for (int i = 0; i < ntNames.length; i++) {            list.add(getNodeType(ntNames[i]));        }        return new IteratorHelper(Collections.unmodifiableCollection(list));    }    /**     * {@inheritDoc}     */    public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException {        QName[] ntNames = ntReg.getRegisteredNodeTypes();        ArrayList list = new ArrayList(ntNames.length);        for (int i = 0; i < ntNames.length; i++) {            NodeType nt = getNodeType(ntNames[i]);            if (!nt.isMixin()) {                list.add(nt);            }        }        return new IteratorHelper(Collections.unmodifiableCollection(list));    }    /**     * {@inheritDoc}     */    public NodeTypeIterator getMixinNodeTypes() throws RepositoryException {        QName[] ntNames = ntReg.getRegisteredNodeTypes();        ArrayList list = new ArrayList(ntNames.length);        for (int i = 0; i < ntNames.length; i++) {            NodeType nt = getNodeType(ntNames[i]);            if (nt.isMixin()) {                list.add(nt);            }        }        return new IteratorHelper(Collections.unmodifiableCollection(list));    }    /**     * {@inheritDoc}     */    public NodeType getNodeType(String nodeTypeName)            throws NoSuchNodeTypeException {        try {            return getNodeType(NameFormat.parse(nodeTypeName, nsResolver));        } catch (NameException e) {            throw new NoSuchNodeTypeException(nodeTypeName, e);        }    }    //--------------------------------------------< JackrabbitNodeTypeManager >    /**     * Internal helper method for registering a list of node type definitions.     * Returns an array containing the registered node types.     *     * @param defs a collection of <code>NodeTypeDef<code> objects     * @returns registered node types     * @throws InvalidNodeTypeDefException     * @throws RepositoryException     */    private NodeType[] registerNodeTypes(List defs)            throws InvalidNodeTypeDefException, RepositoryException {        ntReg.registerNodeTypes(defs);        Set types = new HashSet();        Iterator iterator = defs.iterator();        while (iterator.hasNext()) {            try {                NodeTypeDef def = (NodeTypeDef) iterator.next();                types.add(getNodeType(def.getName()));            } catch (NoSuchNodeTypeException e) {                // ignore            }        }        return (NodeType[]) types.toArray(new NodeType[types.size()]);    }    /**     * Registers the node types defined in the given XML stream.  This     * is a trivial implementation that just invokes the existing     * {@link NodeTypeReader} and {@link NodeTypeRegistry} methods and     * heuristically creates the returned node type array.  It will also     * register any namespaces defined in the input source that have not     * already been registered.     *     * {@inheritDoc}     */    public NodeType[] registerNodeTypes(InputSource in)            throws SAXException, RepositoryException {        try {            return registerNodeTypes(in.getByteStream(), TEXT_XML);        } catch (IOException e) {            throw new SAXException("Error reading node type stream", e);        }    }    private static final String APPLICATION_XML = "application/xml";    /**     * Registers the node types defined in the given input stream depending     * on the content type specified for the stream. This will also register     * any namespaces identified in the input stream if they have not already     * been registered.     *     * {@inheritDoc}     */    public NodeType[] registerNodeTypes(InputStream in, String contentType)            throws IOException, RepositoryException {        return registerNodeTypes(in, contentType, false);    }    /**     * {@inheritDoc}     */    public boolean hasNodeType(String name) throws RepositoryException {        try {            QName qname = NameFormat.parse(name, nsResolver);            return getNodeTypeRegistry().isRegistered(qname);        } catch (NameException e) {           throw new RepositoryException();        }    }    //-------------------------------------------------------------< Dumpable >    /**     * {@inheritDoc}     */    public void dump(PrintStream ps) {        ps.println("NodeTypeManager (" + this + ")");        ps.println();        ntReg.dump(ps);    }}

⌨️ 快捷键说明

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