Skip to content

Commit

Permalink
Migrating Java methods to the EMF generated classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jadelkhoury committed Apr 30, 2022
1 parent 4fba395 commit 34b18cf
Show file tree
Hide file tree
Showing 19 changed files with 439 additions and 436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Export-Package: adaptorinterface,
adaptorinterface.util
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport,
org.eclipse.lyo.tools.vocabulary.model;visibility:=reexport
org.eclipse.lyo.tools.vocabulary.model;visibility:=reexport,
org.eclipse.lyo.oslc4j.core.oslc4j-core
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.eclipse.emf.ecore.EObject;
import vocabulary.Vocabulary;

import javax.xml.namespace.QName;

/**
* <!-- begin-user-doc -->
* A representation of the model object '<em><b>Domain Specification</b></em>'.
Expand All @@ -33,7 +35,10 @@
* @generated
*/
public interface DomainSpecification extends EObject {
/**

QName deduceVocabulary();

/**
* Returns the value of the '<em><b>Name</b></em>' attribute.
* <!-- begin-user-doc -->
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import org.eclipse.emf.common.util.EList;

import java.net.URI;
import javax.xml.namespace.QName;

/**
* <!-- begin-user-doc -->
* A representation of the model object '<em><b>Resource</b></em>'.
Expand All @@ -29,6 +32,13 @@
* @generated
*/
public interface Resource extends Shape {

QName deduceDescribes();
URI deduceDescribesAsUri ();
String deduceDescribesComment();
URI getResourceShapeURI();
String toString (Boolean withShapeLabel, Boolean withPrefix);

/**
* Returns the value of the '<em><b>Id</b></em>' attribute.
* <!-- begin-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@


import org.eclipse.emf.common.util.EList;
import java.net.URI;
import javax.xml.namespace.QName;
import org.eclipse.lyo.oslc4j.core.model.Occurs;
import org.eclipse.lyo.oslc4j.core.model.Representation;
import org.eclipse.lyo.oslc4j.core.model.ValueType;

import vocabulary.Property;

/**
Expand Down Expand Up @@ -35,6 +41,18 @@
* @generated
*/
public interface ResourceProperty extends ShapeProperty {

QName deducePropertyDefinition();
URI deducePropertyDefinitionAsUri ();
String deducePropertyDefinitionComment();
URI getPropertyShapeURI();
boolean isCardinalityMany ();
boolean isLiteral ();
Occurs oslcCardinality ();
ValueType oslcValueType ();
Representation oslcRepresentation ();
String toString (Boolean withShapeLabel, Boolean withPrefix, Boolean withConstraints);

/**
* Returns the value of the '<em><b>Id</b></em>' attribute.
* <!-- begin-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ public enum ResourcePropertyOccurs implements Enumerator {
*/
public static final List<ResourcePropertyOccurs> VALUES = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));

public String toStringNumeric () {
switch (this) {
case EXACTLY_ONE:
return "[1]";
case ZERO_OR_ONE:
return "[0..1]";
case ZERO_OR_MANY:
return "[0..*]";
case ONE_OR_MANY:
return "[1..*]";
default:
return "[*..*]";
}
}


/**
* Returns the '<em><b>Resource Property Occurs</b></em>' literal with the specified literal value.
* <!-- begin-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.eclipse.emf.ecore.util.InternalEList;
import vocabulary.Vocabulary;

import javax.xml.namespace.QName;

/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Domain Specification</b></em>'.
Expand Down Expand Up @@ -181,6 +183,17 @@ protected DomainSpecificationImpl() {
super();
}

@Override
public QName deduceVocabulary() {
if (null != this.getDefaultVocabulary()) {
Vocabulary v = (Vocabulary)this.getDefaultVocabulary();
return new QName(v.getNamespaceURI(), v.getLabel(), v.getPreferredNamespacePrefix());
}
return new QName(this.getNamespaceURI(), this.getName(), this.getNamespacePrefix().getName());
}



/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;

import java.net.URI;
import javax.xml.namespace.QName;
import adaptorinterface.DomainSpecification;
import vocabulary.Vocabulary;


/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Resource</b></em>'.
Expand Down Expand Up @@ -190,6 +196,56 @@ protected ResourceImpl() {
super();
}

@Override
public QName deduceDescribes() {
if (null != this.getDescribes()) {
Vocabulary v = (Vocabulary)this.getDescribes().eContainer();
return new QName(v.getNamespaceURI(), this.getDescribes().getName(), v.getPreferredNamespacePrefix());
}
DomainSpecification ds = (DomainSpecification)this.eContainer();
QName deducedVocabulary = ds.deduceVocabulary();
return new QName(deducedVocabulary.getNamespaceURI(), this.getName(), deducedVocabulary.getPrefix());
}

@Override
public URI deduceDescribesAsUri () {
//I Cannot use UriBuilder to construct the URI since the "#" in the paths gets lost.
//return UriBuilder.fromUri(v.getNamespaceURI()).path(resource.getDescribes().getName()).build().toString();
QName qName = deduceDescribes();
return URI.create(qName.getNamespaceURI() + qName.getLocalPart());
}


@Override
public String deduceDescribesComment() {
if (null != this.getDescribes()) {
return this.getDescribes().getComment();
}
return this.getVocabularyComment();
}

@Override
public URI getResourceShapeURI() {
return java.net.URI.create(((DomainSpecification)this.eContainer()).getNamespaceURI() + this.getName());
}

@Override
public String toString (Boolean withShapeLabel, Boolean withPrefix) {
String s = "";
if (withShapeLabel) {
DomainSpecification ds = (DomainSpecification)this.eContainer();
s += (withPrefix ? ds.getNamespacePrefix().getName() + ":" : "");
s += this.getName();
}
else {
s += (withPrefix ? this.deduceDescribes().getPrefix() + ":" : "");
s += this.deduceDescribes().getLocalPart();

}
return s;
}


/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import vocabulary.Property;

import vocabulary.Vocabulary;
import java.net.URI;
import javax.xml.namespace.QName;
import adaptorinterface.DomainSpecification;
import org.eclipse.lyo.oslc4j.core.model.Occurs;
import org.eclipse.lyo.oslc4j.core.model.Representation;
import org.eclipse.lyo.oslc4j.core.model.ValueType;

/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Resource Property</b></em>'.
Expand Down Expand Up @@ -326,6 +334,163 @@ protected ResourcePropertyImpl() {
super();
}


/**
* <p>
* get the PropertyDefinition.
* The definition is either explicitly defined in the model as a Vocabulary Property term, or
* implied by constructing it from the Property shape.
* </p>
*
* @param self
* The ResourceProperty that is in question.
*/
@Override
public QName deducePropertyDefinition() {
if (null != this.getPropertyDefinition()) {
Vocabulary v = (Vocabulary)this.getPropertyDefinition().eContainer();
return new QName(v.getNamespaceURI(), this.getPropertyDefinition().getName(), v.getPreferredNamespacePrefix());
}
DomainSpecification ds = (DomainSpecification)this.eContainer();
QName deducedVocabulary = ds.deduceVocabulary();
return new QName(deducedVocabulary.getNamespaceURI(), this.getName(), deducedVocabulary.getPrefix());
}

@Override
public URI deducePropertyDefinitionAsUri () {
//I Cannot use UriBuilder to construct the URI since the "#" in the paths gets lost.
//return UriBuilder.fromUri(v.getNamespaceURI()).path(resource.getDescribes().getName()).build().toString();
QName qName = deducePropertyDefinition();
return URI.create(qName.getNamespaceURI() + qName.getLocalPart());
}

@Override
public String deducePropertyDefinitionComment() {
if (null != this.getPropertyDefinition()) {
return this.getPropertyDefinition().getComment();
}
return this.getVocabularyComment();
}

@Override
public URI getPropertyShapeURI() {
return java.net.URI.create(((DomainSpecification)this.eContainer()).getNamespaceURI() + this.getName());
}

@Override
public boolean isCardinalityMany () {
return
this.getOccurs().compareTo(ResourcePropertyOccurs.EXACTLY_ONE) != 0
&& this.getOccurs().compareTo(ResourcePropertyOccurs.ZERO_OR_ONE) != 0
;
}

@Override
public boolean isLiteral () {
return
this.getValueType().compareTo(ResourcePropertyValueType.LOCAL_RESOURCE) != 0
&& this.getValueType().compareTo(ResourcePropertyValueType.RESOURCE) != 0
;
}

@Override
public Occurs oslcCardinality () {
switch (this.getOccurs()) {
case EXACTLY_ONE:
return Occurs.ExactlyOne;
case ONE_OR_MANY:
return Occurs.OneOrMany;
case ZERO_OR_MANY:
return Occurs.ZeroOrMany;
case ZERO_OR_ONE:
return Occurs.ZeroOrOne;
default:
return Occurs.ExactlyOne;
}
}

@Override
public ValueType oslcValueType () {
switch (this.getValueType()) {
case BOOLEAN:
return ValueType.Boolean;
case DATE_TIME:
return ValueType.DateTime;
case DOUBLE:
return ValueType.Double;
case FLOAT:
return ValueType.Float;
case INTEGER:
return ValueType.Integer;
case LOCAL_RESOURCE:
return ValueType.LocalResource;
case RESOURCE:
return ValueType.Resource;
case STRING:
return ValueType.String;
case URI:
return ValueType.Resource;
case XML_LITERAL:
return ValueType.XMLLiteral;
default:
return ValueType.String;
}
}


//TODO: What to do with EITHER, and NA?
@Override
public Representation oslcRepresentation () {
switch(this.getRepresentation()) {
case REFERENCE:
return Representation.Reference;
case INLINE:
return Representation.Inline;
case EITHER:
return null;
case NA:
return null;
default:
return Representation.Reference;
}
}

@Override
public String toString (Boolean withShapeLabel, Boolean withPrefix, Boolean withConstraints) {
String s = "";
if (withShapeLabel) {
DomainSpecification ds = (DomainSpecification)this.eContainer();
s += (withPrefix ? ds.getNamespacePrefix().getName() + ":" : "");
s += this.getName();
}
else {
s += (withPrefix ? this.deducePropertyDefinition().getPrefix() + ":" : "");
s += this.deducePropertyDefinition().getLocalPart();

}
if (withConstraints) {
s+= " : ";
if (this.isLiteral()) {
s+= this.getValueType().getName();
}
else {
if (this.getRange().size() == 0) {
s += "Resource";
}
else {
s+= this.getRange().get(0).getName() + (this.getRange().size() > 1 ? "++" : "");
}
}

if (this.isCardinalityMany()) {
s+= "[]";
}
}
return s;
}



/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down
Loading

0 comments on commit 34b18cf

Please sign in to comment.