001/*
002 *  Copyright 2019 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.catalog;
017
018import java.util.ArrayList;
019import java.util.Collection;
020import java.util.Collections;
021import java.util.List;
022
023import org.apache.avalon.framework.activity.Initializable;
024import org.apache.avalon.framework.component.Component;
025import org.apache.avalon.framework.service.ServiceException;
026import org.apache.avalon.framework.service.ServiceManager;
027import org.apache.avalon.framework.service.Serviceable;
028
029import org.ametys.runtime.model.ElementDefinition;
030import org.ametys.runtime.model.Model;
031import org.ametys.runtime.model.ModelItem;
032import org.ametys.runtime.model.type.ModelItemTypeConstants;
033
034/**
035 * Model of catalog objects
036 */
037public class CatalogModel implements Model, Serviceable, Initializable, Component
038{
039    /** Avalon Role */
040    public static final String ROLE = CatalogModel.class.getName();
041    
042    /** title attribute. */
043    public static final String TITLE = "title";
044    
045    /** isDefault attribute. */
046    public static final String IS_DEFAULT = "isDefault";
047    
048    private CatalogDataTypeExtensionPoint _catalogDataTypeExtensionPoint;
049    private List<ModelItem> _modelItems = new ArrayList<>();
050
051    public void service(ServiceManager manager) throws ServiceException
052    {
053        _catalogDataTypeExtensionPoint = (CatalogDataTypeExtensionPoint) manager.lookup(CatalogDataTypeExtensionPoint.ROLE);
054    }
055
056    public void initialize() throws Exception
057    {
058        ElementDefinition<String> title = new ElementDefinition<>();
059        title.setName(TITLE);
060        title.setType(_catalogDataTypeExtensionPoint.getExtension(ModelItemTypeConstants.STRING_TYPE_ID));
061        _modelItems.add(title);
062        
063        ElementDefinition<Boolean> isDefault = new ElementDefinition<>();
064        isDefault.setName(IS_DEFAULT);
065        isDefault.setType(_catalogDataTypeExtensionPoint.getExtension(ModelItemTypeConstants.BOOLEAN_TYPE_ID));
066        _modelItems.add(isDefault);
067    }
068
069    public Collection< ? extends ModelItem> getModelItems()
070    {
071        return Collections.unmodifiableList(_modelItems);
072    }
073
074    public String getId()
075    {
076        return CatalogModel.class.getName();
077    }
078
079    public String getFamilyId()
080    {
081        return CatalogModel.class.getName();
082    }
083}