Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
af3
kernel
Commits
8889beda
Commit
8889beda
authored
8 years ago
by
Vincent Aravantinos
Browse files
Options
Downloads
Patches
Plain Diff
IConstraint -> Constraint in service implementation
adds cancellation refs 2553
parent
977c4de8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ConstraintVerificationService.java
+95
-50
95 additions, 50 deletions
...ooling/kernel/internal/ConstraintVerificationService.java
with
95 additions
and
50 deletions
org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ConstraintVerificationService.java
+
95
−
50
View file @
8889beda
package
org.fortiss.tooling.kernel.internal
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
org
.
eclipse
.
emf
.
ecore
.
xmi
.
XMLResource
.
OPTION_PROCESS_DANGLING_HREF
;
import
static
org
.
eclipse
.
emf
.
ecore
.
xmi
.
XMLResource
.
OPTION_PROCESS_DANGLING_HREF_DISCARD
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
ExtensionPointUtils
.
getBundle
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
ExtensionPointUtils
.
getConfigurationElements
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
ExtensionPointUtils
.
loadClass
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
LoggingUtils
.
error
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
LoggingUtils
.
warning
;
import
java.io.ByteArrayOutputStream
;
import
java.io.FileOutputStream
;
...
...
@@ -9,10 +15,12 @@ import java.io.ObjectOutputStream;
import
java.math.BigInteger
;
import
java.security.MessageDigest
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.eclipse.core.runtime.IConfigurationElement
;
import
org.eclipse.emf.common.util.EList
;
import
org.eclipse.emf.common.util.URI
;
import
org.eclipse.emf.ecore.EObject
;
...
...
@@ -23,18 +31,20 @@ import org.fortiss.tooling.kernel.ToolingKernelActivator;
import
org.fortiss.tooling.kernel.extension.IConstraintVerifier
;
import
org.fortiss.tooling.kernel.extension.data.ITopLevelElement
;
import
org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem
;
import
org.fortiss.tooling.kernel.introspection.IIntrospectionItem
;
import
org.fortiss.tooling.kernel.introspection.IIntrospectiveKernelService
;
import
org.fortiss.tooling.kernel.introspection.items.ConstraintVerificationServiceIntrospectionDetailsItem
;
import
org.fortiss.tooling.kernel.model.INamedElement
;
import
org.fortiss.tooling.kernel.model.constraints.ConstrainedWithChecksum
;
import
org.fortiss.tooling.kernel.model.constraints.Constraint
;
import
org.fortiss.tooling.kernel.model.constraints.ConstraintsFactory
;
import
org.fortiss.tooling.kernel.model.constraints.IConstrained
;
import
org.fortiss.tooling.kernel.model.constraints.IConstraint
;
import
org.fortiss.tooling.kernel.service.IConstraintVerificationService
;
import
org.fortiss.tooling.kernel.service.IKernelIntrospectionSystemService
;
import
org.fortiss.tooling.kernel.service.IPersistencyService
;
import
org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase
;
import
org.fortiss.tooling.kernel.utils.EcoreUtils
;
import
org.fortiss.tooling.kernel.utils.LoggingUtils
;
import
org.osgi.framework.Bundle
;
/**
* Implementation of {@link IConstraintVerificationService}.
...
...
@@ -42,32 +52,66 @@ import org.fortiss.tooling.kernel.utils.LoggingUtils;
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash:
DBE8840892D099FA011822EF6EB4ED9E
* @ConQAT.Rating YELLOW Hash:
28F933A29C87BB09AD7E9B8A74313878
*/
public
final
class
ConstraintVerificationService
extends
EObjectAwareServiceBase
<
IConstraintVerifier
<
IConstraint
>>
implements
public
final
class
ConstraintVerificationService
implements
IIntrospectiveKernelService
,
IConstraintVerificationService
{
/** The singleton instance. */
private
static
final
ConstraintVerificationService
INSTANCE
=
new
ConstraintVerificationService
();
/** Stores the class to handler map. */
protected
final
Map
<
String
,
IConstraintVerifier
>
handlerMap
=
new
HashMap
<
String
,
IConstraintVerifier
>();
/** Returns singleton instance of the service. */
public
static
ConstraintVerificationService
getInstance
()
{
return
INSTANCE
;
}
/** {@inheritDoc} */
@Override
/** Starts the service. */
public
void
startService
()
{
IKernelIntrospectionSystemService
.
getInstance
().
registerService
(
this
);
}
/** Initializes the service by setting up the handler map. */
public
void
initializeService
()
{
setupHandlerMap
();
}
/** Initializes the handler map from plugin extensions. */
private
void
setupHandlerMap
()
{
for
(
IConfigurationElement
ce
:
getConfigurationElements
(
getExtensionPointName
(),
getConfigurationElementName
()))
{
Bundle
bundle
=
getBundle
(
ce
);
try
{
Class
<?>
handlerClass
=
loadClass
(
ce
.
getAttribute
(
getHandlerClassAttribute
()),
bundle
);
IConstraintVerifier
handler
=
(
IConstraintVerifier
)
handlerClass
.
getConstructor
().
newInstance
();
addHandler
(
handler
.
getID
(),
handler
);
}
catch
(
Exception
ex
)
{
error
(
ToolingKernelActivator
.
getDefault
(),
ex
.
getMessage
(),
ex
);
}
}
}
/** Adds the given handler to the map and the set. */
protected
void
addHandler
(
String
id
,
IConstraintVerifier
handler
)
{
IConstraintVerifier
existingVerifier
=
handlerMap
.
get
(
id
);
if
(
existingVerifier
!=
null
)
{
warning
(
ToolingKernelActivator
.
getDefault
(),
"Encountered more than one handler registered with "
+
getExtensionPointName
()
+
"("
+
handler
.
getClass
()
+
","
+
existingVerifier
.
getClass
()
+
")"
);
}
handlerMap
.
put
(
id
,
handler
);
}
/** {@inheritDoc} */
@Override
@SuppressWarnings
(
"unchecked"
)
public
<
T
extends
IConstraint
>
void
registerConstraintVerifier
(
IConstraintVerifier
<
T
>
verifier
,
Class
<
T
>
constraintElementClass
)
{
addHandler
(
constraintElementClass
,
(
IConstraintVerifier
<
IConstraint
>)
verifier
);
public
void
registerConstraintVerifier
(
IConstraintVerifier
verifier
)
{
addHandler
(
verifier
.
getID
(),
verifier
);
}
/** {@inheritDoc} */
...
...
@@ -97,8 +141,8 @@ public final class ConstraintVerificationService extends
/** {@inheritDoc} */
@Override
public
void
verify
(
I
Constraint
constraint
)
{
IConstraintVerifier
<
IConstraint
>
verifier
=
getFirstVerifier
(
constraint
);
public
void
verify
(
Constraint
constraint
)
{
IConstraintVerifier
verifier
=
getFirstVerifier
(
constraint
);
if
(
verifier
!=
null
)
{
ITopLevelElement
modelContext
=
IPersistencyService
.
getInstance
().
getTopLevelElementFor
(
constraint
);
...
...
@@ -127,9 +171,9 @@ public final class ConstraintVerificationService extends
/** {@inheritDoc} */
@Override
public
<
T
extends
IConstraint
>
List
<
IFix
>
fixes
(
T
c
)
{
public
List
<
IFix
>
fixes
(
Constraint
c
)
{
List
<
IFix
>
fixes
=
null
;
IConstraintVerifier
<
IConstraint
>
verifier
=
getFirstVerifier
(
c
);
IConstraintVerifier
verifier
=
getFirstVerifier
(
c
);
if
(
verifier
!=
null
)
{
fixes
=
verifier
.
fixes
(
c
,
c
.
getVerificationStatus
());
}
...
...
@@ -138,7 +182,7 @@ public final class ConstraintVerificationService extends
/** {@inheritDoc} */
@Override
public
boolean
isUpToDate
(
I
Constraint
constraint
)
{
public
boolean
isUpToDate
(
Constraint
constraint
)
{
for
(
ConstrainedWithChecksum
cwc
:
constraint
.
getConstrainedsWithChecksum
())
{
BigInteger
computeCheckSum
=
computeCheckSum
(
cwc
.
getConstrained
(),
constraint
);
if
(
computeCheckSum
==
null
||
!
computeCheckSum
.
equals
(
cwc
.
getChecksum
()))
{
...
...
@@ -152,7 +196,7 @@ public final class ConstraintVerificationService extends
* @param constraint
* Updates all the checksums of <code>constraint</code>.
*/
private
void
updateChecksums
(
I
Constraint
constraint
)
{
private
void
updateChecksums
(
Constraint
constraint
)
{
List
<
ConstrainedWithChecksum
>
newCwcs
=
new
ArrayList
<
ConstrainedWithChecksum
>();
for
(
ConstrainedWithChecksum
cwc
:
constraint
.
getConstrainedsWithChecksum
())
{
ConstrainedWithChecksum
newCwc
=
...
...
@@ -184,7 +228,7 @@ public final class ConstraintVerificationService extends
* necessary because it has a potential impact on what is relevant for the checksum or
* not.
*/
protected
BigInteger
computeCheckSum
(
IConstrained
constrained
,
I
Constraint
constraint
)
{
protected
BigInteger
computeCheckSum
(
IConstrained
constrained
,
Constraint
constraint
)
{
if
(
constrained
==
null
)
{
return
null
;
}
...
...
@@ -238,9 +282,9 @@ public final class ConstraintVerificationService extends
* Generally, all verification statuses and checksums are removed. Each verifier can
* also provide per-constraint adaptations.
*/
protected
EObject
getChecksumRelevantEObject
(
IConstrained
constrained
,
I
Constraint
constraint
)
{
protected
EObject
getChecksumRelevantEObject
(
IConstrained
constrained
,
Constraint
constraint
)
{
EObject
res
=
EcoreUtils
.
copy
(
constrained
);
IConstraintVerifier
<
IConstraint
>
verifier
=
getFirstVerifier
(
constraint
);
IConstraintVerifier
verifier
=
getFirstVerifier
(
constraint
);
if
(
verifier
!=
null
)
{
verifier
.
removeConstraintIrrelevantContent
(
res
);
}
...
...
@@ -248,62 +292,45 @@ public final class ConstraintVerificationService extends
}
/**
* @param clazz
* @return the first registered verifier which can verify a constraint of class
* <code>clazz</code>.
* @param id
* @return the first registered verifier which can verify a constraint of type <code>id</code>.
*/
protected
IConstraintVerifier
<
IConstraint
>
getFirstVerifier
(
Class
<?>
clazz
)
{
List
<
IConstraintVerifier
<
IConstraint
>>
list
=
getRegisteredHandlers
(
clazz
);
if
(
l
ist
==
null
||
list
.
isEmpty
()
)
{
protected
IConstraintVerifier
getFirstVerifier
(
String
id
)
{
IConstraintVerifier
existingVerifier
=
handlerMap
.
get
(
id
);
if
(
ex
ist
ingVerifier
==
null
)
{
LoggingUtils
.
error
(
ToolingKernelActivator
.
getDefault
(),
String
.
format
(
"Cannot find verifier for constraint %s"
,
clazz
));
String
.
format
(
"Cannot find verifier for constraint %s"
,
id
));
return
null
;
}
// get(0) because we know the list is not empty and because we want the first element
return
list
.
get
(
0
);
return
existingVerifier
;
}
/**
* @param constraint
* @return The first registered verifier which can verify <code>constraint</code>.
*/
protected
IConstraintVerifier
<
IConstraint
>
getFirstVerifier
(
I
Constraint
constraint
)
{
return
getFirstVerifier
(
constraint
.
getC
lass
());
protected
IConstraintVerifier
getFirstVerifier
(
Constraint
constraint
)
{
return
getFirstVerifier
(
constraint
.
getC
onstraintTypeID
());
}
/** {@inheritDoc} */
@Override
/** Returns the extension point name. */
protected
String
getExtensionPointName
()
{
return
"org.fortiss.tooling.kernel.constraintVerifier"
;
}
/** {@inheritDoc} */
@Override
/** Returns the configuration element name. */
protected
String
getConfigurationElementName
()
{
return
"constraintVerifier"
;
}
/** {@inheritDoc} */
@Override
/** Returns the handler class attribute name. */
protected
String
getHandlerClassAttribute
()
{
return
"constraintVerifier"
;
}
/** {@inheritDoc} */
@Override
protected
String
getClassAttribute
()
{
return
"constraint"
;
}
/** {@inheritDoc} */
@Override
protected
String
getClassConfigurationElement
()
{
return
"constraint"
;
}
/** {@inheritDoc} */
@Override
public
void
setConstrained
(
IConstraint
constraint
,
IConstrained
constrained
,
int
index
)
{
public
void
setConstrained
(
Constraint
constraint
,
IConstrained
constrained
,
int
index
)
{
EList
<
ConstrainedWithChecksum
>
cwcs
=
constraint
.
getConstrainedsWithChecksum
();
if
(
cwcs
.
size
()
<=
index
)
{
for
(
int
i
=
cwcs
.
size
();
i
<=
index
;
i
++)
{
...
...
@@ -318,6 +345,12 @@ public final class ConstraintVerificationService extends
cwc
.
setChecksum
(
computeCheckSum
(
constrained
,
constraint
));
}
/** {@inheritDoc} */
@Override
public
void
cancel
(
Constraint
constraint
)
{
getFirstVerifier
(
constraint
.
getConstraintTypeID
()).
cancel
(
constraint
);
}
/** {@inheritDoc} */
@Override
public
String
getIntrospectionLabel
()
{
...
...
@@ -329,4 +362,16 @@ public final class ConstraintVerificationService extends
public
IIntrospectionDetailsItem
getDetailsItem
()
{
return
new
ConstraintVerificationServiceIntrospectionDetailsItem
(
handlerMap
);
}
/** {@inheritDoc} */
@Override
public
boolean
showInIntrospectionNavigation
()
{
return
true
;
}
/** {@inheritDoc} */
@Override
public
Collection
<
IIntrospectionItem
>
getIntrospectionItems
()
{
return
emptyList
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment