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