summaryrefslogtreecommitdiffstats
path: root/sdo-java/branches/sdo-1.1-incubating/impl/src/main/java/org/apache/tuscany/sdo/model/internal/impl/InternalFactoryImpl.java
blob: 06d002ea74deb4ac1e021513f13127c3580feb1e (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/**
 *
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.apache.tuscany.sdo.model.internal.impl;

import commonj.sdo.helper.HelperContext;
import org.apache.tuscany.sdo.helper.TypeHelperImpl;

import commonj.sdo.DataObject;
import commonj.sdo.Property;
import commonj.sdo.Type;

import org.apache.tuscany.sdo.impl.FactoryBase;

import org.apache.tuscany.sdo.model.internal.*;
import org.eclipse.emf.ecore.xml.type.XMLTypeFactory;

/**
 * <!-- begin-user-doc -->
 * An implementation of the commonj.sdo.internal model factory.
 * This model is generated from sdoInternal.xsd, in the tuscany-sdo-impl project.
 * Until the SDO code generator supports regen/merge, follow the following steps to regenerate this model:
 *   1. Regenerate the model into a temporary directory:
 *         XSD2JavaGenerator -generateBuiltIn http://www.apache.org/tuscany/commonj.sdo.internal -targetDirectory <temp-dir> -javaPackage org.apache.tuscany.sdo.model.internal <tuscany-sdo-impl-dir>/src/main/resources/xml/sdoInternal.xsd
 *   2. Delete all the createXXXFromString() and convertXXXToString() methods in the newly generated InternalFactoryImpl and
 *      replace them with the ones from this file (resolve any missing imports).
 *   3. Comment out all simple depedencies (SDOUtil.registerStaticTypes calls) in the init() method.
 *   4. Make sure the top of each generated file contains the ASF License.      
 *   5. Move this JavaDoc comment into the newly generated ModelFactoryImpl class.
 * <!-- end-user-doc -->
 * @generated
 */
public class InternalFactoryImpl extends FactoryBase implements InternalFactory
{

  /**
   * The package namespace URI.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public static final String NAMESPACE_URI = "http://www.apache.org/tuscany/commonj.sdo.internal";

  /**
   * The package namespace name.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public static final String NAMESPACE_PREFIX = "internal";

  /**
   * The version of the generator pattern used to generate this class.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public static final String PATTERN_VERSION = "1.2";
  
  public static final int BASE64_BYTES = 1;	
  public static final int QNAME = 2;
  
  /**
   * Creates an instance of the factory.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public InternalFactoryImpl()
  {
    super(NAMESPACE_URI, NAMESPACE_PREFIX, "org.apache.tuscany.sdo.model.internal");
  }

  /**
   * Registers the Factory instance so that it is available within the supplied scope.
   * @argument scope a HelperContext instance that will make the types supported by this Factory available.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void register(HelperContext scope) 
  {
    if(scope == null) {
      throw new IllegalArgumentException("Scope can not be null");
    }
    
    //Register dependent packages with provided scope
    
    // Initialize this package   
    TypeHelperImpl th = (TypeHelperImpl)scope.getTypeHelper();
    th.getExtendedMetaData().putPackage(NAMESPACE_URI, this);
  }
  
  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public DataObject create(int typeNumber)
  {
    switch (typeNumber)
    {
      default:
        return super.create(typeNumber);
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Object createFromString(int typeNumber, String initialValue)
  {
    switch (typeNumber)
    {
      case BASE64_BYTES:
        return createBase64BytesFromString(initialValue);
      case QNAME:
        return createQNameFromString(initialValue);
      default:
        throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype");
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String convertToString(int typeNumber, Object instanceValue)
  {
    switch (typeNumber)
    {
      case BASE64_BYTES:
        return convertBase64BytesToString(instanceValue);
      case QNAME:
        return convertQNameToString(instanceValue);
      default:
        throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype");
    }
  }
  
  // Following creates and initializes SDO metadata for the supported types.		
  protected Type base64BytesType = null;

  public Type getBase64Bytes()
  {
    return base64BytesType;
  }
    
  protected Type qNameType = null;

  public Type getQName()
  {
    return qNameType;
  }
  

  private static InternalFactoryImpl instance = null; 
  public static InternalFactoryImpl init()
  {
    if (instance != null ) return instance;
    instance = new InternalFactoryImpl();

    // Initialize dependent packages
    
    // Create package meta-data objects
    instance.createMetaData();

    // Initialize created meta-data
    instance.initializeMetaData();
    
    // Mark meta-data to indicate it can't be changed
    //theInternalFactoryImpl.freeze(); //FB do we need to freeze / should we freeze ????

    return instance;
  }
  
  private boolean isCreated = false;

  public void createMetaData()
  {
    if (isCreated) return;
    isCreated = true;

    // Create data types
    base64BytesType = createType(true, BASE64_BYTES );
    qNameType = createType(true, QNAME );
  }
  
  private boolean isInitialized = false;

  public void initializeMetaData()
  {
    if (isInitialized) return;
    isInitialized = true;
    Property property = null;

    // Add supertypes to types

    // Initialize types and properties
    // Initialize data types
    initializeType(base64BytesType, byte[].class, "Base64Bytes", true, false);
    setInstanceProperty (base64BytesType, "commonj.sdo/java", "instanceClass", "byte[]");

    initializeType(qNameType, String.class, "QName", true, false);
    setInstanceProperty (qNameType, "commonj.sdo/java", "instanceClass", "java.lang.String");

    createXSDMetaData();
  }
    
  protected void createXSDMetaData()
  {
    super.initXSD();
    
    Property property = null;
    

    addXSDMapping
      (base64BytesType,
       new String[] 
       {
       "name", "Base64Bytes"
       });

    addXSDMapping
      (qNameType,
       new String[] 
       {
       "name", "QName"
       });

  }
    
  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated NOT
   */
  public byte[] createBase64BytesFromString(String initialValue)
  {
      return XMLTypeFactory.eINSTANCE.createBase64Binary(initialValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated NOT
   */
  public String convertBase64BytesToString(Object instanceValue)
  {
      if (instanceValue instanceof byte[]) {
          return XMLTypeFactory.eINSTANCE.convertBase64Binary((byte[])instanceValue);
        } else {
          return XMLTypeFactory.eINSTANCE.convertBase64Binary(instanceValue.toString().getBytes());
      }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String createQNameFromString(String initialValue)
  {
    return (String)super.createFromString(QNAME, initialValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String convertQNameToString(Object instanceValue)
  {
    return super.convertToString(QNAME, instanceValue);
  }

} //InternalFactoryImpl