View Javadoc
1   package net.sf.logdistiller;
2   
3   /*
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  import java.io.Serializable;
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.regex.Pattern;
21  
22  /**
23   * @since 1.1
24   */
25  public class Attributes
26      implements Serializable
27  {
28      private static final long serialVersionUID = -3748978489200255819L;
29  
30      public static final Extension[] NO_EXTENSIONS = new Extension[0];
31  
32      private final String attributes;
33  
34      private final Extension[] extensions;
35  
36      public Attributes( String attributes, Extension[] extensions )
37      {
38          this.attributes = attributes;
39          this.extensions = extensions;
40      }
41  
42      public int getExtensionsCount()
43      {
44          return extensions.length;
45      }
46  
47      public Extension[] getExtensions()
48      {
49          return extensions;
50      }
51  
52      public String getAttributes()
53      {
54          return attributes;
55      }
56  
57      public static class Extension
58          implements Serializable
59      {
60          private static final long serialVersionUID = 4511835440598290789L;
61  
62          private final String source;
63  
64          private final List<String> provides;
65  
66          private transient final Pattern regexp;
67  
68          public Extension( String source, String provides, String regexp )
69          {
70              this.source = source;
71              String[] attributes = provides.split( "," );
72              this.provides = new ArrayList<String>( attributes.length );
73              for ( int i = 0; i < attributes.length; i++ )
74              {
75                  String attribute = attributes[i].trim();
76                  this.provides.add( attribute );
77              }
78              this.regexp = Pattern.compile( regexp );
79          }
80  
81          public String getSource()
82          {
83              return source;
84          }
85  
86          public List<String> getProvides()
87          {
88              return provides;
89          }
90  
91          public Pattern getRegexp()
92          {
93              return regexp;
94          }
95      }
96  }