@Override
        public Object handlePropertyAccess(Object self, ValueImpl impl, Object... args) {
          ValueDescriptorImpl<?> descriptor = impl.descriptor;

          boolean first = true;
          StringBuilder result = new StringBuilder(descriptor.getValueInterface().getName());
          result.append('{');
          for (PropertyImpl property : descriptor.internalGetProperties()) {
            Object selfValue = property.getGetHandler().handlePropertyAccess(self, impl);

            if (first) {
              first = false;
            } else {
              result.append("; ");
            }
            result.append(property.getName());
            result.append(": ");
            if (property.getKind() == Kind.PRIMITIVE) {
              result.append(property.getParser().unparse(selfValue));
            } else {
              result.append(selfValue);
            }
          }
          result.append('}');

          return result.toString();
        }
        @Override
        public Object handlePropertyAccess(Object self, ValueImpl impl, Object... args) {
          Object other = args[0];
          if (other == self) {
            return true;
          }

          ValueDescriptorImpl<?> descriptor = impl.descriptor;
          if (!descriptor.getValueInterface().isInstance(other)) {
            return false;
          }

          try {
            for (PropertyImpl property : descriptor.internalGetProperties()) {
              Object selfValue = property.getGetHandler().handlePropertyAccess(self, impl);
              Object otherValue = property.getGetter().invoke(other);
              if (!property.getParser().equals(selfValue, otherValue)) {
                return false;
              }
            }
            return true;
          } catch (IllegalAccessException e) {
            throw (AssertionError) new AssertionError().initCause(e);
          } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
              throw ((RuntimeException) cause);
            }
            if (cause instanceof Error) {
              throw ((Error) cause);
            }
            // Getters must not declare exceptions.
            throw (AssertionError) new AssertionError().initCause(e);
          }
        }
 public ValueImpl(ValueDescriptorImpl<?> descriptor) {
   this.descriptor = descriptor;
   this.values = new Object[descriptor.getSize()];
   Collection<PropertyImpl> properties = descriptor.internalGetProperties();
   for (PropertyImpl property : properties) {
     values[property.getIndex()] = property.getInitializer().init();
   }
 }
 @Override
 public Object handlePropertyAccess(Object self, ValueImpl impl, Object... args) {
   PropertyImpl property = (PropertyImpl) args[0];
   Object value = args[1];
   if (value == null) {
     value = property.getInitializer().init();
   }
   return property.getSetHandler().handlePropertyAccess(self, impl, value);
 }
        @Override
        public Object handlePropertyAccess(Object self, ValueImpl impl, Object... args) {
          ValueDescriptorImpl<?> descriptor = impl.descriptor;

          int result = 0;
          for (PropertyImpl property : descriptor.internalGetProperties()) {
            Object value = property.getGetHandler().handlePropertyAccess(self, impl);
            result += (property.getIndex() + 1) * property.getParser().hashCode(value);
          }
          return result;
        }
 @Override
 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
   if (ea.matches(entryTag)) {
     state.loader = entryLoader;
   } else {
     super.childElement(state, ea);
   }
 }
Beispiel #7
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void eSet(int featureID, Object newValue) {
   switch (featureID) {
     case ThingmlPackage.DICTIONARY__INDEX_TYPE:
       setIndexType((Type) newValue);
       return;
   }
   super.eSet(featureID, newValue);
 }
 @Override
 public void leaveElement(State state, TagName ea) throws SAXException {
   super.leaveElement(state, ea);
   try {
     acc.set(target, map);
   } catch (AccessorException ex) {
     handleGenericException(ex, true);
   }
 }
Beispiel #9
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void eUnset(int featureID) {
   switch (featureID) {
     case ThingmlPackage.DICTIONARY__INDEX_TYPE:
       setIndexType((Type) null);
       return;
   }
   super.eUnset(featureID);
 }
Beispiel #10
0
  @Test
  public void basicConfigRoundtrip() throws Exception {
    DumbSlave s = j.createSlave();
    HtmlForm f =
        j.createWebClient()
            .goTo("computer/" + s.getNodeName() + "/configure")
            .getFormByName("config");
    ((HtmlLabel) DomNodeUtil.selectSingleNode(f, ".//LABEL[text()='PropertyImpl']")).click();
    j.submit(f);
    PropertyImpl p = j.jenkins.getNode(s.getNodeName()).getNodeProperties().get(PropertyImpl.class);
    assertEquals("Duke", p.name);

    p.name = "Kohsuke";
    j.configRoundtrip(s);

    PropertyImpl p2 =
        j.jenkins.getNode(s.getNodeName()).getNodeProperties().get(PropertyImpl.class);
    assertNotSame(p, p2);
    j.assertEqualDataBoundBeans(p, p2);
  }
Beispiel #11
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void eUnset(int featureID) {
   switch (featureID) {
     case SimplespecPackage.ASSOCIATION__MULTIPLICITY:
       setMultiplicity(MULTIPLICITY_EDEFAULT);
       return;
     case SimplespecPackage.ASSOCIATION__TYPE:
       setType((Entity) null);
       return;
   }
   super.eUnset(featureID);
 }
Beispiel #12
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void eSet(int featureID, Object newValue) {
   switch (featureID) {
     case SimplespecPackage.ASSOCIATION__MULTIPLICITY:
       setMultiplicity((String) newValue);
       return;
     case SimplespecPackage.ASSOCIATION__TYPE:
       setType((Entity) newValue);
       return;
   }
   super.eSet(featureID, newValue);
 }
 @Override
 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
   if (ea.matches(keyTag)) {
     state.loader = keyLoader;
     state.receiver = keyReceiver;
     return;
   }
   if (ea.matches(valueTag)) {
     state.loader = valueLoader;
     state.receiver = valueReceiver;
     return;
   }
   super.childElement(state, ea);
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void eUnset(int featureID) {
   switch (featureID) {
     case EnvironmentPackage.REFERENCE__IS_COMPOSITE:
       setIsComposite(IS_COMPOSITE_EDEFAULT);
       return;
     case EnvironmentPackage.REFERENCE__NAVIGABLE:
       setNavigable(NAVIGABLE_EDEFAULT);
       return;
     case EnvironmentPackage.REFERENCE__OPPOSITE_OF:
       setOppositeOf((Reference) null);
       return;
     case EnvironmentPackage.REFERENCE__CONTAINING_TYPE:
       setContainingType((StructuredType) null);
       return;
     case EnvironmentPackage.REFERENCE__REFERENCED_TYPE:
       setReferencedType((StructuredType) null);
       return;
   }
   super.eUnset(featureID);
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void eSet(int featureID, Object newValue) {
   switch (featureID) {
     case EnvironmentPackage.REFERENCE__IS_COMPOSITE:
       setIsComposite((Boolean) newValue);
       return;
     case EnvironmentPackage.REFERENCE__NAVIGABLE:
       setNavigable((Boolean) newValue);
       return;
     case EnvironmentPackage.REFERENCE__OPPOSITE_OF:
       setOppositeOf((Reference) newValue);
       return;
     case EnvironmentPackage.REFERENCE__CONTAINING_TYPE:
       setContainingType((StructuredType) newValue);
       return;
     case EnvironmentPackage.REFERENCE__REFERENCED_TYPE:
       setReferencedType((StructuredType) newValue);
       return;
   }
   super.eSet(featureID, newValue);
 }
Beispiel #16
0
 public Object getParameterValue(QueryExecutionContext context) {
   return property.getParameterValue(context, parameterName);
 }
 @Override
 public Object handlePropertyAccess(Object self, ValueImpl impl, Object... args) {
   PropertyImpl property = (PropertyImpl) args[0];
   return property.getGetHandler().handlePropertyAccess(self, impl);
 }
  /** Completes the analysis of the {@link #getValueInterface()}. */
  public void init() {
    Map<String, PropertyImpl> propertyByRawName = new HashMap<String, PropertyImpl>();
    Map<Method, PropertyImpl> propertyByMethod = new HashMap<Method, PropertyImpl>();
    for (Method method : valueInterface.getMethods()) {
      if (method.getDeclaringClass().isAssignableFrom(Value.class)) {
        // Ignore Value and Object type methods.
        continue;
      }

      int modifiers = method.getModifiers();
      if (!Modifier.isPublic(modifiers)) {
        throw new AssertionError("Expected public modifier on '" + method + "'");
      }

      if (Modifier.isStatic(modifiers)) {
        throw new AssertionError("No static methods allowed on '" + method + "'");
      }

      if (method.getExceptionTypes().length > 0) {
        throw new AssertionError("Method must not declare exceptions: " + method);
      }

      boolean isGetter;
      String prefix;
      String methodName = method.getName();
      if (methodName.startsWith("get")) {
        prefix = "get";
        isGetter = true;
      } else if (methodName.startsWith("set")) {
        prefix = "set";
        isGetter = false;
      } else if (methodName.startsWith("is")) {
        prefix = "is";
        isGetter = true;
      } else if (methodName.startsWith("has")) {
        prefix = "has";
        isGetter = true;
      } else if (methodName.startsWith("can")) {
        prefix = "can";
        isGetter = true;
      } else if (methodName.startsWith("must")) {
        prefix = "must";
        isGetter = true;
      } else {
        throw new AssertionError("Invalid method prefix: " + method);
      }

      Class<?> type;
      if (isGetter) {
        Class<?>[] types = method.getParameterTypes();
        if (types.length != 0) {
          throw new AssertionError("Getter must not have parameters: " + method);
        }

        type = method.getReturnType();
        if (type == Void.class || type == void.class) {
          throw new AssertionError("Getter must not have void return type: " + method);
        }

        boolean isBoolean = type == boolean.class || type == Boolean.class;
        if (!prefix.equals("get") && !isBoolean) {
          throw new AssertionError(
              "Non boolean getters must have '" + "get" + "' prefix: " + method);
        }
      } else {
        Class<?>[] types = method.getParameterTypes();
        if (types.length != 1) {
          throw new AssertionError("Setter must have exactly one argument: " + method);
        }

        Class<?> returnType = method.getReturnType();
        if (returnType != void.class) {
          throw new AssertionError("Setter must have void return type: " + method);
        }

        type = types[0];
      }

      String postfix = methodName.substring(prefix.length());

      if (Character.isLowerCase(postfix.charAt(0))) {
        throw new AssertionError("Expected upper case letter after method prefix: " + method);
      }

      String rawName = Character.toLowerCase(postfix.charAt(0)) + postfix.substring(1);

      PropertyImpl property = propertyByRawName.get(rawName);
      if (property == null) {
        int index = propertyByRawName.size();
        property = new PropertyImpl(this, rawName, index);
        propertyByRawName.put(rawName, property);
      }

      if (isGetter) {
        property.initGetter(method);
      }

      propertyByMethod.put(method, property);
    }

    for (PropertyImpl property : propertyByRawName.values()) {
      PropertyImpl clash = properties.put(property.getName(), property);
      if (clash != null) {
        throw new IllegalArgumentException(
            "Properties must have unique names in interface '"
                + valueInterface.getName()
                + "': "
                + clash.getName());
      }
    }

    for (Entry<Method, PropertyImpl> entry : propertyByMethod.entrySet()) {
      Method method = entry.getKey();
      boolean isGetter = !method.getName().startsWith("set");
      PropertyImpl property = entry.getValue();
      handlerByMethod.put(method, isGetter ? property.getGetHandler() : property.getSetHandler());
    }

    // Add object methods.
    handlerByMethod.put(EQUALS_METHOD, EQUALS_IMPL);
    handlerByMethod.put(HASH_CODE_METHOD, HASH_CODE_IMPL);
    handlerByMethod.put(TO_STRING_METHOD, TO_STRING_IMPL);

    // Add value interface methods.
    handlerByMethod.put(DESCRIPTOR_METHOD, DESCRIPTOR_IMPL);
    handlerByMethod.put(VALUE_METHOD, VALUE_IMPL);
    handlerByMethod.put(PUT_VALUE_METHOD, PUT_VALUE_IMPL);
  }