001/* 002 * Copyright 2015 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.core.datasource.dbtype; 017 018import java.util.Collections; 019import java.util.HashMap; 020import java.util.Map; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.apache.avalon.framework.service.Serviceable; 025 026import org.ametys.runtime.i18n.I18nizableText; 027import org.ametys.runtime.model.Enumerator; 028 029/** 030 * Enumerator for {@link SQLDatabaseType}. 031 */ 032public class SQLDatabaseTypeEnumerator implements Enumerator<String>, Serviceable, org.ametys.runtime.parameter.Enumerator 033{ 034 /** The extension point handling the database types */ 035 private SQLDatabaseTypeExtensionPoint _sqlDatabaseTypeExtensionPoint; 036 037 @Override 038 public void service(ServiceManager manager) throws ServiceException 039 { 040 _sqlDatabaseTypeExtensionPoint = (SQLDatabaseTypeExtensionPoint) manager.lookup(SQLDatabaseTypeExtensionPoint.ROLE); 041 } 042 043 @Override 044 public I18nizableText getEntry(String value) throws Exception 045 { 046 SQLDatabaseType dbType = _sqlDatabaseTypeExtensionPoint.getExtension(value); 047 return dbType != null ? dbType.getLabel() : null; 048 } 049 050 @Override 051 public Map<String, I18nizableText> getTypedEntries() throws Exception 052 { 053 return _sqlDatabaseTypeExtensionPoint.getSQLDatabaseTypes(); 054 } 055 056 // TODO NEWATTRIBUTEAPI: remove this method when org.ametys.runtime.parameter.Enumerator will be removed 057 public Map<Object, I18nizableText> getEntries() 058 { 059 Map<Object, I18nizableText> result = new HashMap<>(); 060 for (Map.Entry<String, I18nizableText> entry : _sqlDatabaseTypeExtensionPoint.getSQLDatabaseTypes().entrySet()) 061 { 062 result.put(entry.getKey(), entry.getValue()); 063 } 064 return Collections.unmodifiableMap(result); 065 } 066 067 @Override 068 // TODO NEWATTRIBUTEAPI: remove this method when org.ametys.runtime.parameter.Enumerator will be removed 069 public Map<String, Object> getConfiguration() 070 { 071 return Collections.EMPTY_MAP; 072 } 073}