/machinelearning/5.0.x/drools-core/src/main/java/org/drools/process/core/context/variable/Variable.java

https://github.com/etirelli/droolsjbpm-contributed-experiments · Java · 82 lines · 48 code · 14 blank · 20 comment · 4 complexity · 2e68614d18f266cdbe5129c42a97294c MD5 · raw file

  1. package org.drools.process.core.context.variable;
  2. /*
  3. * Copyright 2005 JBoss Inc
  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. import java.io.Serializable;
  18. import org.drools.process.core.TypeObject;
  19. import org.drools.process.core.ValueObject;
  20. import org.drools.process.core.datatype.DataType;
  21. import org.drools.process.core.datatype.impl.type.UndefinedDataType;
  22. /**
  23. * Default implementation of a variable.
  24. *
  25. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  26. */
  27. public class Variable implements TypeObject, ValueObject, Serializable {
  28. private static final long serialVersionUID = 400L;
  29. private String name;
  30. private DataType type;
  31. private Object value;
  32. public Variable() {
  33. this.type = UndefinedDataType.getInstance();
  34. }
  35. public String getName() {
  36. return this.name;
  37. }
  38. public void setName(final String name) {
  39. this.name = name;
  40. }
  41. public DataType getType() {
  42. return this.type;
  43. }
  44. public void setType(final DataType type) {
  45. if ( type == null ) {
  46. throw new IllegalArgumentException( "type is null" );
  47. }
  48. this.type = type;
  49. }
  50. public Object getValue() {
  51. return this.value;
  52. }
  53. public void setValue(final Object value) {
  54. if ( this.type.verifyDataType( value ) ) {
  55. this.value = value;
  56. } else {
  57. final StringBuffer sb = new StringBuffer();
  58. sb.append( "Value <" );
  59. sb.append( value );
  60. sb.append( "> is not valid for datatype: " );
  61. sb.append( this.type );
  62. throw new IllegalArgumentException( sb.toString() );
  63. }
  64. }
  65. public String toString() {
  66. return this.name;
  67. }
  68. }