| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FileNameMappingFactory |
|
| 5.333333333333333;5.333 |
| 1 | package org.apache.maven.plugin.ear.output; | |
| 2 | ||
| 3 | /* | |
| 4 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 5 | * or more contributor license agreements. See the NOTICE file | |
| 6 | * distributed with this work for additional information | |
| 7 | * regarding copyright ownership. The ASF licenses this file | |
| 8 | * to you under the Apache License, Version 2.0 (the | |
| 9 | * "License"); you may not use this file except in compliance | |
| 10 | * with the License. You may obtain a copy of the License at | |
| 11 | * | |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 13 | * | |
| 14 | * Unless required by applicable law or agreed to in writing, | |
| 15 | * software distributed under the License is distributed on an | |
| 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 17 | * KIND, either express or implied. See the License for the | |
| 18 | * specific language governing permissions and limitations | |
| 19 | * under the License. | |
| 20 | */ | |
| 21 | ||
| 22 | import java.util.HashMap; | |
| 23 | import java.util.Map; | |
| 24 | ||
| 25 | /** | |
| 26 | * Provides access to {@link FileNameMapping} implementations. | |
| 27 | * <p/> | |
| 28 | * Two basic implementations are provided by default: | |
| 29 | * <ul> | |
| 30 | * <li>standard: the default implementation</li> | |
| 31 | * <li>full: an implementation that maps to a 'full' file name, i.e. containing the groupId</li> | |
| 32 | * </ul> | |
| 33 | * | |
| 34 | * @author <a href="snicoll@apache.org">Stephane Nicoll</a> | |
| 35 | * @version $Id: FileNameMappingFactory.java 942855 2010-05-10 19:13:52Z krosenvold $ | |
| 36 | */ | |
| 37 | public class FileNameMappingFactory | |
| 38 | { | |
| 39 | static final String STANDARD_FILE_NAME_MAPPING = "standard"; | |
| 40 | ||
| 41 | static final String FULL_FILE_NAME_MAPPING = "full"; | |
| 42 | ||
| 43 | private FileNameMappingFactory() | |
| 44 | 0 | { |
| 45 | 0 | } |
| 46 | ||
| 47 | public static FileNameMapping getDefaultFileNameMapping() | |
| 48 | { | |
| 49 | 2 | return new StandardFileNameMapping() ; |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * Returns the file name mapping implementation based on a logical name | |
| 54 | * of a fully qualified name of the class. | |
| 55 | * | |
| 56 | * @param nameOrClass a name of the fqn of the implementation | |
| 57 | * @return the file name mapping implementation | |
| 58 | * @throws IllegalStateException if the implementation is not found | |
| 59 | */ | |
| 60 | public static FileNameMapping getFileNameMapping( final String nameOrClass ) | |
| 61 | throws IllegalStateException | |
| 62 | { | |
| 63 | 5 | if (STANDARD_FILE_NAME_MAPPING.equals( nameOrClass )){ |
| 64 | 1 | return getDefaultFileNameMapping(); |
| 65 | } | |
| 66 | 4 | if (FULL_FILE_NAME_MAPPING.equals( nameOrClass )){ |
| 67 | 1 | return new FullFileNameMapping(); |
| 68 | } | |
| 69 | try | |
| 70 | { | |
| 71 | 3 | final Class c = Class.forName( nameOrClass ); |
| 72 | 2 | return (FileNameMapping) c.newInstance(); |
| 73 | } | |
| 74 | 1 | catch ( ClassNotFoundException e ) |
| 75 | { | |
| 76 | 1 | throw new IllegalStateException( |
| 77 | "File name mapping implementation[" + nameOrClass + "] was not found " + e.getMessage() ); | |
| 78 | } | |
| 79 | 0 | catch ( InstantiationException e ) |
| 80 | { | |
| 81 | 0 | throw new IllegalStateException( "Could not instanciate file name mapping implementation[" + |
| 82 | nameOrClass + "] make sure it has a default public constructor" ); | |
| 83 | } | |
| 84 | 0 | catch ( IllegalAccessException e ) |
| 85 | { | |
| 86 | 0 | throw new IllegalStateException( "Could not access file name mapping implementation[" + nameOrClass + |
| 87 | "] make sure it has a default public constructor" ); | |
| 88 | } | |
| 89 | 0 | catch ( ClassCastException e ) |
| 90 | { | |
| 91 | 0 | throw new IllegalStateException( "Specified class[" + nameOrClass + "] does not implement[" + |
| 92 | 0 | FileNameMapping.class.getName() + "]" ); |
| 93 | } | |
| 94 | } | |
| 95 | } |