1   /*
2    * Copyright 2003 - 2013 The eFaps Team
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   * Revision:        $Rev$
17   * Last Changed:    $Date$
18   * Last Changed By: $Author$
19   */
20  
21  
22  package org.efaps.ci;
23  
24  import org.efaps.util.cache.CacheReloadException;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  
29  /**
30   * Each class that extends this abstract class represents a configuration
31   * item for a type from eFaps. It is used to have easy access during the
32   * coding of esjp etc. to the configuration items without having the problem
33   * of using strings to access them. The classes are created automatically
34   * with a maven target.
35   *
36   * @author The eFaps Team
37   * @version $Id$
38   */
39  //CHECKSTYLE:OFF
40  public abstract class CIType
41      extends CIObject
42  {
43  
44      /**
45       * Logging instance used in this class.
46       */
47      private static final Logger LOG = LoggerFactory.getLogger(CIObject.class);
48  
49      /**
50       * ID attribute. Each type must have it.
51       */
52      public final CIAttribute ID = new CIAttribute(this, "ID");
53  
54      /**
55       * OID attribute.Each type must have it.
56       */
57      public final CIAttribute OID = new CIAttribute(this, "OID");
58  
59      /**
60       * Type attribute.Each type must have it.
61       */
62      public final CIAttribute Type = new CIAttribute(this, "Type");
63     //CHECKSTYLE:ON
64      /**
65       * Constructor setting the uuid.
66       * @param _uuid UUID of this type
67       */
68      protected CIType(final String _uuid)
69      {
70          super(_uuid);
71      }
72  
73      /**
74       * Get the type this Configuration item represents.
75       *
76       * @return Type
77       */
78      public org.efaps.admin.datamodel.Type getType()
79      {
80          org.efaps.admin.datamodel.Type ret = null;
81          try {
82              ret =  org.efaps.admin.datamodel.Type.get(this.uuid);
83          } catch (final CacheReloadException e) {
84              CIType.LOG.error("Error on retrieving Type for CIType with uuid: {}", this.uuid);
85          }
86          return ret;
87      }
88  
89      /**
90       * Tests, if this type is kind of the type in the parameter (question is, is
91       * this type a child of the parameter type).
92       *
93       * @param _type type to test for parent
94       * @return true if this type is a child, otherwise false
95       */
96      public boolean isKindOf(final org.efaps.admin.datamodel.Type _type)
97      {
98          return getType().isKindOf(_type);
99      }
100 
101     /**
102      * Tests, if this type the type in the parameter .
103      *
104      * @param _type type to test
105      * @return true if this type otherwise false
106      */
107     public boolean isType(final org.efaps.admin.datamodel.Type _type)
108     {
109         return getType().equals(_type);
110     }
111 }