Package org.eclipse.emf.ecore

Examples of org.eclipse.emf.ecore.EPackage$Registry


              {
                if (!ePackages.isEmpty())
                {
                  for (Iterator i = ePackages.iterator(); i.hasNext();)
                  {
                    EPackage ePackage = (EPackage)i.next();
                    ePackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl());
                    Resource resource = resourceSet.createResource(URI.createURI("*.ecore"));
                    resource.getContents().add(ePackage);
                    if (ePackage.getNsURI() != null)
                    {
                      resource.setURI(URI.createURI(ePackage.getNsURI()));
                    }

                    if (extendedMetaData != null)
                    {
                      extendedMetaData.putPackage(extendedMetaData.getNamespace(ePackage), ePackage);
                    }
                    else
                    {
                      packageRegistry.put(ePackage.getNsURI(), ePackage);
                    }
                  }
                  handleForwardReferences();
                }
                isInModels = false;
              }
              super.endElement(uri, localName, name);
            }

            protected EPackage getPackageForURI(String uriString)
            {
              if ("commonj.sdo".equals(uriString))
              {
                return SDOPackage.eINSTANCE;
              }
              else
              {
                return super.getPackageForURI(uriString);
              }
            }

            protected EObject createObjectFromFactory(EFactory factory, String typeName)
            {
              if (factory == SDOFactory.eINSTANCE)
              {
                if ("datagraph".equals(typeName))
                {
                  return super.createObjectFromFactory(factory, "EDataGraph");
                }
              }
              return super.createObjectFromFactory(factory, typeName);
            }

            protected EcoreBuilder createEcoreBuilder(Map options, ExtendedMetaData extendedMetaData)
            {
              return new DefaultEcoreBuilder(extendedMetaData)
                {
                  public Collection generate(Map urisToLocations) throws Exception
                  {
                    Collection result = super.generate(urisToLocations);
                    return updateDynamicFactory(result);
                  }

                  public Collection generate(Collection urisToLocations) throws Exception
                  {
                    Collection result = super.generate(urisToLocations);
                    return updateDynamicFactory(result);
                  }

                  protected Collection updateDynamicFactory(Collection result)
                  {
                    for (Iterator i = result.iterator(); i.hasNext();)
                    {
                      Resource resource = (Resource)i.next();
                      for (Iterator j = EcoreUtil.getObjectsByType(resource.getContents(), EcorePackage.eINSTANCE.getEPackage()).iterator(); j.hasNext();)
                      {
                        EPackage ePackage = (EPackage)j.next();
                        ePackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl());
                      }
                    }
                    return result;
                  }

                };
            }

            protected EPackage handleMissingPackage(String uriString)
            {
              EPackage result = super.handleMissingPackage(uriString);
              if (processAnyXML && objects.size() == 1)
              {
                result = extendedMetaData.demandPackage(uriString);
              }
              return result;
View Full Code Here


 
  public static Type createType(TypeHelper scope, String uri, String name, boolean isDataType)
  {
    ExtendedMetaData extendedMetaData = ((TypeHelperImpl)scope).getExtendedMetaData();
   
    EPackage ePackage = extendedMetaData.getPackage(uri);
    if (ePackage == null)
    {
      ePackage = EcoreFactory.eINSTANCE.createEPackage();
      ePackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl());
      ePackage.setNsURI(uri);
      String packagePrefix = URI.createURI(uri).trimFileExtension().lastSegment();
      ePackage.setName(packagePrefix);
      ePackage.setNsPrefix(packagePrefix);
      extendedMetaData.putPackage(uri, ePackage);
    }

    EClassifier eClassifier = ePackage.getEClassifier(name);
    if (eClassifier != null)
      throw new IllegalArgumentException(); // already defined
   
    if (name != null)
    {
      eClassifier = isDataType ? (EClassifier)SDOFactory.eINSTANCE.createDataType() : (EClassifier)SDOFactory.eINSTANCE.createClass();
      eClassifier.setName(name);
    }
    else
    {
      eClassifier = DataObjectUtil.createDocumentRoot();
    }
   
    ePackage.getEClassifiers().add(eClassifier);

    return (Type)eClassifier;
  }
View Full Code Here

                // Populate list of GenPackages and a map of GenClasses keyed by EClass
                List<GenPackage> genPackages = new ArrayList<GenPackage>();
                Map<EClass, GenClass> genClasses = new HashMap<EClass, GenClass>();
                for (Iterator iter = packageRegistry.values().iterator(); iter.hasNext();) {
                    EPackage currentEPackage = (EPackage)iter.next();
                    String currentBasePackage = extractBasePackageName(currentEPackage, xsdJavaPackage);
                    String currentPrefix = CodeGenUtil.capName(currentEPackage.getName());

                    GenPackage currentGenPackage = createGenPackage(currentEPackage, currentBasePackage,
                                                                    currentPrefix, genOptions, resourceSet);
                    genPackages.add(currentGenPackage);
                    for (GenClass genClass : (List<GenClass>)currentGenPackage.getGenClasses()) {
                        genClasses.put(genClass.getEcoreClass(), genClass);
                    }

                }

                // Process all the SDO packages
                // Populate the qname -> interfaceName typeMapping table
                for (GenPackage currentGenPackage : genPackages) {
                    EPackage currentEPackage = currentGenPackage.getEcorePackage();
                   
                    // Populate the type mappings for all the complex types
                    for (GenClass genClass : (List<GenClass>)currentGenPackage.getGenClasses()) {
                        QName qname = new QName(extendedMetaData.getNamespace(currentEPackage),
                                                extendedMetaData.getName(genClass.getEcoreClass()));
View Full Code Here

    MetadataPackageImpl.init();
  }
 
  public Type getType(String uri, String typeName)
  {
    EPackage ePackage = extendedMetaData.getPackage(uri);
    if (ePackage != null)
    {
      EClassifier eClassifier = ePackage.getEClassifier(typeName);
      if (eClassifier == null)
      {
        eClassifier = extendedMetaData.getType(ePackage, typeName);
      }
      return (Type)eClassifier;
View Full Code Here

    for (Iterator iter = EPackage.Registry.INSTANCE.values().iterator(); iter.hasNext(); )
    {
      Object value = iter.next();
      if (value instanceof EPackage)
      {
        EPackage ePackage = (EPackage)value;
        for (Iterator iter2 = ePackage.getEClassifiers().iterator(); iter2.hasNext(); )
        {
          EClassifier eClassifier = (EClassifier)iter2.next();
          if (eClassifier.getInstanceClass() == interfaceClass)
          {
            return (Type)eClassifier;
View Full Code Here

    ResourceSet resourceSet = DataObjectUtil.createResourceSet();
    List usedGenPackages = new ArrayList();
    GenModel genModel = null;
    for (Iterator iter = packageList.iterator(); iter.hasNext();)
    {
      EPackage currentEPackage = (EPackage)iter.next();
      String currentBasePackage = extractBasePackageName(currentEPackage, javaPackage);
      String currentPrefix = prefix == null ? CodeGenUtil.capName(shortName != null ? shortName : currentEPackage.getName()) : prefix;
      GenPackage currentGenPackage = createGenPackage(currentEPackage, currentBasePackage, currentPrefix, genOptions, resourceSet);
      if (currentEPackage.getNsURI().equals(packageURI))
      {
        genModel = currentGenPackage.getGenModel();
      }
      else
      {
View Full Code Here

  //public static FactoryBase getStaticFactory(String namespaceURI)
  // temporarily return Object - until everything is gen'd with new codegen pattern
  public static Object getStaticFactory(String namespaceURI)
  {
    EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(namespaceURI);
    //return (FactoryBase)ePackage;
    return ePackage instanceof FactoryBase ? (Object)ePackage : (Object)ePackage.getEFactoryInstance();
  }
View Full Code Here

      List newTypes = new ArrayList();
      for (Iterator schemaIter = model.getContents().iterator(); schemaIter.hasNext(); )
      {
        XSDSchema schema = (XSDSchema)schemaIter.next();   

        EPackage ePackage = extendedMetaData.getPackage(schema.getTargetNamespace());
        if (ePackage == null)
        {
          Collection originalEPackages = new HashSet(ecoreBuilder.getTargetNamespaceToEPackageMap().values());
          ecoreBuilder.generate(schema);
          Collection newEPackages = ecoreBuilder.getTargetNamespaceToEPackageMap().values();
     
          for (Iterator iter = newEPackages.iterator(); iter.hasNext();)
          {
            EPackage currentPackage = (EPackage)iter.next();
            if (!originalEPackages.contains(currentPackage))
            {
              currentPackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl());
              EcoreUtil.freeze(currentPackage);
              newTypes.addAll(currentPackage.getEClassifiers());
            }
          }
        }
      }
     
View Full Code Here

      EPackage.Registry packageRegistry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);

      // Create an EPackage for the generated SDO
      if (packageURI == null)
        packageURI = "http://" + javaPackage;
      EPackage implEPackage = EcoreFactory.eINSTANCE.createEPackage();
      implEPackage.setNsURI(packageURI);
      String shortName = shortName(packageURI);
      implEPackage.setName(shortName);
      implEPackage.setNsPrefix(shortName.toLowerCase());
      packageRegistry.put(packageURI, implEPackage);

      // Create EClasses for all the given Java interfaces
      Map eClasses = new HashMap();
      for (Iterator iter = javaInterfaces.iterator(); iter.hasNext();)
      {
        String interfaceName = (String)iter.next();
        Class instanceClass = Class.forName(interfaceName, true, classLoader);

        EClass implEClass = EcoreFactory.eINSTANCE.createEClass();
        String className = shortName(instanceClass.getName());
        implEClass.setName(className);
        implEClass.setInstanceClass(instanceClass);

        eClasses.put(instanceClass, implEClass);
        implEPackage.getEClassifiers().add(implEClass);
      }

      // Populate the EClasses with EAttributes and EReferences for their properties
      for (Iterator iter = implEPackage.getEClassifiers().iterator(); iter.hasNext();)
      {
        EClass implEClass = (EClass)iter.next();
        Class instanceClass = implEClass.getInstanceClass();
        Method[] methods = instanceClass.getMethods();
        for (int m = 0; m < methods.length; m++)
View Full Code Here

   * @generated NOT
   */
  public EClassifier getEClassifier(String namespaceURI, String typeName)
  {
    ExtendedMetaData extendedMetaData = getExtendedMetaData();
    EPackage ePackage = extendedMetaData.getPackage(namespaceURI);
    if (ePackage != null)
    {
      EClassifier eClassifier = ePackage.getEClassifier(typeName);
      if (eClassifier == null)
      {
        eClassifier = extendedMetaData.getType(ePackage, typeName);
      }
      return eClassifier;
View Full Code Here

TOP

Related Classes of org.eclipse.emf.ecore.EPackage$Registry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.