org.eclipse.emf.ecore.xmi.util.XMLProcessor Java Examples

The following examples show how to use org.eclipse.emf.ecore.xmi.util.XMLProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EMFComponent.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Load the XML file with a given XML schema. This method should be used in
 * conjuction with the nullary constructor.
 * 
 * @param schema
 * @param file
 * @return
 */
public boolean load(File schema, File file) {
	// Create a new XMLProcessor to be used in creating
	// and persisting XML Resources
	try {
		xmlProcessor = new XMLProcessor(URI.createFileURI(schema.getAbsolutePath()));
	} catch (SAXException e) {
		logger.error(getClass().getName() + " Exception!", e);
		return false;
	}

	return load(file);
}
 
Example #2
Source File: PublishOrganizationOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected String toString(final Organization organization) throws IOException {
    final XMLResource resource = createResourceFromOrganization(organization);
    final XMLProcessor processor = new OrganizationXMLProcessor();
    final Map<String, Object> options = new HashMap<>();
    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
    options.put(XMLResource.OPTION_XML_VERSION, "1.0");
    options.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
    return processor.saveToString(resource, options);
}
 
Example #3
Source File: EMFComponent.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * The constructor, takes a Java file pointing to the XML schema model.
 * 
 * @param file
 *            The XML Schema
 */
public EMFComponent(File file) {
	super();

	// Initialize class data
	iceEMFTree = new EMFTreeComposite();
	xmlResource = new XMLResourceImpl();

	// Make sure we have a valid File object.
	if (file != null) {
		// Create a new XMLProcessor to be used in creating
		// and persisting XML Resources
		try {
			xmlProcessor = new XMLProcessor(URI.createFileURI(file.getAbsolutePath()));
		} catch (SAXException e) {
			logger.error(getClass().getName() + " Exception!", e);
		}

		if (xmlProcessor != null) {

			// Get the package containing the model
			EPackage ePackage = (EPackage) xmlProcessor.getEPackageRegistry().values().toArray()[0];

			// Get the TreeIterator to walk over the elements
			TreeIterator<EObject> tree = ePackage.eAllContents();
			while (tree.hasNext()) {
				// Get the Element
				EObject obj = tree.next();

				// We only care about EClass instances bc those
				// are the nodes of the tree.
				if (obj instanceof EClass) {
					EClass eClass = (EClass) obj;
					// Add the new EMFTreeComposite corresponding to the
					// current
					// EClass instance to the mapping
					if ("DocumentRoot".equals(eClass.getName())) {
						// This will give us a root node, and the
						// constructor
						// will take care of constructing possible exemplar
						// children nodes.
						iceEMFTree = new EMFTreeComposite(eClass);
						break;
					}
				}
			}
		}
	}

	return;
}