Skip to main content
summaryrefslogtreecommitdiffstats
blob: d9431cf2af80b309ca248de1feaa9b36ff896bf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*******************************************************************************
 * Copyright (c) 2003, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.common.internal.annotations.core;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.wst.common.internal.emf.utilities.CloneablePublic;



/**
 * @author mdelder
 *  
 */
public class AnnotationsAdapter extends AdapterImpl implements CloneablePublic {

	public static final String GENERATED = "generated"; //$NON-NLS-1$

	protected final static String ADAPTER_TYPE = AnnotationsAdapter.class.getName();

	public final static EStructuralFeature NOTIFICATION_FEATURE = new EStructuralFeatureImpl() {
		// anonymous inner class
	};

	private Map annotationsMap;

	/**
	 *  
	 */
	public AnnotationsAdapter() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#clone()
	 */
	public Object clone() { // throws CloneNotSupportedException {
		//return super.clone();
		return null;
	}

	/**
	 * @param emfObject
	 * @param string
	 */
	public static void addAnnotations(EObject emfObject, String name, Object value) {
		if (emfObject == null)
			return;
		AnnotationsAdapter adapter = getAdapter(emfObject);
		adapter.addAnnotations(name, value);
	}


	/**
	 * @param emfObject
	 * @param string
	 */
	public static Object getAnnotations(EObject emfObject, String name) {
		if (emfObject == null)
			return null;
		return internalGetAnnotations(emfObject, name);
	}

	protected static Object internalGetAnnotations(EObject emfObject, String name) {
		if (emfObject == null)
			return null;
		AnnotationsAdapter adapter = getAdapter(emfObject);
		return (adapter == null) ? internalGetAnnotations(emfObject.eContainer(), name) : adapter.getAnnotations(name);
	}


	/**
	 * @param emfObject
	 * @param string
	 */
	public static Object removeAnnotations(EObject emfObject, String name) {
		if (emfObject == null)
			return null;
		AnnotationsAdapter adapter = getAdapter(emfObject);
		return adapter.removeAnnotations(name);
	}

	/**
	 * @param name
	 * @param value
	 */
	protected void addAnnotations(String name, Object value) {
		getAnnnotations().put(name, value);
	}

	protected Object getAnnotations(String name) {
		return getAnnnotations().get(name);
	}

	protected Object removeAnnotations(String name) {
		return getAnnnotations().remove(name);
	}

	/**
	 * @return
	 */
	protected Map getAnnnotations() {
		if (annotationsMap == null)
			annotationsMap = new HashMap();
		return annotationsMap;
	}

	/**
	 * @param emfObject
	 * @return
	 */
	protected static AnnotationsAdapter getAdapter(EObject emfObject) {
		AnnotationsAdapter adapter = retrieveExistingAdapter(emfObject);
		return adapter == null ? createAdapter(emfObject) : adapter;
	}

	/**
	 * @param emfObject
	 * @return
	 */
	protected static AnnotationsAdapter createAdapter(EObject emfObject) {
		AnnotationsAdapter adapter = new AnnotationsAdapter();
		adapter.setTarget(emfObject);
		emfObject.eAdapters().add(adapter);
		return adapter;
	}

	/**
	 * @param emfObject
	 * @return
	 */
	protected static AnnotationsAdapter retrieveExistingAdapter(EObject emfObject) {
		return (AnnotationsAdapter) EcoreUtil.getExistingAdapter(emfObject, ADAPTER_TYPE);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
	 */
	public boolean isAdapterForType(Object type) {
		return ADAPTER_TYPE.equals(type);
	}

}

Back to the top