diff --git a/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.notation b/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.notation index bdcea3540..2cc8bcaba 100644 --- a/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.notation +++ b/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.notation @@ -23,7 +23,7 @@ - + @@ -49,13 +49,13 @@ - + - + @@ -63,7 +63,7 @@ - + @@ -71,7 +71,7 @@ - + @@ -102,7 +102,7 @@ - + @@ -110,7 +110,7 @@ - + @@ -120,7 +120,7 @@ - + @@ -130,7 +130,7 @@ - + diff --git a/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.properties b/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.properties index e14de5f7b..c615a72e1 100644 --- a/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.properties +++ b/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.properties @@ -1,4 +1,4 @@ -#Wed Jul 12 16:34:05 EDT 2023 +#Mon Jun 10 18:14:14 EDT 2024 _label_DDS4CCM__DDSExtensions__MessageField__isKey=Is Key _mesg_DDS4CCM__DDS4CCM__DDS4CCMModel__check_model_migration=Model migration is required. Right click the root of the model and use Refactor -> Migrate Model action. _label_DDS4CCM__QoSProfiles__QoSProfile__qosForEntity=Qos For Entity @@ -76,3 +76,5 @@ _label_DDS4CCM__QoSProfiles__QoSEntity__type=Type _label_DDS4CCM__DDS4CCM=DDS4CCM _label_DDS4CCM__DDS4CCM__IDLIncludeDependency=IDL Include Dependency _label_DDS4CCM__DDS4CCM__DDS4CCMModel__fixedFooter=Fixed Footer +_desc_DDS4CCM__Constraints__valid_name=Entity names can contain only letters, digits or underscores, and begin with a letter or underscore character. +_mesg_DDS4CCM__Constraints__valid_name=Invalid element name: "{0}" diff --git a/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.uml b/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.uml index aec26cb12..b1d6e0619 100644 --- a/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.uml +++ b/bundles/com.zeligsoft.domain.dds4ccm/models/DDS4CCM.uml @@ -1,25 +1,25 @@ - + - + - + - + - + - - + + %_desc_DDS4CCM__DDS4CCM__DDS4CCMModel__check_model_migration @@ -27,52 +27,52 @@ com.zeligsoft.domain.dds4ccm.constraints.java.CheckModelMigrationConstraint - + - + - + - + - + - + - + - + - + - + @@ -81,61 +81,61 @@ - + - + - + - + - + - + - + - + - + - + - -
+ +
- + @@ -150,22 +150,22 @@ - - + + - + - + - + - - + + %_desc_DDS4CCM__DDSExtensions__MessageField__check_container @@ -177,8 +177,8 @@ - - + + %_desc_DDS4CCM__DDSExtensions__MessageField__sub_structure_is_key @@ -186,127 +186,127 @@ com.zeligsoft.domain.dds4ccm.constraints.java.SubStructureIsKeyConstraint - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -332,8 +332,8 @@ - - + + %_desc_DDS4CCM__Constraints__port_delegation_complete @@ -342,8 +342,8 @@ com.zeligsoft.domain.dds4ccm.constraints.java.PortDelegationCompleteConstraint - - + + %_desc_DDS4CCM__Constraints__check_container_corba_field @@ -357,8 +357,8 @@ endif - - + + %_desc_DDS4CCM__Constraints__ExternalDomainConstraint @@ -367,8 +367,8 @@ endif self.oclAsType(uml::Operation).type <> null - - + + %_desc_DDS4CCM__Constraints__connector_type_compatibility @@ -377,8 +377,8 @@ endif com.zeligsoft.domain.dds4ccm.constraints.java.ConnectorTypeCompatibilityConstraint - - + + %_desc_DDS4CCM__Constraints__connector_type_not_empty @@ -387,8 +387,8 @@ endif com.zeligsoft.domain.dds4ccm.constraints.java.ConnectorTypeNotEmptyConstraint - - + + %_desc_DDS4CCM__Constraints__deployment_parts_with_local_interface_collocation @@ -397,8 +397,8 @@ endif com.zeligsoft.domain.dds4ccm.constraints.java.DeploymentPartsWithLocalInterfaceCollocationConstraint - - + + %_desc_DDS4CCM__Constraints__valid_external_references @@ -407,29 +407,36 @@ endif com.zeligsoft.domain.dds4ccm.constraints.java.ValidExternalReferenceConstraint - + Java com.zeligsoft.domain.dds4ccm.constraints.java.ValidAXCIOMADelegateConnectorConstraint + + + + Java + com.zeligsoft.domain.dds4ccm.constraints.java.ValidNameConstraint + + - - + + - + - - + + - + @@ -525,6 +532,7 @@ endif - + + diff --git a/bundles/com.zeligsoft.domain.dds4ccm/src/com/zeligsoft/domain/dds4ccm/constraints/java/ValidNameConstraint.java b/bundles/com.zeligsoft.domain.dds4ccm/src/com/zeligsoft/domain/dds4ccm/constraints/java/ValidNameConstraint.java new file mode 100644 index 000000000..ba18800b2 --- /dev/null +++ b/bundles/com.zeligsoft.domain.dds4ccm/src/com/zeligsoft/domain/dds4ccm/constraints/java/ValidNameConstraint.java @@ -0,0 +1,61 @@ +/** + * Copyright 2023 Northrop Grumman Systems Corporation. + * + * Licensed 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 com.zeligsoft.domain.dds4ccm.constraints.java; + +import java.util.function.Predicate; +import java.util.regex.Pattern; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.validation.AbstractModelConstraint; +import org.eclipse.emf.validation.IValidationContext; + +import com.zeligsoft.base.zdl.Activator; +import com.zeligsoft.base.zdl.util.ZDLUtil; +import com.zeligsoft.domain.zml.util.ZMLMMNames; + +/** + * Validates whether an entity name is valid, i.e. that it doesn't contain illegal characters. + * + * @author Ernesto Posse + */ +public class ValidNameConstraint extends AbstractModelConstraint { + + private static final String VALID_NAME_REGEX = "[a-zA-Z_]\\w*"; + private static final Pattern VALID_NAME_PATTERN = Pattern.compile(VALID_NAME_REGEX); + private static final Predicate VALID_NAME_PREDICATE = VALID_NAME_PATTERN.asMatchPredicate(); + + @Override + public IStatus validate(IValidationContext ctx) { + + EObject objToVerify = ctx.getTarget(); + + if (ZDLUtil.isZDLConcept(objToVerify, ZMLMMNames.NAMED_ELEMENT)) { + Object nameObj = ZDLUtil.getValue(objToVerify, ZMLMMNames.NAMED_ELEMENT, ZMLMMNames.NAMED_ELEMENT__NAME); + if (nameObj instanceof String) { + String name = (String)nameObj; + if (VALID_NAME_PREDICATE.test(name)) { + return ctx.createSuccessStatus(); + } + } + return ctx.createFailureStatus(nameObj.toString()); + } + + return null; + } +}