1package org.apache.archiva.metadata.model.facets;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import org.apache.archiva.metadata.model.MetadataFacet;
23import org.apache.archiva.metadata.model.MetadataFacetFactory;
2425/**26 * @author Martin Stockhammer <martin_s@apache.org>27 */28publicabstractclass AbstractMetadataFacetFactory<T extends MetadataFacet> implements MetadataFacetFactory<T>
29 {
30privatefinal String facetId;
31privatefinal Class<T> facetClazz;
3233protectedAbstractMetadataFacetFactory( Class<T> facetClazz, String facetId) {
34this.facetId = facetId;
35this.facetClazz = facetClazz;
36 }
3738protectedAbstractMetadataFacetFactory(Class<T> facetClazz ) {
39this.facetClazz = facetClazz;
40try41 {
42this.facetId = (String) this.facetClazz.getField( "FACET_ID" ).get(null);
43 }
44catch ( Throwable e)
45 {
46thrownew RuntimeException( "There is no FACET_ID static public field on the class " + facetClazz );
47 }
48 }
4950 @Override
51publicabstract T createMetadataFacet( );
5253 @Override
54publicabstract T createMetadataFacet( String repositoryId, String name );
5556 @Override
57public Class<T> getFacetClass( )
58 {
59return facetClazz;
60 }
6162 @Override
63public String getFacetId( )
64 {
65return facetId;
66 }
67 }