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  package tools.gsf.facade.assetapi.listener;
17  
18  import COM.FutureTense.Interfaces.ICS;
19  import com.fatwire.assetapi.common.AssetAccessException;
20  import com.fatwire.assetapi.data.AssetData;
21  import com.fatwire.assetapi.data.AssetId;
22  import com.openmarket.basic.event.AbstractAssetEventListener;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import tools.gsf.facade.assetapi.AssetDataUtils;
26  import tools.gsf.facade.install.AssetListenerInstall;
27  import tools.gsf.runtime.DebugHelper;
28  
29  public class BlockingDebugAssetListener extends AbstractAssetEventListener {
30  
31      protected static final Logger LOG = LoggerFactory.getLogger("tools.gsf.facade.assetapi.listener.BlockingDebugAssetListener");
32      private ICS ics;
33  
34      void printAsset(final AssetId id) {
35          if (LOG.isDebugEnabled()) {
36  
37              final ICS ics = getICS();// ;
38              final AssetData ad = AssetDataUtils.getAssetData(ics, id);
39              try {
40                  LOG.debug("Print asset with current ICS " + id);
41                  LOG.debug(DebugHelper.printAsset(ad));
42              } catch (final AssetAccessException e) {
43                  LOG.error("Exception thrown whilst accessing asset " + id, e);
44              }
45          }
46  
47      }
48  
49      protected ICS getICS() {
50          if (ics == null) {
51              throw new IllegalStateException(
52                      "ICS cannot be null. The listener needs to be configured as blocking");
53          }
54          return ics;
55      }
56  
57      @Override
58      public void assetAdded(final AssetId id) {
59          LOG.debug("Asset added " + id);
60          printAsset(id);
61      }
62  
63      @Override
64      public void assetDeleted(final AssetId id) {
65          LOG.debug("Asset deleted " + id);
66          printAsset(id);
67  
68      }
69  
70      @Override
71      public void assetUpdated(final AssetId id) {
72          LOG.debug("Asset updated " + id);
73          printAsset(id);
74  
75      }
76  
77      public void install(final ICS ics) {
78          AssetListenerInstall.register(ics,
79                  BlockingDebugAssetListener.class.getName(), true);
80      }
81  
82      @Override
83      public void init(ICS ics) {
84          this.ics = ics;
85  
86      }
87  
88  }