Beispiel #1
0
void LLRNGWriter::addDefinition(const std::string& type_name, const LLInitParam::BaseBlock& block)
{
	if (mDefinedElements.find(type_name) != mDefinedElements.end()) return;
	mDefinedElements.insert(type_name);

	LLXMLNodePtr node = mGrammarNode->createChild("define", false);
	node->createChild("name", true)->setStringValue(type_name);

	mElementNode = node->createChild("element", false);
	mElementNode->createChild("name", true)->setStringValue(type_name);
	mChildrenNode = mElementNode->createChild("zeroOrMore", false)->createChild("choice", false);

	mAttributesWritten.first = mElementNode;
	mAttributesWritten.second.clear();
	mElementsWritten.clear();

	block.inspectBlock(*this);

	// add includes for all possible children
	const std::type_info* type = *LLWidgetTypeRegistry::instance().getValue(type_name);
	const widget_registry_t* widget_registryp = LLChildRegistryRegistry::instance().getValue(type);
	
	// add include declarations for all valid children
	for (widget_registry_t::Registrar::registry_map_t::const_iterator it = widget_registryp->currentRegistrar().beginItems();
		it != widget_registryp->currentRegistrar().endItems();
		++it)
	{
		std::string child_name = it->first;
		if (child_name == type_name)
		{
			continue;
		}
		
		LLXMLNodePtr old_element_node = mElementNode;
		LLXMLNodePtr old_child_node = mChildrenNode;
		//FIXME: add LLDefaultParamBlockRegistry back when working on schema generation
		//addDefinition(child_name, (*LLDefaultParamBlockRegistry::instance().getValue(type))());
		mElementNode = old_element_node;
		mChildrenNode = old_child_node;

		mChildrenNode->createChild("ref", false)->createChild("name", true)->setStringValue(child_name);
	}

	if (mChildrenNode->mChildren.isNull())
	{
		// remove unused children node
		mChildrenNode->mParent->mParent->deleteChild(mChildrenNode->mParent);
	}
}
Beispiel #2
0
void LLXSDWriter::writeXSD(const std::string& type_name, LLXMLNodePtr node, const LLInitParam::BaseBlock& block, const std::string& xml_namespace)
{
	mSchemaNode = node;
	node->setName("xs:schema");
	node->createChild("attributeFormDefault", true)->setStringValue("unqualified");
	node->createChild("elementFormDefault", true)->setStringValue("qualified");
	node->createChild("targetNamespace", true)->setStringValue(xml_namespace);
	node->createChild("xmlns:xs", true)->setStringValue("http://www.w3.org/2001/XMLSchema");
	node->createChild("xmlns", true)->setStringValue(xml_namespace);

	node = node->createChild("xs:complexType", false);
	node->createChild("name", true)->setStringValue(type_name);
	node->createChild("mixed", true)->setStringValue("true");

	mAttributeNode = node;
	mElementNode = node->createChild("xs:choice", false);
	mElementNode->createChild("minOccurs", true)->setStringValue("0");
	mElementNode->createChild("maxOccurs", true)->setStringValue("unbounded");
	block.inspectBlock(*this);

	// duplicate element choices
	LLXMLNodeList children;
	mElementNode->getChildren("xs:element", children, FALSE);
	for (LLXMLNodeList::iterator child_it = children.begin(); child_it != children.end(); ++child_it)
	{
		LLXMLNodePtr child_copy = child_it->second->deepCopy();
		std::string child_name;
		child_copy->getAttributeString("name", child_name);
		child_copy->setAttributeString("name", type_name + "." + child_name);
		mElementNode->addChild(child_copy);
	}

	LLXMLNodePtr element_declaration_node = mSchemaNode->createChild("xs:element", false);
	element_declaration_node->createChild("name", true)->setStringValue(type_name);
	element_declaration_node->createChild("type", true)->setStringValue(type_name);
}