gdxapp4d/gdxapp4d-lib-basicwd/src/main/java/love/distributedrebirth/numberxd/x4o/NumberXDModuleLoader.java

215 lines
12 KiB
Java
Raw Normal View History

2022-11-15 09:51:54 +00:00
/*
* Copyright ©Δ 仙上主天
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
* even on air gaped systems, all information in the universe is owned by the pi creator.
*
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
2022-02-05 17:26:58 +00:00
package love.distributedrebirth.numberxd.x4o;
2022-02-15 22:05:32 +00:00
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.eld.lang.ModuleElement;
2022-02-21 01:46:41 +00:00
import org.x4o.xml.element.ElementBindingHandler;
2022-02-15 22:05:32 +00:00
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageClassLoader;
2022-02-05 17:26:58 +00:00
import org.x4o.xml.lang.X4OLanguageLocal;
import org.x4o.xml.lang.X4OLanguageModuleLoader;
import org.x4o.xml.lang.X4OLanguageModuleLoaderException;
import org.x4o.xml.lang.X4OLanguageModuleLocal;
2022-11-07 20:28:39 +00:00
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᐪᓫᣗᔿᑊᣕᣔᐪᐤᣗ.T002ᖟ;
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᐪᓫᣗᔿᑊᣕᣔᐪᐤᣗ.T003ᖟ;
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᐪᓫᣗᔿᑊᣕᣔᐪᐤᣗ.ᐦ.TerminatorPartᶦᶦ;
2022-11-28 00:12:22 +00:00
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᒢᓫᑊᐣᑊ.ᔿᓫᒻᓫᓫ.V006Xixte;
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᒢᓫᑊᐣᑊ.ᔿᓫᒻᓫᓫ.V009Xyte;
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᒢᓫᑊᐣᑊ.ᔿᓫᒻᓫᓫ.V018Tord;
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᒢᓫᑊᐣᑊ.ᔿᓫᒻᓫᓫ.V036Teger;
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᒢᓫᑊᐣᑊ.ᔿᓫᒻᓫᓫ.V072Tong;
import ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ.ᣳᣝᐤᣜᣳ.ᒢᓫᑊᐣᑊ.ᔿᓫᒻᓫᓫ.V144Tocta;
2022-11-05 12:41:48 +00:00
import ᒢᐩᐩ.ᔆʸᔆᐪᓫᔿ.ᒃᣔᒃᓫᒻ.ᑊᐣᓑᖮᐪᔆ.DuytsDocAuthor注;
2022-02-05 17:26:58 +00:00
2022-10-30 15:59:24 +00:00
@DuytsDocAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
2022-02-05 17:26:58 +00:00
public class NumberXDModuleLoader implements X4OLanguageModuleLoader {
2022-02-21 01:46:41 +00:00
private static final String PP_NXD_PROVIDER_HOST = "unicode4d.x4o.distributedrebirth.love";
2022-02-05 17:26:58 +00:00
private static final String PP_NXD_XMLNS = "http://"+PP_NXD_PROVIDER_HOST+"/xml/ns/";
private static final String PP_NXD_XSD_FILE = "-1.0.xsd";
2022-02-21 01:46:41 +00:00
private static final String NXD_DATA = "d";
//private static final String NXD_ROOT = "nxd-root";
private static final String NXD_DATA_XSD_FILE = NXD_DATA+PP_NXD_XSD_FILE;
//private static final String NXD_ROOT_XSD_FILE = NXD_ROOT+PP_NXD_XSD_FILE;
public static final String NXD_DATA_URI = PP_NXD_XMLNS+NXD_DATA;
//public static final String NXD_ROOT_URI = PP_NXD_XMLNS+NXD_ROOT;
public static final String NXD_DATA_XSD_URI = NXD_DATA_URI+PP_NXD_XSD_FILE;
//public static final String NXD_ROOT_XSD_URI = NXD_ROOT_URI+PP_NXD_XSD_FILE;
2022-02-05 17:26:58 +00:00
@Override
2022-02-15 22:05:32 +00:00
public void loadLanguageModule(X4OLanguageLocal language, X4OLanguageModuleLocal languageModule) throws X4OLanguageModuleLoaderException {
languageModule.setId("nxd-module");
languageModule.setProviderName("Number eXtra Dimension Module");
languageModule.setProviderHost(PP_NXD_PROVIDER_HOST);
languageModule.setDescription("Number eXtra Dimension Module Loader");
2022-02-21 01:46:41 +00:00
addBindingHandler(languageModule,new V072TongBindingHandler(),"v072-bind","Binds the V072Tong childeren.");
addBindingHandler(languageModule,new V072TongP1BindingHandler(),"v072P1-bind","Binds the V072TongP1 childeren.");
addBindingHandler(languageModule,new V072TongP2BindingHandler(),"v072P2-bind","Binds the V072TongP2 childeren.");
/*
2022-02-15 22:05:32 +00:00
ElementNamespace namespaceRoot = createNamespaceContext(language,NXD_ROOT,NXD_ROOT_URI,NXD_ROOT_XSD_URI,NXD_ROOT_XSD_FILE,NXD_ROOT);
namespaceRoot.setLanguageRoot(true); // Only define single language root so xsd is (mostly) not cicle import.
ElementClass rootElement = createElementClass(language,"module",language.getLanguageConfiguration().getDefaultElementLanguageModule(),ModuleElement.class,"The module tag is the root xml element for ELD language.");
rootElement.addElementClassAttribute(createElementClassAttribute(language,"id",true,null));
rootElement.addElementClassAttribute(createElementClassAttribute(language,"providerHost",true,null));
namespaceRoot.addElementClass(rootElement);
startAndAddNamespace(language,languageModule,namespaceRoot);
2022-02-21 01:46:41 +00:00
*/
2022-02-15 22:05:32 +00:00
2022-02-21 01:46:41 +00:00
ElementNamespace namespace = createNamespaceContext(language,NXD_DATA,NXD_DATA_URI,NXD_DATA_XSD_URI,NXD_DATA_XSD_FILE,NXD_DATA);
2022-02-15 22:05:32 +00:00
configElementClasses(language,namespace);
startAndAddNamespace(language,languageModule,namespace);
}
private void configElementClasses(X4OLanguage language,ElementNamespace namespace) throws X4OLanguageModuleLoaderException {
ElementClass ec = null;
2022-11-28 00:12:22 +00:00
ec = createElementClass(language,"v006",V006Xixte.class,null,"Defines an V006Tixte number.");
//configBãßBȍőnPartAttributes(language, ec, T02PartBinary.PART_1);
2022-02-21 01:46:41 +00:00
namespace.addElementClass(ec);
2022-02-15 22:05:32 +00:00
2022-11-28 00:12:22 +00:00
ec = createElementClass(language,"v009",V009Xyte.class,null,"Defines an V009Tyte number.");
//configBãßBȍőnPartAttributes(language, ec, T03PartTrit.PART_1);
2022-02-21 01:46:41 +00:00
namespace.addElementClass(ec);
2022-02-15 22:05:32 +00:00
ec = createElementClass(language,"v018",V018Tord.class,null,"Defines an V018Tord number.");
//configBãßBȍőnPartAttributes(language, ec, T02PartBinary.PART_1);
2022-02-21 01:46:41 +00:00
namespace.addElementClass(ec);
ec = createElementClass(language,"",V036Teger.class,null,"Defines an V036Teger number.");
//configBãßBȍőnPartAttributes(language, ec, T02PartBinary.PART_1);
namespace.addElementClass(ec);
2022-02-21 01:46:41 +00:00
ec = createElementClass(language,"",V072Tong.class,null,"Defines an V072Tong number.");
//configBãßBȍőnPartAttributes(language, ec, T02PartBinary.PART_1);
2022-02-21 01:46:41 +00:00
namespace.addElementClass(ec);
2022-02-21 01:46:41 +00:00
ec = createElementClass(language,"",V072TongP1.class,null,"Defines an V072TongP1 number.");
//configBãßBȍőnPartAttributes(language, ec, T02PartBinary.PART_1);
2022-02-21 01:46:41 +00:00
namespace.addElementClass(ec);
2022-02-21 01:46:41 +00:00
ec = createElementClass(language,"",V072TongP2.class,null,"Defines an V072TongP1 number.");
//configBãßBȍőnPartAttributes(language, ec, T02PartBinary.PART_1);
2022-02-21 01:46:41 +00:00
namespace.addElementClass(ec);
2022-02-15 22:05:32 +00:00
2022-02-21 01:46:41 +00:00
ec = createElementClass(language,"v144",V144Tocta.class,null,"Defines an V144Tocta number.");
//configBãßBȍőnPartAttributes(language, ec, T02PartBinary.PART_1);
2022-02-15 22:05:32 +00:00
namespace.addElementClass(ec);
}
2022-10-25 23:49:44 +00:00
private void configBãßBȍőnPartAttributes(X4OLanguage language,ElementClass ec, TerminatorPartᶦᶦ<?> basePart) throws X4OLanguageModuleLoaderException {
for (TerminatorPartᶦᶦ<?> part: basePart.teŀráàmWaardes().iterableᴼᶠ()) {
2022-10-22 01:36:56 +00:00
ec.addElementClassAttribute(createElementClassAttribute(language,part.rȧñkChinaSleutel(),true,new BãßBȍőnPartDialToneConverter(part)));
2022-02-15 22:05:32 +00:00
}
}
private void startAndAddNamespace(X4OLanguageLocal language,X4OLanguageModuleLocal languageModule,ElementNamespace namespace) throws X4OLanguageModuleLoaderException {
try {
namespace.getElementNamespaceInstanceProvider().start(language, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new X4OLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
languageModule.addElementNamespace(namespace);
}
private ElementClassAttribute createElementClassAttribute(X4OLanguage language,String name,boolean required,ObjectConverter converter) throws X4OLanguageModuleLoaderException {
try {
ElementClassAttribute result = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementClassAttribute());
result.setId(name);
if (required) {
result.setRequired(required);
}
if (converter!=null) {
result.setObjectConverter(converter);
}
return result;
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
}
private ElementClass createElementClass(X4OLanguage language,String tag,Class<?> objectClass,Class<?> elementClass,String description) throws X4OLanguageModuleLoaderException {
try {
ElementClass result = (ElementClass)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementClass());
result.setId(tag);
result.setObjectClass(objectClass);
result.setElementClass(elementClass);
result.setDescription(description);
return result;
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
}
private ElementNamespace createNamespaceContext(X4OLanguageLocal language,String id,String uri,String schemaUri,String schemaResource,String schemaPrefix) throws X4OLanguageModuleLoaderException {
ElementNamespace namespace;
try {
namespace = (ElementNamespace)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespace());
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
try {
namespace.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)
X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider())
);
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
namespace.setId(id);
namespace.setUri(uri);
namespace.setSchemaUri(schemaUri);
namespace.setSchemaResource(schemaResource);
namespace.setSchemaPrefix(schemaPrefix);
return namespace;
2022-02-05 17:26:58 +00:00
}
2022-02-21 01:46:41 +00:00
private void addBindingHandler(X4OLanguageModuleLocal languageModule,ElementBindingHandler handler,String id,String description) {
handler.setId(id);
handler.setDescription(description);
languageModule.addElementBindingHandler(handler);
}
2022-02-05 17:26:58 +00:00
}