/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ #include "apache/das/DataGraphPrinter.h" namespace apache { namespace das { DataGraphPrinter::DataGraphPrinter(commonj::sdo::DataObjectPtr root) { this->root = root; } DataGraphPrinter::~DataGraphPrinter(void) {} void DataGraphPrinter::printMetaData(std::ostream& out) { tabCount = 0; const commonj::sdo::TypeList& typeList = root->getDataFactory()->getTypes(); for (unsigned int i = 0 ; i < typeList.size() ; i++) { out << std::endl << "[" << typeList[i].getName(); const commonj::sdo::Type* base = typeList[i].getBaseType(); /*out << "{"; out << " baseType = " << ((base == 0) ? "NULL" : base->getName()); out << " uri = " << typeList[i].getURI(); out << " abstractType = " << typeList[i].isAbstractType(); out << " changeSummaryType = " << typeList[i].isChangeSummaryType(); out << " dataObjectType = " << typeList[i].isDataObjectType(); out << " dataType = " << typeList[i].isDataType(); out << " openType = " << typeList[i].isOpenType(); out << " sequencedType = " << typeList[i].isSequencedType() << " } ";*/ out << "]" << std::endl; commonj::sdo::PropertyList propertyList = typeList[i].getProperties(); for (unsigned int j = 0 ; j < propertyList.size() ; j++) { out << propertyList[j].getName() << std::endl; /*out << "{"; out << " type = " << propertyList[j].getType().getName(); out << " alias = " << propertyList[j].getAlias(); out << " aliasCount = " << propertyList[j].getAliasCount(); out << " contaiment = " << propertyList[j].isContainment(); out << " defaulted = " << propertyList[j].isDefaulted(); out << " many = " << propertyList[j].isMany(); out << " readOnly = " << propertyList[j].isReadOnly(); out << " reference = " << propertyList[j].isReference(); out << "}" << std::endl;*/ } } out << std::endl; } void DataGraphPrinter::printDataGraph(commonj::sdo::DataObjectPtr dataObject, bool ref) { std::ostream& out = *this->out; commonj::sdo::PropertyList& propertyList = dataObject->getType().getProperties(); out << getTab(tabCount) << "[" << dataObject->getType().getURI() << "." << dataObject->getType().getName() << "]"; tabCount++; for (unsigned int i = 0 ; i < propertyList.size() ; i++) { if (propertyList[i].isMany()) { out << getTab(tabCount) << ((propertyList[i].isReference()) ? "-> " : "") << "[" << propertyList[i].getType().getName() << " LIST]"; tabCount++; commonj::sdo::DataObjectList& objectList = dataObject->getList(propertyList[i]); for (unsigned int j = 0 ; j < objectList.size() ; j++) { if (objectList[j]->getType().isDataType()) { std::string typeName = objectList[j]->getType().getName(); if (typeName == "String") { wchar_t* buf = new wchar_t[200]; int copied = dataObject->getString((((std::string) propertyList[j].getName()) + "[" + StringWrapper::toString(j) + "]").c_str(), buf, 200); buf[copied] = 0; std::wstring wstr = buf; std::string str(wstr.begin(), wstr.end()); str.assign(wstr.begin(), wstr.end()); out << getTab(tabCount) << str << " : " << objectList[j]->getType().getName(); delete [] buf; } else if (typeName == "Integer") { out << getTab(tabCount) << dataObject->getInt((((std::string) propertyList[j].getName()) + "[" + StringWrapper::toString(j) + "]").c_str()) << " : " << objectList[j]->getType().getName(); } } else if (!ref) { printDataGraph(objectList[j], propertyList[i].isReference()); } } if (objectList.size() == 0) { out << getTab(tabCount) << "--empty--"; } tabCount--; } else { commonj::sdo::DataObjectPtr actual = dataObject->getDataObject(propertyList[i]); if (actual) { std::string typeName = actual->getType().getName(); if (typeName == "String") { wchar_t* buf = new wchar_t[200]; int copied = dataObject->getString(propertyList[i], buf, 200); buf[copied] = 0; std::wstring wstr = buf; std::string str(wstr.begin(), wstr.end()); str.assign(wstr.begin(), wstr.end()); out << getTab(tabCount) << ((propertyList[i].isReference()) ? "-> " : "") << str << " : " << actual->getType().getName(); delete [] buf; } else if (typeName == "Int") { out << getTab(tabCount) << dataObject->getInt(propertyList[i]) << " : " << actual->getType().getName(); } else if (typeName == "Boolean") { out << getTab(tabCount) << dataObject->getBoolean(propertyList[i]) << " : " << actual->getType().getName(); } } else { out << getTab(tabCount) << "NULL : " << propertyList[i].getType().getName(); } } if (propertyList.size() == 0) { out << getTab(tabCount) << "--empty--"; } } tabCount--; } void DataGraphPrinter::print(std::ostream& out) { tabCount = 0; this->out = &out; printDataGraph(root); out << std::endl; } std::string DataGraphPrinter::getTab(int count) const { std::string ret; ret.append(count* 3, ' '); return "\n" + ret; } }; };