BrightSide Workbench Full Report + Source Code
org.turro.elephant.impl.context.ContextFactory Class Reference

Static Public Member Functions

static IContext getContext (IConstructor constructor)
 
static IContext getContext (IConstructor constructor, String path)
 
static IElement getContextElement (IContext context, Element node)
 
static IElement getContextElement (IContext context, String type, Element node)
 
static IAction getAction (IConstructor constructor)
 
static Element getInclude (IConstructor constructor)
 
static Element getRedirection (String path)
 
static Element getVirtual (String server)
 
static List getImplementationNamesByType (String type)
 
static Object getImplementation (IElement iel, String name)
 
static Object getImplementation (IConstructor constructor, String name)
 
static Object getJavaClass (String jClass)
 
static Object getInstance (String node, Class defaultClass)
 
static void resetImplementationsStartingWith (String name)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 51 of file ContextFactory.java.

Member Function Documentation

◆ getAction()

static IAction org.turro.elephant.impl.context.ContextFactory.getAction ( IConstructor  constructor)
static

Definition at line 100 of file ContextFactory.java.

100  {
101  IAction impl = null;
102  String type = constructor.getRequest().getServletPath().substring(9);
103  Element element = getConfNode("actions/action[@type='" + type + "']");
104  if(element != null) {
105  try {
106  String jClass = element.getAttributeValue("java-class");
107  Class cls = Class.forName(makeItTurro(jClass));
108  if(cls != null) {
109  Constructor cons = cls.getConstructor(new Class[] {});
110  if(cons != null) {
111  impl = (IAction)cons.newInstance(new Object[] {});
112  }
113  }
114  } catch(Exception ex) {
115  Logger.getLogger(ContextFactory.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
116  }
117  }
118  if(impl != null) {
119  impl.setConstructor(constructor);
120  }
121  return impl;
122  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContext() [1/2]

static IContext org.turro.elephant.impl.context.ContextFactory.getContext ( IConstructor  constructor)
static

Definition at line 57 of file ContextFactory.java.

57  {
58  return getContext(constructor, null);
59  }
static IContext getContext(IConstructor constructor)
Here is the caller graph for this function:

◆ getContext() [2/2]

static IContext org.turro.elephant.impl.context.ContextFactory.getContext ( IConstructor  constructor,
String  path 
)
static

Definition at line 61 of file ContextFactory.java.

61  {
62  IContext impl = new DefaultContext(); //(IContext) getInstance("context", DefaultContext.class);
63  if(impl != null) {
64  impl.setConstructor(constructor, path);
65  }
66  return impl;
67  }
Here is the call graph for this function:

◆ getContextElement() [1/2]

static IElement org.turro.elephant.impl.context.ContextFactory.getContextElement ( IContext  context,
Element  node 
)
static

Definition at line 69 of file ContextFactory.java.

69  {
70  return getContextElement(context, node.getAttributeValue("type"), node);
71  }
static IElement getContextElement(IContext context, Element node)

◆ getContextElement() [2/2]

static IElement org.turro.elephant.impl.context.ContextFactory.getContextElement ( IContext  context,
String  type,
Element  node 
)
static

Definition at line 73 of file ContextFactory.java.

73  {
74  IElement impl = null;
75  Element element = null;
76  if(!"none".equals(type)) {
77  element = getConfNode("elements/element[@type='" + type + "']");
78  }
79  if(element != null) {
80  try {
81  String jClass = element.getAttributeValue("java-class");
82  Class cls = Class.forName(makeItTurro(jClass));
83  if(cls != null) {
84  Constructor cons = cls.getConstructor(new Class[] {});
85  if(cons != null) {
86  impl = (IElement)cons.newInstance(new Object[] {});
87  }
88  }
89  } catch(ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
90  Logger.getLogger(ContextFactory.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
91  }
92  }
93  if(impl instanceof AbstractElement) {
94  ((AbstractElement) impl).setConfiguration(node, element);
95  //impl.setContext(context);
96  }
97  return impl;
98  }
Here is the call graph for this function:

◆ getImplementation() [1/2]

static Object org.turro.elephant.impl.context.ContextFactory.getImplementation ( IConstructor  constructor,
String  name 
)
static

Definition at line 169 of file ContextFactory.java.

169  {
170  Object impl = null;
171  Element element = getConfNode("implementations/impl[@interface='" + name + "']");
172  if(element != null) {
173  try {
174  String jClass = element.getAttributeValue("java-class");
175  Class cls = Class.forName(makeItTurro(jClass));
176  if(cls != null) {
177  Constructor cons = cls.getConstructor(new Class[] {});
178  if(cons != null) {
179  impl = cons.newInstance(new Object[] {});
180  }
181  }
182  } catch(Exception ex) {
183  Logger.getLogger(ContextFactory.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
184  }
185  }
186  if(impl != null) {
187  if(impl instanceof IImplementation) {
188  ((IImplementation)impl).setConstructor(constructor);
189  if(element != null) {
190  ((IImplementation)impl).setConfiguration((Element)element.clone());
191  }
192  }
193  }
194  return impl;
195  }
Here is the call graph for this function:

◆ getImplementation() [2/2]

static Object org.turro.elephant.impl.context.ContextFactory.getImplementation ( IElement  iel,
String  name 
)
static

Definition at line 154 of file ContextFactory.java.

154  {
155  IConstructor xpcons = null;
156  Object impl = null;
157  if(iel != null) xpcons = iel.getConstructor();
158  if(xpcons != null) {
159  impl = getImplementation(xpcons, name);
160  if(impl != null) {
161  if(impl instanceof IImplementation) {
162  ((IImplementation)impl).setElement(iel);
163  }
164  }
165  }
166  return impl;
167  }
static Object getImplementation(IElement iel, String name)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getImplementationNamesByType()

static List org.turro.elephant.impl.context.ContextFactory.getImplementationNamesByType ( String  type)
static

Definition at line 137 of file ContextFactory.java.

137  {
138  List list = new ArrayList();
139  for(Element element : (List<Element>) getConfNodes("implementations")) {
140  if(element != null) {
141  try {
142  Iterator it = XPath.selectNodes(element, "impl[starts-with(@interface,'" + type + "_')]/@interface").iterator();
143  while(it.hasNext()) {
144  list.add(((Attribute)it.next()).getValue());
145  }
146  } catch(Exception ex) {
147  Logger.getLogger(ContextFactory.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
148  }
149  }
150  }
151  return list;
152  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getInclude()

static Element org.turro.elephant.impl.context.ContextFactory.getInclude ( IConstructor  constructor)
static

Definition at line 124 of file ContextFactory.java.

124  {
125  String type = constructor.getRequest().getServletPath();
126  return getConfNode("includes/include[@type='" + type + "']");
127  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getInstance()

static Object org.turro.elephant.impl.context.ContextFactory.getInstance ( String  node,
Class  defaultClass 
)
static

Definition at line 213 of file ContextFactory.java.

213  {
214  Constructor cons = impls.get(node);
215  if(cons == null) {
216  Class javaClass = null;
217  Element element = getConfNode(node);
218  if(element != null) {
219  try {
220  String jClass = element.getAttributeValue("java-class");
221  javaClass = Class.forName(makeItTurro(jClass));
222  } catch(Exception ex) {
223  Logger.getLogger(ContextFactory.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
224  }
225  }
226  if(javaClass == null) {
227  javaClass = defaultClass;
228  }
229  try {
230  impls.put(node, javaClass.getConstructor(new Class[] {}));
231  return Reflections.of(javaClass).instance();
232  } catch (Exception ex) {
233  Logger.getLogger(ContextFactory.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
234  }
235  } else {
236  try {
237  return cons.newInstance(new Object[] {} );
238  } catch (Exception ex) {
239  Logger.getLogger(ContextFactory.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
240  }
241  }
242  return null;
243  }
Here is the call graph for this function:

◆ getJavaClass()

static Object org.turro.elephant.impl.context.ContextFactory.getJavaClass ( String  jClass)
static

Definition at line 197 of file ContextFactory.java.

197  {
198  Object impl = null;
199  try {
200  Class cls = Class.forName(makeItTurro(jClass));
201  if(cls != null) {
202  Constructor cons = cls.getConstructor(new Class[] {});
203  if(cons != null) {
204  impl = cons.newInstance(new Object[] {});
205  }
206  }
207  } catch(Exception ex) {
208  Logger.getLogger(ContextFactory.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
209  }
210  return impl;
211  }
Here is the call graph for this function:

◆ getRedirection()

static Element org.turro.elephant.impl.context.ContextFactory.getRedirection ( String  path)
static

Definition at line 129 of file ContextFactory.java.

129  {
130  return getConfNode("redirections/redirect[@request and starts-with('" + path + "',@request)]");
131  }

◆ getVirtual()

static Element org.turro.elephant.impl.context.ContextFactory.getVirtual ( String  server)
static

Definition at line 133 of file ContextFactory.java.

133  {
134  return getConfNode("virtuals/virtual[@server='" + server + "']");
135  }

◆ resetImplementationsStartingWith()

static void org.turro.elephant.impl.context.ContextFactory.resetImplementationsStartingWith ( String  name)
static

Definition at line 245 of file ContextFactory.java.

245  {
246  elements.entrySet().removeIf(e -> e.getKey().startsWith("implementations/impl[@interface='" + name));
247  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: