001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.odf.orgunit;
017
018import javax.jcr.Node;
019
020import org.apache.avalon.framework.service.ServiceException;
021import org.apache.avalon.framework.service.ServiceManager;
022
023import org.ametys.cms.repository.ContentFactory;
024import org.ametys.cms.repository.ModifiableContentFactory;
025import org.ametys.plugins.repository.AmetysRepositoryException;
026import org.ametys.plugins.repository.RepositoryConstants;
027
028/**
029 * {@link ContentFactory} for handling {@link OrgUnit}
030 */
031public class OrgUnitFactory extends ModifiableContentFactory
032{
033    /** {@link OrgUnit} nodetype for resources collection */
034    public static final String ORGUNIT_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":orgunitContent";
035
036    /** {@link OrgUnit} content type */
037    public static final String ORGUNIT_CONTENT_TYPE = "org.ametys.plugins.odf.Content.orgunit";
038
039    /** The root OrgUnit node name */
040    public static final String ODF_ORGUNIT_ROOT_NODE = "root-orgunit";
041
042    private RootOrgUnitProvider _rootOrgUnitProvider;
043    
044    @Override
045    public void service(ServiceManager manager) throws ServiceException
046    {
047        super.service(manager);
048        _rootOrgUnitProvider = (RootOrgUnitProvider) manager.lookup(RootOrgUnitProvider.ROLE);
049    }
050    
051    @Override
052    public OrgUnit getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException
053    {
054        return new OrgUnit(node, parentPath, this);
055    }
056
057    String _getRootOrgUnitUAI()
058    {
059        return _rootOrgUnitProvider.getRoot().getUAICode();
060    }
061}