/** * This methods can be used to provide a different ExtendedMetaData. * Note that if this method creates a new EPackage.Registry it must also assign the global registry * variable. * @return ExtendedMetaData */ protected ExtendedMetaData createExtendedMetaData() { if (registry == null) { registry = new EPackageRegistryImpl(); } return new BasicExtendedMetaData(registry); } }
switch (getFeatureKind(eStructuralFeature)) if (isDocumentRoot(eStructuralFeature.getEContainingClass())) String namespace = getNamespace(eStructuralFeature); String name = getName(eStructuralFeature); EStructuralFeature result = getLocalAttribute(eClass, namespace, name); if (result != null) List<EStructuralFeature> allAttributes = getAllAttributes(eClass); for (int i = 0, size = allAttributes.size(); i < size; ++i) if (matches(getWildcards(result), namespace)) if (isDocumentRoot(eStructuralFeature.getEContainingClass())) for (EStructuralFeature affiliation = eStructuralFeature; affiliation != null; affiliation = getAffiliation(affiliation)) String namespace = getNamespace(affiliation); String name = getName(affiliation); EStructuralFeature result = getLocalElement(eClass, namespace, name); if (result != null) String namespace = getNamespace(eStructuralFeature); if (XMLTypePackage.eNS_URI.equals(namespace)) return getMixedFeature(eClass); List<EStructuralFeature> allElements = getAllElements(eClass);
public EClassifier getType(String namespace, String name) { EPackage ePackage = getPackage(namespace); return ePackage == null ? null : getType(ePackage, name); }
public EStructuralFeature getAttribute(String namespace, String name) { EPackage ePackage = getPackage(namespace); if (ePackage != null) { EClass documentRoot = getDocumentRoot(ePackage); if (documentRoot != null) { return getLocalAttribute(documentRoot, namespace, name); } } return null; }
public EStructuralFeature getElement(String namespace, String name) { EPackage ePackage = getPackage(namespace); if (ePackage != null) { EClass documentRoot = getDocumentRoot(ePackage); if (documentRoot != null) { return getLocalElement(documentRoot, namespace, name); } } return null; }
public void setItemType(EDataType eDataType, EDataType itemType) { if (itemType == null) { EAnnotation eAnnotation = getAnnotation(eDataType, false); if (eAnnotation != null) { eAnnotation.getDetails().removeKey("itemType"); } } else { EAnnotation eAnnotation = getAnnotation(eDataType, true); eAnnotation.getDetails().put("itemType", getQualifiedName(getNamespace(eDataType), itemType)); } getExtendedMetaData(eDataType).setItemType(itemType); }
protected EStructuralFeature getLocalElement(EClass eClass, String namespace, String name) if (isFeatureKindSpecific()) List<EStructuralFeature> allElements = getAllElements(eClass); for (int i = 0, size = allElements.size(); i < size; ++i) if (name.equals(getName(eStructuralFeature))) String featureNamespace = getNamespace(eStructuralFeature); if (namespace == null) switch (getFeatureKind(eStructuralFeature)) if (name.equals(getName(eStructuralFeature))) String featureNamespace = getNamespace(eStructuralFeature); if (namespace == null) return isFeatureNamespaceMatchingLax() ? result : null;
public EStructuralFeature getLocalAttribute(EClass eClass, String namespace, String name) if (isFeatureKindSpecific()) List<EStructuralFeature> allAttributes = getAllAttributes(eClass); for (int i = 0, size = allAttributes.size(); i < size; ++i) if (name.equals(getName(eStructuralFeature))) String featureNamespace = getNamespace(eStructuralFeature); if (namespace == null) switch (getFeatureKind(eStructuralFeature)) if (name.equals(getName(eStructuralFeature))) String featureNamespace = getNamespace(eStructuralFeature); if (namespace == null) return isFeatureNamespaceMatchingLax() ? result : null;
protected EStructuralFeature basicGetGroup(EStructuralFeature eStructuralFeature) EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); if (eAnnotation != null) namespace = ePackage == null ? null : getNamespace(ePackage); name = qualifiedName; switch (getFeatureKind(eStructuralFeature)) getAttribute (eContainingClass, namespace, getElement (eContainingClass, namespace,
protected String getQualifiedName(String defaultNamespace, EStructuralFeature eStructuralFeature) { String namespace = getNamespace(eStructuralFeature); String name = getName(eStructuralFeature); if (namespace == null) { return namespace == defaultNamespace ? name : "#" + name; } else { return namespace.equals(defaultNamespace) ? name : namespace + "#" + name; } }
protected EStructuralFeature basicGetAffiliation(EStructuralFeature eStructuralFeature) { EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); if (eAnnotation != null) { String qualifiedName = eAnnotation.getDetails().get("affiliation"); if (qualifiedName != null) { int fragmentIndex = qualifiedName.lastIndexOf('#'); if (fragmentIndex == -1) { EPackage ePackage = eStructuralFeature.getEContainingClass().getEPackage(); EClass documentRoot = getDocumentRoot(ePackage); if (documentRoot != null) { return getLocalElement(documentRoot, getNamespace(ePackage), qualifiedName); } } else if (fragmentIndex == 0) { return getElement(null, qualifiedName.substring(1)); } else { return getElement(qualifiedName.substring(0, fragmentIndex), qualifiedName.substring(fragmentIndex + 1)); } } } return null; }
public void setWildcards(EStructuralFeature eStructuralFeature, List<String> wildcards) { if (wildcards.isEmpty()) { EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); if (eAnnotation != null) { eAnnotation.getDetails().remove("wildcards"); eAnnotation.getDetails().remove("name"); } } else { String namespace = getNamespace(eStructuralFeature.getEContainingClass().getEPackage()); EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); eAnnotation.getDetails().put("wildcards", getEncodedWildcards(namespace, wildcards)); eAnnotation.getDetails().put("name",""); } getExtendedMetaData(eStructuralFeature).setWildcards(wildcards); }
@Override public String getNamespace(EPackage ePackage) { return ePackage == EcorePackage.eINSTANCE ? EMOF_PACKAGE_NS_URI_2_0 : super.getNamespace(ePackage); }
public boolean isDocumentRoot(EClass eClass) { return "".equals(getName(eClass)); }
public void setNamespace(EStructuralFeature eStructuralFeature, String namespace) { String packageNamespace = getNamespace(eStructuralFeature.getEContainingClass().getEPackage()); String convertedNamespace = namespace; if (namespace == null ? packageNamespace == null : namespace.equals(packageNamespace)) { convertedNamespace="##targetNamespace"; } if (convertedNamespace != null) { EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); eAnnotation.getDetails().put("namespace", convertedNamespace); } else { EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); if (eAnnotation != null) { eAnnotation.getDetails().remove("namespace"); } } getExtendedMetaData(eStructuralFeature).setNamespace(namespace); }
public EAttribute getMixedFeature(EClass eClass) { switch (getContentKind(eClass)) { case MIXED_CONTENT: case SIMPLE_CONTENT: { List<EAttribute> eAllAttributes = eClass.getEAllAttributes(); for (int i = 0, size = eAllAttributes.size(); i < size; ++i) { EAttribute eAttribute = eAllAttributes.get(i); if (getFeatureKind(eAttribute) == ExtendedMetaData.ELEMENT_WILDCARD_FEATURE) { return eAttribute; } } break; } } return null; }
public EReference getXMLNSPrefixMapFeature(EClass eClass) { if (getContentKind(eClass) == MIXED_CONTENT) { List<EReference> eAllReferences = eClass.getEAllReferences(); for (int i = 0, size = eAllReferences.size(); i < size; ++i) { EReference eReference = eAllReferences.get(i); if ("xmlns:prefix".equals(getName(eReference))) { return eReference; } } } return null; }
public List<EStructuralFeature> getAttributes(EClass eClass) { List<EStructuralFeature> eStructuralFeatures = eClass.getEStructuralFeatures(); List<EStructuralFeature> result = null; for (int i = 0, size = eStructuralFeatures.size(); i < size; ++i) { EStructuralFeature eStructuralFeature = eStructuralFeatures.get(i); switch (getFeatureKind(eStructuralFeature)) { case ATTRIBUTE_FEATURE: case ATTRIBUTE_WILDCARD_FEATURE: { if (result == null) { result = new ArrayList<EStructuralFeature>(); } result.add(eStructuralFeature); } } } return result == null ? Collections.<EStructuralFeature>emptyList() : result; }
public EClassifier demandType(String namespace, String name) { EPackage ePackage = demandPackage(namespace); EClassifier eClassifier = getType(ePackage, name); if (eClassifier != null) { return eClassifier; } else { EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName(name); eClass.getESuperTypes().add(XMLTypePackage.eINSTANCE.getAnyType()); setContentKind(eClass, MIXED_CONTENT); ePackage.getEClassifiers().add(eClass); return eClass; } }
public void setWildcards(EStructuralFeature eStructuralFeature, List<String> wildcards) { if (wildcards.isEmpty()) { EAnnotation eAnnotation = getAnnotation(eStructuralFeature, false); if (eAnnotation != null) { eAnnotation.getDetails().removeKey("wildcards"); eAnnotation.getDetails().removeKey("name"); } } else { String namespace = getPackageNamespace(eStructuralFeature); EAnnotation eAnnotation = getAnnotation(eStructuralFeature, true); eAnnotation.getDetails().put("wildcards", getEncodedWildcards(namespace, wildcards)); eAnnotation.getDetails().put("name",""); } getExtendedMetaData(eStructuralFeature).setWildcards(wildcards); }