View Javadoc

1   /*
2    * Copyright 2007 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.myfaces.config;
17  
18  import org.apache.myfaces.config.element.FacesConfig;
19  import org.apache.myfaces.config.element.OrderSlot;
20  import org.apache.myfaces.config.impl.digester.DigesterFacesConfigUnmarshallerImpl;
21  import org.apache.myfaces.config.impl.digester.elements.AbsoluteOrdering;
22  import org.apache.myfaces.config.impl.digester.elements.ConfigOthersSlot;
23  import org.apache.myfaces.config.impl.digester.elements.FacesConfigNameSlot;
24  import org.apache.myfaces.config.impl.digester.elements.Ordering;
25  import org.apache.myfaces.test.base.AbstractJsfTestCase;
26  
27  import javax.faces.FacesException;
28  import java.util.ArrayList;
29  import java.util.Collections;
30  import java.util.List;
31  import java.util.logging.Level;
32  import java.util.logging.Logger;
33  
34  public class OrderingFacesConfigTest extends AbstractJsfTestCase
35  {
36      private static final Logger log = Logger.getLogger(OrderingFacesConfigTest.class.getName());
37      
38      private DigesterFacesConfigUnmarshallerImpl _impl;
39      
40      public OrderingFacesConfigTest(String name)
41      {
42          super(name);
43      }
44      
45      protected void setUp() throws Exception
46      {
47          super.setUp();
48          _impl = new DigesterFacesConfigUnmarshallerImpl(null);
49      }
50      
51      public void printFacesConfigList(String label, List<FacesConfig> appConfigResources)
52      {
53          System.out.println("");
54          System.out.print(""+label+": [");
55          for (int i = 0; i < appConfigResources.size();i++)
56          {
57              if (appConfigResources.get(i).getName() == null)
58              {
59                  System.out.print("No_id,");
60              }
61              else
62              {
63                  System.out.print(appConfigResources.get(i).getName()+",");
64              }
65          }
66          System.out.println("]");
67  
68      }
69      
70      /**
71       * A before others
72       * B after C
73       * C after others
74       * 
75       * preferred result:
76       * 
77       * A C B No_id No_id 
78       * 
79       * @throws Exception
80       */
81      public void testSimpleOrdering() throws Exception
82      {
83          FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
84          "empty-config.xml"), "empty-config.xml");
85          FacesConfig cfgA = _impl.getFacesConfig(getClass().getResourceAsStream(
86              "a-config.xml"), "a-config.xml");
87          FacesConfig cfgB = _impl.getFacesConfig(getClass().getResourceAsStream(
88              "b-config.xml"), "b-config.xml");
89          FacesConfig cfgC = _impl.getFacesConfig(getClass().getResourceAsStream(
90              "c-config.xml"), "c-config.xml");
91          
92          
93          List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
94          appConfigResources.add(cfgA);
95          appConfigResources.add(cfgB);
96          appConfigResources.add(cfgC);
97          appConfigResources.add(cfg);
98          appConfigResources.add(cfg);
99          
100         //Brute force       
101         for (int i = 0; i < 30; i++)
102         {
103             Collections.shuffle(appConfigResources);
104             applyAlgorithm(appConfigResources);
105         }
106     }
107     
108     /**
109      * A before B
110      * A before E
111      * C after A
112      * C after B
113      * C before D
114      * C before E
115      * E after D
116      * D before others
117      * 
118      * preferred results:
119      * 
120      * A B C D E No_id
121      * 
122      * @throws Exception
123      */
124     public void testMiddleOrdering() throws Exception
125     {
126         FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
127         "empty-config.xml"), "empty-config.xml");        
128         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgA = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
129         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
130         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
131         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgD = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
132         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgE = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
133         
134         cfgA.setName("A");
135         cfgB.setName("B");
136         cfgC.setName("C");
137         cfgD.setName("D");
138         cfgE.setName("E");
139         
140         cfgC.setOrdering(new Ordering());
141         FacesConfigNameSlot temp = new FacesConfigNameSlot();
142         temp.setName("D");
143         cfgC.getOrdering().getBeforeList().add(temp);
144         temp = new FacesConfigNameSlot();
145         temp.setName("E");
146         cfgC.getOrdering().getBeforeList().add(temp);        
147         temp = new FacesConfigNameSlot();
148         temp.setName("A");
149         cfgC.getOrdering().getAfterList().add(temp);
150         temp = new FacesConfigNameSlot();
151         temp.setName("B");
152         cfgC.getOrdering().getAfterList().add(temp);
153         
154         cfgA.setOrdering(new Ordering());
155         temp = new FacesConfigNameSlot();
156         temp.setName("B");
157         cfgA.getOrdering().getBeforeList().add(temp);
158         temp = new FacesConfigNameSlot();
159         temp.setName("E");
160         cfgA.getOrdering().getBeforeList().add(temp);
161         
162         cfgE.setOrdering(new Ordering());
163         temp = new FacesConfigNameSlot();
164         temp.setName("D");
165         cfgE.getOrdering().getAfterList().add(temp);
166         
167         cfgD.setOrdering(new Ordering());
168         cfgD.getOrdering().getBeforeList().add(new ConfigOthersSlot());
169         
170         List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
171         appConfigResources.add(cfgA);
172         appConfigResources.add(cfgB);
173         appConfigResources.add(cfgC);
174         appConfigResources.add(cfgD);
175         appConfigResources.add(cfgE);
176         appConfigResources.add(cfg);
177         
178         //Brute force       
179         for (int i = 0; i < 30; i++)
180         {
181             Collections.shuffle(appConfigResources);
182             applyAlgorithm(appConfigResources);
183         }
184     }
185     
186     /**
187      * A before B
188      * A before C
189      * B after A
190      * B before C
191      * C after A
192      * C after B
193      * 
194      * preferred result
195      * 
196      * A B C
197      * 
198      * @throws Exception
199      */
200     public void testMaxConditionsOrdering() throws Exception
201     {
202         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
203         "empty-config.xml"), "empty-config.xml");        
204         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgA = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
205         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
206         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
207 
208         cfgA.setName("A");
209         cfgB.setName("B");
210         cfgC.setName("C");
211         
212         cfgA.setOrdering(new Ordering());
213         FacesConfigNameSlot temp = new FacesConfigNameSlot();
214         temp.setName("B");
215         cfgA.getOrdering().getBeforeList().add(temp);
216         temp = new FacesConfigNameSlot();
217         temp.setName("C");
218         cfgA.getOrdering().getBeforeList().add(temp);
219         
220         cfgB.setOrdering(new Ordering());
221         temp = new FacesConfigNameSlot();
222         temp.setName("A");
223         cfgB.getOrdering().getAfterList().add(temp);
224         temp = new FacesConfigNameSlot();
225         temp.setName("C");
226         cfgB.getOrdering().getBeforeList().add(temp);
227         
228         cfgC.setOrdering(new Ordering());
229         temp = new FacesConfigNameSlot();
230         temp.setName("A");
231         cfgC.getOrdering().getAfterList().add(temp);
232         temp = new FacesConfigNameSlot();
233         temp.setName("B");
234         cfgC.getOrdering().getAfterList().add(temp);
235         //cfgC.getOrdering().getBeforeList().add(new ConfigOthersSlot());
236         
237         List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
238         appConfigResources.add(cfgC);
239         appConfigResources.add(cfgA);
240         appConfigResources.add(cfgB);
241         
242         //Brute force       
243         for (int i = 0; i < 30; i++)
244         {
245             Collections.shuffle(appConfigResources);
246             applyAlgorithm(appConfigResources);
247         }
248     }
249     
250     public void testEx1()
251     {      
252         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgA = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
253         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
254         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
255         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgD = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
256         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgE = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
257         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgF = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
258 
259         cfgA.setName("A");
260         cfgB.setName("B");
261         cfgC.setName("C");
262         cfgD.setName("D");
263         cfgE.setName("E");
264         cfgF.setName("F");
265         
266         cfgA.setOrdering(new Ordering());
267         cfgA.getOrdering().getAfterList().add(new ConfigOthersSlot());
268         FacesConfigNameSlot temp = new FacesConfigNameSlot();
269         temp.setName("C");
270         cfgA.getOrdering().getAfterList().add(temp);
271         
272         cfgB.setOrdering(new Ordering());
273         cfgB.getOrdering().getBeforeList().add(new ConfigOthersSlot());
274 
275         cfgC.setOrdering(new Ordering());
276         cfgC.getOrdering().getAfterList().add(new ConfigOthersSlot());
277 
278         cfgF.setOrdering(new Ordering());
279         cfgF.getOrdering().getBeforeList().add(new ConfigOthersSlot());
280         temp = new FacesConfigNameSlot();
281         temp.setName("B");
282         cfgF.getOrdering().getBeforeList().add(temp);
283         
284         
285         List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
286         appConfigResources.add(cfgA);
287         appConfigResources.add(cfgB);
288         appConfigResources.add(cfgC);
289         appConfigResources.add(cfgD);
290         appConfigResources.add(cfgE);
291         appConfigResources.add(cfgF);
292         
293         //Brute force       
294         for (int i = 0; i < 30; i++)
295         {
296             Collections.shuffle(appConfigResources);
297             applyAlgorithm(appConfigResources);
298         }
299     }
300     
301     public void testEx2()
302     {
303         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfg = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
304         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
305         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
306         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgD = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
307         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgE = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
308         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgF = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
309 
310         cfgB.setName("B");
311         cfgC.setName("C");
312         cfgD.setName("D");
313         cfgE.setName("E");
314         cfgF.setName("F");
315         
316         cfg.setOrdering(new Ordering());
317         cfg.getOrdering().getAfterList().add(new ConfigOthersSlot());
318         FacesConfigNameSlot temp = new FacesConfigNameSlot();
319         temp.setName("C");
320         cfg.getOrdering().getBeforeList().add(temp);
321 
322         cfgB.setOrdering(new Ordering());
323         cfgB.getOrdering().getBeforeList().add(new ConfigOthersSlot());
324         
325         cfgD.setOrdering(new Ordering());
326         cfgD.getOrdering().getAfterList().add(new ConfigOthersSlot());
327 
328         cfgE.setOrdering(new Ordering());
329         cfgE.getOrdering().getBeforeList().add(new ConfigOthersSlot());
330 
331         List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
332         appConfigResources.add(cfg);
333         appConfigResources.add(cfgB);
334         appConfigResources.add(cfgC);
335         appConfigResources.add(cfgD);
336         appConfigResources.add(cfgE);
337         appConfigResources.add(cfgF);
338 
339         //Brute force       
340         for (int i = 0; i < 30; i++)
341         {
342             Collections.shuffle(appConfigResources);
343             applyAlgorithm(appConfigResources);
344         }
345     }
346     
347     public void testEx3()
348     {
349         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgA = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
350         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
351         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
352         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgD = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
353 
354         cfgA.setName("A");
355         cfgB.setName("B");
356         cfgC.setName("C");
357         cfgD.setName("D");
358 
359         cfgA.setOrdering(new Ordering());
360         FacesConfigNameSlot temp = new FacesConfigNameSlot();
361         temp.setName("B");
362         cfgA.getOrdering().getAfterList().add(temp);
363 
364         cfgC.setOrdering(new Ordering());
365         cfgC.getOrdering().getBeforeList().add(new ConfigOthersSlot());
366         
367         List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
368         appConfigResources.add(cfgA);
369         appConfigResources.add(cfgB);
370         appConfigResources.add(cfgC);
371         appConfigResources.add(cfgD);
372 
373         //Brute force       
374         for (int i = 0; i < 30; i++)
375         {
376             Collections.shuffle(appConfigResources);
377             applyAlgorithm(appConfigResources);
378         }
379     }
380     
381     public void testEx4() throws Exception
382     {
383         FacesConfig cfgA = _impl.getFacesConfig(getClass().getResourceAsStream(
384             "transitive-a-config.xml"), "transitive-a-config.xml");
385         FacesConfig cfgB = _impl.getFacesConfig(getClass().getResourceAsStream(
386             "transitive-b-config.xml"), "transitive-b-config.xml");
387         FacesConfig cfgC = _impl.getFacesConfig(getClass().getResourceAsStream(
388             "transitive-c-config.xml"), "transitive-c-config.xml");
389         
390         List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
391         appConfigResources.add(cfgA);
392         appConfigResources.add(cfgB);
393         appConfigResources.add(cfgC);
394         
395         //Brute force       
396         for (int i = 0; i < 30; i++)
397         {
398             Collections.shuffle(appConfigResources);
399             applyAlgorithm(appConfigResources);
400         }
401     }
402 
403     public void applyAlgorithm(List<FacesConfig> appConfigResources) throws FacesException
404     {
405         DefaultFacesConfigurationMerger merger = new DefaultFacesConfigurationMerger();
406 
407         List<FacesConfig> postOrderedList = merger.getPostOrderedList(appConfigResources);
408         
409         List<FacesConfig> sortedList = merger.sortRelativeOrderingList(postOrderedList);
410         
411         if (sortedList == null)
412         {
413             //The previous algorithm can't sort correctly, try this one
414             sortedList = merger.applySortingAlgorithm(appConfigResources);
415         }
416         
417         //printFacesConfigList("Sorted List", sortedList);
418     }
419 
420     /*
421     public void applyAlgorithm(List<FacesConfig> appConfigResources) throws FacesException
422     {
423         printFacesConfigList("Start List", appConfigResources);
424         
425         //0. Convert the references into a graph
426         List<Vertex> vertexList = new ArrayList<Vertex>();
427         for (FacesConfig config : appConfigResources)
428         {
429             Vertex v = null;
430             if (config.getName() != null)
431             {
432                 v = new Vertex(config.getName(), config);
433             }
434             else
435             {
436                 v = new Vertex(config);
437             }
438             vertexList.add(v);
439         }
440         
441         //1. Resolve dependencies (before-after rules) and mark referenced vertex
442         boolean[] referencedVertex = new boolean[vertexList.size()];
443 
444         for (int i = 0; i < vertexList.size(); i++)
445         {
446             Vertex v = vertexList.get(i);
447             FacesConfig f = (FacesConfig) v.getNode();
448             
449             if (f.getOrdering() != null)
450             {
451                 for (OrderSlot slot : f.getOrdering().getBeforeList())
452                 {
453                     if (slot instanceof FacesConfigNameSlot)
454                     {
455                         String name = ((FacesConfigNameSlot) slot).getName();
456                         int j = findVertex(vertexList, name);
457                         Vertex v1 = vertexList.get(j);
458                         if (v1 != null)
459                         {
460                             referencedVertex[i] = true;
461                             referencedVertex[j] = true;
462                             v1.addDependency(v);
463                         }
464                     }
465                 }
466                 for (OrderSlot slot : f.getOrdering().getAfterList())
467                 {
468                     if (slot instanceof FacesConfigNameSlot)
469                     {
470                         String name = ((FacesConfigNameSlot) slot).getName();
471                         int j = findVertex(vertexList, name);
472                         Vertex v1 = vertexList.get(j);
473                         if (v1 != null)
474                         {
475                             referencedVertex[i] = true;
476                             referencedVertex[j] = true;
477                             v.addDependency(v1);
478                         }
479                     }
480                 }
481             }
482         }
483 
484         //2. Classify into categories
485         List<Vertex> beforeAfterOthersList = new ArrayList<Vertex>();
486         List<Vertex> othersList = new ArrayList<Vertex>();
487         List<Vertex> referencedList = new ArrayList<Vertex>();
488         
489         for (int i = 0; i < vertexList.size(); i++)
490         {
491             if (!referencedVertex[i])
492             {
493                 Vertex v = vertexList.get(i);
494                 FacesConfig f = (FacesConfig) v.getNode();
495                 boolean added = false;
496                 if (f.getOrdering() != null)
497                 {
498                     if (!f.getOrdering().getBeforeList().isEmpty())
499                     {
500                         added = true;
501                         beforeAfterOthersList.add(v);                        
502                     }
503                     else if (!f.getOrdering().getAfterList().isEmpty())
504                     {
505                         added = true;
506                         beforeAfterOthersList.add(v);
507                     }
508                 }
509                 if (!added)
510                 {
511                     othersList.add(v);
512                 }
513             }
514             else
515             {
516                 referencedList.add(vertexList.get(i));
517             }
518         }
519         
520         //3. Sort all referenced nodes
521         try
522         {
523             DirectedAcyclicGraphVerifier.topologicalSort(referencedList);
524         }
525         catch (CyclicDependencyException e)
526         {
527             e.printStackTrace();
528         }
529 
530         //4. Add referenced nodes
531         List<FacesConfig> sortedList = new ArrayList<FacesConfig>();
532         for (Vertex v : referencedList)
533         {
534             sortedList.add((FacesConfig)v.getNode());
535         }
536         
537         //5. add nodes without instructions at the end
538         for (Vertex v : othersList)
539         {
540             sortedList.add((FacesConfig)v.getNode());
541         }
542         
543         //6. add before/after nodes
544         for (Vertex v : beforeAfterOthersList)
545         {
546             FacesConfig f = (FacesConfig) v.getNode();
547             boolean added = false;
548             if (f.getOrdering() != null)
549             {
550                 if (!f.getOrdering().getBeforeList().isEmpty())
551                 {
552                     added = true;
553                     sortedList.add(0,f);                        
554                 }
555             }
556             if (!added)
557             {
558                 sortedList.add(f);
559             }            
560         }
561         
562         printFacesConfigList("Sorted List", sortedList);
563         
564         //Check
565         for (int i = 0; i < sortedList.size(); i++)
566         {
567             FacesConfig resource = sortedList.get(i);
568             
569             if (resource.getOrdering() != null)
570             {
571                 for (OrderSlot slot : resource.getOrdering().getBeforeList())
572                 {
573                     if (slot instanceof FacesConfigNameSlot)
574                     {
575                         String name = ((FacesConfigNameSlot) slot).getName();
576                         if (name != null && !"".equals(name))
577                         {
578                             boolean founded = false;                                
579                             for (int j = i-1; j >= 0; j--)
580                             {
581                                 if (name.equals(sortedList.get(j).getName()))
582                                 {
583                                     founded=true;
584                                     break;
585                                 }
586                             }
587                             if (founded)
588                             {
589                                 log.severe("Circular references detected when sorting " +
590                                           "application config resources. Use absolute ordering instead.");
591                                 throw new FacesException("Circular references detected when sorting " +
592                                         "application config resources. Use absolute ordering instead.");
593                             }
594                         }
595                     }
596                 }
597                 for (OrderSlot slot : resource.getOrdering().getAfterList())
598                 {
599                     if (slot instanceof FacesConfigNameSlot)
600                     {
601                         String name = ((FacesConfigNameSlot) slot).getName();
602                         if (name != null && !"".equals(name))
603                         {
604                             boolean founded = false;                                
605                             for (int j = i+1; j < sortedList.size(); j++)
606                             {
607                                 if (name.equals(sortedList.get(j).getName()))
608                                 {
609                                     founded=true;
610                                     break;
611                                 }
612                             }
613                             if (founded)
614                             {
615                                 log.severe("Circular references detected when sorting " +
616                                     "application config resources. Use absolute ordering instead.");
617                                 throw new FacesException("Circular references detected when sorting " +
618                                     "application config resources. Use absolute ordering instead.");
619                             }
620                         }
621                     }
622                 }
623             }
624         }
625     }
626     
627     public int findVertex(List<Vertex> vertexList, String name)
628     {
629         for (int i = 0; i < vertexList.size(); i++)
630         {
631             Vertex v = vertexList.get(i);
632             if (name.equals(v.getName()))
633             {
634                 return i;
635             }
636         }
637         return -1;
638     }*/
639 
640     public void applyAlgorithm2(List<FacesConfig> appConfigResources) throws FacesException
641     {
642         DefaultFacesConfigurationMerger merger = new DefaultFacesConfigurationMerger();
643         
644         System.out.println("");
645         System.out.print("Start List: [");
646         for (int i = 0; i < appConfigResources.size();i++)
647         {
648             if (appConfigResources.get(i).getName() == null)
649             {
650                 System.out.print("No id,");
651             }
652             else
653             {
654                 System.out.print(appConfigResources.get(i).getName()+",");
655             }
656         }
657         System.out.println("]");
658         
659         List<FacesConfig> postOrderedList = merger.getPostOrderedList(appConfigResources);
660         
661         System.out.print("Pre-Ordered-List: [");
662         for (int i = 0; i < postOrderedList.size();i++)
663         {
664             if (postOrderedList.get(i).getName() == null)
665             {
666                 System.out.print("No id,");
667             }
668             else
669             {
670                 System.out.print(postOrderedList.get(i).getName()+",");
671             }
672         }
673         System.out.println("]");
674         
675         List<FacesConfig> sortedList = merger.sortRelativeOrderingList(postOrderedList);
676         
677         System.out.print("Sorted-List: [");
678         for (int i = 0; i < sortedList.size();i++)
679         {
680             if (sortedList.get(i).getName() == null)
681             {
682                 System.out.print("No id,");
683             }
684             else
685             {
686                 System.out.print(sortedList.get(i).getName()+",");
687             }
688         }
689         System.out.println("]");
690     }
691     
692     public void testAbsoluteOrdering1() throws Exception
693     {
694         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgAbs = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
695         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgMK = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
696         org.apache.myfaces.config.impl.digester.elements.FacesConfig cfgOWB = new org.apache.myfaces.config.impl.digester.elements.FacesConfig();
697 
698         cfgMK.setName("cz_markoc_faces");
699         
700         AbsoluteOrdering ao = new AbsoluteOrdering();
701         FacesConfigNameSlot temp = new FacesConfigNameSlot();
702         temp.setName("cz_markoc_faces");
703         ao.addOrderSlot(temp);
704         ao.addOrderSlot(new ConfigOthersSlot());
705         
706         cfgAbs.setAbsoluteOrdering(ao);
707 
708         List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
709         appConfigResources.add(cfgMK);
710         appConfigResources.add(cfgOWB);
711         
712         //printFacesConfigList("Start List: [", appConfigResources);
713         
714         List<FacesConfig> sortedResources = orderAndFeedArtifactsAbsolute(appConfigResources, cfgAbs);
715         
716         //printFacesConfigList("Sorted-List: [", sortedResources);
717         
718         assertTrue(sortedResources.containsAll(appConfigResources));
719 
720         appConfigResources = new ArrayList<FacesConfig>();
721         appConfigResources.add(cfgOWB);
722         appConfigResources.add(cfgMK);
723         
724         //printFacesConfigList("Start List: [", appConfigResources);
725         
726         sortedResources = orderAndFeedArtifactsAbsolute(appConfigResources, cfgAbs);
727         
728         //printFacesConfigList("Sorted-List: [", sortedResources);
729         
730         assertTrue(sortedResources.containsAll(appConfigResources));
731 
732     }
733     
734     public List<FacesConfig> orderAndFeedArtifactsAbsolute(List<FacesConfig> appConfigResources, FacesConfig webAppConfig)
735     {
736         FacesConfigurator configurator = new FacesConfigurator(externalContext);
737 
738         if (webAppConfig != null && webAppConfig.getAbsoluteOrdering() != null)
739         {
740             if (webAppConfig.getOrdering() != null)
741             {
742                 if (log.isLoggable(Level.WARNING))
743                 {
744                     log.warning("<ordering> element found in application faces config. " +
745                             "This description will be ignored and the actions described " +
746                             "in <absolute-ordering> element will be taken into account instead.");
747                 }                
748             }
749             //Absolute ordering
750             
751             //1. Scan all appConfigResources and create a list
752             //containing all resources not mentioned directly, preserving the
753             //order founded
754             List<FacesConfig> othersResources = new ArrayList<FacesConfig>();
755             List<OrderSlot> slots = webAppConfig.getAbsoluteOrdering().getOrderList();
756             for (FacesConfig resource : appConfigResources)
757             {
758                 // First condition: if faces-config.xml does not have name it is 1) pre-JSF-2.0 or 2) has no <name> element,
759                 // -> in both cases cannot be ordered
760                 // Second condition : faces-config.xml has a name but <ordering> element does not have slot with that name
761                 //  -> resource can be ordered, but will fit into <others /> element
762                 if ((resource.getName() == null) || (resource.getName() != null && !containsResourceInSlot(slots, resource.getName())))
763                 {
764                     othersResources.add(resource);
765                 }
766             }
767 
768             List<FacesConfig> sortedResources = new ArrayList<FacesConfig>();
769             //2. Scan slot by slot and merge information according
770             for (OrderSlot slot : webAppConfig.getAbsoluteOrdering().getOrderList())
771             {
772                 if (slot instanceof ConfigOthersSlot)
773                 {
774                     //Add all mentioned in othersResources
775                     for (FacesConfig resource : othersResources)
776                     {
777                         sortedResources.add(resource);
778                     }
779                 }
780                 else
781                 {
782                     //Add it to the sorted list
783                     FacesConfigNameSlot nameSlot = (FacesConfigNameSlot) slot;
784                     sortedResources.add(getFacesConfig(appConfigResources, nameSlot.getName()));
785                 }
786             }
787             
788             return sortedResources;
789         }
790         
791         return null;
792     }
793 
794     private FacesConfig getFacesConfig(List<FacesConfig> appConfigResources, String name)
795     {
796         for (FacesConfig cfg: appConfigResources)
797         {
798             if (cfg.getName() != null && name.equals(cfg.getName()))
799             {
800                 return cfg;
801             }
802         }
803         return null;
804     }
805     
806     private boolean containsResourceInSlot(List<OrderSlot> slots, String name)
807     {
808         for (OrderSlot slot: slots)
809         {
810             if (slot instanceof FacesConfigNameSlot)
811             {
812                 FacesConfigNameSlot nameSlot = (FacesConfigNameSlot) slot;
813                 if (name.equals(nameSlot.getName()))
814                 {
815                     return true;
816                 }
817             }
818         }
819         return false;
820     }
821 
822     /**
823      * Sort a list of pre ordered elements. It scans one by one the elements
824      * and apply the conditions mentioned by Ordering object if it is available.
825      * 
826      * The preOrderedList ensures that application config resources referenced by
827      * other resources are processed first, making more easier the sort procedure. 
828      * 
829      * @param preOrderedList
830      * @return
831      */
832     /*
833     private List<FacesConfig> sortRelativeOrderingList(List<FacesConfig> preOrderedList) throws FacesException
834     {
835         List<FacesConfig> sortedList = new ArrayList<FacesConfig>();
836         
837         for (int i=0; i < preOrderedList.size(); i++)
838         {
839             FacesConfig resource = preOrderedList.get(i);
840             if (resource.getOrdering() != null)
841             {
842                 if (resource.getOrdering().getBeforeList().isEmpty() &&
843                     resource.getOrdering().getAfterList().isEmpty())
844                 {
845                     //No order rules, just put it as is
846                     sortedList.add(resource);
847                 }
848                 else if (resource.getOrdering().getBeforeList().isEmpty())
849                 {
850                     //Only after rules
851                     applyAfterRule(sortedList, resource);
852                 }
853                 else if (resource.getOrdering().getAfterList().isEmpty())
854                 {
855                     //Only before rules
856                     
857                     //Resolve if there is a later reference to this node before
858                     //apply it
859                     boolean referenceNode = false;
860 
861                     for (int j = i+1; j < preOrderedList.size(); j++)
862                     {
863                         FacesConfig pointingResource = preOrderedList.get(j);
864                         for (OrderSlot slot : pointingResource.getOrdering().getBeforeList())
865                         {
866                             if (slot instanceof FacesConfigNameSlot &&
867                                     resource.getName().equals(((FacesConfigNameSlot)slot).getName()) )
868                             {
869                                 referenceNode = true;
870                             }
871                             if (slot instanceof ConfigOthersSlot)
872                             {
873                                 //No matter if there is a reference, because this rule
874                                 //is not strict and before other ordering is unpredictable.
875                                 //
876                                 referenceNode = false;
877                                 break;
878                             }
879                         }
880                         if (referenceNode)
881                         {
882                             break;
883                         }
884                         for (OrderSlot slot : pointingResource.getOrdering().getAfterList())
885                         {
886                             if (slot instanceof FacesConfigNameSlot &&
887                                 resource.getName().equals(((FacesConfigNameSlot)slot).getName()) )
888                             {
889                                 referenceNode = true;
890                                 break;
891                             }
892                         }
893                     }
894                     
895                     applyBeforeRule(sortedList, resource, referenceNode);
896                 }
897                 else
898                 {
899                     //Both before and after rules
900                     //In this case we should compare before and after rules
901                     //and the one with names takes precedence over the other one.
902                     //It both have names references, before rules takes
903                     //precedence over after
904                     //after some action is applied a check of the condition is made.
905                     int beforeWeight = 0;
906                     int afterWeight = 0;
907                     for (OrderSlot slot : resource.getOrdering()
908                             .getBeforeList())
909                     {
910                         if (slot instanceof FacesConfigNameSlot)
911                         {
912                             beforeWeight++;
913                         }
914                     }
915                     for (OrderSlot slot : resource.getOrdering()
916                             .getAfterList())
917                     {
918                         if (slot instanceof FacesConfigNameSlot)
919                         {
920                             afterWeight++;
921                         }
922                     }
923                     
924                     if (beforeWeight >= afterWeight)
925                     {
926                         applyBeforeRule(sortedList, resource,false);
927                     }
928                     else
929                     {
930                         applyAfterRule(sortedList, resource);
931                     }
932                     
933                     
934                 }
935             }
936             else
937             {
938                 //No order rules, just put it as is
939                 sortedList.add(resource);
940             }
941         }
942         
943         //Check
944         for (int i = 0; i < sortedList.size(); i++)
945         {
946             FacesConfig resource = sortedList.get(i);
947             
948             if (resource.getOrdering() != null)
949             {
950                 for (OrderSlot slot : resource.getOrdering().getBeforeList())
951                 {
952                     if (slot instanceof FacesConfigNameSlot)
953                     {
954                         String name = ((FacesConfigNameSlot) slot).getName();
955                         if (name != null && !"".equals(name))
956                         {
957                             boolean founded = false;                                
958                             for (int j = i-1; j >= 0; j--)
959                             {
960                                 if (name.equals(sortedList.get(j).getName()))
961                                 {
962                                     founded=true;
963                                     break;
964                                 }
965                             }
966                             if (founded)
967                             {
968                                 //LOG WARN MESSAGE ABOUT IT
969                                 throw new FacesException();
970                             }
971                         }
972                     }
973                 }
974                 for (OrderSlot slot : resource.getOrdering().getAfterList())
975                 {
976                     if (slot instanceof FacesConfigNameSlot)
977                     {
978                         String name = ((FacesConfigNameSlot) slot).getName();
979                         if (name != null && !"".equals(name))
980                         {
981                             boolean founded = false;                                
982                             for (int j = i+1; j < sortedList.size(); j++)
983                             {
984                                 if (name.equals(sortedList.get(j).getName()))
985                                 {
986                                     founded=true;
987                                     break;
988                                 }
989                             }
990                             if (founded)
991                             {
992                                 //LOG WARN MESSAGE ABOUT IT
993                                 throw new FacesException();
994                             }
995                         }
996                     }
997                 }
998             }
999         }
1000         
1001         return sortedList;
1002     }
1003     
1004     private void applyBeforeRule(List<FacesConfig> sortedList, FacesConfig resource, boolean referenced) throws FacesException
1005     {
1006         //Only before rules
1007         boolean configOthers = false;
1008         List<String> names = new ArrayList<String>();
1009         
1010         for (OrderSlot slot : resource.getOrdering().getBeforeList())
1011         {
1012             if (slot instanceof ConfigOthersSlot)
1013             {
1014                 configOthers = true;
1015                 break;
1016             }
1017             else
1018             {
1019                 FacesConfigNameSlot nameSlot = (FacesConfigNameSlot) slot;
1020                 names.add(nameSlot.getName());
1021             }
1022         }
1023         
1024         if (configOthers)
1025         {
1026             //<before>....<others/></before> case
1027             //other reference where already considered when
1028             //pre ordered list was calculated, so just add to the end.
1029             
1030             //There is one very special case, and it is when there
1031             //is another resource with a reference on it. In this case,
1032             //it is better do not apply this rule and add it to the end
1033             //to give the chance to the other one to be applied.
1034             if (resource.getOrdering().getBeforeList().size() > 1)
1035             {
1036                 //If there is a reference apply it
1037                 sortedList.add(0,resource);
1038             }
1039             else if (!referenced)
1040             {
1041                 //If it is not referenced apply it
1042                 sortedList.add(0,resource);
1043             }
1044             else
1045             {
1046                 //if it is referenced bypass the rule and add it to the end
1047                 sortedList.add(resource);
1048             }
1049         }
1050         else
1051         {
1052             //Scan the nearest reference and add it after
1053             boolean founded = false;
1054             for (int i = 0; i < sortedList.size() ; i++)
1055             {
1056                 if (names.contains(sortedList.get(i).getName()))
1057                 {
1058                     sortedList.add(i,resource);
1059                     founded = true;
1060                     break;
1061                 }
1062             }
1063             if (!founded)
1064             {
1065                 //just add it to the end
1066                 sortedList.add(resource);
1067             }
1068         }        
1069     }
1070     
1071     private void applyAfterRule(List<FacesConfig> sortedList, FacesConfig resource) throws FacesException
1072     {
1073         boolean configOthers = false;
1074         List<String> names = new ArrayList<String>();
1075         
1076         for (OrderSlot slot : resource.getOrdering().getAfterList())
1077         {
1078             if (slot instanceof ConfigOthersSlot)
1079             {
1080                 configOthers = true;
1081                 break;
1082             }
1083             else
1084             {
1085                 FacesConfigNameSlot nameSlot = (FacesConfigNameSlot) slot;
1086                 names.add(nameSlot.getName());
1087             }
1088         }
1089         
1090         if (configOthers)
1091         {
1092             //<after>....<others/></after> case
1093             //other reference where already considered when
1094             //pre ordered list was calculated, so just add to the end.
1095             sortedList.add(resource);
1096         }
1097         else
1098         {
1099             //Scan the nearest reference and add it after
1100             boolean founded = false;
1101             for (int i = sortedList.size()-1 ; i >=0 ; i--)
1102             {
1103                 if (names.contains(sortedList.get(i).getName()))
1104                 {
1105                     if (i+1 < sortedList.size())
1106                     {
1107                         sortedList.add(i+1,resource);
1108                     }
1109                     else
1110                     {
1111                         sortedList.add(resource);
1112                     }
1113                     founded = true;
1114                     break;
1115                 }
1116             }
1117             if (!founded)
1118             {
1119                 //just add it to the end
1120                 sortedList.add(resource);
1121             }
1122         }        
1123     }*/
1124     
1125     
1126     /**
1127      * Pre Sort the appConfigResources, detecting cyclic references, so when sort process
1128      * start, it is just necessary to traverse the preOrderedList once. To do that, we just
1129      * scan "before" and "after" lists for references, and then those references are traversed
1130      * again, so the first elements of the pre ordered list does not have references and
1131      * the next elements has references to the already added ones.
1132      * 
1133      * The elements on the preOrderedList looks like this:
1134      * 
1135      * [ no ordering elements , referenced elements ... more referenced elements, 
1136      *  before others / after others non referenced elements]
1137      * 
1138      * @param appConfigResources
1139      * @return
1140      */
1141     /*
1142     private List<FacesConfig> getPostOrderedList(final List<FacesConfig> appConfigResources) throws FacesException
1143     {
1144         
1145         List<FacesConfig> appFilteredConfigResources = new ArrayList<FacesConfig>(); 
1146         
1147         //0. Clean up: remove all not found resource references from the ordering 
1148         //descriptions.
1149         List<String> availableReferences = new ArrayList<String>();
1150         for (FacesConfig resource : appFilteredConfigResources)
1151         {
1152             String name = resource.getName();
1153             if (name != null && "".equals(name))
1154             {
1155                 availableReferences.add(name);
1156             }
1157         }
1158         
1159         for (FacesConfig resource : appFilteredConfigResources)
1160         {
1161             for (Iterator<OrderSlot> it =  resource.getOrdering().getBeforeList().iterator();it.hasNext();)
1162             {
1163                 OrderSlot slot = it.next();
1164                 if (slot instanceof FacesConfigNameSlot)
1165                 {
1166                     String name = ((FacesConfigNameSlot) slot).getName();
1167                     if (!availableReferences.contains(name))
1168                     {
1169                         it.remove();
1170                     }
1171                 }
1172             }
1173             for (Iterator<OrderSlot> it =  resource.getOrdering().getAfterList().iterator();it.hasNext();)
1174             {
1175                 OrderSlot slot = it.next();
1176                 if (slot instanceof FacesConfigNameSlot)
1177                 {
1178                     String name = ((FacesConfigNameSlot) slot).getName();
1179                     if (!availableReferences.contains(name))
1180                     {
1181                         it.remove();
1182                     }
1183                 }
1184             }
1185         }
1186         
1187         //1. Pre filtering: Sort nodes according to its weight. The weight is the number of named
1188         //nodes containing in both before and after lists. The sort is done from the more complex
1189         //to the most simple
1190         if (appConfigResources instanceof ArrayList)
1191         {
1192             appFilteredConfigResources = (List<FacesConfig>)
1193                 ((ArrayList<FacesConfig>)appConfigResources).clone();
1194         }
1195         else
1196         {
1197             appFilteredConfigResources = new ArrayList<FacesConfig>();
1198             appFilteredConfigResources.addAll(appConfigResources);
1199         }
1200         Collections.sort(appFilteredConfigResources,
1201                 new Comparator<FacesConfig>()
1202                 {
1203                     public int compare(FacesConfig o1, FacesConfig o2)
1204                     {
1205                         int o1Weight = 0;
1206                         int o2Weight = 0;
1207                         if (o1.getOrdering() != null)
1208                         {
1209                             for (OrderSlot slot : o1.getOrdering()
1210                                     .getBeforeList())
1211                             {
1212                                 if (slot instanceof FacesConfigNameSlot)
1213                                 {
1214                                     o1Weight++;
1215                                 }
1216                             }
1217                             for (OrderSlot slot : o1.getOrdering()
1218                                     .getAfterList())
1219                             {
1220                                 if (slot instanceof FacesConfigNameSlot)
1221                                 {
1222                                     o1Weight++;
1223                                 }
1224                             }
1225                         }
1226                         if (o2.getOrdering() != null)
1227                         {
1228                             for (OrderSlot slot : o2.getOrdering()
1229                                     .getBeforeList())
1230                             {
1231                                 if (slot instanceof FacesConfigNameSlot)
1232                                 {
1233                                     o2Weight++;
1234                                 }
1235                             }
1236                             for (OrderSlot slot : o2.getOrdering()
1237                                     .getAfterList())
1238                             {
1239                                 if (slot instanceof FacesConfigNameSlot)
1240                                 {
1241                                     o2Weight++;
1242                                 }
1243                             }
1244                         }
1245                         return o2Weight - o1Weight;
1246                     }
1247                 });
1248         
1249         List<FacesConfig> postOrderedList = new LinkedList<FacesConfig>();
1250         List<FacesConfig> othersList = new ArrayList<FacesConfig>();
1251         
1252         List<String> nameBeforeStack = new ArrayList<String>();
1253         List<String> nameAfterStack = new ArrayList<String>();
1254         
1255         boolean[] visitedSlots = new boolean[appFilteredConfigResources.size()];
1256         
1257         //2. Scan and resolve conflicts
1258         for (int i = 0; i < appFilteredConfigResources.size(); i++)
1259         {
1260             if (!visitedSlots[i])
1261             {
1262                 resolveConflicts(appFilteredConfigResources, i, visitedSlots, 
1263                         nameBeforeStack, nameAfterStack, postOrderedList, othersList, false);
1264             }
1265         }
1266         
1267         //Add othersList to postOrderedList so <before><others/></before> and <after><others/></after>
1268         //ordering conditions are handled at last if there are not referenced by anyone
1269         postOrderedList.addAll(othersList);
1270         
1271         return postOrderedList;
1272     }
1273         
1274     private void resolveConflicts(final List<FacesConfig> appConfigResources, int index, boolean[] visitedSlots,
1275             List<String> nameBeforeStack, List<String> nameAfterStack, List<FacesConfig> postOrderedList,
1276             List<FacesConfig> othersList, boolean indexReferenced) throws FacesException
1277     {
1278         FacesConfig facesConfig = appConfigResources.get(index);
1279         
1280         if (nameBeforeStack.contains(facesConfig.getName()))
1281         {
1282             //Already referenced, just return. Later if there exists a
1283             //circular reference, it will be detected and solved.
1284             return;
1285             //log.fatal("Circular references detected when ordering " +
1286             //        "application faces config resources:"+nameBeforeStack.toString() +
1287             //        " already visited and trying to resolve "+facesConfig.getName());
1288             //throw new FacesException("Circular references detected when ordering " +
1289             //        "application faces config resources:"+nameBeforeStack.toString() +
1290             //        " already visited and trying to resolve "+facesConfig.getName());
1291         }
1292         
1293         if (nameAfterStack.contains(facesConfig.getName()))
1294         {
1295             //Already referenced, just return. Later if there exists a
1296             //circular reference, it will be detected and solved.
1297             return;
1298             //log.fatal("Circular references detected when ordering " +
1299             //        "application faces config resources:"+nameAfterStack.toString() +
1300             //        " already visited and trying to resolve "+facesConfig.getName());
1301             //throw new FacesException("Circular references detected when ordering " +
1302             //        "application faces config resources:"+nameAfterStack.toString() +
1303             //        " already visited and trying to resolve "+facesConfig.getName());
1304         }
1305         
1306         if (facesConfig.getOrdering() != null)
1307         {
1308             boolean pointingResource = false;
1309             
1310             //Deal with before restrictions first
1311             for (OrderSlot slot : facesConfig.getOrdering().getBeforeList())
1312             {
1313                 if (slot instanceof FacesConfigNameSlot)
1314                 {
1315                     FacesConfigNameSlot nameSlot = (FacesConfigNameSlot) slot;
1316                     //The resource pointed is not added yet?
1317                     boolean alreadyAdded = false;
1318                     for (FacesConfig res : postOrderedList)
1319                     {
1320                         if (nameSlot.getName().equals(res.getName()))
1321                         {
1322                             alreadyAdded = true;
1323                             break;
1324                         }
1325                     }
1326                     if (!alreadyAdded)
1327                     {
1328                         int indexSlot = -1;
1329                         //Find it
1330                         for (int i = 0; i < appConfigResources.size(); i++)
1331                         {
1332                             FacesConfig resource = appConfigResources.get(i);
1333                             if (resource.getName() != null && nameSlot.getName().equals(resource.getName()))
1334                             {
1335                                 indexSlot = i;
1336                                 break;
1337                             }
1338                         }
1339                         
1340                         //Resource founded on appConfigResources
1341                         if (indexSlot != -1)
1342                         {
1343                             pointingResource = true;
1344                             //Add to nameStac
1345                             nameBeforeStack.add(facesConfig.getName());
1346                             
1347                             resolveConflicts(appConfigResources, indexSlot, visitedSlots, 
1348                                     nameBeforeStack, nameAfterStack, postOrderedList,
1349                                     othersList,true);
1350                             
1351                             nameBeforeStack.remove(facesConfig.getName());
1352                         }
1353                     }
1354                     else
1355                     {
1356                         pointingResource = true;
1357                     }
1358                 }
1359             }
1360             
1361             for (OrderSlot slot : facesConfig.getOrdering().getAfterList())
1362             {
1363                 if (slot instanceof FacesConfigNameSlot)
1364                 {
1365                     FacesConfigNameSlot nameSlot = (FacesConfigNameSlot) slot;
1366                     //The resource pointed is not added yet?
1367                     boolean alreadyAdded = false;
1368                     for (FacesConfig res : postOrderedList)
1369                     {
1370                         if (nameSlot.getName().equals(res.getName()))
1371                         {
1372                             alreadyAdded = true;
1373                             break;
1374                         }
1375                     }
1376                     if (!alreadyAdded)
1377                     {
1378                         int indexSlot = -1;
1379                         //Find it
1380                         for (int i = 0; i < appConfigResources.size(); i++)
1381                         {
1382                             FacesConfig resource = appConfigResources.get(i);
1383                             if (resource.getName() != null && nameSlot.getName().equals(resource.getName()))
1384                             {
1385                                 indexSlot = i;
1386                                 break;
1387                             }
1388                         }
1389                         
1390                         //Resource founded on appConfigResources
1391                         if (indexSlot != -1)
1392                         {
1393                             pointingResource = true;
1394                             //Add to nameStac
1395                             nameAfterStack.add(facesConfig.getName());
1396                             
1397                             resolveConflicts(appConfigResources, indexSlot, visitedSlots, 
1398                                     nameBeforeStack, nameAfterStack, postOrderedList,
1399                                     othersList,true);
1400                             
1401                             nameAfterStack.remove(facesConfig.getName());
1402                         }
1403                     }
1404                     else
1405                     {
1406                         pointingResource = true;
1407                     }
1408                 }
1409             }
1410             
1411             if (facesConfig.getOrdering().getBeforeList().isEmpty() &&
1412                 facesConfig.getOrdering().getAfterList().isEmpty())
1413             {
1414                 //Fits in the category "others", put at beginning
1415                 postOrderedList.add(0,appConfigResources.get(index));
1416             }
1417             else if (pointingResource || indexReferenced)
1418             {
1419                 //If the node points to other or is referenced from other,
1420                 //add to the postOrderedList at the end
1421                 postOrderedList.add(appConfigResources.get(index));                    
1422             }
1423             else
1424             {
1425                 //Add to othersList
1426                 othersList.add(appConfigResources.get(index));
1427             }
1428         }
1429         else
1430         {
1431             //Add at start of the list, since does not have any ordering
1432             //instructions and on the next step makes than "before others" and "after others"
1433             //works correctly
1434             postOrderedList.add(0,appConfigResources.get(index));
1435         }
1436         //Set the node as visited
1437         visitedSlots[index] = true;
1438     }*/
1439     
1440 }