00001 package org.andromda.cartridges.arc;
00002
00003 import java.util.Collection;
00004 import java.util.Iterator;
00005
00009 public class KeyResponsibility extends Responsibility {
00010 public static final String KEY_ID="Key";
00011 public static final String ALTERNATIVE_KEY_ID="AlternativeKey";
00012
00013 private Collection key;
00014 private Collection alternativeKey;
00015
00016 public Collection getKey() { return key; }
00017 public Collection getAlternativeKey() { return alternativeKey; }
00018
00019 public void setKey(Collection key) { this.key=key; }
00020 public void setAlternativeKey(Collection alternativeKey) { this.alternativeKey=alternativeKey; }
00021
00022 public Object get(String id) {
00023 if(id.equals(KEY_ID)) return getKey();
00024 else if(id.equals(ALTERNATIVE_KEY_ID)) return getAlternativeKey();
00025 else return super.get(id);
00026 }
00027
00028 public void set(String id, Object value) {
00029 if(id.equals(KEY_ID)) setKey((Collection)value);
00030 else if(id.equals(ALTERNATIVE_KEY_ID)) setAlternativeKey((Collection)value);
00031 else super.set(id, value);
00032 }
00033
00034 public String getDescription() {
00035 String description=null;
00036 description="Key { ";
00037 Iterator key_iter=getKey().iterator();
00038 while(key_iter.hasNext()) description+=key_iter.next()+", ";
00039 description=description.substring(0, description.length()-2)+" }";
00040 if(!alternativeKey.isEmpty()) {
00041 description+=" Alternative Key { ";
00042 key_iter=getAlternativeKey().iterator();
00043 while(key_iter.hasNext()) description+=key_iter.next()+", ";
00044 description=description.substring(0, description.length()-2)+" }";
00045 }
00046 return description;
00047 }
00048
00049
00050 public void show() {
00051 String tmp;
00052 Iterator key_iter;
00053 if(getKey()==null) System.out.println("key: null");
00054 else if(getKey().isEmpty()) System.out.println("alternative key: empty");
00055 else {
00056 tmp="key: ";
00057 key_iter=getKey().iterator();
00058 while(key_iter.hasNext()) tmp+=key_iter.next()+", ";
00059 tmp=tmp.substring(0, tmp.length()-2);
00060 System.out.println(tmp);
00061 }
00062 if(getAlternativeKey()==null) System.out.println("alternative key: null");
00063 else if(getAlternativeKey().isEmpty()) System.out.println("alternative key: empty");
00064 else {
00065 tmp="alternative key: ";
00066 key_iter=getAlternativeKey().iterator();
00067 while(key_iter.hasNext()) tmp+=key_iter.next()+", ";
00068 tmp=tmp.substring(0, tmp.length()-2);
00069 System.out.println(tmp);
00070 }
00071 super.show();
00072 }
00073
00074 public KeyResponsibility() {
00075 setName("Key");
00076 setModelElement("Class");
00077 }
00078
00079 public KeyResponsibility(String modelElementName, Collection key, Collection alternativeKey) {
00080 super("Key", "Class", modelElementName);
00081 setKey(key);
00082 setAlternativeKey(alternativeKey);
00083 }
00084 }