Location: PHPKode > scripts > BoUML File Parser > test_bouml_component_reader.php
<?php
/**
 * Script that intends to read from a BoUML (http://bouml.free.fr/) file set its artifacts
 * Completly open license; don't worry, use it as you want!
 * 
 * Plenty of work need to be done like:
 * 1. Add up all uml artifacts supported by boUML within UML_Parser_Configuration_BoUML class
 * 2. Manage error better with more exceptions
 * 
 * This is not meant to be a 'final' version or tool; only to embed in whatever you need to understand with BoUML files
 * 
 * We at http://www.innox.com.mx use this code to be sure that all components designed in bouml are actually implemented in code :)
 * @author hide@address.com
 * 
 * Browse down in this script for a step by step classes configuration procedure 
 */


require_once("UML_Package.php");

require_once("UML_Parser_Configuration.php");
require_once("UML_Parser_Configuration_BoUML.php");

require_once("UML_Artifact.php");
require_once("UML_Project.php");

require_once("UML_Data_Source.php");

/**
 * Ths the source class configuration that handles how raw data from files is read
 * @author jgonzalez
 *
 */
class UML_Data_Source_BoUML extends UML_Data_Source_Abstract {
	public function getSource($source = NULL) {
		$complete_file_name = $this->configuration->getProjectPath()."/".$this->getArtifactName();
		
		$source = NULL;
		if (is_readable($complete_file_name)) {
			$source = utf8_encode(file_get_contents($complete_file_name));
		} else {
			throw new Exception("BoUML::getSource() -> Unable to read file [$complete_file_name]");
		}
		
		return $source;
	}
}

/**
 * Script
 * Version .1alpha
 * 
 * todos:
 * a) Add in all artifact types to UML_Parser_Configuration_BoUML
 */

// 1. Create configuration manager class
$configuration = new UML_Parser_Configuration_BoUML();

// 2. Configure the root folder for project files
$configuration->setProjectPath('/Users/jgonzalez/Documents/Documentos_Putty/karmaki_docs/diseno_global/Karmaki-Diseno_global');

// 3. Select main file
$bouml_data_source = new UML_Data_Source_BoUML('Karmaki-Diseno_global.prj');
$bouml_data_source->setConfiguration($configuration);

// 4. Create project from main source assigning configuration class
$bouml_project = UML_Project::createFromSource($bouml_data_source, $configuration);

// 5. Finally user can browse
foreach($bouml_project->getPackages() as $package) {
	foreach($package->getArtifactsByType($configuration->getArtifactNameForComponent()) as $component) {
		print($component->getName()."\n");
	}
}
Return current item: BoUML File Parser