Пример #1
0
  public static Type getType(String name) {
    Type t = new Type();
    ElementType et = get(name);
    t.setId(et.getId());
    t.setName(et.toString());

    return t;
  }
 private void removeEmptyContentElements(ElementType elementType) {
   List<Serializable> contentToDelete = newArrayList();
   for (Serializable content : elementType.getContent()) {
     if (content instanceof String && ((String) content).matches("[\\n ].*")) {
       contentToDelete.add(content);
     }
   }
   elementType.getContent().removeAll(contentToDelete);
 }
 private <A extends Annotation> Annotation createAnnotation(
     AnnotationType annotationType, Class<A> returnType) {
   AnnotationDescriptor<A> annotationDescriptor = new AnnotationDescriptor<A>(returnType);
   for (ElementType elementType : annotationType.getElement()) {
     String name = elementType.getName();
     Class<?> parameterType = getAnnotationParameterType(returnType, name);
     Object elementValue = getElementValue(elementType, parameterType);
     annotationDescriptor.setValue(name, elementValue);
   }
   return AnnotationFactory.create(annotationDescriptor);
 }
Пример #4
0
 public List removeTypes(List types) {
   if (types != null) {
     for (ElementType elementType : this.ElementType) {
       IElementType type = elementType.getElementType(elementType.typeID);
       if (type != null && types.contains(type)) {
         types.remove(type);
       }
     }
   }
   return types;
 }
Пример #5
0
 private Element getInformXMWPElement(
     String namespaceURI, String localName, String raxName, Attributes atts) throws XMWPException {
   ElementType type;
   try {
     type = ElementType.valueOf(raxName.substring(5));
   } catch (Exception e) {
     throw new XMWPException("unknown inform xmwp element : " + raxName.substring(5));
   }
   Element element = type.newInformInstance();
   element.setAttributes(atts);
   return element;
 }
Пример #6
0
  private void generateElementAndElementTypes() {
    // Laptop
    ElementType laptopType = new ElementType("Laptop");

    List<Element> elementList = new ArrayList<>();
    elementList.add(new Element("Acer"));
    elementList.add(new Element("Dell"));
    elementList.add(new Element("Samsung"));
    elementList.add(new Element("Apple"));
    elementList.add(new Element("Asus"));

    laptopType.setElementList(elementList);

    elementTypeService.saveElementType(laptopType);

    // CellPhone
    ElementType cellPhoneType = new ElementType("CellPhone");

    List<Element> cellPhoneList = new ArrayList<>();
    cellPhoneList.add(new Element("Samsung"));
    cellPhoneList.add(new Element("Apple"));
    cellPhoneList.add(new Element("Nokia"));
    cellPhoneList.add(new Element("Huawei"));
    cellPhoneList.add(new Element("LG"));
    cellPhoneList.add(new Element("Motorola"));
    cellPhoneList.add(new Element("BlackBerry"));

    cellPhoneType.setElementList(cellPhoneList);

    elementTypeService.saveElementType(cellPhoneType);

    // SmartWatch
    ElementType watchType = new ElementType("Watch");

    List<Element> watchList = new ArrayList<>();
    watchList.add(new Element("iWatch"));
    watchList.add(new Element("Gear S"));
    watchList.add(new Element("Rolex"));
    watchList.add(new Element("Bowlex"));
    watchList.add(new Element("FitBit"));
    watchList.add(new Element("Moto360"));
    watchList.add(new Element("Watch Urbane"));

    watchType.setElementList(watchList);

    elementTypeService.saveElementType(watchType);

    // Email
    ElementType emailType = new ElementType("Email");

    List<Element> emailList = new ArrayList<>();
    emailList.add(new Element("Work"));
    emailList.add(new Element("Personal"));
    emailList.add(new Element("Delegated"));

    emailType.setElementList(emailList);

    elementTypeService.saveElementType(emailType);
  }
  @Override
  public void setAsText(String text) throws IllegalArgumentException {

    String capitalized = text.toUpperCase();
    ElementType currency = ElementType.valueOf(capitalized);
    setValue(currency);
  }
Пример #8
0
 private void configureAnnotationFromDefinition(AnnotationNode definition, AnnotationNode root) {
   ClassNode type = definition.getClassNode();
   if (!type.isResolved()) return;
   Class clazz = type.getTypeClass();
   if (clazz == Retention.class) {
     Expression exp = definition.getMember("value");
     if (!(exp instanceof PropertyExpression)) return;
     PropertyExpression pe = (PropertyExpression) exp;
     String name = pe.getPropertyAsString();
     RetentionPolicy policy = RetentionPolicy.valueOf(name);
     setRetentionPolicy(policy, root);
   } else if (clazz == Target.class) {
     Expression exp = definition.getMember("value");
     if (!(exp instanceof ListExpression)) return;
     ListExpression le = (ListExpression) exp;
     int bitmap = 0;
     for (Expression e : le.getExpressions()) {
       PropertyExpression element = (PropertyExpression) e;
       String name = element.getPropertyAsString();
       ElementType value = ElementType.valueOf(name);
       bitmap |= getElementCode(value);
     }
     root.setAllowedTargets(bitmap);
   }
 }
Пример #9
0
 private void write(String key, Document document, DocumentType type, ValueList valueList) {
   Set<String> keySet = type.types.keySet();
   for (String keyName : keySet) {
     ElementType elType = type.types.get(keyName);
     Object value = document.get(keyName);
     if (value == null) {
       valueList.append((String) null);
       continue;
     }
     if (elType.isBasicType()) {
       valueList.append(value);
       // for now only datatypes can be indexed
       indexMap = allIndices.get(keyName);
       if (indexMap != null) {
         setIndex(keyName, value, key);
       }
     } else if ((elType.type == ElementType.TYPE_REFERENCE)
         || (elType.type == ElementType.TYPE_REFERENCE_ARRAY)) {
       String dbid =
           writeReference(
               key, (Document) value, elType.nestedType, elType.reference, elType.referenceKey);
       valueList.append(dbid);
     } else if (value instanceof Document) {
       writeDocument(key, (Document) value, elType.nestedType, valueList, scratchList);
     } else if (value instanceof Document[]) {
       scratchList.clear();
       writeList.clear();
       for (int j = 0; j < ((Document[]) value).length; j++) {
         writeDocument(key, ((Document[]) value)[j], elType.nestedType, scratchList, writeList);
       }
       valueList.append(scratchList);
     } else if (elType.type == ElementType.TYPE_STRING_ARRAY) {
       writeStringArray((String[]) value);
     } else if ((elType.type == ElementType.TYPE_INTEGER_ARRAY)
         || (elType.type == ElementType.TYPE_INTEGER_WRAPPER_ARRAY)) {
       writeIntArray(value, elType.type);
     } else if ((elType.type == ElementType.TYPE_LONG_ARRAY)
         || (elType.type == ElementType.TYPE_LONG_WRAPPER_ARRAY)) {
       writeLongArray(value, elType.type);
     } else if ((elType.type == ElementType.TYPE_DOUBLE_ARRAY)
         || (elType.type == ElementType.TYPE_DOUBLE_WRAPPER_ARRAY)) {
       writeDoubleArray(value, elType.type);
     } else { // if (type == ElementType.TYPE_BACK_REFERENCE) {
       valueList.append(value);
     }
   }
 }
Пример #10
0
 public boolean containsElement(ElementType elementType) {
   if (type.equals(elementType)
       || (leftChild != null && leftChild.containsElement(elementType))
       || (rightChild != null && rightChild.containsElement(elementType))) {
     return true;
   }
   return false;
 }
  private <A extends Annotation, T> MetaConstraint<?> createMetaConstraint(
      ConstraintType constraint, Class<T> beanClass, Member member, String defaultPackage) {
    @SuppressWarnings("unchecked")
    Class<A> annotationClass = (Class<A>) getClass(constraint.getAnnotation(), defaultPackage);
    AnnotationDescriptor<A> annotationDescriptor = new AnnotationDescriptor<A>(annotationClass);

    if (constraint.getMessage() != null) {
      annotationDescriptor.setValue(MESSAGE_PARAM, constraint.getMessage());
    }
    annotationDescriptor.setValue(GROUPS_PARAM, getGroups(constraint.getGroups(), defaultPackage));
    annotationDescriptor.setValue(
        PAYLOAD_PARAM, getPayload(constraint.getPayload(), defaultPackage));

    for (ElementType elementType : constraint.getElement()) {
      String name = elementType.getName();
      checkNameIsValid(name);
      Class<?> returnType = getAnnotationParameterType(annotationClass, name);
      Object elementValue = getElementValue(elementType, returnType);
      annotationDescriptor.setValue(name, elementValue);
    }

    A annotation;
    try {
      annotation = AnnotationFactory.create(annotationDescriptor);
    } catch (RuntimeException e) {
      throw log.getUnableToCreateAnnotationForConfiguredConstraintException(e);
    }

    java.lang.annotation.ElementType type = java.lang.annotation.ElementType.TYPE;
    if (member instanceof Method) {
      type = java.lang.annotation.ElementType.METHOD;
    } else if (member instanceof Field) {
      type = java.lang.annotation.ElementType.FIELD;
    }

    // we set initially ConstraintOrigin.DEFINED_LOCALLY for all xml configured constraints
    // later we will make copies of this constraint descriptor when needed and adjust the
    // ConstraintOrigin
    ConstraintDescriptorImpl<A> constraintDescriptor =
        new ConstraintDescriptorImpl<A>(
            annotation, constraintHelper, type, ConstraintOrigin.DEFINED_LOCALLY);

    return new MetaConstraint<A>(
        constraintDescriptor, new BeanConstraintLocation(beanClass, member));
  }
  private Object getElementValue(ElementType elementType, Class<?> returnType) {
    removeEmptyContentElements(elementType);

    boolean isArray = returnType.isArray();
    if (!isArray) {
      if (elementType.getContent().size() != 1) {
        throw log.getAttemptToSpecifyAnArrayWhereSingleValueIsExpectedException();
      }
      return getSingleValue(elementType.getContent().get(0), returnType);
    } else {
      List<Object> values = newArrayList();
      for (Serializable s : elementType.getContent()) {
        values.add(getSingleValue(s, returnType.getComponentType()));
      }
      return values.toArray(
          (Object[]) Array.newInstance(returnType.getComponentType(), values.size()));
    }
  }
Пример #13
0
 protected void makeFlat() {
   super.makeFlat();
   setTagName("<layer>");
   setElementRendererCreator(
       new ElementRendererCreator() {
         public ElementRenderer[] createElementRenderer(final Nifty nifty) {
           return nifty.getRootLayerFactory().createPanelRenderer();
         }
       });
 }
Пример #14
0
  public synchronized void elementChanged(Object source, ElementType element, int pos) {

    LinearElement node = root.getVector().get(pos);
    AnimationUtil.move(
        node,
        node.getX() + boxWidth / 3,
        node.getY(),
        true,
        ((ALinearLayoutManager<ElementType>)
                visualizer.getLayoutManagerOfBuffer((ListenableVector<ElementType>) source))
            .getHighlighting(),
        ((FlexibleShape)
                visualizer.getLayoutManagerOfBuffer((ListenableVector<ElementType>) source))
            .getColor());
    node.setObject(element);

    BoundedShape shape = node.getShape();

    try {
      double shapeStretchFactor = Double.parseDouble(element.toString());
      shape.setWidth((int) (boxWidth * (dynamicWidth ? shapeStretchFactor : 1)));
      shape.setHeight((int) (boxHeight * (dynamicHeight ? shapeStretchFactor : 1)));
    } catch (Exception e) {
      shape.setWidth((int) (boxWidth));
      shape.setHeight((int) (boxHeight));
    }

    if (shape instanceof TextShape) ((TextShape) shape).setText(element.toString());
    if (shape instanceof LabelShape) ((LabelShape) shape).setText(element.toString());

    AnimationUtil.move(
        node,
        node.getX() - boxWidth / 3,
        node.getY(),
        true,
        ((ALinearLayoutManager<ElementType>)
                visualizer.getLayoutManagerOfBuffer((ListenableVector<ElementType>) source))
            .getHighlighting(),
        ((FlexibleShape)
                visualizer.getLayoutManagerOfBuffer((ListenableVector<ElementType>) source))
            .getColor());
  }
Пример #15
0
 private void configureAnnotation(AnnotationNode node, Annotation annotation) {
   Class type = annotation.annotationType();
   if (type == Retention.class) {
     Retention r = (Retention) annotation;
     RetentionPolicy value = r.value();
     setRetentionPolicy(value, node);
     node.setMember(
         "value",
         new PropertyExpression(
             new ClassExpression(ClassHelper.makeWithoutCaching(RetentionPolicy.class, false)),
             value.toString()));
   } else if (type == Target.class) {
     Target t = (Target) annotation;
     ElementType[] elements = t.value();
     ListExpression elementExprs = new ListExpression();
     for (ElementType element : elements) {
       elementExprs.addExpression(
           new PropertyExpression(
               new ClassExpression(ClassHelper.ELEMENT_TYPE_TYPE), element.name()));
     }
     node.setMember("value", elementExprs);
   } else {
     Method[] declaredMethods = type.getDeclaredMethods();
     for (int i = 0; i < declaredMethods.length; i++) {
       Method declaredMethod = declaredMethods[i];
       try {
         Object value = declaredMethod.invoke(annotation);
         Expression valueExpression = annotationValueToExpression(value);
         if (valueExpression == null) continue;
         node.setMember(declaredMethod.getName(), valueExpression);
       } catch (IllegalAccessException e) {
       } catch (InvocationTargetException e) {
       }
     }
   }
 }
Пример #16
0
  private OSXHIDElement createElementFromElementProperties(Map element_properties) {
    /*	long size = getLongFromProperties(element_properties, kIOHIDElementSizeKey);
    // ignore elements that can't fit into the 32 bit value field of a hid event
    if (size > 32)
    	return null;*/
    long element_cookie = getLongFromProperties(element_properties, kIOHIDElementCookieKey);
    int element_type_id = getIntFromProperties(element_properties, kIOHIDElementTypeKey);
    ElementType element_type = ElementType.map(element_type_id);
    int min =
        (int)
            getLongFromProperties(element_properties, kIOHIDElementMinKey, AXIS_DEFAULT_MIN_VALUE);
    int max =
        (int)
            getLongFromProperties(element_properties, kIOHIDElementMaxKey, AXIS_DEFAULT_MAX_VALUE);
    /*		long scaled_min = getLongFromProperties(element_properties, kIOHIDElementScaledMinKey, Long.MIN_VALUE);
    long scaled_max = getLongFromProperties(element_properties, kIOHIDElementScaledMaxKey, Long.MAX_VALUE);*/
    UsagePair device_usage_pair = getUsagePair();
    boolean default_relative =
        device_usage_pair != null
            && (device_usage_pair.getUsage() == GenericDesktopUsage.POINTER
                || device_usage_pair.getUsage() == GenericDesktopUsage.MOUSE);

    boolean is_relative =
        getBooleanFromProperties(element_properties, kIOHIDElementIsRelativeKey, default_relative);
    /*		boolean is_wrapping = getBooleanFromProperties(element_properties, kIOHIDElementIsWrappingKey);
    boolean is_non_linear = getBooleanFromProperties(element_properties, kIOHIDElementIsNonLinearKey);
    boolean has_preferred_state = getBooleanFromProperties(element_properties, kIOHIDElementHasPreferredStateKey);
    boolean has_null_state = getBooleanFromProperties(element_properties, kIOHIDElementHasNullStateKey);*/
    int usage = getIntFromProperties(element_properties, kIOHIDElementUsageKey);
    int usage_page = getIntFromProperties(element_properties, kIOHIDElementUsagePageKey);
    UsagePair usage_pair = createUsagePair(usage_page, usage);
    if (usage_pair == null
        || (element_type != ElementType.INPUT_MISC
            && element_type != ElementType.INPUT_BUTTON
            && element_type != ElementType.INPUT_AXIS)) {
      // log.info("element_type = 0x" + element_type + " | usage = " + usage + " | usage_page = " +
      // usage_page);
      return null;
    } else {
      return new OSXHIDElement(
          this, usage_pair, element_cookie, element_type, min, max, is_relative);
    }
  }
Пример #17
0
 private void updateState(String newMap) {
   for (int i = 0, j = 0; i < newMap.length(); i++, j = i / size) {
     raw[i % size][j] = newMap.charAt(i);
     ElementType type = ElementType.parseChar(newMap.charAt(i));
     Element el;
     if (type == ElementType.ME) {
       me = new Tank(ElementType.ME, i % size, j);
       el = me;
     } else if (type == ElementType.TANK) {
       el = new Tank(ElementType.TANK, i % size, j);
       actors.add((Actor) el);
     } else if (type == ElementType.SHELL) {
       el = new Shell(i % size, j);
       actors.add((Actor) el);
     } else {
       el = new Element(type);
     }
     map[i % size][j] = el;
   }
 }
Пример #18
0
  public ElementRule(Node node, IElement parent) {
    parentRule = parent;
    try {
      name = XMLUtil.getTextContent(node, "name", false);
      if (!name.equals("")) {
        hasElementName = true;
      }
      String mode = XMLUtil.getTextContent(node, "@mode", false);
      if (mode.equalsIgnoreCase("off")) {
        isOn = RunMode.OFF;
        return;
      }

      type = ElementType.valueOf(XMLUtil.getTextContent(node, "@type", true, "UNKNOWN", false));
      switch (type) {
        case SCRIPT:
          Node qoNode = XMLUtil.getNode(node, "events/doscript", false);
          doClassName = getClassName(qoNode, "doscript");
          if (doClassName == null) {
            isValid = false;
          }

          break;

        case INCLUDED_PAGE:
          value = XMLUtil.getTextContent(node, "value", false);
          break;

        default:
          break;
      }

    } catch (Exception e) {
      AppEnv.logger.errorLogEntry(e);
      isValid = false;
    }
  }
Пример #19
0
 /**
  * Returns <CODE>true</CODE> if Element is a halogen (F, Cl, Br, I, At).
  *
  * @return <CODE>true</CODE> if Element is a halogen.
  */
 public boolean isHalogen() {
   return elementType.equals(ElementType.HALOGEN);
 }
Пример #20
0
 /**
  * Returns <CODE>true</CODE> if ElementType is a non-metal.
  *
  * @return <CODE>true</CODE> if ElementType is a non-metal.
  */
 public boolean isNonMetal() {
   return elementType.isNonMetal();
 }
Пример #21
0
 /**
  * Returns <CODE>true</CODE> if ElementType is a metalloid.
  *
  * @return <CODE>true</CODE> if ElementType is a metalloid.
  */
 public boolean isMetalloid() {
   return elementType.isMetalloid();
 }