package org.useware.kernel.model.behaviour;

import org.useware.kernel.model.structure.QName;

/**
 * A resource is an entity that produced and consumed. Typically these are events,
 * domain model entities or generally speaking: data that drives an interaction.
 *
 * @author Heiko Braun
 * @date 10/31/12
 */
public class Resource<T extends Enum<T>> {

    private QName id;
    private QName source;
    private T type;

    public Resource(String namespace, String id, T type) {
        this.id = new QName(namespace, id);
        this.type = type;
    }

    public Resource(QName id, T type) {
        this.id = id;
        this.type = type;
    }

    public QName getId() {
        return id;
    }

    public QName getSource() {
        return source;
    }

    public void setSource(QName source) {
        this.source = source;
    }

    public T getType()
    {
        return type;
    }

    @Override
    public String toString() {
        return "Resource { type=" + type +", "+
                "id='" + id + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Resource)) return false;

        Resource event = (Resource) o;

        if (!id.equalsIgnoreSuffix(event.id)) return false;
        if (!type.equals(event.type)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id.hashCode();
        result = 31 * result + type.hashCode();
        return result;
    }
}

@@ -311,16 +311,22 @@
 %0Apublic 
+final 
 class Re
@@ -362,24 +362,30 @@
     private 
+final 
 QName id;%0A  
@@ -378,24 +378,50 @@
 l QName id;%0A
+    private final T type;%0A
     private 
@@ -437,28 +437,8 @@
 rce;
-%0A    private T type;
 %0A%0A  
@@ -985,18 +985,68 @@
 Resource
- 
 %7B
+%22 +%0A                %22id=%22 + id +%0A                %22,
  type=%22 
@@ -1057,13 +1057,8 @@
 pe +
-%22, %22+
 %0A   
@@ -1074,26 +1074,30 @@
     
-%22id='%22 + id + '%5C''
+//%22, source=%22 + source
  +%0A 
@@ -1281,21 +1281,24 @@
 esource 
-event
+resource
  = (Reso
@@ -1342,21 +1342,24 @@
 eSuffix(
-event
+resource
 .id)) re
@@ -1370,16 +1370,120 @@
  false;%0A
+        //if (source != null ? !source.equals(resource.source) : resource.source != null) return false;%0A
         
@@ -1499,21 +1499,24 @@
 .equals(
-event
+resource
 .type)) 
@@ -1676,32 +1676,105 @@
 ype.hashCode();%0A
+        result = 31 * result + (source != null ? source.hashCode() : 0);%0A
         return r

include source attribute in Resource#hashCode()