View Javadoc

1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
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  
17  package com.fatwire.gst.foundation.facade.ics;
18  
19  import COM.FutureTense.CS.Factory;
20  import COM.FutureTense.Interfaces.ICS;
21  import COM.FutureTense.Interfaces.IPS;
22  import COM.FutureTense.Servlet.IPSRegistry;
23  
24  /**
25   * Factory class for creating new ICS instances. This process is very expensive
26   * so use it sparingly.
27   * 
28   * @author Tony Field
29   * @author Dolf Dijkstra
30   * @since Jul 29, 2010
31   */
32  public final class ICSFactory {
33  
34      /**
35       * Create a new instance of ICS. Expensive operation. Should be used
36       * sparingly. TODO: low priority: Document lifecycle restrictions
37       * 
38       * @return ICS instance, not backed by servlet.
39       */
40      public static ICS newICS() {
41          try {
42              return Factory.newCS();
43          } catch (Exception e) {
44              throw new RuntimeException("Could not create new ICS instance: " + e, e);
45          }
46      }
47  
48      /**
49       * Returns the ICS object from current IPSRegistry or creates a new one if
50       * non is found on the IPSRegistry.
51       * 
52       * @return ICS object
53       */
54      public static ICS getOrCreateICS() {
55          ICS ics = null;
56  
57          IPS ips = IPSRegistry.getInstance().get();
58          ics = (ips != null) ? ips.GetICSObject() : null;
59  
60          if (ics == null) {
61              ics = newICS();
62          }
63          return ics;
64      }
65  }