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 NonBlockingDebugAssetListener extends AbstractAssetEventListener {
33      private static final Log LOG = LogFactory.getLog(NonBlockingDebugAssetListener.class.getPackage().getName());
34      private ICS ics;
35     
36  
37      void printAsset(final AssetId id) {
38          if (LOG.isDebugEnabled()) {
39              final ICS ics = getICS();
40              final AssetData ad = AssetDataUtils.getAssetData(ics, id);
41              try {
42                  LOG.debug("Print asset with new ICS " + id);
43                  LOG.debug(DebugHelper.printAsset(ad));
44              } catch (final AssetAccessException e) {
45                  LOG.error(e);
46              }
47          }
48  
49      }
50  
51      @Override
52      public void assetAdded(final AssetId id) {
53          LOG.debug("Asset added " + id);
54          printAsset(id);
55      }
56  
57      @Override
58      public void assetDeleted(final AssetId id) {
59          LOG.debug("Asset deleted " + id);
60          printAsset(id);
61  
62      }
63  
64      @Override
65      public void assetUpdated(final AssetId id) {
66          LOG.debug("Asset updated " + id);
67          printAsset(id);
68  
69      }
70  
71      public void install(final ICS ics) {
72          AssetListenerInstall.register(ics, NonBlockingDebugAssetListener.class.getName(), false);
73      }
74      protected ICS getICS() {
75          return ics != null ? ics : ICSFactory.getOrCreateICS();
76      }
77  
78      @Override
79      public void init(ICS ics) {
80          this.ics=ics;
81          
82      }
83  }