mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
Implement XML configuration files instead of .properties
Added support for XML configuration files. Instead of each interface loading it's own file, a single XML file will contain all properties and parsing XML file will be done at service start. Created a new annotation: @ConfigurationXPath and removed "name" argument from @ConfigurationPropertySetter and @ConfigurationPropertyGetter. Also, moves @ConfigurationName to ProxyConfigurationService since it is not used by the XML implementation.
This commit is contained in:
72
config/config.xml
Normal file
72
config/config.xml
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="configuration configuration.xsd"
|
||||||
|
xsi:noNamespaceSchemaLocation="configuration">
|
||||||
|
<!-- TODO -->
|
||||||
|
<general>
|
||||||
|
<!-- TODO -->
|
||||||
|
<rates>
|
||||||
|
<!-- TODO -->
|
||||||
|
<experience>1.0</experience>
|
||||||
|
<!-- TODO -->
|
||||||
|
<sp>1.0</sp>
|
||||||
|
</rates>
|
||||||
|
</general>
|
||||||
|
|
||||||
|
<!-- Services configuration section -->
|
||||||
|
<services>
|
||||||
|
<!-- Parameters in this section are used by DatabaseService. If you are
|
||||||
|
not sure on the usage of any parameter, read the "Configuration" section
|
||||||
|
in wiki article about DatabaseService. -->
|
||||||
|
<database>
|
||||||
|
<jdbc>
|
||||||
|
<!-- Defines the connection URL used by JDBC to connect to the database. -->
|
||||||
|
<url>jdbc:mysql://localhost/l2jserver2</url>
|
||||||
|
|
||||||
|
<!-- The driver used to connect to the database. Please note that the
|
||||||
|
driver library must be available in the JVM classpath. -->
|
||||||
|
<driver>com.mysql.jdbc.Driver</driver>
|
||||||
|
|
||||||
|
<!-- The username used to login into the database. NOTE: Try not use
|
||||||
|
"root" in production servers for security reasons. -->
|
||||||
|
<username>l2j</username>
|
||||||
|
|
||||||
|
<!-- The password used to login into the database. -->
|
||||||
|
<password>changeme</password>
|
||||||
|
</jdbc>
|
||||||
|
|
||||||
|
<connections>
|
||||||
|
<!-- The maximum number of active connections -->
|
||||||
|
<active-maximum>20</active-maximum>
|
||||||
|
<!-- The maximum number of idle connections -->
|
||||||
|
<idle-maximum>20</idle-maximum>
|
||||||
|
<!-- The minimum number of idle connections -->
|
||||||
|
<idle-minimum>5</idle-minimum>
|
||||||
|
</connections>
|
||||||
|
</database>
|
||||||
|
|
||||||
|
<!-- Parameters in this section are used by NetworkService. If you are
|
||||||
|
not sure on the usage of any parameter, read the "Configuration" section
|
||||||
|
in wiki article about NetworkService. -->
|
||||||
|
<network>
|
||||||
|
<!-- The address and port in which the server will listen to -->
|
||||||
|
<listen>0.0.0.0:7777</listen>
|
||||||
|
</network>
|
||||||
|
|
||||||
|
<!-- Parameters in this section are used by VFSService. If you are not
|
||||||
|
sure on the usage of any parameter, read the "Configuration" section in wiki
|
||||||
|
article about VFSService. -->
|
||||||
|
<vfs>
|
||||||
|
<root></root>
|
||||||
|
</vfs>
|
||||||
|
|
||||||
|
<!-- Parameters in this section are used by VFSService. If you are not
|
||||||
|
sure on the usage of any parameter, read the "Configuration" section in wiki
|
||||||
|
article about VFSService. -->
|
||||||
|
<template>
|
||||||
|
<!-- The directory in which templates are stored -->
|
||||||
|
<directory>data/templates</directory>
|
||||||
|
</template>
|
||||||
|
</services>
|
||||||
|
<!-- /Services configuration section -->
|
||||||
|
</configuration>
|
||||||
72
dist/config/config.xml
vendored
Normal file
72
dist/config/config.xml
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="configuration configuration.xsd"
|
||||||
|
xsi:noNamespaceSchemaLocation="configuration">
|
||||||
|
<!-- TODO -->
|
||||||
|
<general>
|
||||||
|
<!-- TODO -->
|
||||||
|
<rates>
|
||||||
|
<!-- TODO -->
|
||||||
|
<experience>1.0</experience>
|
||||||
|
<!-- TODO -->
|
||||||
|
<sp>1.0</sp>
|
||||||
|
</rates>
|
||||||
|
</general>
|
||||||
|
|
||||||
|
<!-- Services configuration section -->
|
||||||
|
<services>
|
||||||
|
<!-- Parameters in this section are used by DatabaseService. If you are
|
||||||
|
not sure on the usage of any parameter, read the "Configuration" section
|
||||||
|
in wiki article about DatabaseService. -->
|
||||||
|
<database>
|
||||||
|
<jdbc>
|
||||||
|
<!-- Defines the connection URL used by JDBC to connect to the database. -->
|
||||||
|
<url>jdbc:mysql://localhost/l2jserver2</url>
|
||||||
|
|
||||||
|
<!-- The driver used to connect to the database. Please note that the
|
||||||
|
driver library must be available in the JVM classpath. -->
|
||||||
|
<driver>com.mysql.jdbc.Driver</driver>
|
||||||
|
|
||||||
|
<!-- The username used to login into the database. NOTE: Try not use
|
||||||
|
"root" in production servers for security reasons. -->
|
||||||
|
<username>l2j</username>
|
||||||
|
|
||||||
|
<!-- The password used to login into the database. -->
|
||||||
|
<password>changeme</password>
|
||||||
|
</jdbc>
|
||||||
|
|
||||||
|
<connections>
|
||||||
|
<!-- The maximum number of active connections -->
|
||||||
|
<active-maximum>20</active-maximum>
|
||||||
|
<!-- The maximum number of idle connections -->
|
||||||
|
<idle-maximum>20</idle-maximum>
|
||||||
|
<!-- The minimum number of idle connections -->
|
||||||
|
<idle-minimum>5</idle-minimum>
|
||||||
|
</connections>
|
||||||
|
</database>
|
||||||
|
|
||||||
|
<!-- Parameters in this section are used by NetworkService. If you are
|
||||||
|
not sure on the usage of any parameter, read the "Configuration" section
|
||||||
|
in wiki article about NetworkService. -->
|
||||||
|
<network>
|
||||||
|
<!-- The address and port in which the server will listen to -->
|
||||||
|
<listen>0.0.0.0:7777</listen>
|
||||||
|
</network>
|
||||||
|
|
||||||
|
<!-- Parameters in this section are used by VFSService. If you are not
|
||||||
|
sure on the usage of any parameter, read the "Configuration" section in wiki
|
||||||
|
article about VFSService. -->
|
||||||
|
<vfs>
|
||||||
|
<root></root>
|
||||||
|
</vfs>
|
||||||
|
|
||||||
|
<!-- Parameters in this section are used by VFSService. If you are not
|
||||||
|
sure on the usage of any parameter, read the "Configuration" section in wiki
|
||||||
|
article about VFSService. -->
|
||||||
|
<template>
|
||||||
|
<!-- The directory in which templates are stored -->
|
||||||
|
<directory>data/templates</directory>
|
||||||
|
</template>
|
||||||
|
</services>
|
||||||
|
<!-- /Services configuration section -->
|
||||||
|
</configuration>
|
||||||
@@ -124,7 +124,7 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
|
|||||||
body.text(exception);
|
body.text(exception);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
connection.sendCommunityHTML(template);
|
connection.sendHTML(template);
|
||||||
// order client not to wait any packet
|
// order client not to wait any packet
|
||||||
connection.sendActionFailed();
|
connection.sendActionFailed();
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.l2jserver.service.configuration;
|
package com.l2jserver.service.configuration;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration interface
|
* Configuration interface
|
||||||
* <p>
|
* <p>
|
||||||
@@ -35,23 +36,6 @@ import java.lang.annotation.Target;
|
|||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public interface Configuration {
|
public interface Configuration {
|
||||||
/**
|
|
||||||
* Each configuration can define the name of its configuration. This will be
|
|
||||||
* used by implementations to look for the configuration.
|
|
||||||
*
|
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
|
||||||
@Target(value = ElementType.TYPE)
|
|
||||||
public @interface ConfigurationName {
|
|
||||||
/**
|
|
||||||
* @return the configuration name
|
|
||||||
*/
|
|
||||||
String value();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The getter method for an configuration property
|
* The getter method for an configuration property
|
||||||
* <p>
|
* <p>
|
||||||
@@ -62,11 +46,6 @@ public interface Configuration {
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(value = ElementType.METHOD)
|
@Target(value = ElementType.METHOD)
|
||||||
public @interface ConfigurationPropertyGetter {
|
public @interface ConfigurationPropertyGetter {
|
||||||
/**
|
|
||||||
* @return the property name
|
|
||||||
*/
|
|
||||||
String name();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the default value to be used
|
* @return the default value to be used
|
||||||
*/
|
*/
|
||||||
@@ -83,9 +62,5 @@ public interface Configuration {
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(value = ElementType.METHOD)
|
@Target(value = ElementType.METHOD)
|
||||||
public @interface ConfigurationPropertySetter {
|
public @interface ConfigurationPropertySetter {
|
||||||
/**
|
|
||||||
* @return the property name
|
|
||||||
*/
|
|
||||||
String name();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
@@ -35,7 +40,6 @@ import com.l2jserver.service.AbstractService;
|
|||||||
import com.l2jserver.service.AbstractService.Depends;
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.cache.CacheService;
|
import com.l2jserver.service.cache.CacheService;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter;
|
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter;
|
||||||
import com.l2jserver.service.core.LoggingService;
|
import com.l2jserver.service.core.LoggingService;
|
||||||
@@ -55,7 +59,7 @@ public class ProxyConfigurationService extends AbstractService implements
|
|||||||
/**
|
/**
|
||||||
* The directory in which configuration files are stored
|
* The directory in which configuration files are stored
|
||||||
*/
|
*/
|
||||||
private final File directory = new File("./config");
|
private final File directory = new File("./config/properties");
|
||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
*/
|
*/
|
||||||
@@ -66,6 +70,30 @@ public class ProxyConfigurationService extends AbstractService implements
|
|||||||
*/
|
*/
|
||||||
private Map<Class<?>, Object> cache = CollectionFactory.newWeakMap();
|
private Map<Class<?>, Object> cache = CollectionFactory.newWeakMap();
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Target(value = ElementType.METHOD)
|
||||||
|
public @interface ConfigurationPropertiesKey {
|
||||||
|
String value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Each configuration can define the name of its configuration. This will be
|
||||||
|
* used by implementations to look for the configuration.
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Target(value = ElementType.TYPE)
|
||||||
|
public @interface ConfigurationName {
|
||||||
|
/**
|
||||||
|
* @return the configuration name
|
||||||
|
*/
|
||||||
|
String value();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
if (!directory.exists())
|
if (!directory.exists())
|
||||||
@@ -128,15 +156,23 @@ public class ProxyConfigurationService extends AbstractService implements
|
|||||||
if (args == null || args.length == 0) {
|
if (args == null || args.length == 0) {
|
||||||
final ConfigurationPropertyGetter getter = method
|
final ConfigurationPropertyGetter getter = method
|
||||||
.getAnnotation(ConfigurationPropertyGetter.class);
|
.getAnnotation(ConfigurationPropertyGetter.class);
|
||||||
|
final ConfigurationPropertiesKey propertiesKey = method
|
||||||
|
.getAnnotation(ConfigurationPropertiesKey.class);
|
||||||
if (getter == null)
|
if (getter == null)
|
||||||
return null;
|
return null;
|
||||||
return get(getter, method.getReturnType());
|
if (propertiesKey == null)
|
||||||
|
return null;
|
||||||
|
return get(getter, propertiesKey, method.getReturnType());
|
||||||
} else if (args.length == 1) {
|
} else if (args.length == 1) {
|
||||||
final ConfigurationPropertySetter setter = method
|
final ConfigurationPropertySetter setter = method
|
||||||
.getAnnotation(ConfigurationPropertySetter.class);
|
.getAnnotation(ConfigurationPropertySetter.class);
|
||||||
|
final ConfigurationPropertiesKey propertiesKey = method
|
||||||
|
.getAnnotation(ConfigurationPropertiesKey.class);
|
||||||
if (setter == null)
|
if (setter == null)
|
||||||
return null;
|
return null;
|
||||||
set(setter, args[0], method.getParameterTypes()[0]);
|
if (propertiesKey == null)
|
||||||
|
return null;
|
||||||
|
set(propertiesKey, args[0], method.getParameterTypes()[0]);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -146,16 +182,19 @@ public class ProxyConfigurationService extends AbstractService implements
|
|||||||
*
|
*
|
||||||
* @param getter
|
* @param getter
|
||||||
* the getter annotation
|
* the getter annotation
|
||||||
|
* @param propertiesKey
|
||||||
|
* if properties key annotation
|
||||||
* @param type
|
* @param type
|
||||||
* the transformed type
|
* the transformed type
|
||||||
* @return the untransformed property
|
* @return the untransformed property
|
||||||
*/
|
*/
|
||||||
private Object get(ConfigurationPropertyGetter getter, Class<?> type) {
|
private Object get(ConfigurationPropertyGetter getter,
|
||||||
if (cache.containsKey(getter.name()))
|
ConfigurationPropertiesKey propertiesKey, Class<?> type) {
|
||||||
return cache.get(getter.name());
|
if (cache.containsKey(propertiesKey.value()))
|
||||||
|
return cache.get(propertiesKey.value());
|
||||||
Object o = untransform(
|
Object o = untransform(
|
||||||
getRaw(getter.name(), getter.defaultValue()), type);
|
getRaw(propertiesKey.value(), getter.defaultValue()), type);
|
||||||
cache.put(getter.name(), o);
|
cache.put(propertiesKey.value(), o);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,15 +208,15 @@ public class ProxyConfigurationService extends AbstractService implements
|
|||||||
* @param type
|
* @param type
|
||||||
* the transformed type
|
* the transformed type
|
||||||
*/
|
*/
|
||||||
private void set(ConfigurationPropertySetter setter, Object value,
|
private void set(ConfigurationPropertiesKey setter, Object value,
|
||||||
Class<?> type) {
|
Class<?> type) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
properties.setProperty(setter.name(),
|
properties.setProperty(setter.value(),
|
||||||
transform(value.toString(), type));
|
transform(value.toString(), type));
|
||||||
cache.remove(setter.name());
|
cache.remove(setter.value());
|
||||||
} else {
|
} else {
|
||||||
properties.remove(setter.name());
|
properties.remove(setter.value());
|
||||||
cache.remove(setter.name());
|
cache.remove(setter.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,343 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of l2jserver <l2jserver.com>.
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jserver.service.configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
|
import com.l2jserver.service.ServiceStartException;
|
||||||
|
import com.l2jserver.service.cache.CacheService;
|
||||||
|
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
||||||
|
import com.l2jserver.service.core.LoggingService;
|
||||||
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
import com.l2jserver.util.transformer.Transformer;
|
||||||
|
import com.l2jserver.util.transformer.TransformerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Configuration} object through Java {@link Proxy}. Uses the
|
||||||
|
* annotations in the interface to retrieve and store values.
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
@Depends({ LoggingService.class, CacheService.class })
|
||||||
|
public class XMLConfigurationService extends AbstractService implements
|
||||||
|
ConfigurationService {
|
||||||
|
/**
|
||||||
|
* The directory in which configuration files are stored
|
||||||
|
*/
|
||||||
|
private File file = new File("./config/config.xml");
|
||||||
|
/**
|
||||||
|
* The logger
|
||||||
|
*/
|
||||||
|
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DOM {@link DocumentBuilderFactory}
|
||||||
|
*/
|
||||||
|
private DocumentBuilderFactory factory;
|
||||||
|
/**
|
||||||
|
* The DOM {@link DocumentBuilder}
|
||||||
|
*/
|
||||||
|
private DocumentBuilder builder;
|
||||||
|
|
||||||
|
private Document properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cache of configuration objects
|
||||||
|
*/
|
||||||
|
private Map<Class<?>, Object> cache = CollectionFactory.newWeakMap();
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface ConfigurationXPath {
|
||||||
|
String value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new empty instance
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
protected XMLConfigurationService() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new service instance. <b>This is used for tests</b>
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* the configuration file
|
||||||
|
*/
|
||||||
|
protected XMLConfigurationService(File file) {
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doStart() throws ServiceStartException {
|
||||||
|
factory = DocumentBuilderFactory.newInstance();
|
||||||
|
try {
|
||||||
|
builder = factory.newDocumentBuilder();
|
||||||
|
properties = builder.parse(file);
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
throw new ServiceStartException(e);
|
||||||
|
} catch (SAXException e) {
|
||||||
|
throw new ServiceStartException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ServiceStartException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <C extends Configuration> C get(Class<C> config) {
|
||||||
|
Preconditions.checkNotNull(config, "config");
|
||||||
|
|
||||||
|
if (cache.containsKey(config))
|
||||||
|
return (C) cache.get(config);
|
||||||
|
log.debug("Trying to create {} proxy", config);
|
||||||
|
|
||||||
|
C proxy = (C) Proxy.newProxyInstance(this.getClass().getClassLoader(),
|
||||||
|
new Class<?>[] { config }, new ConfigInvocationHandler(
|
||||||
|
properties));
|
||||||
|
cache.put(config, proxy);
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The invocation handler for configuration interfaces
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
private class ConfigInvocationHandler implements InvocationHandler {
|
||||||
|
/**
|
||||||
|
* The invocation handler properties
|
||||||
|
*/
|
||||||
|
private final Document properties;
|
||||||
|
/**
|
||||||
|
* The invocation cache
|
||||||
|
*/
|
||||||
|
private Map<String, Object> cache = CollectionFactory.newWeakMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param properties
|
||||||
|
* the properties
|
||||||
|
*/
|
||||||
|
public ConfigInvocationHandler(Document properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args)
|
||||||
|
throws Throwable {
|
||||||
|
log.debug("Configuration service, method invoked: {}",
|
||||||
|
method.getName());
|
||||||
|
if (args == null || args.length == 0) {
|
||||||
|
final ConfigurationPropertyGetter getter = method
|
||||||
|
.getAnnotation(ConfigurationPropertyGetter.class);
|
||||||
|
final ConfigurationXPath xpath = method
|
||||||
|
.getAnnotation(ConfigurationXPath.class);
|
||||||
|
if (getter == null)
|
||||||
|
return null;
|
||||||
|
if (xpath == null)
|
||||||
|
return null;
|
||||||
|
return get(getter, xpath, method.getReturnType());
|
||||||
|
} else if (args.length == 1) {
|
||||||
|
final ConfigurationXPath xpath = method
|
||||||
|
.getAnnotation(ConfigurationXPath.class);
|
||||||
|
if (xpath == null)
|
||||||
|
return null;
|
||||||
|
set(xpath, args[0], method.getParameterTypes()[0]);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the untransformed value of an property
|
||||||
|
*
|
||||||
|
* @param getter
|
||||||
|
* the getter annotation
|
||||||
|
* @param xpath
|
||||||
|
* the xpath annotation
|
||||||
|
* @param type
|
||||||
|
* the transformed type
|
||||||
|
* @return the untransformed property
|
||||||
|
*/
|
||||||
|
private Object get(ConfigurationPropertyGetter getter,
|
||||||
|
ConfigurationXPath xpath, Class<?> type) {
|
||||||
|
if (cache.containsKey(xpath.value()))
|
||||||
|
return cache.get(xpath.value());
|
||||||
|
Object o;
|
||||||
|
try {
|
||||||
|
o = untransform(getRaw(xpath.value(), getter.defaultValue()),
|
||||||
|
type);
|
||||||
|
} catch (XPathExpressionException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
cache.put(xpath.value(), o);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the transformed value of an property
|
||||||
|
*
|
||||||
|
* @param xpath
|
||||||
|
* the xpath annotation
|
||||||
|
* @param value
|
||||||
|
* the untransformed value
|
||||||
|
* @param type
|
||||||
|
* the transformed type
|
||||||
|
* @throws XPathExpressionException
|
||||||
|
* if any error occur while compiling the XPath
|
||||||
|
*/
|
||||||
|
private void set(ConfigurationXPath xpath, Object value, Class<?> type)
|
||||||
|
throws XPathExpressionException {
|
||||||
|
Node node = (Node) XPathFactory.newInstance().newXPath()
|
||||||
|
.compile(xpath.value())
|
||||||
|
.evaluate(properties, XPathConstants.NODE);
|
||||||
|
if (value != null) {
|
||||||
|
node.setNodeValue(transform(value.toString(), type));
|
||||||
|
cache.put(xpath.value(), value);
|
||||||
|
} else {
|
||||||
|
node.getParentNode().removeChild(node);
|
||||||
|
cache.remove(xpath.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Untransforms an value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* the raw value
|
||||||
|
* @param type
|
||||||
|
* the output type
|
||||||
|
* @return the untransformed value
|
||||||
|
*/
|
||||||
|
private Object untransform(String value, Class<?> type) {
|
||||||
|
if (value == null)
|
||||||
|
return null;
|
||||||
|
if (type == String.class)
|
||||||
|
return value;
|
||||||
|
final Transformer<?> transformer = TransformerFactory
|
||||||
|
.getTransfromer(type);
|
||||||
|
if (transformer == null)
|
||||||
|
return null;
|
||||||
|
return transformer.untransform(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms an value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* the raw typed value
|
||||||
|
* @param type
|
||||||
|
* the input type
|
||||||
|
* @return the string representing <tt>value</tt>
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
private String transform(Object value, Class<?> type) {
|
||||||
|
if (value == null)
|
||||||
|
return null;
|
||||||
|
if (value instanceof String)
|
||||||
|
return (String) value;
|
||||||
|
final Transformer transformer = TransformerFactory
|
||||||
|
.getTransfromer(type);
|
||||||
|
if (transformer == null)
|
||||||
|
return null;
|
||||||
|
return transformer.transform(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the raw value from the property file
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* the key
|
||||||
|
* @param defaultValue
|
||||||
|
* the default value
|
||||||
|
* @return the value found or default value
|
||||||
|
* @throws XPathExpressionException
|
||||||
|
* if any XPath exception occur
|
||||||
|
*/
|
||||||
|
private String getRaw(String key, String defaultValue)
|
||||||
|
throws XPathExpressionException {
|
||||||
|
if (properties == null)
|
||||||
|
return defaultValue;
|
||||||
|
String value = XPathFactory.newInstance().newXPath()
|
||||||
|
.evaluate(key, properties);
|
||||||
|
if (value == null || value.length() == 0)
|
||||||
|
return defaultValue;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to find an annotation in the class or any parent-class.
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* the annotation type
|
||||||
|
* @param annotationClass
|
||||||
|
* the annotation class
|
||||||
|
* @param clazz
|
||||||
|
* the class to look for annotations
|
||||||
|
* @return the annotation found
|
||||||
|
*/
|
||||||
|
private <T extends Annotation> T findAnnotation(Class<T> annotationClass,
|
||||||
|
Class<?> clazz) {
|
||||||
|
Preconditions.checkNotNull(annotationClass, "annotationClass");
|
||||||
|
Preconditions.checkNotNull(clazz, "clazz");
|
||||||
|
|
||||||
|
T ann = clazz.getAnnotation(annotationClass);
|
||||||
|
if (ann != null)
|
||||||
|
return ann;
|
||||||
|
|
||||||
|
for (Class<?> clazz2 : annotationClass.getInterfaces()) {
|
||||||
|
if (clazz2 == clazz)
|
||||||
|
continue;
|
||||||
|
ann = findAnnotation(annotationClass, clazz2);
|
||||||
|
if (ann != null)
|
||||||
|
return ann;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the configuration store directory
|
||||||
|
*/
|
||||||
|
public File getFile() {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,9 @@ import java.nio.file.Path;
|
|||||||
import com.l2jserver.service.Service;
|
import com.l2jserver.service.Service;
|
||||||
import com.l2jserver.service.ServiceConfiguration;
|
import com.l2jserver.service.ServiceConfiguration;
|
||||||
import com.l2jserver.service.configuration.Configuration;
|
import com.l2jserver.service.configuration.Configuration;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationName;
|
||||||
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationPropertiesKey;
|
||||||
|
import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The VFS service is responsible for creating a Virtual File System that is
|
* The VFS service is responsible for creating a Virtual File System that is
|
||||||
@@ -42,14 +44,18 @@ public interface VFSService extends Service {
|
|||||||
/**
|
/**
|
||||||
* @return the VFS root {@link URI}
|
* @return the VFS root {@link URI}
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "vfs.root", defaultValue = "")
|
@ConfigurationPropertyGetter(defaultValue = "")
|
||||||
|
@ConfigurationPropertiesKey("vfs.root")
|
||||||
|
@ConfigurationXPath("/configuration/services/vfs/root")
|
||||||
Path getRoot();
|
Path getRoot();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param root
|
* @param root
|
||||||
* the new VFS root {@link URI}
|
* the new VFS root {@link URI}
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "vfs.root")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("vfs.root")
|
||||||
|
@ConfigurationXPath("/configuration/services/vfs/root")
|
||||||
void setRoot(Path root);
|
void setRoot(Path root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import com.l2jserver.model.id.ID;
|
|||||||
import com.l2jserver.service.Service;
|
import com.l2jserver.service.Service;
|
||||||
import com.l2jserver.service.ServiceConfiguration;
|
import com.l2jserver.service.ServiceConfiguration;
|
||||||
import com.l2jserver.service.configuration.Configuration;
|
import com.l2jserver.service.configuration.Configuration;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service provides access to an database implementation. Each
|
* This service provides access to an database implementation. Each
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ import com.l2jserver.service.ServiceStopException;
|
|||||||
import com.l2jserver.service.cache.Cache;
|
import com.l2jserver.service.cache.Cache;
|
||||||
import com.l2jserver.service.cache.CacheService;
|
import com.l2jserver.service.cache.CacheService;
|
||||||
import com.l2jserver.service.configuration.ConfigurationService;
|
import com.l2jserver.service.configuration.ConfigurationService;
|
||||||
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationPropertiesKey;
|
||||||
|
import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath;
|
||||||
import com.l2jserver.service.core.LoggingService;
|
import com.l2jserver.service.core.LoggingService;
|
||||||
import com.l2jserver.service.core.threading.ScheduledAsyncFuture;
|
import com.l2jserver.service.core.threading.ScheduledAsyncFuture;
|
||||||
import com.l2jserver.service.core.threading.ThreadService;
|
import com.l2jserver.service.core.threading.ThreadService;
|
||||||
@@ -155,92 +157,120 @@ public class JDBCDatabaseService extends AbstractService implements
|
|||||||
/**
|
/**
|
||||||
* @return the jdbc url
|
* @return the jdbc url
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "jdbc.url", defaultValue = "jdbc:mysql://localhost/l2jserver2")
|
@ConfigurationPropertyGetter(defaultValue = "jdbc:mysql://localhost/l2jserver2")
|
||||||
|
@ConfigurationPropertiesKey("jdbc.url")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/jdbc/url")
|
||||||
String getJdbcUrl();
|
String getJdbcUrl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param jdbcUrl
|
* @param jdbcUrl
|
||||||
* the new jdbc url
|
* the new jdbc url
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "jdbc.url")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("jdbc.url")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/jdbc/url")
|
||||||
void setJdbcUrl(String jdbcUrl);
|
void setJdbcUrl(String jdbcUrl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the jdbc driver class
|
* @return the jdbc driver class
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "jdbc.driver", defaultValue = "com.jdbc.jdbc.Driver")
|
@ConfigurationPropertyGetter(defaultValue = "com.jdbc.jdbc.Driver")
|
||||||
|
@ConfigurationPropertiesKey("jdbc.driver")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/jdbc/driver")
|
||||||
String getDriver();
|
String getDriver();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param driver
|
* @param driver
|
||||||
* the new jdbc driver
|
* the new jdbc driver
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "jdbc.driver")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("jdbc.driver")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/jdbc/driver")
|
||||||
void setDriver(Class<?> driver);
|
void setDriver(Class<?> driver);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the jdbc database username
|
* @return the jdbc database username
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "jdbc.username", defaultValue = "l2j")
|
@ConfigurationPropertyGetter(defaultValue = "l2j")
|
||||||
|
@ConfigurationPropertiesKey("jdbc.username")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/jdbc/username")
|
||||||
String getUsername();
|
String getUsername();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param username
|
* @param username
|
||||||
* the jdbc database username
|
* the jdbc database username
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "jdbc.username")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("jdbc.username")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/jdbc/username")
|
||||||
void setUsername(String username);
|
void setUsername(String username);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the jdbc database password
|
* @return the jdbc database password
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "jdbc.password", defaultValue = "changeme")
|
@ConfigurationPropertyGetter(defaultValue = "changeme")
|
||||||
|
@ConfigurationPropertiesKey("jdbc.password")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/jdbc/password")
|
||||||
String getPassword();
|
String getPassword();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param password
|
* @param password
|
||||||
* the jdbc database password
|
* the jdbc database password
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "jdbc.password")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("jdbc.password")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/jdbc/password")
|
||||||
void setPassword(String password);
|
void setPassword(String password);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maximum number of active connections
|
* @return the maximum number of active connections
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "jdbc.active.max", defaultValue = "20")
|
@ConfigurationPropertyGetter(defaultValue = "20")
|
||||||
|
@ConfigurationPropertiesKey("jdbc.active.max")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/connections/active-maximum")
|
||||||
int getMaxActiveConnections();
|
int getMaxActiveConnections();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param password
|
* @param password
|
||||||
* the maximum number of active connections
|
* the maximum number of active connections
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "jdbc.active.max")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("jdbc.active.max")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/connections/active-maximum")
|
||||||
void setMaxActiveConnections(int password);
|
void setMaxActiveConnections(int password);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maximum number of idle connections
|
* @return the maximum number of idle connections
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "jdbc.idle.max", defaultValue = "20")
|
@ConfigurationPropertyGetter(defaultValue = "20")
|
||||||
|
@ConfigurationPropertiesKey("jdbc.idle.max")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/connections/idle-maximum")
|
||||||
int getMaxIdleConnections();
|
int getMaxIdleConnections();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param password
|
* @param password
|
||||||
* the maximum number of idle connections
|
* the maximum number of idle connections
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "jdbc.idle.max")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("jdbc.idle.max")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/connections/idle-maximum")
|
||||||
void setMaxIdleConnections(int password);
|
void setMaxIdleConnections(int password);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the minimum number of idle connections
|
* @return the minimum number of idle connections
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "jdbc.idle.min", defaultValue = "5")
|
@ConfigurationPropertyGetter(defaultValue = "5")
|
||||||
|
@ConfigurationPropertiesKey("jdbc.idle.min")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/connections/idle-minimum")
|
||||||
int getMinIdleConnections();
|
int getMinIdleConnections();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param password
|
* @param password
|
||||||
* the minimum number of idle connections
|
* the minimum number of idle connections
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "jdbc.idle.min")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("jdbc.idle.min")
|
||||||
|
@ConfigurationXPath("/configuration/services/database/connections/idle-minimum")
|
||||||
void setMinIdleConnections(int password);
|
void setMinIdleConnections(int password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,10 @@ import com.l2jserver.service.ServiceStartException;
|
|||||||
import com.l2jserver.service.ServiceStopException;
|
import com.l2jserver.service.ServiceStopException;
|
||||||
import com.l2jserver.service.cache.Cache;
|
import com.l2jserver.service.cache.Cache;
|
||||||
import com.l2jserver.service.cache.CacheService;
|
import com.l2jserver.service.cache.CacheService;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
|
||||||
import com.l2jserver.service.configuration.ConfigurationService;
|
import com.l2jserver.service.configuration.ConfigurationService;
|
||||||
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationName;
|
||||||
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationPropertiesKey;
|
||||||
|
import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath;
|
||||||
import com.l2jserver.service.core.LoggingService;
|
import com.l2jserver.service.core.LoggingService;
|
||||||
import com.l2jserver.service.core.vfs.VFSService;
|
import com.l2jserver.service.core.vfs.VFSService;
|
||||||
import com.l2jserver.util.jaxb.CharacterTemplateIDAdapter;
|
import com.l2jserver.util.jaxb.CharacterTemplateIDAdapter;
|
||||||
@@ -139,14 +141,18 @@ public class XMLTemplateService extends AbstractService implements
|
|||||||
/**
|
/**
|
||||||
* @return the directory in which templates are stored
|
* @return the directory in which templates are stored
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "template.directory", defaultValue = "data/templates")
|
@ConfigurationPropertyGetter(defaultValue = "data/templates")
|
||||||
|
@ConfigurationPropertiesKey("template.directory")
|
||||||
|
@ConfigurationXPath("/configuration/services/template/directory")
|
||||||
URI getTemplateDirectory();
|
URI getTemplateDirectory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param file
|
* @param file
|
||||||
* the directory in which templates are stored
|
* the directory in which templates are stored
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "template.directory")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("template.directory")
|
||||||
|
@ConfigurationXPath("/configuration/services/template/directory")
|
||||||
void setTemplateDirectory(URI file);
|
void setTemplateDirectory(URI file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ import com.l2jserver.model.world.L2Character;
|
|||||||
import com.l2jserver.service.Service;
|
import com.l2jserver.service.Service;
|
||||||
import com.l2jserver.service.ServiceConfiguration;
|
import com.l2jserver.service.ServiceConfiguration;
|
||||||
import com.l2jserver.service.configuration.Configuration;
|
import com.l2jserver.service.configuration.Configuration;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationName;
|
||||||
|
import com.l2jserver.service.configuration.ProxyConfigurationService.ConfigurationPropertiesKey;
|
||||||
|
import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The network service is responsible for communicating the server with the game
|
* The network service is responsible for communicating the server with the game
|
||||||
@@ -78,7 +80,9 @@ public interface NetworkService extends Service {
|
|||||||
*
|
*
|
||||||
* @return the listen address
|
* @return the listen address
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertyGetter(name = "listen", defaultValue = "0.0.0.0:7777")
|
@ConfigurationPropertyGetter(defaultValue = "0.0.0.0:7777")
|
||||||
|
@ConfigurationPropertiesKey("network.listen")
|
||||||
|
@ConfigurationXPath("/configuration/services/network/listen")
|
||||||
InetSocketAddress getListenAddress();
|
InetSocketAddress getListenAddress();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +91,9 @@ public interface NetworkService extends Service {
|
|||||||
* @param addr
|
* @param addr
|
||||||
* the listen address
|
* the listen address
|
||||||
*/
|
*/
|
||||||
@ConfigurationPropertySetter(name = "listen")
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationPropertiesKey("network.listen")
|
||||||
|
@ConfigurationXPath("/configuration/services/network/listen")
|
||||||
void setListenAddress(InetSocketAddress addr);
|
void setListenAddress(InetSocketAddress addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of l2jserver <l2jserver.com>.
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jserver.service.configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.l2jserver.service.ServiceStartException;
|
||||||
|
import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class XMLConfigurationServiceTest {
|
||||||
|
/**
|
||||||
|
* The {@link TestConfig} proxy
|
||||||
|
*/
|
||||||
|
private TestConfig config;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void tearUp() throws ServiceStartException {
|
||||||
|
final XMLConfigurationService service = new XMLConfigurationService(
|
||||||
|
new File("src/test/resources/test-config.xml"));
|
||||||
|
service.start();
|
||||||
|
config = service.get(TestConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testString() throws ServiceStartException {
|
||||||
|
Assert.assertEquals("test", config.getTestString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultValue() throws ServiceStartException {
|
||||||
|
Assert.assertEquals("default", config.getDefaultTestString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInteger() throws ServiceStartException {
|
||||||
|
Assert.assertEquals(256, config.getTestInteger());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetter() throws ServiceStartException {
|
||||||
|
config.setTestString("new-value");
|
||||||
|
Assert.assertEquals("new-value", config.getTestString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullSetter() throws ServiceStartException {
|
||||||
|
config.setTestString(null);
|
||||||
|
Assert.assertEquals("test-default", config.getTestString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The TestConfig interface
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
public interface TestConfig extends Configuration {
|
||||||
|
@ConfigurationPropertyGetter(defaultValue = "test-default")
|
||||||
|
@ConfigurationXPath("/configuration/test/testvalue")
|
||||||
|
String getTestString();
|
||||||
|
|
||||||
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationXPath("/configuration/test/testvalue")
|
||||||
|
void setTestString(String value);
|
||||||
|
|
||||||
|
@ConfigurationPropertyGetter(defaultValue = "default")
|
||||||
|
@ConfigurationXPath("/configuration/test/nonexistentkey")
|
||||||
|
String getDefaultTestString();
|
||||||
|
|
||||||
|
@ConfigurationPropertyGetter(defaultValue = "0")
|
||||||
|
@ConfigurationXPath("/configuration/test/integer")
|
||||||
|
int getTestInteger();
|
||||||
|
|
||||||
|
@ConfigurationPropertySetter
|
||||||
|
@ConfigurationXPath("/configuration/test/integer")
|
||||||
|
void setTestInteger(Integer n);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/test/resources/test-config.xml
Normal file
10
src/test/resources/test-config.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="configuration configuration.xsd"
|
||||||
|
xsi:noNamespaceSchemaLocation="configuration">
|
||||||
|
<configuration>
|
||||||
|
<test>
|
||||||
|
<testvalue>test</testvalue>
|
||||||
|
<integer>256</integer>
|
||||||
|
</test>
|
||||||
|
</configuration>
|
||||||
Reference in New Issue
Block a user