| Class | Line # | Actions | |||||
|---|---|---|---|---|---|---|---|
| MimeMessageFactoryProvider | 36 | 5 | 0% | 3 | 1 |
| 1 | /* | |
| 2 | * See the NOTICE file distributed with this work for additional | |
| 3 | * information regarding copyright ownership. | |
| 4 | * | |
| 5 | * This is free software; you can redistribute it and/or modify it | |
| 6 | * under the terms of the GNU Lesser General Public License as | |
| 7 | * published by the Free Software Foundation; either version 2.1 of | |
| 8 | * the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This software is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this software; if not, write to the Free | |
| 17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
| 18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
| 19 | */ | |
| 20 | package org.xwiki.mail.internal.script; | |
| 21 | ||
| 22 | import java.lang.reflect.Type; | |
| 23 | ||
| 24 | import org.xwiki.component.manager.ComponentLookupException; | |
| 25 | import org.xwiki.component.manager.ComponentManager; | |
| 26 | import org.xwiki.component.util.DefaultParameterizedType; | |
| 27 | import org.xwiki.mail.MimeMessageFactory; | |
| 28 | ||
| 29 | /** | |
| 30 | * Get a {@link MimeMessageFactory} component instance for a Script Service, based on a component hint and a source | |
| 31 | * Type. | |
| 32 | * | |
| 33 | * @version $Id: 25003df106312eb2ed17705fbf2c15d4d7520ada $ | |
| 34 | * @since 6.4M3 | |
| 35 | */ | |
| 36 | public final class MimeMessageFactoryProvider | |
| 37 | { | |
| 38 | 0 | private MimeMessageFactoryProvider() |
| 39 | { | |
| 40 | // Hide the default constructor for utility classes | |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * @param hint the component hint of the {@link org.xwiki.mail.MimeMessageFactory} component to find | |
| 45 | * @param returnType the type returned by the {@link org.xwiki.mail.MimeMessageFactory} to find | |
| 46 | * @param componentManager used to dynamically load all MimeMessageIterator | |
| 47 | * @return MimeMessage Factory | |
| 48 | * @throws ComponentLookupException when an error occurs | |
| 49 | */ | |
| 50 | 3 | public static MimeMessageFactory get(String hint, Type returnType, ComponentManager componentManager) |
| 51 | throws ComponentLookupException | |
| 52 | { | |
| 53 | 3 | MimeMessageFactory factory; |
| 54 | // Step 1: Look for a secure version first | |
| 55 | 3 | try { |
| 56 | 3 | factory = componentManager.getInstance(new DefaultParameterizedType(null, MimeMessageFactory.class, |
| 57 | returnType), String.format("%s/secure", hint)); | |
| 58 | } catch (ComponentLookupException e) { | |
| 59 | // Step 2: Look for a non secure version if a secure one doesn't exist... | |
| 60 | 1 | factory = componentManager.getInstance(new DefaultParameterizedType(null, MimeMessageFactory.class, |
| 61 | returnType), hint); | |
| 62 | } | |
| 63 | ||
| 64 | 3 | return factory; |
| 65 | } | |
| 66 | } |