/**
   * Checks modelObject.getModelRoot() referred definitions, do match of modelObject's Definition
   *
   * @param modelObject which is supposed to be from referred definition.
   * @return referred Description, or null
   */
  public static IDescription getReferredDescription(IModelObject modelObject) {
    if (modelObject instanceof IFault) {
      final Collection<IParameter> parameters = ((IFault) modelObject).getParameters();
      modelObject = parameters.isEmpty() ? null : parameters.iterator().next();
    }
    if (modelObject == null || !(modelObject.getModelRoot() instanceof IWsdlModelRoot)) {
      return null;
    }

    final IWsdlModelRoot wsdlModelRoot = (IWsdlModelRoot) modelObject.getModelRoot();
    final IDescription description = wsdlModelRoot.getDescription();

    // get referred Definition
    EObject referredDefinition = modelObject.getComponent();
    while (referredDefinition != null && !(referredDefinition instanceof Definition)) {
      referredDefinition = referredDefinition.eContainer();
    }

    if (referredDefinition != null) {
      for (final IDescription referredDescription : description.getReferencedServices()) {
        if (referredDefinition.equals(referredDescription.getComponent())) {
          return referredDescription;
        }
      }
    }
    return null;
  }
  /**
   * Checks modelObject.getModelRoot() referred schemas, do match modelObject's XSDSchema
   *
   * @param modelObject which is supposed to be from referred schema.
   * @return referred ISchema, or null
   */
  public static ISchema getReferredSchema(final IModelObject modelObject) {
    if (modelObject == null || !(modelObject.getModelRoot() instanceof IXSDModelRoot)) {
      return null;
    }

    final IXSDModelRoot xsdModelRoot = (IXSDModelRoot) modelObject.getModelRoot();
    final ISchema schema = xsdModelRoot.getSchema();

    // get referred XSDSchema
    EObject referredXSDSchema = modelObject.getComponent();
    while (referredXSDSchema != null && !(referredXSDSchema instanceof XSDSchema)) {
      referredXSDSchema = referredXSDSchema.eContainer();
    }

    if (referredXSDSchema != null) {
      for (final ISchema referredSchema : schema.getAllReferredSchemas()) {
        if (referredXSDSchema.equals(referredSchema.getComponent())) {
          return referredSchema;
        }
      }
    }
    return null;
  }
  /** Check whether 'modelObject' is part of 'modelRoot' resource. */
  public static boolean isModelObjectPartOfModelRoot(
      final IModelRoot modelRoot, final IModelObject modelObject) {
    if (modelObject == null) {
      return false;
    }

    final EObject childComponent = modelObject.getComponent();
    final EObject rootComponent = modelRoot.getModelObject().getComponent();

    EObject currentComponent = childComponent;
    while (currentComponent != null && !rootComponent.equals(currentComponent)) {
      currentComponent = currentComponent.eContainer();
    }

    return currentComponent != null;
  }
 private EObject getEObject(IModelObject modelObject) {
   if (modelObject instanceof Description
       || modelObject instanceof OperationFault
       || modelObject instanceof OperationParameter
       || modelObject instanceof ServiceInterface
       || modelObject instanceof ServiceOperation
       || modelObject instanceof ISchema
       || modelObject instanceof IType
       || modelObject instanceof IElement
       || modelObject instanceof IFacet) {
     return modelObject.getComponent();
   }
   logger.log(
       new Status(
           IStatus.WARNING,
           Activator.PLUGIN_ID,
           "EObject not found for " + modelObject)); // $NON-NLS-1$
   return null;
 }