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 com.fatwire.gst.foundation.facade.assetapi.listener;
17  
18  import COM.FutureTense.Interfaces.ICS;
19  
20  import com.fatwire.assetapi.common.AssetAccessException;
21  import com.fatwire.assetapi.data.AssetData;
22  import com.fatwire.assetapi.data.AssetId;
23  import com.fatwire.gst.foundation.DebugHelper;
24  import com.fatwire.gst.foundation.facade.assetapi.AssetDataUtils;
25  import com.fatwire.gst.foundation.facade.ics.ICSFactory;
26  import com.fatwire.gst.foundation.facade.install.AssetListenerInstall;
27  import com.openmarket.basic.event.AbstractAssetEventListener;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  
32  public class BlockingDebugAssetListener extends AbstractAssetEventListener {
33      private static final Log LOG = LogFactory.getLog(BlockingDebugAssetListener.class.getPackage().getName());
34      private ICS ics;
35  
36      void printAsset(final AssetId id) {
37          if (LOG.isDebugEnabled()) {
38  
39              final ICS ics = getICS();// ;
40              final AssetData ad = AssetDataUtils.getAssetData(ics, id);
41              try {
42                  LOG.debug("Print asset with current ICS " + id);
43                  LOG.debug(DebugHelper.printAsset(ad));
44              } catch (final AssetAccessException e) {
45                  LOG.error(e);
46              }
47          }
48  
49      }
50  
51      protected ICS getICS() {
52          return ics != null ? ics : ICSFactory.getOrCreateICS();
53      }
54  
55      @Override
56      public void assetAdded(final AssetId id) {
57          LOG.debug("Asset added " + id);
58          printAsset(id);
59      }
60  
61      @Override
62      public void assetDeleted(final AssetId id) {
63          LOG.debug("Asset deleted " + id);
64          printAsset(id);
65  
66      }
67  
68      @Override
69      public void assetUpdated(final AssetId id) {
70          LOG.debug("Asset updated " + id);
71          printAsset(id);
72  
73      }
74  
75      public void install(final ICS ics) {
76          AssetListenerInstall.register(ics, BlockingDebugAssetListener.class.getName(), true);
77      }
78  
79      @Override
80      public void init(ICS ics) {
81          this.ics = ics;
82  
83      }
84  
85  }