1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 08:23:11 +00:00

Implemented XML templates

This commit is contained in:
2011-05-24 22:55:31 -03:00
parent 6497016e14
commit cc44946831
10377 changed files with 309163 additions and 6171 deletions

View File

@@ -0,0 +1,54 @@
/*
* 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.util.jaxb;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.google.inject.Inject;
import com.l2jserver.model.id.template.CharacterTemplateID;
import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
import com.l2jserver.model.world.character.CharacterClass;
/**
* TODO this should use an {@link ItemTemplateIDProvider}!
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterTemplateIDAdapter extends
XmlAdapter<CharacterClass, CharacterTemplateID> {
private final CharacterTemplateIDProvider provider;
@Inject
public CharacterTemplateIDAdapter(CharacterTemplateIDProvider provider) {
this.provider = provider;
}
@Override
public CharacterTemplateID unmarshal(CharacterClass v) throws Exception {
if (v == null)
return null;
return provider.createID(v.id);
}
@Override
public CharacterClass marshal(CharacterTemplateID v) throws Exception {
if (v == null)
return null;
return CharacterClass.fromID(v.getID());
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.util.jaxb;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.google.inject.Inject;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
/**
* TODO this should use an {@link ItemTemplateIDProvider}!
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ItemTemplateIDAdapter extends XmlAdapter<Integer, ItemTemplateID> {
private final ItemTemplateIDProvider provider;
@Inject
public ItemTemplateIDAdapter(ItemTemplateIDProvider provider) {
this.provider = provider;
}
@Override
public ItemTemplateID unmarshal(Integer v) throws Exception {
if (v == 0)
return null;
return provider.createID(v);
}
@Override
public Integer marshal(ItemTemplateID v) throws Exception {
if (v == null)
return 0;
return v.getID();
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.util.jaxb;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.l2jserver.util.jaxb.MapAdapter.MapElements;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class MapAdapter extends XmlAdapter<MapElements[], Map<String, String>> {
@Override
public MapElements[] marshal(Map<String, String> map) throws Exception {
return map.values().toArray(new MapElements[map.size()]);
}
@Override
public Map<String, String> unmarshal(MapElements[] elems) throws Exception {
Map<String, String> r = new HashMap<String, String>();
for (MapElements mapelement : elems)
r.put(mapelement.key, mapelement.value);
return r;
}
public static class MapElements {
@XmlAttribute(name = "id")
public String key;
@XmlValue
public String value;
protected MapElements() {
}
public MapElements(String key, String value) {
this.key = key;
this.value = value;
}
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.util.jaxb;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.google.inject.Inject;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
/**
* TODO this should use an {@link ItemTemplateIDProvider}!
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NPCTemplateIDAdapter extends XmlAdapter<Integer, NPCTemplateID> {
private final NPCTemplateIDProvider provider;
@Inject
public NPCTemplateIDAdapter(NPCTemplateIDProvider provider) {
this.provider = provider;
}
@Override
public NPCTemplateID unmarshal(Integer v) throws Exception {
if (v == 0)
return null;
return provider.createID(v);
}
@Override
public Integer marshal(NPCTemplateID v) throws Exception {
if (v == null)
return 0;
return v.getID();
}
}