BrightSide Workbench Full Report + Source Code
Controls.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.entities;
20 
21 import org.turro.string.Strings;
22 import org.turro.annotation.ElephantControl;
23 import org.turro.elephant.context.IConstructor;
24 import org.turro.reflection.ClassNames;
25 import org.turro.reflection.Reflections;
26 
31 public class Controls {
32 
33  public static final String
34  CTRL_ATTACHMENT = "attachment",
35  CTRL_FILES = "files";
36 
37  public static Object getControl(String name) {
38  return getControl(name, null, null);
39  }
40 
41  public static Object getControl(String name, String entityPath) {
42  return getControl(name, null, entityPath);
43  }
44 
45  public static Object getControl(String name, IConstructor constructor) {
46  return getControl(name, constructor, null);
47  }
48 
49  public static Object getControl(String name, IConstructor constructor, String entityPath) {
50  if(!Strings.isBlank(name)) {
51  for(String sclass : ClassNames.cached().byAnnotation(ElephantControl.class.getName())) {
52  Class pclass = Reflections.check(sclass);
53  if(pclass != null && ((ElephantControl) pclass.getAnnotation(ElephantControl.class)).name().equals(name)) {
54  if(constructor != null) {
55  return Reflections.of(pclass).classes(IConstructor.class).objects(constructor).instance();
56  } else if(!Strings.isBlank(entityPath)) {
57  return Reflections.of(pclass).classes(String.class).objects(entityPath).instance();
58  }
59  return Reflections.of(pclass).instance();
60  }
61  }
62  }
63  return null;
64  }
65 
66  private Controls() {
67  }
68 
69 }
static Object getControl(String name, String entityPath)
Definition: Controls.java:41
static final String CTRL_ATTACHMENT
Definition: Controls.java:34
static Object getControl(String name, IConstructor constructor)
Definition: Controls.java:45
static Object getControl(String name)
Definition: Controls.java:37
static Object getControl(String name, IConstructor constructor, String entityPath)
Definition: Controls.java:49