/**
  * Calculates the index the specified {@link CompositeData} value would have, if it was to be
  * added to this {@link TabularData} instance. This method includes a check that the type of the
  * given value is the same as the row type of this instance, but not a check for existing
  * instances of the given value. The value must also not be <code>null</code>. Possible indices
  * are selected by the {@link TabularType#getIndexNames()} method of this instance's tabular type.
  * The returned indices are the values of the fields in the supplied {@link CompositeData}
  * instance that match the names given in the {@link TabularType}.
  *
  * @param val the {@link CompositeData} value whose index should be calculated.
  * @return the index the value would take on, if it were to be added.
  * @throws NullPointerException if the value is <code>null</code>.
  * @throws InvalidOpenTypeException if the value does not match the row type of this instance.
  */
 public Object[] calculateIndex(CompositeData val) {
   if (!(val.getCompositeType().equals(tabularType.getRowType())))
     throw new InvalidOpenTypeException(
         "The type of the given value " + "does not match the row type " + "of this instance.");
   List<String> indexNames = tabularType.getIndexNames();
   List<String> matchingIndicies = new ArrayList<String>(indexNames.size());
   for (String name : indexNames) matchingIndicies.add(val.get(name).toString());
   return matchingIndicies.toArray();
 }
Example #2
0
  public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    final Composite composite = new Composite(parent, SWT.NULL);
    composite.setFont(parent.getFont());
    composite.setLayout(initGridLayout(new GridLayout(1, false), false));
    composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    // create UI elements
    fNameGroup = new NameGroup(composite, fInitialName, getShell());
    fPHPLocationGroup = new LocationGroup(composite, fNameGroup, getShell());

    CompositeData data = new CompositeData();
    data.setParetnt(composite);
    data.setSettings(getDialogSettings());
    data.setObserver(fPHPLocationGroup);
    fragment =
        (WizardFragment)
            Platform.getAdapterManager()
                .loadAdapter(data, PHPProjectWizardFirstPage.class.getName());

    fVersionGroup = new VersionGroup(composite);
    fLayoutGroup = new LayoutGroup(composite);
    fJavaScriptSupportGroup = new JavaScriptSupportGroup(composite, this);

    fDetectGroup = new DetectGroup(composite, fPHPLocationGroup, fNameGroup);

    // establish connections
    fNameGroup.addObserver(fPHPLocationGroup);
    fDetectGroup.addObserver(fLayoutGroup);

    fPHPLocationGroup.addObserver(fDetectGroup);
    // initialize all elements
    fNameGroup.notifyObservers();
    // create and connect validator
    fPdtValidator = new Validator();

    fNameGroup.addObserver(fPdtValidator);
    fPHPLocationGroup.addObserver(fPdtValidator);

    setControl(composite);
    Dialog.applyDialogFont(composite);

    // set the focus to the project name
    fNameGroup.postSetFocus();

    setHelpContext(composite);
  }
Example #3
0
  /**
   * Compares the specified <var>obj</var> parameter with this <code>CompositeDataSupport</code>
   * instance for equality.
   *
   * <p>Returns <tt>true</tt> if and only if all of the following statements are true:
   *
   * <ul>
   *   <li><var>obj</var> is non null,
   *   <li><var>obj</var> also implements the <code>CompositeData</code> interface,
   *   <li>their composite types are equal
   *   <li>their contents, i.e. (name, value) pairs are equal. If a value contained in the content
   *       is an array, the value comparison is done as if by calling the {@link
   *       j86.java.util.Arrays#deepEquals(Object[], Object[]) deepEquals} method for arrays of
   *       object reference types or the appropriate overloading of {@code Arrays.equals(e1,e2)} for
   *       arrays of primitive types
   * </ul>
   *
   * <p>This ensures that this <tt>equals</tt> method works properly for <var>obj</var> parameters
   * which are different implementations of the <code>CompositeData</code> interface, with the
   * restrictions mentioned in the {@link j86.java.util.Collection#equals(Object) equals} method of
   * the <tt>j86.java.util.Collection</tt> interface.
   *
   * @param obj the object to be compared for equality with this <code>CompositeDataSupport</code>
   *     instance.
   * @return <code>true</code> if the specified object is equal to this <code>CompositeDataSupport
   *     </code> instance.
   */
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    // if obj is not a CompositeData, return false
    if (!(obj instanceof CompositeData)) {
      return false;
    }

    CompositeData other = (CompositeData) obj;

    // their compositeType should be equal
    if (!this.getCompositeType().equals(other.getCompositeType())) {
      return false;
    }

    if (contents.size() != other.values().size()) {
      return false;
    }

    for (Map.Entry<String, Object> entry : contents.entrySet()) {
      Object e1 = entry.getValue();
      Object e2 = other.get(entry.getKey());

      if (e1 == e2) continue;
      if (e1 == null) return false;

      boolean eq =
          e1.getClass().isArray()
              ? Arrays.deepEquals(new Object[] {e1}, new Object[] {e2})
              : e1.equals(e2);

      if (!eq) return false;
    }

    // All tests for equality were successful
    //
    return true;
  }
  private Object unmarshall(Object value) {
    if (value instanceof ObjectName) {
      ObjectName name = (ObjectName) value;

      return new MBean(_server, name);
    } else if (value instanceof ObjectName[]) {
      ObjectName[] names = (ObjectName[]) value;

      MBean[] mbeans = new MBean[names.length];

      for (int i = 0; i < names.length; i++) mbeans[i] = new MBean(_server, names[i]);

      return mbeans;
    } else if (value instanceof CompositeData) {
      CompositeData compositeValue = (CompositeData) value;

      CompositeType type = compositeValue.getCompositeType();

      if (type != null) {
        String typeName = type.getTypeName();

        try {
          ClassLoader loader = Thread.currentThread().getContextClassLoader();

          Class typeClass = Class.forName(typeName, false, loader);

          Method from = typeClass.getMethod("from", new Class[] {CompositeData.class});

          if (from != null) return from.invoke(null, compositeValue);
        } catch (Exception e) {
          log.log(Level.FINER, e.toString(), e);
        }
      }

      return new CompositeDataBean(compositeValue);
    } else return value;
  }
 public String toString() {
   return _data.getCompositeType().toString();
 }
 public Set getKeys() {
   return _data.getCompositeType().keySet();
 }
 /** Returns an attribute. */
 public Object __getField(String attrName) {
   return _data.get(attrName);
 }
 /**
  * Returns true iff this instance of the {@link TabularData} class contains the specified {@link
  * CompositeData} value. In any other circumstance, including if the given value is <code>null
  * </code> or of the incorrect type, according to the {@link TabularType} of this instance, this
  * method returns false.
  *
  * @param val the value to test for.
  * @return true if the value exists.
  */
 public boolean containsValue(CompositeData val) {
   if (val == null) return false;
   if (!(val.getCompositeType().equals(tabularType.getRowType()))) return false;
   return dataMap.containsValue(val);
 }
 public Builder add(String name, CompositeData data) throws OpenDataException {
   if (data != null) return add(name, data.getCompositeType(), data);
   return add(name, SimpleType.VOID, null);
 }
Example #10
0
  /**
   * Sets the TabularData to the AaplicationTable
   *
   * @param data The TabularData to be set to the AaplicationTable
   */
  public void setAlarmTable(TabularData data) throws Exception {
    AgentException ae = null;

    for (Enumeration e = data.enumerate(); e.hasMoreElements(); ) {
      Object[] index = (Object[]) e.nextElement();
      CompositeData comp = data.getRow(index);

      if (table != null)
        entry =
            (AlarmEntry)
                Utilities.getEntryFromCompositeData(table, comp, indexNames, instrClassName);
      else if (vec != null)
        entry =
            (AlarmEntry) Utilities.getEntryFromCompositeData(vec, comp, indexNames, instrClassName);

      if (comp.getOperationType().equals(CompositeData.CREATED)) { // create new entry

        if (entry != null)
          throw new AgentException("Row already exist", CommonUtils.ROWCREATIONFAILED); // no i18n
        entry = new AlarmEntry();

        if (table != null) table.put(index, entry);
        else if (vec != null) vec.addElement(entry);
        for (Enumeration ce = comp.enumerate(); ce.hasMoreElements(); ) {
          String key = (String) ce.nextElement();
          try {
            Utilities.setField(entry, instrClassName, key, comp.getDataItem(key));
          } catch (AgentException aexp) {
            ae = aexp;
          }
        }
      } else if (comp.getOperationType().equals(CompositeData.DELETED)) {

        if (table != null) {
          for (Enumeration en = table.keys(); en.hasMoreElements(); ) {
            Object keyObject = en.nextElement();
            if (entry.equals(table.get(keyObject))) table.remove(keyObject);
          }
        } else if (vec != null)
          if (!vec.removeElement(entry))
            throw new AgentException("Invalid Index", CommonUtils.INVALIDINDEX); // no i18n
        data.deleteRow(index);
      } else if (comp.getOperationType().equals(CompositeData.MODIFIED)) {

        for (Enumeration ce = comp.enumerate(); ce.hasMoreElements(); ) {
          String key = (String) ce.nextElement();
          if (!comp.isModified(key)) continue;
          try {

            Utilities.setField(entry, instrClassName, key, comp.getDataItem(key));
          } catch (AgentException aexp) {
            ae = aexp;
          }
        }
      }

      comp.setOperationType(CompositeData.NOCHANGES);
    }

    if (ae != null) throw ae;
  }