.
- *
- * l2jserver is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * l2jserver is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with l2jserver. If not, see .
- */
-
-package com.l2jserver.service.game.scripting.scriptmanager;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Unmarshaller;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.l2jserver.service.game.scripting.ScriptContext;
-import com.l2jserver.service.game.scripting.ScriptContextFactory;
-
-/**
- * Class that represents managers of script contexes. It loads, reloads and
- * unload script contexes. In the future it may be extended to support
- * programatic manipulation of contexes, but for now it's not needed.
- *
- * Example:
- *
- *
- * ScriptManager sm = new ScriptManager();
- * sm.load(new File("st/contexts.xml"));
- * ...
- * sm.shutdown();
- *
- *
- * @author Rogiel
- */
-public class ScriptManager {
- /**
- * Logger for script context
- */
- private static final Logger log = LoggerFactory
- .getLogger(ScriptManager.class);
-
- /**
- * Collection of script contexts
- */
- private Set contexts = new HashSet();
-
- /**
- * Loads script contexes from descriptor
- *
- * @param scriptDescriptor
- * xml file that describes contexes
- * @throws Exception
- * if can't load file
- */
- public synchronized void load(File scriptDescriptor) throws Exception {
-
- JAXBContext c = JAXBContext.newInstance(ScriptInfo.class,
- ScriptList.class);
- Unmarshaller u = c.createUnmarshaller();
- ScriptList list = (ScriptList) u.unmarshal(scriptDescriptor);
-
- for (ScriptInfo si : list.getScriptInfos()) {
- ScriptContext context = createContext(si, null);
- if (context != null) {
- contexts.add(context);
- context.init();
- }
- }
- }
-
- /**
- * Creates new context and checks to not produce copies
- *
- * @param si
- * script context descriptor
- * @param parent
- * parent script context
- * @return created script context
- * @throws Exception
- * if can't create context
- */
- private ScriptContext createContext(ScriptInfo si, ScriptContext parent)
- throws Exception {
- ScriptContext context = ScriptContextFactory.getScriptContext(
- si.getRoot(), parent);
- context.setLibraries(si.getLibraries());
- context.setCompilerClassName(si.getCompilerClass());
-
- if (parent == null && contexts.contains(context)) {
- log.warn("Double root script context definition: "
- + si.getRoot().getAbsolutePath());
- return null;
- }
-
- if (si.getScriptInfos() != null && !si.getScriptInfos().isEmpty()) {
- for (ScriptInfo child : si.getScriptInfos()) {
- createContext(child, context);
- }
- }
-
- return context;
- }
-
- /**
- * Initializes shutdown on all contexes
- */
- public synchronized void shutdown() {
- for (ScriptContext context : contexts) {
- context.shutdown();
- }
-
- contexts.clear();
- }
-
- /**
- * Reloads all contexes
- */
- public synchronized void reload() {
- for (ScriptContext context : contexts) {
- context.reload();
- }
- }
-
- /**
- * Returns unmodifiable set with script contexes
- *
- * @return unmodifiable set of script contexes
- */
- public synchronized Collection getScriptContexts() {
- return Collections.unmodifiableSet(contexts);
- }
-}
diff --git a/src/main/java/com/l2jserver/service/game/template/StaticTemplateService.java b/src/main/java/com/l2jserver/service/game/template/StaticTemplateService.java
new file mode 100644
index 000000000..82b5cf2f7
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/game/template/StaticTemplateService.java
@@ -0,0 +1,80 @@
+package com.l2jserver.service.game.template;
+
+import java.util.Map;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.l2jserver.model.id.TemplateID;
+import com.l2jserver.model.template.Template;
+import com.l2jserver.service.AbstractService;
+import com.l2jserver.service.ServiceStartException;
+import com.l2jserver.service.ServiceStopException;
+import com.l2jserver.service.configuration.ConfigurationService;
+import com.l2jserver.service.game.scripting.ScriptContext;
+import com.l2jserver.service.game.scripting.ScriptingService;
+import com.l2jserver.util.factory.CollectionFactory;
+
+public class StaticTemplateService extends AbstractService implements
+ TemplateService {
+ private final ScriptingService scriptingService;
+ private final StaticTemplateServiceConfiguration config;
+ private final Injector injector;
+
+ private ScriptContext context;
+
+ private Map templates = CollectionFactory.newMap(
+ TemplateID.class, Template.class);
+
+ @Inject
+ public StaticTemplateService(ScriptingService scriptingService,
+ ConfigurationService configService, Injector injector) {
+ this.scriptingService = scriptingService;
+ this.injector = injector;
+ this.config = configService
+ .get(StaticTemplateServiceConfiguration.class);
+ }
+
+ @Override
+ public void start() throws ServiceStartException {
+ if (context == null) {
+ try {
+ context = scriptingService.load(config.getTemplateDescriptor())
+ .get(0);
+ } catch (Exception e) {
+ throw new ServiceStartException(e);
+ }
+ return;
+ }
+ if (context.isInitialized())
+ context.shutdown();
+ context.init();
+ }
+
+ @Override
+ public Template getTemplate(TemplateID id) {
+ return templates.get(id);
+ }
+
+ public void addTemplate(Class extends Template> t) {
+ final Template template = injector.getInstance(t);
+ System.out.println(template.getID() + " -> " + template);
+ if (template.getID() != null)
+ templates.put(template.getID(), template);
+ }
+
+ public void removeTemplate(Template t) {
+ // TODO templates.remove(t);
+ }
+
+ @Override
+ public void reload() {
+ context.reload();
+ }
+
+ @Override
+ public void stop() throws ServiceStopException {
+ if (context.isInitialized())
+ context.shutdown();
+ context = null;
+ }
+}
diff --git a/src/main/java/com/l2jserver/service/game/template/StaticTemplateServiceConfiguration.java b/src/main/java/com/l2jserver/service/game/template/StaticTemplateServiceConfiguration.java
new file mode 100644
index 000000000..42f2937c1
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/game/template/StaticTemplateServiceConfiguration.java
@@ -0,0 +1,14 @@
+package com.l2jserver.service.game.template;
+
+import java.io.File;
+
+import com.l2jserver.service.configuration.Configuration;
+import com.l2jserver.service.configuration.Configuration.ConfigurationName;
+
+@ConfigurationName("template")
+public interface StaticTemplateServiceConfiguration extends Configuration {
+ @ConfigurationPropertyGetter(name = "template.descriptor", defaultValue = "data/script/template/template.xml")
+ File getTemplateDescriptor();
+ @ConfigurationPropertySetter(name = "template.descriptor")
+ void setTemplateDescriptor(File file);
+}
diff --git a/src/main/java/com/l2jserver/service/game/template/TemplateService.java b/src/main/java/com/l2jserver/service/game/template/TemplateService.java
index d04b2f31f..6d7fb8bdc 100644
--- a/src/main/java/com/l2jserver/service/game/template/TemplateService.java
+++ b/src/main/java/com/l2jserver/service/game/template/TemplateService.java
@@ -1,7 +1,7 @@
package com.l2jserver.service.game.template;
import com.l2jserver.model.id.TemplateID;
-import com.l2jserver.model.template.AbstractTemplate;
+import com.l2jserver.model.template.Template;
import com.l2jserver.service.Service;
public interface TemplateService extends Service {
@@ -12,14 +12,10 @@ public interface TemplateService extends Service {
* the template id
* @return the template matching the id
*/
- AbstractTemplate getTemplate(TemplateID id);
+ Template getTemplate(TemplateID id);
/**
- * Recompile the template with id id. This can be used to reload
- * the template.
- *
- * @param id
- * the template id
+ * Reload the template list.
*/
- void recompile(TemplateID id);
+ void reload();
}
diff --git a/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java b/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java
index f50c2c1d5..c73972658 100644
--- a/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java
+++ b/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java
@@ -9,11 +9,12 @@ import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.filter.WorldObjectFilter;
import com.l2jserver.model.world.filter.impl.InstanceFilter;
import com.l2jserver.model.world.iterator.FilterIterator;
+import com.l2jserver.service.AbstractService;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.util.factory.CollectionFactory;
-public class WorldServiceImpl implements WorldService {
+public class WorldServiceImpl extends AbstractService implements WorldService {
private final Set objects = CollectionFactory
.newSet(WorldObject.class);
private final WorldEventDispatcher dispatcher;
diff --git a/src/main/java/com/l2jserver/service/network/NettyNetworkService.java b/src/main/java/com/l2jserver/service/network/NettyNetworkService.java
index 111cae205..6124ac02d 100644
--- a/src/main/java/com/l2jserver/service/network/NettyNetworkService.java
+++ b/src/main/java/com/l2jserver/service/network/NettyNetworkService.java
@@ -9,9 +9,10 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.l2jserver.game.net.Lineage2PipelineFactory;
+import com.l2jserver.service.AbstractService;
import com.l2jserver.service.configuration.ConfigurationService;
-public class NettyNetworkService implements NetworkService {
+public class NettyNetworkService extends AbstractService implements NetworkService {
private final NetworkConfiguration config;
private final Injector injector;
private ServerBootstrap server;
diff --git a/src/test/java/com/l2jserver/model/id/factory/IDFactoryTest.java b/src/test/java/com/l2jserver/model/id/factory/IDFactoryTest.java
index 3d1676996..6c817727b 100644
--- a/src/test/java/com/l2jserver/model/id/factory/IDFactoryTest.java
+++ b/src/test/java/com/l2jserver/model/id/factory/IDFactoryTest.java
@@ -4,10 +4,10 @@ import junit.framework.Assert;
import org.junit.Test;
-import script.dao.mysql5.DAOModuleMySQL5;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.l2jserver.db.dao.DAOModuleMySQL5;
import com.l2jserver.model.id.CharacterID;
import com.l2jserver.model.id.ID;
import com.l2jserver.model.world.L2Character;
diff --git a/src/test/java/com/l2jserver/service/game/scripting/ScriptingServiceImplTest.java b/src/test/java/com/l2jserver/service/game/scripting/ScriptingServiceImplTest.java
new file mode 100644
index 000000000..a492b94bb
--- /dev/null
+++ b/src/test/java/com/l2jserver/service/game/scripting/ScriptingServiceImplTest.java
@@ -0,0 +1,44 @@
+package com.l2jserver.service.game.scripting;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Scopes;
+
+public class ScriptingServiceImplTest {
+ private final Injector injector = Guice
+ .createInjector(new AbstractModule() {
+ @Override
+ protected void configure() {
+ bind(ScriptingService.class).to(ScriptingServiceImpl.class)
+ .in(Scopes.SINGLETON);
+ }
+ });
+ private final ScriptingService service = injector
+ .getInstance(ScriptingService.class);
+
+ @Test
+ public void testLoading() throws Exception {
+ final List contexts = service.load(new File(
+ "src/test/resources/scripting/testcase.xml"));
+ Assert.assertEquals(1, contexts.size());
+ }
+
+ @Test
+ public void testCreatingInstance() throws Exception {
+ final List contexts = service.load(new File(
+ "src/test/resources/scripting/testcase.xml"));
+ Assert.assertEquals(1, contexts.size());
+ final ScriptContext context = contexts.get(0);
+ Class> clazz = context.getClassLoader().loadClass("test.ScriptingCompilerTest");
+ Assert.assertNotNull(clazz);
+ Assert.assertEquals("ScriptingCompilerTest", clazz.getSimpleName());
+ }
+}
diff --git a/src/test/java/com/l2jserver/service/game/template/StaticTemplateServiceTest.java b/src/test/java/com/l2jserver/service/game/template/StaticTemplateServiceTest.java
new file mode 100644
index 000000000..0a9c31f66
--- /dev/null
+++ b/src/test/java/com/l2jserver/service/game/template/StaticTemplateServiceTest.java
@@ -0,0 +1,35 @@
+package com.l2jserver.service.game.template;
+
+import org.junit.Test;
+
+import script.template.item.AdenaItemTemplate;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Scopes;
+import com.l2jserver.service.BasicServiceModule;
+import com.l2jserver.service.ServiceStartException;
+import com.l2jserver.service.game.scripting.ScriptingService;
+import com.l2jserver.service.game.scripting.ScriptingServiceImpl;
+
+public class StaticTemplateServiceTest {
+ private final Injector injector = Guice
+ .createInjector(new BasicServiceModule(), new AbstractModule() {
+ @Override
+ protected void configure() {
+ bind(ScriptingService.class).to(ScriptingServiceImpl.class)
+ .in(Scopes.SINGLETON);
+ bind(TemplateService.class).to(StaticTemplateService.class)
+ .in(Scopes.SINGLETON);
+ }
+ });
+ private final TemplateService service = injector
+ .getInstance(TemplateService.class);
+
+ @Test
+ public void testAdena() throws ServiceStartException {
+ service.start();
+ System.out.println(service.getTemplate(AdenaItemTemplate.ID));
+ }
+}
diff --git a/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java b/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java
index 416f0fbad..84535d43e 100644
--- a/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java
+++ b/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java
@@ -7,12 +7,12 @@ import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
-import script.dao.mysql5.DAOModuleMySQL5;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Scopes;
+import com.l2jserver.db.dao.DAOModuleMySQL5;
import com.l2jserver.model.id.factory.CharacterIDFactory;
import com.l2jserver.model.id.factory.IDFactoryModule;
import com.l2jserver.model.id.factory.ItemIDFactory;
diff --git a/src/test/resources/scripting/ScriptingCompilerTest.java b/src/test/resources/scripting/ScriptingCompilerTest.java
new file mode 100644
index 000000000..4bf6a2a7b
--- /dev/null
+++ b/src/test/resources/scripting/ScriptingCompilerTest.java
@@ -0,0 +1,4 @@
+package test;
+
+public class ScriptingCompilerTest {
+}
diff --git a/src/test/resources/scripting/testcase.xml b/src/test/resources/scripting/testcase.xml
new file mode 100644
index 000000000..a54b1de9b
--- /dev/null
+++ b/src/test/resources/scripting/testcase.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/target/test-classes/scripting/ScriptingCompilerTest.java b/target/test-classes/scripting/ScriptingCompilerTest.java
new file mode 100644
index 000000000..4bf6a2a7b
--- /dev/null
+++ b/target/test-classes/scripting/ScriptingCompilerTest.java
@@ -0,0 +1,4 @@
+package test;
+
+public class ScriptingCompilerTest {
+}
diff --git a/target/test-classes/scripting/testcase.xml b/target/test-classes/scripting/testcase.xml
new file mode 100644
index 000000000..a54b1de9b
--- /dev/null
+++ b/target/test-classes/scripting/testcase.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
\ No newline at end of file