KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > impl > DynamicEObjectImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: DynamicEObjectImpl.java,v 1.5 2005/06/08 06:20:10 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.impl;
18
19
20 import org.eclipse.emf.common.util.EList;
21 import org.eclipse.emf.common.util.URI;
22 import org.eclipse.emf.ecore.EClass;
23 import org.eclipse.emf.ecore.EStructuralFeature;
24 import org.eclipse.emf.ecore.resource.Resource;
25
26
27 /**
28  * An implementation of the model object '<em><b>EObject</b></em>' that's tuned for dynamic use.
29  */

30 public class DynamicEObjectImpl extends EObjectImpl implements EStructuralFeature.Internal.DynamicValueHolder
31 {
32   /**
33    * An internal class for holding less frequently members variables.
34    */

35   protected static class DynamicEPropertiesHolderImpl implements BasicEObjectImpl.EPropertiesHolder
36   {
37     protected URI eProxyURI;
38     protected Resource.Internal eResource;
39     protected EList eContents;
40     protected EList eCrossReferences;
41
42     public EClass getEClass()
43     {
44       throw new UnsupportedOperationException JavaDoc();
45     }
46
47     public void setEClass(EClass eClass)
48     {
49       throw new UnsupportedOperationException JavaDoc();
50     }
51
52     public URI getEProxyURI()
53     {
54       return eProxyURI;
55     }
56
57     public void setEProxyURI(URI eProxyURI)
58     {
59       this.eProxyURI = eProxyURI;
60     }
61
62     public Resource.Internal getEResource()
63     {
64       return eResource;
65     }
66
67     public void setEResource(Resource.Internal eResource)
68     {
69       this.eResource = eResource;
70     }
71
72     public EList getEContents()
73     {
74       return eContents;
75     }
76
77     public void setEContents(EList eContents)
78     {
79       this.eContents = eContents;
80     }
81
82     public EList getECrossReferences()
83     {
84       return eCrossReferences;
85     }
86
87     public void setECrossReferences(EList eCrossReferences)
88     {
89       this.eCrossReferences = eCrossReferences;
90     }
91
92     public boolean hasSettings()
93     {
94       throw new UnsupportedOperationException JavaDoc();
95     }
96
97     public void allocateSettings(int maximumDynamicFeatureID)
98     {
99       throw new UnsupportedOperationException JavaDoc();
100     }
101
102     public Object JavaDoc dynamicGet(int dynamicFeatureID)
103     {
104       throw new UnsupportedOperationException JavaDoc();
105     }
106
107     public void dynamicSet(int dynamicFeatureID, Object JavaDoc value)
108     {
109       throw new UnsupportedOperationException JavaDoc();
110     }
111
112     public void dynamicUnset(int dynamicFeatureID)
113     {
114       throw new UnsupportedOperationException JavaDoc();
115     }
116   }
117
118   protected EClass eClass;
119   protected Object JavaDoc [] eSettings;
120
121   protected static final Object JavaDoc [] ENO_SETTINGS = new Object JavaDoc [0];
122
123   /**
124    * Creates a dynamic EObject.
125    */

126   public DynamicEObjectImpl()
127   {
128     super();
129   }
130
131   /**
132    * Creates a dynamic EObject.
133    */

134   public DynamicEObjectImpl(EClass eClass)
135   {
136     super();
137     eSetClass(eClass);
138   }
139
140   protected int eStaticFeatureCount()
141   {
142     return 0;
143   }
144
145   public int eDerivedStructuralFeatureID(EStructuralFeature eStructuralFeature)
146   {
147     return eClass().getFeatureID(eStructuralFeature);
148   }
149
150   protected BasicEObjectImpl.EPropertiesHolder eProperties()
151   {
152     if (eProperties == null)
153     {
154       eProperties = new DynamicEPropertiesHolderImpl();
155     }
156     return eProperties;
157   }
158
159   protected boolean eHasSettings()
160   {
161     return eSettings != null;
162   }
163
164   protected EStructuralFeature.Internal.DynamicValueHolder eSettings()
165   {
166     if (eSettings == null)
167     {
168       int size = eClass().getFeatureCount() - eStaticFeatureCount();
169       eSettings = size == 0 ? ENO_SETTINGS : new Object JavaDoc [size];
170     }
171
172     return this;
173   }
174
175   protected EClass eDynamicClass()
176   {
177     return eClass;
178   }
179
180   public EClass eClass()
181   {
182     return eClass;
183   }
184
185   public void eSetClass(EClass eClass)
186   {
187     this.eClass = eClass;
188   }
189
190   public Object JavaDoc dynamicGet(int dynamicFeatureID)
191   {
192     return eSettings[dynamicFeatureID];
193   }
194
195   public void dynamicSet(int dynamicFeatureID, Object JavaDoc value)
196   {
197     eSettings[dynamicFeatureID] = value;
198   }
199
200   public void dynamicUnset(int dynamicFeatureID)
201   {
202     eSettings[dynamicFeatureID] = null;
203   }
204
205 /*
206   public String toString()
207   {
208     String result = super.toString();
209     int index = result.indexOf("DynamicEObjectImpl");
210     return index == -1 ? result : result.substring(0, index) + result.substring(index + 7);
211   }
212 */

213 }
214
Popular Tags