X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2FXMLObjectBuilder.cpp;h=982f6a2f51274147d88ba5bd6fe1a31bc2b7d876;hb=64dcaec957e9befd960779498d7fe35bbb62141a;hp=c3aa88103cf78dddd503e34dc4652c967eb8323f;hpb=d5a0f969f3695b01120b8a473892feebbe1f6061;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/XMLObjectBuilder.cpp b/xmltooling/XMLObjectBuilder.cpp index c3aa881..982f6a2 100644 --- a/xmltooling/XMLObjectBuilder.cpp +++ b/xmltooling/XMLObjectBuilder.cpp @@ -1,71 +1,72 @@ -/* - * Copyright 2001-2006 Internet2 - * - * 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. - */ - -/** - * XMLObjectBuilder.cpp - * - * Factory interface for XMLObjects - */ - -#include "internal.h" -#include "XMLObjectBuilder.h" -#include "util/NDC.h" -#include "util/XMLHelper.h" - -#include - -using namespace xmltooling; -using namespace log4cpp; -using namespace std; - -map XMLObjectBuilder::m_map; -XMLObjectBuilder* XMLObjectBuilder::m_default=NULL; - -const XMLObjectBuilder* XMLObjectBuilder::getBuilder(const DOMElement* domElement) -{ -#ifdef _DEBUG - xmltooling::NDC ndc("getBuilder"); -#endif - Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObjectBuilder"); - - auto_ptr schemaType(XMLHelper::getXSIType(domElement)); - const XMLObjectBuilder* xmlObjectBuilder = getBuilder(*(schemaType.get())); - if (xmlObjectBuilder) { - if (log.isDebugEnabled()) { - log.debug("Located XMLObjectBuilder for schema type: %s", schemaType->toString().c_str()); - } - return xmlObjectBuilder; - } - - auto_ptr elementName(XMLHelper::getNodeQName(domElement)); - xmlObjectBuilder = getBuilder(*(elementName.get())); - if (xmlObjectBuilder) { - if (log.isDebugEnabled()) { - log.debug("Located XMLObjectBuilder for element name: %s", elementName->toString().c_str()); - } - return xmlObjectBuilder; - } - - log.error("No XMLObjectBuilder was registered for element: %s", elementName->toString().c_str()); - return NULL; -} - -void XMLObjectBuilder::destroyBuilders() -{ - for_each(m_map.begin(),m_map.end(),cleanup_pair()); - m_map.clear(); - deregisterDefaultBuilder(); -} +/* + * Copyright 2001-2007 Internet2 + * + * 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. + */ + +/** + * XMLObjectBuilder.cpp + * + * Factory interface for XMLObjects + */ + +#include "internal.h" +#include "logging.h" +#include "XMLObjectBuilder.h" +#include "util/NDC.h" +#include "util/XMLHelper.h" + +using namespace xmltooling::logging; +using namespace xmltooling; +using namespace std; + +map XMLObjectBuilder::m_map; +XMLObjectBuilder* XMLObjectBuilder::m_default=NULL; + +const XMLObjectBuilder* XMLObjectBuilder::getBuilder(const DOMElement* domElement) +{ +#ifdef _DEBUG + xmltooling::NDC ndc("getBuilder"); +#endif + Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObject.Builder"); + + auto_ptr schemaType(XMLHelper::getXSIType(domElement)); + const XMLObjectBuilder* xmlObjectBuilder = schemaType.get() ? getBuilder(*(schemaType.get())) : NULL; + if (xmlObjectBuilder) { + if (log.isDebugEnabled()) { + log.debug("located XMLObjectBuilder for schema type: %s", schemaType->toString().c_str()); + } + return xmlObjectBuilder; + } + + auto_ptr elementName(XMLHelper::getNodeQName(domElement)); + xmlObjectBuilder = getBuilder(*(elementName.get())); + if (xmlObjectBuilder) { + if (log.isDebugEnabled()) { + log.debug("located XMLObjectBuilder for element name: %s", elementName->toString().c_str()); + } + return xmlObjectBuilder; + } + + if (log.isDebugEnabled()) { + log.debug("no XMLObjectBuilder registered for element (%s), returning default", elementName->toString().c_str()); + } + return m_default; +} + +void XMLObjectBuilder::destroyBuilders() +{ + for_each(m_map.begin(),m_map.end(),cleanup_pair()); + m_map.clear(); + deregisterDefaultBuilder(); +}