001package net.sf.logdistiller; 002 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 */ 016 017import java.io.Serializable; 018import java.util.ArrayList; 019import java.util.List; 020import java.util.regex.Pattern; 021 022/** 023 * @since 1.1 024 */ 025public class Attributes 026 implements Serializable 027{ 028 private static final long serialVersionUID = -3748978489200255819L; 029 030 public static final Extension[] NO_EXTENSIONS = new Extension[0]; 031 032 private final String attributes; 033 034 private final Extension[] extensions; 035 036 public Attributes( String attributes, Extension[] extensions ) 037 { 038 this.attributes = attributes; 039 this.extensions = extensions; 040 } 041 042 public int getExtensionsCount() 043 { 044 return extensions.length; 045 } 046 047 public Extension[] getExtensions() 048 { 049 return extensions; 050 } 051 052 public String getAttributes() 053 { 054 return attributes; 055 } 056 057 public static class Extension 058 implements Serializable 059 { 060 private static final long serialVersionUID = 4511835440598290789L; 061 062 private final String source; 063 064 private final List<String> provides; 065 066 private transient final Pattern regexp; 067 068 public Extension( String source, String provides, String regexp ) 069 { 070 this.source = source; 071 String[] attributes = provides.split( "," ); 072 this.provides = new ArrayList<String>( attributes.length ); 073 for ( int i = 0; i < attributes.length; i++ ) 074 { 075 String attribute = attributes[i].trim(); 076 this.provides.add( attribute ); 077 } 078 this.regexp = Pattern.compile( regexp ); 079 } 080 081 public String getSource() 082 { 083 return source; 084 } 085 086 public List<String> getProvides() 087 { 088 return provides; 089 } 090 091 public Pattern getRegexp() 092 { 093 return regexp; 094 } 095 } 096}