View Javadoc
1   /*
2    * Copyright 2001-2005 The Apache Software Foundation.
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  package org.apache.logging.log4j.catalog.api.dao;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.apache.logging.log4j.catalog.api.Attribute;
22  import org.apache.logging.log4j.catalog.api.CatalogData;
23  import org.apache.logging.log4j.catalog.api.CatalogReader;
24  import org.apache.logging.log4j.catalog.api.Category;
25  import org.apache.logging.log4j.catalog.api.Event;
26  import org.apache.logging.log4j.catalog.api.Product;
27  
28  public abstract class AbstractCatalogReader implements CatalogReader {
29      protected CatalogData catalogData = null;
30  
31      protected final Map<String, Attribute> attributes = new HashMap<>();
32  
33      @Override
34      public Map<String, Attribute> getAttributes() {
35          return attributes;
36      }
37  
38      @Override
39      public Attribute getAttribute(String name) {
40          return attributes.get(name);
41      }
42  
43      @Override
44      public Category getCategory(String name) {
45          if (catalogData.getCategories() != null) {
46              return catalogData.getCategories().stream().filter(c -> c.getName().equals(name)).findFirst().orElse(null);
47          }
48          return null;
49      }
50  
51  
52      @Override
53      public Event getEvent(String name) {
54          if (catalogData.getEvents() != null) {
55              return catalogData.getEvents().stream().filter(e -> e.getName().equals(name)).findFirst().orElse(null);
56          }
57          return null;
58      }
59  
60  
61      @Override
62      public Product getProduct(String name) {
63          if (catalogData.getProducts() != null) {
64              return catalogData.getProducts().stream().filter(p -> p.getName().equals(name)).findFirst().orElse(null);
65          }
66          return null;
67      }
68  
69      public String readCatalog() {
70          return null;
71      }
72  
73      @Override
74      public CatalogData read() {
75          return catalogData;
76      }
77  }