Java tutorial
// Description: Java 7 XML SAX Parser for CFSecurity. /* * CF Security Core Implementation * * Copyright (c) 2010-2014 Mark Sobkow * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * *********************************************************************** * * Code manufactured by MSS Code Factory */ package net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecuritySaxLoader; import java.io.File; import java.lang.reflect.*; import java.math.*; import java.net.URL; import java.sql.*; import java.text.*; import java.util.*; import javax.naming.*; import javax.sql.*; import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.*; import org.apache.commons.codec.binary.Base64; import org.xml.sax.*; import net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurity.*; import net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityObj.*; public class CFSecuritySaxLoader extends CFLibXmlCoreSaxParser implements ContentHandler { // The namespace URI of the supported schema public final static String SCHEMA_XMLNS = "uri://net.sourceforge.msscodefactory.cfsecurity.v2_0/cfsecurityloader"; // The source for loading the supported schema public final static String SCHEMA_URI = "xsd/cfsecurity-20-structured.xsd"; public final static String SCHEMA_ROOT_URI = "/xsd/cfsecurity-20-structured.xsd"; // The schema instance to load in to private ICFSecuritySchemaObj schemaObj = null; // Loader behaviour configuration attributes public enum LoaderBehaviourEnum { Insert, Update, Replace }; private LoaderBehaviourEnum auditActionLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum clusterLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum hostNodeLoaderBehaviour = LoaderBehaviourEnum.Update; private LoaderBehaviourEnum iSOCountryLoaderBehaviour = LoaderBehaviourEnum.Update; private LoaderBehaviourEnum iSOCountryCurrencyLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum iSOCountryLanguageLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum iSOCurrencyLoaderBehaviour = LoaderBehaviourEnum.Update; private LoaderBehaviourEnum iSOLanguageLoaderBehaviour = LoaderBehaviourEnum.Update; private LoaderBehaviourEnum iSOTimezoneLoaderBehaviour = LoaderBehaviourEnum.Update; private LoaderBehaviourEnum secAppLoaderBehaviour = LoaderBehaviourEnum.Update; private LoaderBehaviourEnum secFormLoaderBehaviour = LoaderBehaviourEnum.Update; private LoaderBehaviourEnum secGroupLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum secGroupFormLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum secGroupIncludeLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum secGroupMemberLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum secSessionLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum secUserLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum serviceLoaderBehaviour = LoaderBehaviourEnum.Update; private LoaderBehaviourEnum serviceTypeLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum tSecGroupLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum tSecGroupIncludeLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum tSecGroupMemberLoaderBehaviour = LoaderBehaviourEnum.Insert; private LoaderBehaviourEnum tenantLoaderBehaviour = LoaderBehaviourEnum.Insert; // Constructors public CFSecuritySaxLoader() { super(); setRootElementHandler(getSaxRootHandler()); File file = new File(SCHEMA_URI); if (file.exists()) { addSchema(SCHEMA_URI); } else { URL url = getClass().getResource(SCHEMA_ROOT_URI); if (url != null) { addSchema(url.toString()); } } initParser(); } public CFSecuritySaxLoader(ICFLibMessageLog logger) { super(logger); setRootElementHandler(getSaxRootHandler()); File file = new File(SCHEMA_URI); if (file.exists()) { addSchema(SCHEMA_URI); } else { URL url = getClass().getResource(SCHEMA_ROOT_URI); if (url != null) { addSchema(url.toString()); } } initParser(); } // Element Handler instances private CFSecuritySaxLoaderAuditActionHandler auditActionHandler = null; private CFSecuritySaxLoaderClusterHandler clusterHandler = null; private CFSecuritySaxLoaderHostNodeHandler hostNodeHandler = null; private CFSecuritySaxLoaderISOCountryHandler iSOCountryHandler = null; private CFSecuritySaxLoaderISOCountryCurrencyHandler iSOCountryCurrencyHandler = null; private CFSecuritySaxLoaderISOCountryLanguageHandler iSOCountryLanguageHandler = null; private CFSecuritySaxLoaderISOCurrencyHandler iSOCurrencyHandler = null; private CFSecuritySaxLoaderISOLanguageHandler iSOLanguageHandler = null; private CFSecuritySaxLoaderISOTimezoneHandler iSOTimezoneHandler = null; private CFSecuritySaxLoaderSecAppHandler secAppHandler = null; private CFSecuritySaxLoaderSecFormHandler secFormHandler = null; private CFSecuritySaxLoaderSecGroupHandler secGroupHandler = null; private CFSecuritySaxLoaderSecGroupFormHandler secGroupFormHandler = null; private CFSecuritySaxLoaderSecGroupIncludeHandler secGroupIncludeHandler = null; private CFSecuritySaxLoaderSecGroupMemberHandler secGroupMemberHandler = null; private CFSecuritySaxLoaderSecSessionHandler secSessionHandler = null; private CFSecuritySaxLoaderSecUserHandler secUserHandler = null; private CFSecuritySaxLoaderServiceHandler serviceHandler = null; private CFSecuritySaxLoaderServiceTypeHandler serviceTypeHandler = null; private CFSecuritySaxLoaderTSecGroupHandler tSecGroupHandler = null; private CFSecuritySaxLoaderTSecGroupIncludeHandler tSecGroupIncludeHandler = null; private CFSecuritySaxLoaderTSecGroupMemberHandler tSecGroupMemberHandler = null; private CFSecuritySaxLoaderTenantHandler tenantHandler = null; private CFSecuritySaxRootHandler saxRootHandler = null; private CFSecuritySaxDocHandler saxDocHandler = null; // Schema object accessors // SchemaObj accessors public ICFSecuritySchemaObj getSchemaObj() { return (schemaObj); } public void setSchemaObj(ICFSecuritySchemaObj value) { schemaObj = value; } // Element Handler Resolver Factories protected CFSecuritySaxLoaderAuditActionHandler getAuditActionHandler() { if (auditActionHandler == null) { auditActionHandler = new CFSecuritySaxLoaderAuditActionHandler(this); } return (auditActionHandler); } protected CFSecuritySaxLoaderClusterHandler getClusterHandler() { if (clusterHandler == null) { clusterHandler = new CFSecuritySaxLoaderClusterHandler(this); clusterHandler.addElementHandler("HostNode", getHostNodeHandler()); clusterHandler.addElementHandler("Tenant", getTenantHandler()); clusterHandler.addElementHandler("SecApp", getSecAppHandler()); clusterHandler.addElementHandler("SecGroup", getSecGroupHandler()); } return (clusterHandler); } protected CFSecuritySaxLoaderHostNodeHandler getHostNodeHandler() { if (hostNodeHandler == null) { hostNodeHandler = new CFSecuritySaxLoaderHostNodeHandler(this); hostNodeHandler.addElementHandler("Service", getServiceHandler()); } return (hostNodeHandler); } protected CFSecuritySaxLoaderISOCountryHandler getISOCountryHandler() { if (iSOCountryHandler == null) { iSOCountryHandler = new CFSecuritySaxLoaderISOCountryHandler(this); iSOCountryHandler.addElementHandler("ISOCountryCurrency", getISOCountryCurrencyHandler()); iSOCountryHandler.addElementHandler("ISOCountryLanguage", getISOCountryLanguageHandler()); } return (iSOCountryHandler); } protected CFSecuritySaxLoaderISOCountryCurrencyHandler getISOCountryCurrencyHandler() { if (iSOCountryCurrencyHandler == null) { iSOCountryCurrencyHandler = new CFSecuritySaxLoaderISOCountryCurrencyHandler(this); } return (iSOCountryCurrencyHandler); } protected CFSecuritySaxLoaderISOCountryLanguageHandler getISOCountryLanguageHandler() { if (iSOCountryLanguageHandler == null) { iSOCountryLanguageHandler = new CFSecuritySaxLoaderISOCountryLanguageHandler(this); } return (iSOCountryLanguageHandler); } protected CFSecuritySaxLoaderISOCurrencyHandler getISOCurrencyHandler() { if (iSOCurrencyHandler == null) { iSOCurrencyHandler = new CFSecuritySaxLoaderISOCurrencyHandler(this); } return (iSOCurrencyHandler); } protected CFSecuritySaxLoaderISOLanguageHandler getISOLanguageHandler() { if (iSOLanguageHandler == null) { iSOLanguageHandler = new CFSecuritySaxLoaderISOLanguageHandler(this); } return (iSOLanguageHandler); } protected CFSecuritySaxLoaderISOTimezoneHandler getISOTimezoneHandler() { if (iSOTimezoneHandler == null) { iSOTimezoneHandler = new CFSecuritySaxLoaderISOTimezoneHandler(this); } return (iSOTimezoneHandler); } protected CFSecuritySaxLoaderSecAppHandler getSecAppHandler() { if (secAppHandler == null) { secAppHandler = new CFSecuritySaxLoaderSecAppHandler(this); secAppHandler.addElementHandler("SecForm", getSecFormHandler()); } return (secAppHandler); } protected CFSecuritySaxLoaderSecFormHandler getSecFormHandler() { if (secFormHandler == null) { secFormHandler = new CFSecuritySaxLoaderSecFormHandler(this); } return (secFormHandler); } protected CFSecuritySaxLoaderSecGroupHandler getSecGroupHandler() { if (secGroupHandler == null) { secGroupHandler = new CFSecuritySaxLoaderSecGroupHandler(this); secGroupHandler.addElementHandler("SecGroupInclude", getSecGroupIncludeHandler()); secGroupHandler.addElementHandler("SecGroupMember", getSecGroupMemberHandler()); secGroupHandler.addElementHandler("SecGroupForm", getSecGroupFormHandler()); } return (secGroupHandler); } protected CFSecuritySaxLoaderSecGroupFormHandler getSecGroupFormHandler() { if (secGroupFormHandler == null) { secGroupFormHandler = new CFSecuritySaxLoaderSecGroupFormHandler(this); } return (secGroupFormHandler); } protected CFSecuritySaxLoaderSecGroupIncludeHandler getSecGroupIncludeHandler() { if (secGroupIncludeHandler == null) { secGroupIncludeHandler = new CFSecuritySaxLoaderSecGroupIncludeHandler(this); } return (secGroupIncludeHandler); } protected CFSecuritySaxLoaderSecGroupMemberHandler getSecGroupMemberHandler() { if (secGroupMemberHandler == null) { secGroupMemberHandler = new CFSecuritySaxLoaderSecGroupMemberHandler(this); } return (secGroupMemberHandler); } protected CFSecuritySaxLoaderSecSessionHandler getSecSessionHandler() { if (secSessionHandler == null) { secSessionHandler = new CFSecuritySaxLoaderSecSessionHandler(this); } return (secSessionHandler); } protected CFSecuritySaxLoaderSecUserHandler getSecUserHandler() { if (secUserHandler == null) { secUserHandler = new CFSecuritySaxLoaderSecUserHandler(this); secUserHandler.addElementHandler("SecSession", getSecSessionHandler()); } return (secUserHandler); } protected CFSecuritySaxLoaderServiceHandler getServiceHandler() { if (serviceHandler == null) { serviceHandler = new CFSecuritySaxLoaderServiceHandler(this); } return (serviceHandler); } protected CFSecuritySaxLoaderServiceTypeHandler getServiceTypeHandler() { if (serviceTypeHandler == null) { serviceTypeHandler = new CFSecuritySaxLoaderServiceTypeHandler(this); } return (serviceTypeHandler); } protected CFSecuritySaxLoaderTSecGroupHandler getTSecGroupHandler() { if (tSecGroupHandler == null) { tSecGroupHandler = new CFSecuritySaxLoaderTSecGroupHandler(this); tSecGroupHandler.addElementHandler("TSecGroupInclude", getTSecGroupIncludeHandler()); tSecGroupHandler.addElementHandler("TSecGroupMember", getTSecGroupMemberHandler()); } return (tSecGroupHandler); } protected CFSecuritySaxLoaderTSecGroupIncludeHandler getTSecGroupIncludeHandler() { if (tSecGroupIncludeHandler == null) { tSecGroupIncludeHandler = new CFSecuritySaxLoaderTSecGroupIncludeHandler(this); } return (tSecGroupIncludeHandler); } protected CFSecuritySaxLoaderTSecGroupMemberHandler getTSecGroupMemberHandler() { if (tSecGroupMemberHandler == null) { tSecGroupMemberHandler = new CFSecuritySaxLoaderTSecGroupMemberHandler(this); } return (tSecGroupMemberHandler); } protected CFSecuritySaxLoaderTenantHandler getTenantHandler() { if (tenantHandler == null) { tenantHandler = new CFSecuritySaxLoaderTenantHandler(this); tenantHandler.addElementHandler("TSecGroup", getTSecGroupHandler()); } return (tenantHandler); } // Root Element Handler Resolver Factory protected CFSecuritySaxRootHandler getSaxRootHandler() { if (saxRootHandler == null) { saxRootHandler = new CFSecuritySaxRootHandler(this); saxRootHandler.addElementHandler("CFSecurity", getSaxDocHandler()); } return (saxRootHandler); } // Root Element Handler /* * CFSecuritySaxRootHandler XML SAX Root Element Handler implementation */ public class CFSecuritySaxRootHandler extends CFLibXmlCoreElementHandler { public CFSecuritySaxRootHandler(CFSecuritySaxLoader saxLoader) { super(saxLoader); } public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { } public void endElement(String uri, String localName, String qName) throws SAXException { } } // Document Element Handler Resolver Factory protected CFSecuritySaxDocHandler getSaxDocHandler() { if (saxDocHandler == null) { saxDocHandler = new CFSecuritySaxDocHandler(this); saxDocHandler.addElementHandler("AuditAction", getAuditActionHandler()); saxDocHandler.addElementHandler("Cluster", getClusterHandler()); saxDocHandler.addElementHandler("ISOCountry", getISOCountryHandler()); saxDocHandler.addElementHandler("ISOCurrency", getISOCurrencyHandler()); saxDocHandler.addElementHandler("ISOLanguage", getISOLanguageHandler()); saxDocHandler.addElementHandler("ISOTimezone", getISOTimezoneHandler()); saxDocHandler.addElementHandler("SecUser", getSecUserHandler()); saxDocHandler.addElementHandler("ServiceType", getServiceTypeHandler()); } return (saxDocHandler); } // Document Element Handler /* * CFSecuritySaxDocHandler XML SAX Doc Element Handler implementation */ public class CFSecuritySaxDocHandler extends CFLibXmlCoreElementHandler { public CFSecuritySaxDocHandler(CFSecuritySaxLoader saxLoader) { super(saxLoader); } public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { } public void endElement(String uri, String localName, String qName) throws SAXException { } } // Loader behaviour configuration accessors public LoaderBehaviourEnum getAuditActionLoaderBehaviour() { return (auditActionLoaderBehaviour); } public void setAuditActionLoaderBehaviour(LoaderBehaviourEnum value) { auditActionLoaderBehaviour = value; } public LoaderBehaviourEnum getClusterLoaderBehaviour() { return (clusterLoaderBehaviour); } public void setClusterLoaderBehaviour(LoaderBehaviourEnum value) { clusterLoaderBehaviour = value; } public LoaderBehaviourEnum getHostNodeLoaderBehaviour() { return (hostNodeLoaderBehaviour); } public void setHostNodeLoaderBehaviour(LoaderBehaviourEnum value) { hostNodeLoaderBehaviour = value; } public LoaderBehaviourEnum getISOCountryLoaderBehaviour() { return (iSOCountryLoaderBehaviour); } public void setISOCountryLoaderBehaviour(LoaderBehaviourEnum value) { iSOCountryLoaderBehaviour = value; } public LoaderBehaviourEnum getISOCountryCurrencyLoaderBehaviour() { return (iSOCountryCurrencyLoaderBehaviour); } public void setISOCountryCurrencyLoaderBehaviour(LoaderBehaviourEnum value) { iSOCountryCurrencyLoaderBehaviour = value; } public LoaderBehaviourEnum getISOCountryLanguageLoaderBehaviour() { return (iSOCountryLanguageLoaderBehaviour); } public void setISOCountryLanguageLoaderBehaviour(LoaderBehaviourEnum value) { iSOCountryLanguageLoaderBehaviour = value; } public LoaderBehaviourEnum getISOCurrencyLoaderBehaviour() { return (iSOCurrencyLoaderBehaviour); } public void setISOCurrencyLoaderBehaviour(LoaderBehaviourEnum value) { iSOCurrencyLoaderBehaviour = value; } public LoaderBehaviourEnum getISOLanguageLoaderBehaviour() { return (iSOLanguageLoaderBehaviour); } public void setISOLanguageLoaderBehaviour(LoaderBehaviourEnum value) { iSOLanguageLoaderBehaviour = value; } public LoaderBehaviourEnum getISOTimezoneLoaderBehaviour() { return (iSOTimezoneLoaderBehaviour); } public void setISOTimezoneLoaderBehaviour(LoaderBehaviourEnum value) { iSOTimezoneLoaderBehaviour = value; } public LoaderBehaviourEnum getSecAppLoaderBehaviour() { return (secAppLoaderBehaviour); } public void setSecAppLoaderBehaviour(LoaderBehaviourEnum value) { secAppLoaderBehaviour = value; } public LoaderBehaviourEnum getSecFormLoaderBehaviour() { return (secFormLoaderBehaviour); } public void setSecFormLoaderBehaviour(LoaderBehaviourEnum value) { secFormLoaderBehaviour = value; } public LoaderBehaviourEnum getSecGroupLoaderBehaviour() { return (secGroupLoaderBehaviour); } public void setSecGroupLoaderBehaviour(LoaderBehaviourEnum value) { secGroupLoaderBehaviour = value; } public LoaderBehaviourEnum getSecGroupFormLoaderBehaviour() { return (secGroupFormLoaderBehaviour); } public void setSecGroupFormLoaderBehaviour(LoaderBehaviourEnum value) { secGroupFormLoaderBehaviour = value; } public LoaderBehaviourEnum getSecGroupIncludeLoaderBehaviour() { return (secGroupIncludeLoaderBehaviour); } public void setSecGroupIncludeLoaderBehaviour(LoaderBehaviourEnum value) { secGroupIncludeLoaderBehaviour = value; } public LoaderBehaviourEnum getSecGroupMemberLoaderBehaviour() { return (secGroupMemberLoaderBehaviour); } public void setSecGroupMemberLoaderBehaviour(LoaderBehaviourEnum value) { secGroupMemberLoaderBehaviour = value; } public LoaderBehaviourEnum getSecSessionLoaderBehaviour() { return (secSessionLoaderBehaviour); } public void setSecSessionLoaderBehaviour(LoaderBehaviourEnum value) { secSessionLoaderBehaviour = value; } public LoaderBehaviourEnum getSecUserLoaderBehaviour() { return (secUserLoaderBehaviour); } public void setSecUserLoaderBehaviour(LoaderBehaviourEnum value) { secUserLoaderBehaviour = value; } public LoaderBehaviourEnum getServiceLoaderBehaviour() { return (serviceLoaderBehaviour); } public void setServiceLoaderBehaviour(LoaderBehaviourEnum value) { serviceLoaderBehaviour = value; } public LoaderBehaviourEnum getServiceTypeLoaderBehaviour() { return (serviceTypeLoaderBehaviour); } public void setServiceTypeLoaderBehaviour(LoaderBehaviourEnum value) { serviceTypeLoaderBehaviour = value; } public LoaderBehaviourEnum getTSecGroupLoaderBehaviour() { return (tSecGroupLoaderBehaviour); } public void setTSecGroupLoaderBehaviour(LoaderBehaviourEnum value) { tSecGroupLoaderBehaviour = value; } public LoaderBehaviourEnum getTSecGroupIncludeLoaderBehaviour() { return (tSecGroupIncludeLoaderBehaviour); } public void setTSecGroupIncludeLoaderBehaviour(LoaderBehaviourEnum value) { tSecGroupIncludeLoaderBehaviour = value; } public LoaderBehaviourEnum getTSecGroupMemberLoaderBehaviour() { return (tSecGroupMemberLoaderBehaviour); } public void setTSecGroupMemberLoaderBehaviour(LoaderBehaviourEnum value) { tSecGroupMemberLoaderBehaviour = value; } public LoaderBehaviourEnum getTenantLoaderBehaviour() { return (tenantLoaderBehaviour); } public void setTenantLoaderBehaviour(LoaderBehaviourEnum value) { tenantLoaderBehaviour = value; } // Parse a file public void parseFile(String url) { parse(url); } }