/src/away3d/library/naming/ConflictStrategyBase.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 71 lines · 32 code · 9 blank · 30 comment · 2 complexity · 15a5803a4a2c9fc140476de0425ff878 MD5 · raw file

  1. package away3d.library.naming
  2. {
  3. import away3d.errors.AbstractMethodError;
  4. import away3d.events.AssetEvent;
  5. import away3d.library.assets.IAsset;
  6. /**
  7. * Abstract base class for naming conflict resolution classes. Extend this to create a
  8. * strategy class which the asset library can use to resolve asset naming conflicts, or
  9. * use one of the bundled concrete strategy classes:
  10. *
  11. * <ul>
  12. * <li>IgnoreConflictStrategy (ConflictStrategy.IGNORE)</li>
  13. * <li>ErrorConflictStrategy (ConflictStrategy.THROW_ERROR)</li>
  14. * <li>NumSuffixConflictStrategy (ConflictStrategy.APPEND_NUM_SUFFIX)</li>
  15. * </ul>
  16. *
  17. * @see away3d.library.AssetLibrary.conflictStrategy
  18. * @see away3d.library.naming.ConflictStrategy
  19. * @see away3d.library.naming.IgnoreConflictStrategy
  20. * @see away3d.library.naming.ErrorConflictStrategy
  21. * @see away3d.library.naming.NumSuffixConflictStrategy
  22. */
  23. public class ConflictStrategyBase
  24. {
  25. public function ConflictStrategyBase()
  26. {
  27. }
  28. /**
  29. * Resolve a naming conflict between two assets. Must be implemented by concrete strategy
  30. * classes.
  31. */
  32. public function resolveConflict(changedAsset:IAsset, oldAsset:IAsset, assetsDictionary:Object, precedence:String):void
  33. {
  34. throw new AbstractMethodError();
  35. }
  36. /**
  37. * Create instance of this conflict strategy. Used internally by the AssetLibrary to
  38. * make sure the same strategy instance is not used in all AssetLibrary instances, which
  39. * would break any state caching that happens inside the strategy class.
  40. */
  41. public function create():ConflictStrategyBase
  42. {
  43. throw new AbstractMethodError();
  44. }
  45. /**
  46. * Provided as a convenience method for all conflict strategy classes, as a way to finalize
  47. * the conflict resolution by applying the new names and dispatching the correct events.
  48. */
  49. protected function updateNames(ns:String, nonConflictingName:String, oldAsset:IAsset, newAsset:IAsset, assetsDictionary:Object, precedence:String):void
  50. {
  51. var loser_prev_name:String;
  52. var winner:IAsset, loser:IAsset;
  53. winner = (precedence == ConflictPrecedence.FAVOR_NEW)? newAsset : oldAsset;
  54. loser = (precedence == ConflictPrecedence.FAVOR_NEW)? oldAsset : newAsset;
  55. loser_prev_name = loser.name;
  56. assetsDictionary[winner.name] = winner;
  57. assetsDictionary[nonConflictingName] = loser;
  58. loser.resetAssetPath(nonConflictingName, ns, false);
  59. loser.dispatchEvent(new AssetEvent(AssetEvent.ASSET_CONFLICT_RESOLVED, loser, loser_prev_name));
  60. }
  61. }
  62. }