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 org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import COM.FutureTense.CS.Factory;
23 import COM.FutureTense.Interfaces.ICS;
24 import COM.FutureTense.Interfaces.IPS;
25 import COM.FutureTense.Servlet.IPSRegistry;
26
27 /**
28 * Factory class for creating new ICS instances. This process is very expensive
29 * so use it sparingly.
30 *
31 * @author Tony Field
32 * @author Dolf Dijkstra
33 * @since Jul 29, 2010
34 * @deprecated ICS usage and access should be managed by the calling classes. Specifically, creating a new ICS
35 * object should be avoided.
36 */
37 @Deprecated
38 public final class ICSFactory {
39
40 private static final Log LOG = LogFactory.getLog(ICSFactory.class.getName());
41
42 /**
43 * Create a new instance of ICS. Expensive operation. Should be used
44 * sparingly. TODO: low priority: Document lifecycle restrictions
45 *
46 * @deprecated Creates a new un-backed ICS instance, which can very easily be mistaken for a regular ICS object
47 * @return ICS instance, not backed by servlet.
48 */
49 @Deprecated
50 public static ICS newICS() {
51 try {
52 LOG.debug("Creating new ICS object");
53 ICS ics = Factory.newCS();
54 LOG.warn("A new ICS object has just been created. This activity is deprecated.", new Exception());
55 return ics;
56 } catch (Exception e) {
57 throw new RuntimeException("Could not create new ICS instance: " + e, e);
58 }
59 }
60
61 /**
62 * Returns the ICS object from current IPSRegistry or creates a new one if
63 * non is found on the IPSRegistry.
64 *
65 * @deprecated returns an ICS object using an undocumented API, and creates a new one that is only partially-formed
66 * if none is found. Misuse of this ICS object can result in very tricky bugs.
67 * @return ICS object
68 */
69 @Deprecated
70 public static ICS getOrCreateICS() {
71 ICS ics = null;
72
73 IPS ips = IPSRegistry.getInstance().get();
74 ics = (ips != null) ? ips.GetICSObject() : null;
75
76 if (ics == null) {
77 ics = newICS();
78 }
79 return ics;
80 }
81 }