All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openhealthtools.mdht.uml.cda.operations.StrucDocTextOperations Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2009, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.openhealthtools.mdht.uml.cda.operations;

import java.util.Stack;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.FeatureMapUtil;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.openhealthtools.mdht.uml.cda.StrucDocText;

/**
 * 
 * A static utility class that provides operations related to 'Struc Doc Text' model objects.
 * 
 *
 * 

* The following operations are supported: *

    *
  • {@link org.openhealthtools.mdht.uml.cda.StrucDocText#addText(java.lang.String) Add Text}
  • *
  • {@link org.openhealthtools.mdht.uml.cda.StrucDocText#getText() Get Text}
  • *
  • {@link org.openhealthtools.mdht.uml.cda.StrucDocText#getText(java.lang.String) Get Text}
  • *
*

* * @generated */ public class StrucDocTextOperations { /** * * * @generated */ protected StrucDocTextOperations() { super(); } /** * * * @generated NOT */ public static void addText(StrucDocText strucDocText, String text) { if (text == null) { throw new IllegalArgumentException("text is null"); } FeatureMapUtil.addText(strucDocText.getMixed(), text); } /** * * * @generated NOT */ public static String getText(StrucDocText strucDocText) { return getText(strucDocText.getMixed()); } /** * * * @generated NOT */ public static String getText(StrucDocText strucDocText, String id) { return getText(strucDocText.getMixed(), id); } private static String getText(FeatureMap root, String id) { Stack stack = new Stack(); stack.push(root); while (!stack.isEmpty()) { FeatureMap featureMap = stack.pop(); for (FeatureMap.Entry entry : featureMap) { if (entry.getEStructuralFeature() instanceof EReference) { AnyType anyType = (AnyType) entry.getValue(); String attributeValue = getAttributeValue(anyType.getAnyAttribute(), "ID"); if (attributeValue != null && attributeValue.equals(id)) { return getText(anyType.getMixed()); } stack.push(anyType.getMixed()); } } } return null; } private static String getAttributeValue(FeatureMap featureMap, String name) { for (FeatureMap.Entry entry : featureMap) { EStructuralFeature feature = entry.getEStructuralFeature(); if (feature instanceof EAttribute && feature.getName().equals(name)) { return entry.getValue().toString(); } } return null; } private static String getText(FeatureMap featureMap) { StringBuffer buffer = new StringBuffer(""); for (FeatureMap.Entry entry : featureMap) { if (FeatureMapUtil.isText(entry)) { buffer.append(entry.getValue().toString()); } } return buffer.toString(); } } // StrucDocTextOperations




© 2015 - 2024 Weber Informatics LLC | Privacy Policy