ScriptEngine.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.script;
  20. import java.util.Hashtable;
  21. import com.l2jserver.gameserver.script.faenor.FaenorInterface;
  22. /**
  23. * @author Luis Arias
  24. */
  25. public class ScriptEngine
  26. {
  27. protected EngineInterface _utils = FaenorInterface.getInstance();
  28. public static final Hashtable<String, ParserFactory> parserFactories = new Hashtable<>();
  29. protected static Parser createParser(String name) throws ParserNotCreatedException
  30. {
  31. ParserFactory s = parserFactories.get(name);
  32. if (s == null) // shape not found
  33. {
  34. try
  35. {
  36. Class.forName("com.l2jserver.gameserver.script." + name);
  37. // By now the static block with no function would
  38. // have been executed if the shape was found.
  39. // the shape is expected to have put its factory
  40. // in the hashtable.
  41. s = parserFactories.get(name);
  42. if (s == null) // if the shape factory is not there even now
  43. {
  44. throw (new ParserNotCreatedException());
  45. }
  46. }
  47. catch (ClassNotFoundException e)
  48. {
  49. // We'll throw an exception to indicate that
  50. // the shape could not be created
  51. throw (new ParserNotCreatedException());
  52. }
  53. }
  54. return (s.create());
  55. }
  56. }