View Javadoc
1   /*
2    * Copyright 2016 Function1. 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  package tools.gsf.config;
17  
18  import com.fatwire.assetapi.data.AssetDataManager;
19  import com.fatwire.assetapi.site.SiteManager;
20  import com.fatwire.system.Session;
21  import com.fatwire.system.SessionFactory;
22  
23  import COM.FutureTense.Interfaces.ICS;
24  
25  import tools.gsf.config.inject.AnnotationInjector;
26  import tools.gsf.config.inject.BindInjector;
27  import tools.gsf.config.inject.CurrentAssetInjector;
28  import tools.gsf.config.inject.InjectForRequestInjector;
29  import tools.gsf.config.inject.Injector;
30  import tools.gsf.config.inject.MappingInjector;
31  import tools.gsf.facade.assetapi.AssetAccessTemplate;
32  import tools.gsf.facade.assetapi.asset.ScatteredAssetAccessTemplate;
33  import tools.gsf.facade.assetapi.asset.TemplateAsset;
34  import tools.gsf.facade.assetapi.asset.TemplateAssetAccess;
35  import tools.gsf.mapping.IcsMappingService;
36  import tools.gsf.mapping.MappingService;
37  import tools.gsf.time.Stopwatch;
38  import tools.gsf.properties.AssetApiPropertyDao;
39  import tools.gsf.properties.PropertyDao;
40  import tools.gsf.facade.mda.DefaultLocaleService;
41  import tools.gsf.facade.mda.LocaleService;
42  
43  /**
44   * @author Tony Field
45   * @since 2016-08-05
46   */
47  public class IcsBackedFactory extends AbstractDelegatingFactory<ICS> {
48  
49      private final ICS ics;
50  
51      @ServiceProducer(cache = true, name="ics")
52      public ICS getICS() {
53      	return this.ics;
54      }
55  
56      public IcsBackedFactory(ICS ics, Factory delegate) {
57          super(ics, delegate);
58          this.ics = ics;
59      }
60  
61      @ServiceProducer(cache = true, name="bindInjector")
62      public Injector createBindInjector() {
63          return new BindInjector(ics);
64      }
65  
66      @ServiceProducer(cache = true, name="injectForRequestInjector")
67      public Injector createInjectForRequestInjector() {
68          Factory factory = FactoryLocator.locateFactory(ics);
69          return new InjectForRequestInjector(factory);
70      }
71  
72      @ServiceProducer(cache = true)
73      public MappingService createMappingService() {
74          AssetAccessTemplate aat = getObject("assetAccessTemplate", AssetAccessTemplate.class);
75          return new IcsMappingService(ics, aat);
76      }
77  
78      @ServiceProducer(cache = true, name="mappingInjector")
79      public Injector createMappingInjector(final ICS ics) {
80          MappingService mappingService = getObject("mappingService", MappingService.class);
81          return new MappingInjector(ics, mappingService);
82      }
83  
84      @ServiceProducer(cache = true, name="currentAssetInjector")
85      public Injector createCurrentAssetInjector(final ICS ics) {
86          AssetAccessTemplate aat = getObject("assetAccessTemplate", AssetAccessTemplate.class);
87          TemplateAssetAccess taa = getObject("templateAssetAccess", TemplateAssetAccess.class);
88          ScatteredAssetAccessTemplate saa = getObject("scatteredAssetAccessTemplate", ScatteredAssetAccessTemplate.class);
89          return new CurrentAssetInjector(ics, taa, saa, aat);
90      }
91  
92      @ServiceProducer(cache = true, name="compositeInjector")
93      public Injector createCompositeInjector() {
94          Injector bind = getObject("bindInjector", Injector.class);
95          Injector map = getObject("mappingInjector", Injector.class);
96          Injector ifr = getObject("injectForRequestInjector", Injector.class);
97          Injector currentAsset = getObject("currentAssetInjector", Injector.class);
98          Stopwatch stopwatch = getObject("stopwatch", Stopwatch.class);
99          return new AnnotationInjector(stopwatch, bind, map, ifr, currentAsset);
100     }
101 
102     @ServiceProducer(cache = true)
103     public PropertyDao createPropertyDao(final ICS ics) {
104     	Session session = SessionFactory.getSession(ics);
105     	AssetDataManager adm = (AssetDataManager) session.getManager(AssetDataManager.class.getName());
106     	SiteManager sm = (SiteManager) session.getManager(SiteManager.class.getName());
107     	String type = "GSTProperty";
108     	String flexDefName = "GSTProperty";
109     	String propNameAttr = "name";
110     	String propDescAttr = "description";
111     	String propValueAttr = "value";
112     	return new AssetApiPropertyDao(adm, sm, type, flexDefName, propNameAttr, propDescAttr, propValueAttr, ics);
113     }
114 
115     @ServiceProducer(cache = true)
116     public AssetAccessTemplate createAssetAccessTemplate() {
117         return new AssetAccessTemplate(this.ics);
118     }
119     
120     @ServiceProducer(cache = true)
121     public ScatteredAssetAccessTemplate createScatteredAssetAccessTemplate() {
122         return new ScatteredAssetAccessTemplate(this.ics);
123     }
124 
125     @ServiceProducer(cache = true)
126     public TemplateAssetAccess createTemplateAssetAccess() {
127         return new TemplateAssetAccess(this.ics);
128     }
129     
130     @ServiceProducer(cache = true)
131     public LocaleService createLocaleService(final ICS ics) {
132         return new DefaultLocaleService(ics);
133     }
134     
135 }