Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 565011 rebuild the core of condition expression evaluation
- design set of interfaces for the flexible condition expression evaluation Signed-off-by: elena.parovyshnaya <elena.parovyshnaya@gmail.com>
- Loading branch information
1 parent
cf62f6a
commit c2f87a0
Showing
12 changed files
with
278 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...g/eclipse/passage/lic/internal/api/conditions/evaluation/ExpressionEvaluationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
import org.eclipse.passage.lic.internal.api.registry.Service; | ||
|
||
public interface ExpressionEvaluationService extends Service<ExpressionProtocol> { | ||
|
||
boolean evaluate(ParsedExpression expression, ExpressionTokenAssessmentService assessor); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
.../eclipse/passage/lic/internal/api/conditions/evaluation/ExpressionEvaluatorsRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.passage.lic.internal.api.registry.Registry; | ||
|
||
public interface ExpressionEvaluatorsRegistry | ||
extends Supplier<Registry<ExpressionProtocol, ExpressionEvaluationService>> { | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...rg/eclipse/passage/lic/internal/api/conditions/evaluation/ExpressionParsingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
@SuppressWarnings("serial") | ||
public final class ExpressionParsingException extends Exception { | ||
|
||
public ExpressionParsingException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ExpressionParsingException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...org/eclipse/passage/lic/internal/api/conditions/evaluation/ExpressionPasringRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.passage.lic.internal.api.registry.Registry; | ||
|
||
public interface ExpressionPasringRegistry extends Supplier<Registry<ExpressionProtocol, ExpressionPasringService>> { | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
.../org/eclipse/passage/lic/internal/api/conditions/evaluation/ExpressionPasringService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
import org.eclipse.passage.lic.internal.api.registry.Service; | ||
|
||
public interface ExpressionPasringService extends Service<ExpressionProtocol> { | ||
|
||
ParsedExpression parsed(String expression) throws ExpressionParsingException; | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...pi/src/org/eclipse/passage/lic/internal/api/conditions/evaluation/ExpressionProtocol.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.passage.lic.internal.api.registry.ServiceId; | ||
|
||
public abstract class ExpressionProtocol implements ServiceId { | ||
|
||
private final String identifier; | ||
|
||
protected ExpressionProtocol(String identifier) { | ||
Objects.requireNonNull(identifier, "ExpressionProtocol::identifier"); //$NON-NLS-1$ | ||
this.identifier = identifier.trim().toLowerCase(); | ||
} | ||
|
||
public final String identifier() { | ||
return identifier; | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
return Objects.hash(identifier()); | ||
} | ||
|
||
@Override | ||
public final boolean equals(Object object) { | ||
if (!ExpressionProtocol.class.isInstance(object)) { | ||
return false; | ||
} | ||
return identifier.equals(((ExpressionProtocol) object).identifier); | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return identifier; | ||
} | ||
|
||
public static final class Ands extends ExpressionProtocol { | ||
|
||
public Ands() { | ||
super("ands"); //$NON-NLS-1$ | ||
} | ||
|
||
} | ||
|
||
public static final class Default extends ExpressionProtocol { | ||
|
||
public Default() { | ||
super(new Ands().identifier()); | ||
} | ||
|
||
} | ||
|
||
public static final class Of extends ExpressionProtocol { | ||
|
||
public Of(String identifier) { | ||
super(identifier); | ||
} | ||
|
||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...ipse/passage/lic/internal/api/conditions/evaluation/ExpressionTokenAssessmentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
import org.eclipse.passage.lic.internal.api.conditions.EvaluationType; | ||
import org.eclipse.passage.lic.internal.api.registry.Service; | ||
|
||
/** | ||
* <p> | ||
* Condition expression parsing, depending on the protocol used, can boil down | ||
* to a sophisticated construction of predicates. | ||
* </p> | ||
* <p> | ||
* But at the bottom of the evaluation of such a construction there are quite | ||
* simple questions for the runtime environment: is current operating system is | ||
* Linux-like? is the hard disk serial equal to this precise value? - that kind | ||
* of asking. | ||
* </p> | ||
* <p> | ||
* Implementation of this interface for a particular {@linkplain EvaluationType} | ||
* must answer only these simple questions. the rest of the evaluation logic is | ||
* on {@linkplain ExpressionProtocol}-aware services. | ||
* </p> | ||
*/ | ||
public interface ExpressionTokenAssessmentService extends Service<EvaluationType> { | ||
|
||
boolean equal(String key, String value); | ||
|
||
// contains () | ||
|
||
// startsWith () | ||
|
||
// all the things we will ever need -> slice to [Operation]s | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ipse/passage/lic/internal/api/conditions/evaluation/ExpressionTokenAssessorsRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.passage.lic.internal.api.conditions.EvaluationType; | ||
import org.eclipse.passage.lic.internal.api.registry.Registry; | ||
|
||
public interface ExpressionTokenAssessorsRegistry | ||
extends Supplier<Registry<EvaluationType, ExpressionTokenAssessmentService>> { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
....api/src/org/eclipse/passage/lic/internal/api/conditions/evaluation/ParsedExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.api.conditions.evaluation; | ||
|
||
public interface ParsedExpression { | ||
|
||
ExpressionProtocol protocol(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters