protected void setDefaultValue(EAttribute attribute, XSDAttributeDeclaration attrDecl) { if (attribute.getDefaultValueLiteral() != null) { attrDecl.setConstraint(XSDConstraint.DEFAULT_LITERAL); attrDecl.setLexicalValue(attribute.getDefaultValueLiteral()); } }
protected void setDefaultValue(EAttribute attribute, XSDAttributeDeclaration attrDecl) { if (attribute.getDefaultValueLiteral() != null) { attrDecl.setConstraint(XSDConstraint.DEFAULT_LITERAL); attrDecl.setLexicalValue(attribute.getDefaultValueLiteral()); } }
@SuppressWarnings("unchecked") private static void handleDefaults(EObject root) { Queue<EObject> queue = new LinkedList<EObject>(); queue.add(root); // root while (!queue.isEmpty()) { EObject eObject = queue.remove(); EClass eClass = eObject.eClass(); for (EAttribute attribute : eClass.getEAllAttributes()) { // visit if (!eObject.eIsSet(attribute) && attribute.getLowerBound() > 0 && attribute.getDefaultValueLiteral() != null) { if (attribute.isMany()) { List<Object> list = (List<Object>) eObject.eGet(attribute); list.add(attribute.getDefaultValue()); } else { eObject.eSet(attribute, attribute.getDefaultValue()); } } } for (EReference reference : eClass.getEAllReferences()) { // process successors Object value = eObject.eGet(reference); if (value != null) { if (reference.isMany()) { queue.addAll((List<EObject>) value); } else { queue.add((EObject) value); } } } } }
@Override @SuppressWarnings("unchecked") public EObject createPObjectInstance(Object object, PObject po) throws CreateObjectException { EObject poInstance = super.createPObjectInstance(object, po); Map<String, Object> map = (Map<String, Object>) object; List<EAttribute> attributes = po.getEAttributes(); for (EAttribute attribute : attributes) { String attrName = attribute.getName(); Object value = null; if (map.containsKey(attrName)) { value = map.get(attrName); } else { if (attribute.getDefaultValueLiteral() != null) { value = attribute.getDefaultValue(); } else { throw new CreateObjectException(MessageFormat.format("Can''t create instance of {0} protected object: the value of attribute {1} isn''t defined", po.getName(), attrName)); } } try { poInstance.eSet(attribute, value); } catch (ClassCastException e) { throw new CreateObjectException(MessageFormat.format("Can''t create instance of {0} protected object: the value of attribute {1} has incorrect type: {2}", po.getName(), attrName, e.getLocalizedMessage())); } } return poInstance; }
public ScanningConfigSection(String id, IModel<Project> model, Preferences config) { super(id, model); PreferencesPropertyModel includeModel = new PreferencesPropertyModel(config, PreferencesUtil.SCAN_CONFIG_INCLUDE, PropertiesPackage.Literals.SCAN_CONFIGURATION__INCLUDE.getDefaultValueLiteral()); ControlGroup includesGroup = new ControlGroup("includes-group",nls("ScanningConfigSection.includes.label"),nls("ScanningConfigSection.includes.help")); includesGroup.add(new TextArea<String>("inputIncludes", includeModel)); add(includesGroup); ControlGroup excludesGroup = new ControlGroup("excludes-group",nls("ScanningConfigSection.excludes.label"),nls("ScanningConfigSection.excludes.help")); PreferencesPropertyModel excludeModel = new PreferencesPropertyModel(config, PreferencesUtil.SCAN_CONFIG_EXCLUDE, PropertiesPackage.Literals.SCAN_CONFIGURATION__EXCLUDE.getDefaultValueLiteral()); excludesGroup.add(new TextArea<String>("inputExcludes",excludeModel)); add(excludesGroup); ControlGroup templateGroup = new ControlGroup("template-group",nls("ScanningConfigSection.template.locale.label"),nls("ScanningConfigSection.template.locale.help")); PreferencesPropertyModel templateLocaleModel = new PreferencesPropertyModel(config, PreferencesUtil.SCAN_CONFIG_MASTER_LOCALE, PropertiesPackage.Literals.SCAN_CONFIGURATION__MASTER_LOCALE.getDefaultValueLiteral()); templateGroup.add(new TextField<String>("inputTemplateLocale",templateLocaleModel)); add(templateGroup); }
protected static void createMetaAttribute(final BaseObjectMetaInfo poMeta, final EAttribute attribute) { final AttributeMetaInfo am = new AttributeMetaInfo(); am.setId(attribute.getName()); final String description = EcoreUtil.getAnnotation(attribute, UamPackage.eNS_URI, IPObjectConstant.DESCRIPTION_ATTR); am.setDescription(description); am.setName(attribute.getName()); am.setType(attribute.getEAttributeType().getClassifierID()); am.setDefaultValue(attribute.getDefaultValueLiteral()); final String type = attribute.getEAttributeType().getInstanceClassName(); am.setTypeDescription(type.substring(type.lastIndexOf('.') + 1)); poMeta.addAttribute(am); }
protected void initialize(EAttribute eAttribute, XSDSimpleTypeDefinition xsdSimpleTypeDefinition) { if (XSDConstants.isOrIsDerivedFromID(xsdSimpleTypeDefinition)) { eAttribute.setID(true); } // If there is no default value but the type has enumeration facets and the value is a primitive... // if (!eAttribute.isMany() && eAttribute.getDefaultValueLiteral() == null && xsdSimpleTypeDefinition != null && xsdSimpleTypeDefinition.getEffectiveEnumerationFacet() != null && eAttribute.getEType().getDefaultValue() != null) { // Set the default to the first enumeration's value. // eAttribute.setDefaultValueLiteral ((xsdSimpleTypeDefinition. getEffectiveEnumerationFacet(). getSimpleTypeDefinition(). getEnumerationFacets(). get(0)).getLexicalValue()); } }
protected void initialize(EAttribute eAttribute, XSDSimpleTypeDefinition xsdSimpleTypeDefinition) { if (XSDConstants.isOrIsDerivedFromID(xsdSimpleTypeDefinition)) { eAttribute.setID(true); } // If there is no default value but the type has enumeration facets and the value is a primitive... // if (!eAttribute.isMany() && eAttribute.getDefaultValueLiteral() == null && xsdSimpleTypeDefinition != null && xsdSimpleTypeDefinition.getEffectiveEnumerationFacet() != null && eAttribute.getEType().getDefaultValue() != null && !(eAttribute.getEType() instanceof EEnum)) { // Set the default to the first enumeration's value. // setDefaultValueLiteral (eAttribute, xsdSimpleTypeDefinition.getNormalizedLiteral ((xsdSimpleTypeDefinition. getEffectiveEnumerationFacet(). getSimpleTypeDefinition(). getEnumerationFacets(). get(0)).getLexicalValue())); } }
protected void createAttributeElementDeclaration(EAttribute attribute, XSDComplexTypeDefinition xsdComplexTypeDefinition) { XSDModelGroup modelGroup = getModelGroup(xsdComplexTypeDefinition); XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE.createXSDElementDeclaration(); xsdElementDeclaration.setName(getName(attribute)); // If the attribute can have a null value (primitives and enums can't), and // if the attribute can hold many nulls or // it can hold only a single value that is allowed to be null // and it can be considered set when it has the null value... // if (attribute.getEType().getDefaultValue() == null && (attribute.isMany() || (!attribute.isRequired() && (attribute.getDefaultValueLiteral() != null || attribute.isUnsettable())))) { xsdElementDeclaration.setNillable(true); } if (xsdElementDeclaration.isNillable() || attribute.isMany() || !minimizedXMI) { XSDSimpleTypeDefinition attrType = getType(attribute.getEAttributeType()); if (attrType != null) { xsdElementDeclaration.setTypeDefinition(attrType); } XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); particle.setContent(xsdElementDeclaration); setAttributeElementMultiplicity(attribute, particle); modelGroup.getContents().add(particle); map(particle, attribute); } }
protected void createAttributeElementDeclaration(EAttribute attribute, XSDComplexTypeDefinition xsdComplexTypeDefinition) { XSDModelGroup modelGroup = getModelGroup(xsdComplexTypeDefinition); XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE.createXSDElementDeclaration(); xsdElementDeclaration.setName(getName(attribute)); // If the attribute can have a null value (primitives and enums can't), and // if the attribute can hold many nulls or // it can hold only a single value that is allowed to be null // and it can be considered set when it has the null value... // if (attribute.getEType().getDefaultValue() == null && (attribute.isMany() || (!attribute.isRequired() && (attribute.getDefaultValueLiteral() != null || attribute.isUnsettable())))) { xsdElementDeclaration.setNillable(true); } if (xsdElementDeclaration.isNillable() || attribute.isMany() || !minimizedXMI) { XSDSimpleTypeDefinition attrType = getType(attribute.getEAttributeType()); if (attrType != null) { xsdElementDeclaration.setTypeDefinition(attrType); } XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); particle.setContent(xsdElementDeclaration); setAttributeElementMultiplicity(attribute, particle); modelGroup.getContents().add(particle); map(particle, attribute); } }
if (maxOccurs == 1 && (type.getDefaultValue() != null || eAttribute.getDefaultValueLiteral() != null))
if (maxOccurs == 1 && (type.getDefaultValue() != null || eAttribute.getDefaultValueLiteral() != null))