|
| 1 | +/* |
| 2 | + * Copyright 2011-2013 Adele Research Group (http://adele.imag.fr/) |
| 3 | + * LIG Laboratory (http://www.liglab.fr) |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | + |
| 19 | +package fr.liglab.adele.cube.plugins.core.constraints; |
| 20 | + |
| 21 | +import fr.liglab.adele.cube.agent.ConstraintResolver; |
| 22 | +import fr.liglab.adele.cube.agent.CubeAgent; |
| 23 | +import fr.liglab.adele.cube.agent.RuntimeModelController; |
| 24 | +import fr.liglab.adele.cube.agent.defaults.resolver.Variable; |
| 25 | + |
| 26 | + |
| 27 | +/** |
| 28 | + * Author: debbabi |
| 29 | + * Date: 4/28/13 |
| 30 | + * Time: 7:34 PM |
| 31 | + */ |
| 32 | +public class HasNoComponents implements ConstraintResolver { |
| 33 | + |
| 34 | + private static ConstraintResolver instance = new HasNoComponents(); |
| 35 | + |
| 36 | + public static ConstraintResolver instance() { |
| 37 | + return instance; |
| 38 | + } |
| 39 | + |
| 40 | + public void init(CubeAgent agent, Variable subjectVariable, Variable objectVariable) { |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + public boolean check(CubeAgent agent, Variable subjectVariable, Variable objectVariable) { |
| 45 | + Object instance1_uuid = subjectVariable.getValue(); |
| 46 | + Object agentUri = objectVariable.getValue(); |
| 47 | + if (instance1_uuid != null && agentUri != null) { |
| 48 | + RuntimeModelController rmController = agent.getRuntimeModelController(); |
| 49 | + if (rmController != null) { |
| 50 | + String value = rmController.getAgentOfElement(instance1_uuid.toString()); |
| 51 | + if (value != null && value.equalsIgnoreCase(agentUri.toString())) { |
| 52 | + return true; |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + return false; |
| 57 | + } |
| 58 | + |
| 59 | + public boolean applyDescription(CubeAgent agent, Variable subjectVariable, Variable objectVariable) { |
| 60 | + if (subjectVariable != null && objectVariable != null && objectVariable.getValue() != null) { |
| 61 | + subjectVariable.setCubeAgent(objectVariable.getValue().toString()); |
| 62 | + return true; |
| 63 | + } |
| 64 | + return false; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Apply the objective constraint. |
| 69 | + * This should modify the two elements in relation! |
| 70 | + * |
| 71 | + * @param subjectVariable |
| 72 | + * @param objectVariable |
| 73 | + * @return |
| 74 | + */ |
| 75 | + public boolean performObjective(CubeAgent agent, Variable subjectVariable, Variable objectVariable) { |
| 76 | + return false; //To change body of implemented methods use File | Settings | File Templates. |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Cancel the applied objective constraint. |
| 81 | + * This should remove properties or references added by the equivalent 'apply' function. |
| 82 | + * |
| 83 | + * @param subjectVariable |
| 84 | + * @param objectVariable |
| 85 | + * @return |
| 86 | + */ |
| 87 | + public boolean cancelObjective(CubeAgent agent, Variable subjectVariable, Variable objectVariable) { |
| 88 | + return false; //To change body of implemented methods use File | Settings | File Templates. |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Find value from object variable. |
| 93 | + * |
| 94 | + * @param subjectVariable |
| 95 | + * @param objectVariable |
| 96 | + * @return |
| 97 | + */ |
| 98 | + public String find(CubeAgent agent, Variable subjectVariable, Variable objectVariable) { |
| 99 | + return null; //To change body of implemented methods use File | Settings | File Templates. |
| 100 | + } |
| 101 | +} |
0 commit comments