All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.reprezen.genflow.rapidml.xsd.FeatureHelper Maven / Gradle / Ivy
/**
* Copyright © 2013, 2016 Modelsolv, Inc.
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains the property
* of ModelSolv, Inc. See the file license.html in the root directory of
* this project for further information.
*/
package com.reprezen.genflow.rapidml.xsd;
import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import com.reprezen.genflow.api.zenmodel.util.CommonServices;
import com.reprezen.genflow.rapidml.xsd.Helpers;
import com.reprezen.genflow.rapidml.xsd.ParamsHelper;
import com.reprezen.genflow.rapidml.xsd.TraceHelper;
import com.reprezen.genflow.rapidml.xsd.XMLSchemaHelper;
import com.reprezen.rapidml.DataModel;
import com.reprezen.rapidml.Element;
import com.reprezen.rapidml.Feature;
import com.reprezen.rapidml.PrimitiveProperty;
import com.reprezen.rapidml.PrimitiveType;
import com.reprezen.rapidml.PrimitiveTypeSourceReference;
import com.reprezen.rapidml.PropertyRealization;
import com.reprezen.rapidml.PropertyReference;
import com.reprezen.rapidml.ReferenceElement;
import com.reprezen.rapidml.ReferenceEmbed;
import com.reprezen.rapidml.ReferenceLink;
import com.reprezen.rapidml.ReferenceProperty;
import com.reprezen.rapidml.ReferenceTreatment;
import com.reprezen.rapidml.ResourceAPI;
import com.reprezen.rapidml.ServiceDataResource;
import com.reprezen.rapidml.SingleValueType;
import com.reprezen.rapidml.SourceReference;
import com.reprezen.rapidml.Structure;
import com.reprezen.rapidml.TypedMessage;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
@SuppressWarnings("all")
public class FeatureHelper {
@Extension
private XMLSchemaHelper xmlSchemaHelper;
@Extension
private ParamsHelper paramsHelper;
@Extension
private TraceHelper traceHelper;
private final static String UNBOUNDED = "unbounded";
private final CommonServices commonServices = new CommonServices();
public FeatureHelper(final Helpers helpers) {
XMLSchemaHelper _xmlSchemaHelper = helpers.getXmlSchemaHelper();
this.xmlSchemaHelper = _xmlSchemaHelper;
ParamsHelper _paramsHelper = helpers.getParamsHelper();
this.paramsHelper = _paramsHelper;
TraceHelper _traceHelper = helpers.getTraceHelper();
this.traceHelper = _traceHelper;
}
public boolean isRequired(final Feature feature) {
int _minOccurs = feature.getMinOccurs();
return (_minOccurs > 0);
}
public boolean isRequired(final ReferenceElement feature) {
int _minOccurs = feature.getMinOccurs();
return (_minOccurs > 0);
}
public boolean isRequired(final PropertyRealization includedProperty) {
int _minOccurs = includedProperty.getMinOccurs();
return (_minOccurs > 0);
}
public String getLcName(final Element element) {
String _switchResult = null;
boolean _matched = false;
if (!_matched) {
if (element instanceof Feature) {
_matched=true;
String _name = ((Feature)element).getName();
_switchResult = StringExtensions.toFirstLower(_name);
}
}
if (!_matched) {
if (element instanceof ReferenceElement) {
_matched=true;
String _name = ((ReferenceElement)element).getName();
_switchResult = StringExtensions.toFirstLower(_name);
}
}
return _switchResult;
}
public String getLcName(final PropertyRealization property) {
Feature _baseProperty = property.getBaseProperty();
return this.getLcName(_baseProperty);
}
public String getTypeName(final PrimitiveProperty primitiveProperty, final ResourceAPI api) {
String _xifexpression = null;
SingleValueType _type = primitiveProperty.getType();
if ((_type instanceof PrimitiveType)) {
_xifexpression = "xs";
} else {
SingleValueType _type_1 = primitiveProperty.getType();
DataModel _eContainer = this.xmlSchemaHelper.getEContainer(_type_1, DataModel.class);
_xifexpression = this.xmlSchemaHelper.nsPrefix(_eContainer, api);
}
final String prefix = _xifexpression;
String _primitiveFeatureType = this.primitiveFeatureType(primitiveProperty);
return ((prefix + ":") + _primitiveFeatureType);
}
public String getTypeName(final PropertyRealization property, final ResourceAPI api) {
String _xblockexpression = null;
{
final Feature baseProperty = property.getBaseProperty();
String _switchResult = null;
boolean _matched = false;
if (!_matched) {
if (baseProperty instanceof PrimitiveProperty) {
_matched=true;
_switchResult = this.getTypeName(((PrimitiveProperty)baseProperty), api);
}
}
if (!_matched) {
throw new IllegalArgumentException();
}
_xblockexpression = _switchResult;
}
return _xblockexpression;
}
public String getListName(final Element element) {
String _lcName = this.getLcName(element);
final String name = (_lcName + "List");
this.traceHelper.setListElementInTrace(element, name);
return name;
}
public String getListName(final PropertyRealization property) {
Feature _baseProperty = property.getBaseProperty();
return this.getListName(_baseProperty);
}
public String getItemName(final Element element) {
String _elvis = null;
String _listItemElementName = this.paramsHelper.getListItemElementName();
if (_listItemElementName != null) {
_elvis = _listItemElementName;
} else {
_elvis = "item";
}
String _lcName = this.getLcName(element);
final String name = _elvis.replaceAll("\\$\\{property\\}", _lcName);
this.traceHelper.setListItemElementInTrace(element, name);
return name;
}
public String getItemName(final PropertyRealization property) {
Feature _baseProperty = property.getBaseProperty();
return this.getItemName(_baseProperty);
}
public ReferenceLink getReferenceLink(final Feature feature, final Iterable referenceLinks) {
ReferenceLink _xblockexpression = null;
{
final Function1 _function = (ReferenceLink it) -> {
ReferenceElement _referenceElement = it.getReferenceElement();
return Boolean.valueOf(Objects.equal(_referenceElement, feature));
};
final Iterable refs = IterableExtensions.filter(referenceLinks, _function);
ReferenceLink _xifexpression = null;
boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(refs);
if (_isNullOrEmpty) {
_xifexpression = null;
} else {
final Function1 _function_1 = (ReferenceLink it) -> {
return null;
};
_xifexpression = IterableExtensions.findFirst(refs, _function_1);
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
public int getListMinOccurs(final Feature feature) {
int _xifexpression = (int) 0;
boolean _isRequired = this.isRequired(feature);
if (_isRequired) {
_xifexpression = 1;
} else {
_xifexpression = 0;
}
return _xifexpression;
}
public int getListMinOccurs(final ReferenceElement feature) {
int _xifexpression = (int) 0;
boolean _isRequired = this.isRequired(feature);
if (_isRequired) {
_xifexpression = 1;
} else {
_xifexpression = 0;
}
return _xifexpression;
}
public int getListMinOccurs(final PropertyRealization feature) {
int _xifexpression = (int) 0;
boolean _isRequired = this.isRequired(feature);
if (_isRequired) {
_xifexpression = 1;
} else {
_xifexpression = 0;
}
return _xifexpression;
}
public int getListItemMinOccurs(final Feature feature) {
int _xifexpression = (int) 0;
boolean _allowEmptyLists = this.paramsHelper.allowEmptyLists();
if (_allowEmptyLists) {
_xifexpression = 0;
} else {
_xifexpression = 1;
}
return _xifexpression;
}
public int getListItemMinOccurs(final ReferenceElement feature) {
int _xifexpression = (int) 0;
boolean _allowEmptyLists = this.paramsHelper.allowEmptyLists();
if (_allowEmptyLists) {
_xifexpression = 0;
} else {
_xifexpression = 1;
}
return _xifexpression;
}
public int getListItemMinOccurs(final PropertyRealization feature) {
int _xifexpression = (int) 0;
boolean _allowEmptyLists = this.paramsHelper.allowEmptyLists();
if (_allowEmptyLists) {
_xifexpression = 0;
} else {
_xifexpression = 1;
}
return _xifexpression;
}
public Object getListItemMaxOccurs(final Feature feature) {
Object _xifexpression = null;
boolean _or = false;
int _maxOccurs = feature.getMaxOccurs();
boolean _equals = (_maxOccurs == (-1));
if (_equals) {
_or = true;
} else {
int _maxOccurs_1 = feature.getMaxOccurs();
boolean _greaterThan = (_maxOccurs_1 > 1);
_or = _greaterThan;
}
if (_or) {
_xifexpression = FeatureHelper.UNBOUNDED;
} else {
_xifexpression = Integer.valueOf(1);
}
return _xifexpression;
}
public Object getListItemMaxOccurs(final ReferenceElement feature) {
Object _xifexpression = null;
boolean _or = false;
int _maxOccurs = feature.getMaxOccurs();
boolean _equals = (_maxOccurs == (-1));
if (_equals) {
_or = true;
} else {
int _maxOccurs_1 = feature.getMaxOccurs();
boolean _greaterThan = (_maxOccurs_1 > 1);
_or = _greaterThan;
}
if (_or) {
_xifexpression = FeatureHelper.UNBOUNDED;
} else {
_xifexpression = Integer.valueOf(1);
}
return _xifexpression;
}
public Object getListItemMaxOccurs(final PropertyRealization feature) {
Object _xifexpression = null;
boolean _or = false;
int _maxOccurs = feature.getMaxOccurs();
boolean _equals = (_maxOccurs == (-1));
if (_equals) {
_or = true;
} else {
int _maxOccurs_1 = feature.getMaxOccurs();
boolean _greaterThan = (_maxOccurs_1 > 1);
_or = _greaterThan;
}
if (_or) {
_xifexpression = FeatureHelper.UNBOUNDED;
} else {
_xifexpression = Integer.valueOf(1);
}
return _xifexpression;
}
public Iterable getReferenceEmbeds(final TypedMessage message) {
EList _referenceTreatments = message.getReferenceTreatments();
return Iterables.filter(_referenceTreatments, ReferenceEmbed.class);
}
public Iterable getReferenceEmbeds(final ServiceDataResource dataResource) {
EList _referenceTreatments = dataResource.getReferenceTreatments();
return Iterables.filter(_referenceTreatments, ReferenceEmbed.class);
}
public Iterable getPrimitiveProperties(final Iterable features) {
final Function1 _function = (Feature it) -> {
return Boolean.valueOf(this.isPrimitiveProperty(it));
};
Iterable _filter = IterableExtensions.filter(features, _function);
final Function1 _function_1 = (Feature it) -> {
return ((PrimitiveProperty) it);
};
return IterableExtensions.map(_filter, _function_1);
}
public Iterable getReferenceProperties(final Iterable features) {
final Function1 _function = (Feature it) -> {
return Boolean.valueOf((it instanceof ReferenceProperty));
};
Iterable _filter = IterableExtensions.filter(features, _function);
final Function1 _function_1 = (Feature it) -> {
return ((ReferenceProperty) it);
};
return IterableExtensions.map(_filter, _function_1);
}
public Iterable getReferenceProperties(final ServiceDataResource dataResource) {
EList _includedProperties = dataResource.getIncludedProperties();
final Function1 _function = (PropertyRealization it) -> {
Feature _baseProperty = it.getBaseProperty();
return Boolean.valueOf(this.isReferenceProperty(_baseProperty));
};
return IterableExtensions.filter(_includedProperties, _function);
}
public Iterable getReferenceProperties(final TypedMessage message) {
EList _includedProperties = message.getIncludedProperties();
final Function1 _function = (PropertyRealization it) -> {
Feature _baseProperty = it.getBaseProperty();
return Boolean.valueOf(this.isReferenceProperty(_baseProperty));
};
return IterableExtensions.filter(_includedProperties, _function);
}
public boolean isPrimitiveProperty(final Feature feature) {
return (feature instanceof PrimitiveProperty);
}
public Iterable getPrimitiveElementProperties(final Iterable features) {
final Function1 _function = (Feature it) -> {
return Boolean.valueOf(it.isMultiValued());
};
Iterable _filter = IterableExtensions.filter(features, _function);
return this.getPrimitiveProperties(_filter);
}
public Iterable getPrimitiveElementProperties(final ServiceDataResource dataResource) {
EList _includedProperties = dataResource.getIncludedProperties();
final Function1 _function = (PropertyRealization it) -> {
boolean _and = false;
Feature _baseProperty = it.getBaseProperty();
boolean _isPrimitiveProperty = this.isPrimitiveProperty(_baseProperty);
if (!_isPrimitiveProperty) {
_and = false;
} else {
boolean _isMultiValued = this.isMultiValued(it);
_and = _isMultiValued;
}
return Boolean.valueOf(_and);
};
return IterableExtensions.filter(_includedProperties, _function);
}
public Iterable getPrimitiveElementProperties(final TypedMessage message) {
EList _includedProperties = message.getIncludedProperties();
final Function1 _function = (PropertyRealization it) -> {
boolean _and = false;
Feature _baseProperty = it.getBaseProperty();
boolean _isPrimitiveProperty = this.isPrimitiveProperty(_baseProperty);
if (!_isPrimitiveProperty) {
_and = false;
} else {
boolean _isMultiValued = this.isMultiValued(it);
_and = _isMultiValued;
}
return Boolean.valueOf(_and);
};
return IterableExtensions.filter(_includedProperties, _function);
}
public Iterable getPrimitiveSingleFeatures(final Iterable features) {
Iterable _primitiveProperties = this.getPrimitiveProperties(features);
final Function1 _function = (PrimitiveProperty it) -> {
boolean _isMultiValued = it.isMultiValued();
return Boolean.valueOf((!_isMultiValued));
};
return IterableExtensions.filter(_primitiveProperties, _function);
}
public Iterable getPrimitiveSingleProperties(final Iterable properties) {
final Function1 _function = (PropertyRealization it) -> {
boolean _and = false;
Feature _baseProperty = it.getBaseProperty();
boolean _isPrimitiveProperty = this.isPrimitiveProperty(_baseProperty);
if (!_isPrimitiveProperty) {
_and = false;
} else {
Feature _baseProperty_1 = it.getBaseProperty();
boolean _isMultiValued = _baseProperty_1.isMultiValued();
boolean _not = (!_isMultiValued);
_and = _not;
}
return Boolean.valueOf(_and);
};
return IterableExtensions.filter(properties, _function);
}
public boolean isMultiValued(final Feature feature) {
int _maxOccurs = feature.getMaxOccurs();
return (_maxOccurs == (-1));
}
public boolean isSingleValued(final Feature feature) {
boolean _isMultiValued = feature.isMultiValued();
return (!_isMultiValued);
}
public boolean isMultiValued(final ReferenceElement feature) {
int _maxOccurs = feature.getMaxOccurs();
return (_maxOccurs == (-1));
}
public boolean isMultiValued(final PropertyRealization feature) {
int _maxOccurs = feature.getMaxOccurs();
return (_maxOccurs == (-1));
}
public boolean isSingleValued(final PropertyRealization feature) {
boolean _isMultiValued = this.isMultiValued(feature);
return (!_isMultiValued);
}
public boolean isPrimitivePropertyReference(final PropertyReference featureReference) {
PrimitiveProperty _conceptualFeature = featureReference.getConceptualFeature();
return this.isPrimitiveProperty(_conceptualFeature);
}
public boolean isPrimitiveSourceReference(final SourceReference sourceReference) {
boolean _xifexpression = false;
if ((sourceReference instanceof PropertyReference)) {
_xifexpression = this.isPrimitivePropertyReference(((PropertyReference)sourceReference));
} else {
_xifexpression = (sourceReference instanceof PrimitiveTypeSourceReference);
}
return _xifexpression;
}
public boolean isReferencePropertyReference(final PropertyReference featureReference) {
PrimitiveProperty _conceptualFeature = featureReference.getConceptualFeature();
return this.isReferenceProperty(_conceptualFeature);
}
public boolean isReferenceProperty(final Feature feature) {
return (feature instanceof ReferenceProperty);
}
public boolean isReferenceSourceReference(final SourceReference sourceReference) {
boolean _xifexpression = false;
if ((sourceReference instanceof PropertyReference)) {
_xifexpression = this.isReferencePropertyReference(((PropertyReference)sourceReference));
} else {
_xifexpression = false;
}
return _xifexpression;
}
public String primitiveFeatureType(final PrimitiveProperty primitiveProperty) {
SingleValueType _type = primitiveProperty.getType();
return this.xmlSchemaHelper.typeName(_type);
}
public String referenceFeatureType(final ReferenceProperty referenceProperty) {
Structure _type = referenceProperty.getType();
return _type.getName();
}
public String featureType(final Feature feature) {
String _xifexpression = null;
boolean _isPrimitiveProperty = this.isPrimitiveProperty(feature);
if (_isPrimitiveProperty) {
_xifexpression = this.primitiveFeatureType(((PrimitiveProperty) feature));
} else {
_xifexpression = this.referenceFeatureType(((ReferenceProperty) feature));
}
return _xifexpression;
}
public String getPrettyPrintedMultiplicity(final Feature feature) {
return this.commonServices.getPrettyPrintedMultiplicity(feature);
}
public String getPrettyPrintedCardinality(final PropertyRealization includedProperty) {
return this.commonServices.getPrettyPrintedCardinality(includedProperty);
}
}