1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal.factory

File AbstractIteratorMimeMessageFactory.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
9
2
1
83
41
5
0.56
4.5
2
2.5

Classes

Class Line # Actions
AbstractIteratorMimeMessageFactory 42 9 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 13 tests. .

Source view

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.factory;
21   
22    import java.util.Iterator;
23    import java.util.Map;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28    import javax.mail.MessagingException;
29    import javax.mail.internet.MimeMessage;
30   
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.component.util.DefaultParameterizedType;
34    import org.xwiki.mail.MimeMessageFactory;
35   
36    /**
37    * Helper class for locating {@link org.xwiki.mail.MimeMessageFactory} and validating passed parameters.
38    *
39    * @version $Id: 080dc28b26ff36dc912fd4e2980f93a142869c3a $
40    * @since 6.4.1
41    */
 
42    public abstract class AbstractIteratorMimeMessageFactory extends AbstractMimeMessageFactory<Iterator<MimeMessage>>
43    {
44    /**
45    * The component manager instance to use to locate components dynamically.
46    */
47    @Inject
48    @Named("context")
49    protected Provider<ComponentManager> componentManagerProvider;
50   
 
51  35 toggle protected MimeMessageFactory getInternalMimeMessageFactory(String hint) throws MessagingException
52    {
53  35 try {
54  35 return this.componentManagerProvider.get().getInstance(new DefaultParameterizedType(null,
55    MimeMessageFactory.class, MimeMessage.class), hint);
56    } catch (ComponentLookupException e) {
57  3 throw new MessagingException(String.format("Failed to find a [%s<MimeMessage>] for hint [%s]",
58    MimeMessageFactory.class.getSimpleName(), hint));
59    }
60    }
61   
62    /**
63    * Verify the parameters exist for the passed parameter names.
64    *
65    * @param parameters the list of parameters to check
66    * @param names the list of mandatory parameter names to verify
67    * @throws MessagingException when a mandatory parameter doesn't exist
68    */
 
69  44 toggle protected void validateParameters(Map<String, Object> parameters, String... names)
70    throws MessagingException
71    {
72  44 if (parameters == null) {
73  3 throw new MessagingException("You must pass parameters for this Mime Message Factory to work!");
74    }
75   
76  41 for (String name : names) {
77  109 Object parameterValue = parameters.get(name);
78  109 if (parameterValue == null) {
79  6 throw new MessagingException(String.format("The parameter [%s] is mandatory.", name));
80    }
81    }
82    }
83    }