View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.lib.types;
20  
21  import org.apache.syncope.common.lib.request.AnyCR;
22  import org.apache.syncope.common.lib.request.AnyObjectCR;
23  import org.apache.syncope.common.lib.request.AnyObjectUR;
24  import org.apache.syncope.common.lib.request.AnyUR;
25  import org.apache.syncope.common.lib.request.GroupCR;
26  import org.apache.syncope.common.lib.request.GroupUR;
27  import org.apache.syncope.common.lib.request.UserCR;
28  import org.apache.syncope.common.lib.request.UserUR;
29  import org.apache.syncope.common.lib.to.AnyObjectTO;
30  import org.apache.syncope.common.lib.to.AnyTO;
31  import org.apache.syncope.common.lib.to.GroupTO;
32  import org.apache.syncope.common.lib.to.UserTO;
33  
34  public enum AnyTypeKind {
35  
36      USER(UserTO.class, UserCR.class, UserUR.class),
37      GROUP(GroupTO.class, GroupCR.class, GroupUR.class),
38      ANY_OBJECT(AnyObjectTO.class, AnyObjectCR.class, AnyObjectUR.class);
39  
40      private final Class<? extends AnyTO> toClass;
41  
42      private final Class<? extends AnyCR> crClass;
43  
44      private final Class<? extends AnyUR> urClass;
45  
46      AnyTypeKind(
47              final Class<? extends AnyTO> toClass,
48              final Class<? extends AnyCR> crClass,
49              final Class<? extends AnyUR> urClass) {
50  
51          this.toClass = toClass;
52          this.crClass = crClass;
53          this.urClass = urClass;
54      }
55  
56      public Class<? extends AnyTO> getTOClass() {
57          return toClass;
58      }
59  
60      public Class<? extends AnyCR> getCRClass() {
61          return crClass;
62      }
63  
64      public Class<? extends AnyUR> getURClass() {
65          return urClass;
66      }
67  
68      public static AnyTypeKind fromTOClass(final Class<? extends AnyTO> clazz) {
69          return UserTO.class.isAssignableFrom(clazz)
70                  ? AnyTypeKind.USER
71                  : GroupTO.class.isAssignableFrom(clazz)
72                  ? AnyTypeKind.GROUP
73                  : AnyTypeKind.ANY_OBJECT;
74      }
75  }