Пример #1
0
 /**
  * apply compound property in textView position 0:left, 1:top, 2:right, 3:bottom - REF : drawable
  * to load as compoundDrawable - BASE64 : decode as base64 and set as CompoundDrawable
  */
 public static void applyCompoundDrawable(View view, DynamicProperty property, int position) {
   if (view instanceof TextView) {
     TextView textView = (TextView) view;
     Drawable[] d = textView.getCompoundDrawables();
     switch (property.type) {
       case REF:
         {
           try {
             d[position] =
                 view.getContext()
                     .getResources()
                     .getDrawable(getDrawableId(view.getContext(), property.getValueString()));
           } catch (Exception e) {
           }
         }
         break;
       case BASE64:
         {
           d[position] = property.getValueBitmapDrawable();
         }
         break;
       case DRAWABLE:
         {
           d[position] = property.getValueGradientDrawable();
         }
         break;
     }
     textView.setCompoundDrawablesWithIntrinsicBounds(d[0], d[1], d[2], d[3]);
   }
 }
Пример #2
0
  /**
   * @param datacenterName The name of the Datacenter
   * @return ManagedObjectReference to the Datacenter
   */
  private static ManagedObjectReference getDatacenterByName(String datacenterName) {
    ManagedObjectReference retVal = null;
    ManagedObjectReference rootFolder = serviceContent.getRootFolder();
    ManagedObjectReference propCollector = serviceContent.getPropertyCollector();
    try {
      TraversalSpec tSpec = getDatacenterTraversalSpec();
      // Create Property Spec
      PropertySpec propertySpec = new PropertySpec();
      propertySpec.setAll(Boolean.FALSE);
      propertySpec.getPathSet().add("name");
      propertySpec.setType("Datacenter");

      // Now create Object Spec
      ObjectSpec objectSpec = new ObjectSpec();
      objectSpec.setObj(rootFolder);
      objectSpec.setSkip(Boolean.TRUE);
      objectSpec.getSelectSet().add(tSpec);

      // Create PropertyFilterSpec using the PropertySpec and ObjectPec
      // created above.
      PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
      propertyFilterSpec.getPropSet().add(propertySpec);
      propertyFilterSpec.getObjectSet().add(objectSpec);

      List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
      listpfs.add(propertyFilterSpec);
      List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);

      if (listobjcont != null) {
        for (ObjectContent oc : listobjcont) {
          ManagedObjectReference mr = oc.getObj();
          String dcnm = null;
          List<DynamicProperty> dps = oc.getPropSet();
          if (dps != null) {
            // Since there is only one property PropertySpec pathset
            // this array contains only one value
            for (DynamicProperty dp : dps) {
              dcnm = (String) dp.getVal();
            }
          }
          // This is done outside of the previous for loop to break
          // out of the loop as soon as the required datacenter is found.
          if (dcnm != null && dcnm.equals(datacenterName)) {
            retVal = mr;
            break;
          }
        }
      }
    } catch (SOAPFaultException sfe) {
      printSoapFaultException(sfe);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return retVal;
  }
Пример #3
0
  /**
   * Retrieves the MOREF of the host.
   *
   * @param hostName :
   * @return
   */
  private static ManagedObjectReference getHostByHostName(String hostName) {
    ManagedObjectReference retVal = null;
    ManagedObjectReference rootFolder = serviceContent.getRootFolder();
    try {
      TraversalSpec tSpec = getHostSystemTraversalSpec();
      // Create Property Spec
      PropertySpec propertySpec = new PropertySpec();
      propertySpec.setAll(Boolean.FALSE);
      propertySpec.getPathSet().add("name");
      propertySpec.setType("HostSystem");

      // Now create Object Spec
      ObjectSpec objectSpec = new ObjectSpec();
      objectSpec.setObj(rootFolder);
      objectSpec.setSkip(Boolean.TRUE);
      objectSpec.getSelectSet().add(tSpec);

      // Create PropertyFilterSpec using the PropertySpec and ObjectPec
      // created above.
      PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
      propertyFilterSpec.getPropSet().add(propertySpec);
      propertyFilterSpec.getObjectSet().add(objectSpec);
      List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
      listpfs.add(propertyFilterSpec);
      List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);

      if (listobjcont != null) {
        for (ObjectContent oc : listobjcont) {
          ManagedObjectReference mr = oc.getObj();
          String hostnm = null;
          List<DynamicProperty> listDynamicProps = oc.getPropSet();
          DynamicProperty[] dps =
              listDynamicProps.toArray(new DynamicProperty[listDynamicProps.size()]);
          if (dps != null) {
            for (DynamicProperty dp : dps) {
              hostnm = (String) dp.getVal();
            }
          }
          if (hostnm != null && hostnm.equals(hostName)) {
            retVal = mr;
            break;
          }
        }
      } else {
        System.out.println("The Object Content is Null");
      }
    } catch (SOAPFaultException sfe) {
      printSoapFaultException(sfe);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return retVal;
  }
Пример #4
0
  /**
   * Demonstrate how to use the PropertyCollector to retrieve properties of a managed object.
   *
   * <p>Prints Virtual machine name and powerstate of all the VMs in the datacenter (Either VC or
   * ESX host).
   */
  public static void getVMInfo() {
    try {
      TraversalSpec tSpec = getVMTraversalSpec();
      // Create Property Spec
      PropertySpec propertySpec = new PropertySpec();
      propertySpec.setAll(Boolean.FALSE);
      propertySpec.setPathSet(new String[] {"name", "runtime.powerState"});
      propertySpec.setType("VirtualMachine");
      PropertySpec[] propertySpecs = new PropertySpec[] {propertySpec};

      // Now create Object Spec
      ObjectSpec objectSpec = new ObjectSpec();
      objectSpec.setObj(ROOT_FOLDER);
      objectSpec.setSkip(Boolean.TRUE);
      objectSpec.setSelectSet(new SelectionSpec[] {tSpec});
      ObjectSpec[] objectSpecs = new ObjectSpec[] {objectSpec};

      // Create PropertyFilterSpec using the PropertySpec and ObjectPec
      // created above.
      PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
      propertyFilterSpec.setPropSet(propertySpecs);
      propertyFilterSpec.setObjectSet(objectSpecs);

      PropertyFilterSpec[] propertyFilterSpecs = new PropertyFilterSpec[] {propertyFilterSpec};

      ObjectContent[] oCont = VIM_PORT.retrieveProperties(PROP_COLLECTOR, propertyFilterSpecs);
      if (oCont != null) {
        // System.out.println("ObjectContent Length : " + oCont.length);
        StringBuilder sb = new StringBuilder();
        for (ObjectContent oc : oCont) {
          DynamicProperty[] dps = oc.getPropSet();
          if (dps != null) {
            for (DynamicProperty dp : dps) {
              if (dp.getName().equalsIgnoreCase("name")) {
                sb.append(dp.getVal());
                sb.append(" : ");
              } else {
                sb.append(dp.getVal());
                sb.append("\n");
              }
              // System.out.println(dp.getName() + " : " +
              // dp.getVal());
            }
          }
        }
        System.out.println(sb.toString());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #5
0
  /**
   * Get the MOR of the Virtual Machine by its name.
   *
   * @param vmName The name of the Virtual Machine
   * @return The Managed Object reference for this VM
   */
  private static ManagedObjectReference getVmByVMname(String vmname) {
    ManagedObjectReference retVal = null;
    try {
      TraversalSpec tSpec = getVMTraversalSpec();
      // Create Property Spec
      PropertySpec propertySpec = new PropertySpec();
      propertySpec.setAll(Boolean.FALSE);
      propertySpec.getPathSet().add("name");
      propertySpec.setType("VirtualMachine");

      // Now create Object Spec
      ObjectSpec objectSpec = new ObjectSpec();
      objectSpec.setObj(rootRef);
      objectSpec.setSkip(Boolean.TRUE);
      objectSpec.getSelectSet().add(tSpec);

      // Create PropertyFilterSpec using the PropertySpec and ObjectPec
      // created above.
      PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
      propertyFilterSpec.getPropSet().add(propertySpec);
      propertyFilterSpec.getObjectSet().add(objectSpec);

      List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
      listpfs.add(propertyFilterSpec);
      List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);

      if (listobjcont != null) {
        for (ObjectContent oc : listobjcont) {
          ManagedObjectReference mr = oc.getObj();
          String vmnm = null;
          List<DynamicProperty> dps = oc.getPropSet();
          if (dps != null) {
            for (DynamicProperty dp : dps) {
              vmnm = (String) dp.getVal();
            }
          }
          if (vmnm != null && vmnm.equals(vmname)) {
            retVal = mr;
            break;
          }
        }
      }
    } catch (SOAPFaultException sfe) {
      printSoapFaultException(sfe);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return retVal;
  }
Пример #6
0
 /** apply minimum Height in view */
 public static void applyMinHeight(View view, DynamicProperty property) {
   if (view != null) {
     if (property.type == DynamicProperty.TYPE.DIMEN) {
       view.setMinimumHeight(property.getValueInt());
     }
   }
 }
Пример #7
0
 /**
  * apply text (used only in TextView) - STRING : the actual string to set in textView - REF : the
  * name of string resource to apply in textView
  */
 public static void applyText(View view, DynamicProperty property) {
   if (view instanceof TextView) {
     switch (property.type) {
       case STRING:
         {
           ((TextView) view).setText(property.getValueString());
         }
         break;
       case REF:
         {
           ((TextView) view).setText(getStringId(view.getContext(), property.getValueString()));
         }
         break;
     }
   }
 }
Пример #8
0
 /** apply ellipsize property in textView */
 public static void applyEllipsize(View view, DynamicProperty property) {
   if (view instanceof TextView) {
     ((TextView) view)
         .setEllipsize(
             TextUtils.TruncateAt.valueOf(property.getValueString().toUpperCase().trim()));
   }
 }
Пример #9
0
 /**
  * apply src property in imageView - REF => name of drawable - BASE64 => decode value as base64
  * image
  */
 public static void applySrc(View view, DynamicProperty property) {
   if (view instanceof ImageView) {
     switch (property.type) {
       case REF:
         {
           ((ImageView) view)
               .setImageResource(getDrawableId(view.getContext(), property.getValueString()));
         }
         break;
       case BASE64:
         {
           ((ImageView) view).setImageBitmap(property.getValueBitmap());
         }
         break;
     }
   }
 }
  /**
   * Get the MOR of the Virtual Machine by its name.
   *
   * @param vmName The name of the Virtual Machine
   * @return The Managed Object reference for this VM
   */
  ManagedObjectReference getVmByVMname(String vmName)
      throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    ManagedObjectReference retVal = null;
    ManagedObjectReference rootFolder = serviceContent.getRootFolder();
    TraversalSpec tSpec = getVMTraversalSpec();
    // Create Property Spec
    PropertySpec propertySpec = new PropertySpec();
    propertySpec.setAll(Boolean.FALSE);
    propertySpec.getPathSet().add("name");
    propertySpec.setType("VirtualMachine");

    // Now create Object Spec
    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(rootFolder);
    objectSpec.setSkip(Boolean.TRUE);
    objectSpec.getSelectSet().add(tSpec);

    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    // created above.
    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getPropSet().add(propertySpec);
    propertyFilterSpec.getObjectSet().add(objectSpec);

    List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
    listpfs.add(propertyFilterSpec);

    List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);

    if (listobjcont != null) {
      for (ObjectContent oc : listobjcont) {
        ManagedObjectReference mr = oc.getObj();
        String vmnm = null;
        List<DynamicProperty> dps = oc.getPropSet();
        if (dps != null) {
          for (DynamicProperty dp : dps) {
            vmnm = (String) dp.getVal();
          }
        }
        if (vmnm != null && vmnm.equals(vmName)) {
          retVal = mr;
          break;
        }
      }
    }
    return retVal;
  }
Пример #11
0
  /**
   * Demonstrate how to use the PropertyCollector to retrieve properties of a managed object when
   * the managed object reference is known.
   *
   * <p>Retrieves the Virtual machine property.
   *
   * @return String property of the VirtualMachine.
   */
  public static Object getVMProperty(ManagedObjectReference mor, String prop) {
    Object retVal = null;
    try {
      // Create Property Spec
      PropertySpec propertySpec = new PropertySpec();
      propertySpec.setAll(Boolean.FALSE);
      // propertySpec.setPathSet(new String[]{"name"});
      propertySpec.setPathSet(new String[] {prop});
      propertySpec.setType("VirtualMachine");
      PropertySpec[] propertySpecs = new PropertySpec[] {propertySpec};

      // Now create Object Spec
      ObjectSpec objectSpec = new ObjectSpec();
      objectSpec.setObj(mor);
      ObjectSpec[] objectSpecs = new ObjectSpec[] {objectSpec};

      // Create PropertyFilterSpec using the PropertySpec and ObjectPec
      // created above.
      PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
      propertyFilterSpec.setPropSet(propertySpecs);
      propertyFilterSpec.setObjectSet(objectSpecs);

      PropertyFilterSpec[] propertyFilterSpecs = new PropertyFilterSpec[] {propertyFilterSpec};

      ObjectContent[] oCont = VIM_PORT.retrieveProperties(PROP_COLLECTOR, propertyFilterSpecs);
      if (oCont != null) {
        // System.out.println("ObjectContent Length : " + oCont.length);
        for (ObjectContent oc : oCont) {
          // DynamicProperty[] dps = oc.getPropSet();
          DynamicProperty[] dps = oc.getPropSet();
          if (dps != null) {
            for (DynamicProperty dp : dps) {
              // System.out.println(dp.getName() + " : " +
              // dp.getVal());
              retVal = dp.getVal();
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return retVal;
  }
Пример #12
0
  private String getDynamicValue(ProjectInfo info, DynamicProperty property) {

    String result = ""; // $NON-NLS-1$

    // e.g: property.value = "utest.report.base.dir, '/',
    // current.projectName"
    // Split using ',' within tokens.

    String value = property.getValue();
    String[] tokens = value.split(","); // $NON-NLS-1$

    for (int i = 0; i < tokens.length; i++) {
      result = result + getRuntimeValue(info, tokens[i].trim());
    }

    getProject().setProperty(property.getName(), result);

    return result;
  }
Пример #13
0
  /** Prints the Host names. */
  private static void printHostProductDetails() {
    try {
      setHostSystemAttributesList();
      TraversalSpec tSpec = getHostSystemTraversalSpec();
      // Create Property Spec
      PropertySpec propertySpec = new PropertySpec();
      propertySpec.setAll(Boolean.FALSE);
      propertySpec.getPathSet().addAll(hostSystemAttributesArr);
      propertySpec.setType("HostSystem");

      // Now create Object Spec
      ObjectSpec objectSpec = new ObjectSpec();
      objectSpec.setObj(rootRef);
      objectSpec.setSkip(Boolean.TRUE);
      objectSpec.getSelectSet().add(tSpec);

      // Create PropertyFilterSpec using the PropertySpec and ObjectPec
      // created above.
      PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
      propertyFilterSpec.getPropSet().add(propertySpec);
      propertyFilterSpec.getObjectSet().add(objectSpec);
      List<PropertyFilterSpec> pfSpecList = new ArrayList<PropertyFilterSpec>(1);
      pfSpecList.add(propertyFilterSpec);

      List<ObjectContent> listobjcont = retrievePropertiesAllObjects(pfSpecList);

      if (listobjcont != null) {
        for (ObjectContent oc : listobjcont) {
          List<DynamicProperty> dpList = oc.getPropSet();
          if (dpList != null) {
            for (DynamicProperty dp : dpList) {
              System.out.println(dp.getName() + " : " + dp.getVal());
            }
          }
          System.out.println("\n\n***************************************************************");
        }
      }
    } catch (SOAPFaultException sfe) {
      printSoapFaultException(sfe);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #14
0
 /** apply the textStyle in textView */
 public static void applyTextStyle(View view, DynamicProperty property) {
   if (view instanceof TextView) {
     switch (property.type) {
       case INTEGER:
         {
           ((TextView) view).setTypeface(null, property.getValueInt());
         }
         break;
     }
   }
 }
Пример #15
0
 /** apply the textSize in textView */
 public static void applyTextSize(View view, DynamicProperty property) {
   if (view instanceof TextView) {
     switch (property.type) {
       case DIMEN:
         {
           ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, property.getValueFloat());
         }
         break;
     }
   }
 }
Пример #16
0
 /** apply the color in textView */
 public static void applyTextColor(View view, DynamicProperty property) {
   if (view instanceof TextView) {
     switch (property.type) {
       case COLOR:
         {
           ((TextView) view).setTextColor(property.getValueColor());
         }
         break;
     }
   }
 }
Пример #17
0
 /** apply adjustBounds property in ImageView */
 public static void applyAdjustBounds(View view, DynamicProperty property) {
   if (view instanceof ImageView) {
     switch (property.type) {
       case BOOLEAN:
         {
           ((ImageView) view).setAdjustViewBounds(property.getValueBoolean());
         }
         break;
     }
   }
 }
Пример #18
0
 /** apply selected in view */
 public static void applyScaleY(View view, DynamicProperty property) {
   if (view != null) {
     switch (property.type) {
       case BOOLEAN:
         {
           view.setScaleY(property.getValueFloat());
         }
         break;
     }
   }
 }
Пример #19
0
 /** apply clickable in view */
 public static void applyClickable(View view, DynamicProperty property) {
   if (view != null) {
     switch (property.type) {
       case BOOLEAN:
         {
           view.setClickable(property.getValueBoolean());
         }
         break;
     }
   }
 }
Пример #20
0
 /**
  * apply gravity property in textView - INTEGER => valus of gravity in @link(Gravity.java) -
  * STRING => name of variable in @lin(Gravity.java)
  */
 public static void applyGravity(View view, DynamicProperty property) {
   if (view instanceof TextView) {
     switch (property.type) {
       case INTEGER:
         {
           ((TextView) view).setGravity(property.getValueInt());
         }
         break;
       case STRING:
         {
           ((TextView) view)
               .setGravity(
                   (Integer)
                       property.getValueInt(
                           Gravity.class, property.getValueString().toUpperCase()));
         }
         break;
     }
   }
 }
Пример #21
0
 /** apply scaleType property in ImageView */
 public static void applyScaleType(View view, DynamicProperty property) {
   if (view instanceof ImageView) {
     switch (property.type) {
       case STRING:
         {
           ((ImageView) view)
               .setScaleType(ImageView.ScaleType.valueOf(property.getValueString().toUpperCase()));
         }
         break;
     }
   }
 }
Пример #22
0
 /** apply padding in view */
 public static void applyPadding(View view, DynamicProperty property) {
   if (view != null) {
     switch (property.type) {
       case DIMEN:
         {
           int padding = property.getValueInt();
           view.setPadding(padding, padding, padding, padding);
         }
         break;
     }
   }
 }
Пример #23
0
 /**
  * apply background in view. possible type : - COLOR - REF => search for that drawable in
  * resources - BASE64 => convert base64 to bitmap and apply in view
  */
 public static void applyBackground(View view, DynamicProperty property) {
   if (view != null) {
     switch (property.type) {
       case COLOR:
         {
           view.setBackgroundColor(property.getValueColor());
         }
         break;
       case REF:
         {
           view.setBackgroundResource(getDrawableId(view.getContext(), property.getValueString()));
         }
         break;
       case BASE64:
         {
           if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
             view.setBackground(property.getValueBitmapDrawable());
           else view.setBackgroundDrawable(property.getValueBitmapDrawable());
         }
         break;
       case DRAWABLE:
         {
           if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
             view.setBackground(property.getValueGradientDrawable());
           else view.setBackgroundDrawable(property.getValueGradientDrawable());
         }
         break;
     }
   }
 }
Пример #24
0
 /** apply orientation property in LinearLayout - INTEGER => 0:Horizontal , 1:Vertical - STRING */
 public static void applyOrientation(View view, DynamicProperty property) {
   if (view instanceof LinearLayout) {
     switch (property.type) {
       case INTEGER:
         {
           ((LinearLayout) view)
               .setOrientation(
                   property.getValueInt() == 0 ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL);
         }
         break;
       case STRING:
         {
           ((LinearLayout) view)
               .setOrientation(
                   property.getValueString().equalsIgnoreCase("HORIZONTAL")
                       ? LinearLayout.HORIZONTAL
                       : LinearLayout.VERTICAL);
         }
         break;
     }
   }
 }
Пример #25
0
 /** apply padding in view */
 public static void applyPadding(View view, DynamicProperty property, int position) {
   if (view != null) {
     switch (property.type) {
       case DIMEN:
         {
           int[] padding =
               new int[] {
                 view.getPaddingLeft(),
                 view.getPaddingTop(),
                 view.getPaddingRight(),
                 view.getPaddingBottom()
               };
           padding[position] = property.getValueInt();
           view.setPadding(padding[0], padding[1], padding[2], padding[3]);
         }
         break;
     }
   }
 }
Пример #26
0
  /**
   * Returns all the MOREFs of the specified type that are present under the container
   *
   * @param folder {@link ManagedObjectReference} of the container to begin the search from
   * @param morefType Type of the managed entity that needs to be searched
   * @return Map of name and MOREF of the managed objects present. If none exist then empty Map is
   *     returned
   * @throws InvalidPropertyFaultMsg
   * @throws RuntimeFaultFaultMsg
   */
  Map<String, ManagedObjectReference> getMOREFsInContainerByType(
      ManagedObjectReference folder, String morefType)
      throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    String PROP_ME_NAME = "name";
    ManagedObjectReference viewManager = serviceContent.getViewManager();
    ManagedObjectReference containerView =
        vimPort.createContainerView(viewManager, folder, Arrays.asList(morefType), true);

    Map<String, ManagedObjectReference> tgtMoref = new HashMap<String, ManagedObjectReference>();

    // Create Property Spec
    PropertySpec propertySpec = new PropertySpec();
    propertySpec.setAll(Boolean.FALSE);
    propertySpec.setType(morefType);
    propertySpec.getPathSet().add(PROP_ME_NAME);

    TraversalSpec ts = new TraversalSpec();
    ts.setName("view");
    ts.setPath("view");
    ts.setSkip(false);
    ts.setType("ContainerView");

    // Now create Object Spec
    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(containerView);
    objectSpec.setSkip(Boolean.TRUE);
    objectSpec.getSelectSet().add(ts);

    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    // created above.
    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getPropSet().add(propertySpec);
    propertyFilterSpec.getObjectSet().add(objectSpec);

    List<PropertyFilterSpec> propertyFilterSpecs = new ArrayList<PropertyFilterSpec>();
    propertyFilterSpecs.add(propertyFilterSpec);

    RetrieveResult rslts =
        vimPort.retrievePropertiesEx(
            serviceContent.getPropertyCollector(), propertyFilterSpecs, new RetrieveOptions());
    List<ObjectContent> listobjcontent = new ArrayList<ObjectContent>();
    if (rslts != null && rslts.getObjects() != null && !rslts.getObjects().isEmpty()) {
      listobjcontent.addAll(rslts.getObjects());
    }
    String token = null;
    if (rslts != null && rslts.getToken() != null) {
      token = rslts.getToken();
    }
    while (token != null && !token.isEmpty()) {
      rslts = vimPort.continueRetrievePropertiesEx(serviceContent.getPropertyCollector(), token);
      token = null;
      if (rslts != null) {
        token = rslts.getToken();
        if (rslts.getObjects() != null && !rslts.getObjects().isEmpty()) {
          listobjcontent.addAll(rslts.getObjects());
        }
      }
    }
    for (ObjectContent oc : listobjcontent) {
      ManagedObjectReference mr = oc.getObj();
      String entityNm = null;
      List<DynamicProperty> dps = oc.getPropSet();
      if (dps != null) {
        for (DynamicProperty dp : dps) {
          entityNm = (String) dp.getVal();
        }
      }
      tgtMoref.put(entityNm, mr);
    }
    return tgtMoref;
  }
Пример #27
0
 /**
  * apply dynamic properties that are not relative with layout in view
  *
  * @param view
  * @param properties
  */
 public static String applyStyleProperties(View view, List<DynamicProperty> properties) {
   String id = "";
   for (DynamicProperty dynProp : properties) {
     switch (dynProp.name) {
       case ID:
         {
           id = dynProp.getValueString();
         }
         break;
       case BACKGROUND:
         {
           applyBackground(view, dynProp);
         }
         break;
       case TEXT:
         {
           applyText(view, dynProp);
         }
         break;
       case TEXTCOLOR:
         {
           applyTextColor(view, dynProp);
         }
         break;
       case TEXTSIZE:
         {
           applyTextSize(view, dynProp);
         }
         break;
       case TEXTSTYLE:
         {
           applyTextStyle(view, dynProp);
         }
         break;
       case PADDING:
         {
           applyPadding(view, dynProp);
         }
         break;
       case PADDING_LEFT:
         {
           applyPadding(view, dynProp, 0);
         }
         break;
       case PADDING_TOP:
         {
           applyPadding(view, dynProp, 1);
         }
         break;
       case PADDING_RIGHT:
         {
           applyPadding(view, dynProp, 2);
         }
         break;
       case PADDING_BOTTOM:
         {
           applyPadding(view, dynProp, 3);
         }
         break;
       case MINWIDTH:
         {
           applyMinWidth(view, dynProp);
         }
         break;
       case MINHEIGTH:
         {
           applyMinHeight(view, dynProp);
         }
         break;
       case ELLIPSIZE:
         {
           applyEllipsize(view, dynProp);
         }
         break;
       case MAXLINES:
         {
           applyMaxLines(view, dynProp);
         }
         break;
       case ORIENTATION:
         {
           applyOrientation(view, dynProp);
         }
         break;
       case GRAVITY:
         {
           applyGravity(view, dynProp);
         }
         break;
       case SRC:
         {
           applySrc(view, dynProp);
         }
         break;
       case SCALETYPE:
         {
           applyScaleType(view, dynProp);
         }
         break;
       case ADJUSTVIEWBOUNDS:
         {
           applyAdjustBounds(view, dynProp);
         }
         break;
       case DRAWABLELEFT:
         {
           applyCompoundDrawable(view, dynProp, 0);
         }
         break;
       case DRAWABLETOP:
         {
           applyCompoundDrawable(view, dynProp, 1);
         }
         break;
       case DRAWABLERIGHT:
         {
           applyCompoundDrawable(view, dynProp, 2);
         }
         break;
       case DRAWABLEBOTTOM:
         {
           applyCompoundDrawable(view, dynProp, 3);
         }
         break;
       case ENABLED:
         {
           applyEnabled(view, dynProp);
         }
         break;
       case SELECTED:
         {
           applySelected(view, dynProp);
         }
         break;
       case CLICKABLE:
         {
           applyClickable(view, dynProp);
         }
         break;
       case SCALEX:
         {
           applyScaleX(view, dynProp);
         }
         break;
       case SCALEY:
         {
           applyScaleY(view, dynProp);
         }
         break;
       case FUNCTION:
         {
           applyFunction(view, dynProp);
         }
         break;
     }
   }
   return id;
 }
Пример #28
0
 /** apply maxLines property in textView */
 public static void applyMaxLines(View view, DynamicProperty property) {
   if (view instanceof TextView) {
     ((TextView) view).setMaxLines(property.getValueInt());
   }
 }
Пример #29
0
  /**
   * apply dynamic properties for layout in view
   *
   * @param view
   * @param properties : layout properties to apply
   * @param viewGroup : parent view
   * @param ids : hashmap of ids <String, Integer> (string as setted in json, int that we use in
   *     layout)
   */
  public static void applyLayoutProperties(
      View view,
      List<DynamicProperty> properties,
      ViewGroup viewGroup,
      HashMap<String, Integer> ids) {
    if (viewGroup == null) return;
    ViewGroup.LayoutParams params = createLayoutParams(viewGroup);

    for (DynamicProperty dynProp : properties) {
      try {
        switch (dynProp.name) {
          case LAYOUT_HEIGHT:
            {
              params.height = dynProp.getValueInt();
            }
            break;
          case LAYOUT_WIDTH:
            {
              params.width = dynProp.getValueInt();
            }
            break;
          case LAYOUT_MARGIN:
            {
              if (params instanceof ViewGroup.MarginLayoutParams) {
                ViewGroup.MarginLayoutParams p = ((ViewGroup.MarginLayoutParams) params);
                p.bottomMargin = p.topMargin = p.leftMargin = p.rightMargin = dynProp.getValueInt();
              }
            }
            break;
          case LAYOUT_MARGINLEFT:
            {
              if (params instanceof ViewGroup.MarginLayoutParams) {
                ((ViewGroup.MarginLayoutParams) params).leftMargin = dynProp.getValueInt();
              }
            }
            break;
          case LAYOUT_MARGINTOP:
            {
              if (params instanceof ViewGroup.MarginLayoutParams) {
                ((ViewGroup.MarginLayoutParams) params).topMargin = dynProp.getValueInt();
              }
            }
            break;
          case LAYOUT_MARGINRIGHT:
            {
              if (params instanceof ViewGroup.MarginLayoutParams) {
                ((ViewGroup.MarginLayoutParams) params).rightMargin = dynProp.getValueInt();
              }
            }
            break;
          case LAYOUT_MARGINBOTTOM:
            {
              if (params instanceof ViewGroup.MarginLayoutParams) {
                ((ViewGroup.MarginLayoutParams) params).bottomMargin = dynProp.getValueInt();
              }
            }
            break;
          case LAYOUT_ABOVE:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.ABOVE, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_BELOW:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.BELOW, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_TOLEFTOF:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.LEFT_OF, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_TORIGHTOF:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.RIGHT_OF, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_TOSTARTOF:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.START_OF, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_TOENDOF:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.END_OF, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_ALIGNBASELINE:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.ALIGN_BASELINE, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_ALIGNLEFT:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.ALIGN_LEFT, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_ALIGNTOP:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.ALIGN_TOP, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_ALIGNRIGHT:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.ALIGN_RIGHT, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_ALIGNBOTTOM:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.ALIGN_BOTTOM, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_ALIGNSTART:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.ALIGN_START, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_ALIGNEND:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params)
                    .addRule(RelativeLayout.ALIGN_END, ids.get(dynProp.getValueString()));
            }
            break;
          case LAYOUT_ALIGNWITHPARENTIFMISSING:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).alignWithParent = dynProp.getValueBoolean();
            }
            break;
          case LAYOUT_ALIGNPARENTTOP:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_TOP);
            }
            break;
          case LAYOUT_ALIGNPARENTBOTTOM:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            }
            break;
          case LAYOUT_ALIGNPARENTLEFT:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            }
            break;
          case LAYOUT_ALIGNPARENTRIGHT:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            }
            break;
          case LAYOUT_ALIGNPARENTSTART:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_START);
            }
            break;
          case LAYOUT_ALIGNPARENTEND:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_END);
            }
            break;
          case LAYOUT_CENTERHORIZONTAL:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.CENTER_HORIZONTAL);
            }
            break;
          case LAYOUT_CENTERVERTICAL:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.CENTER_VERTICAL);
            }
            break;
          case LAYOUT_CENTERINPARENT:
            {
              if (params instanceof RelativeLayout.LayoutParams)
                ((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.CENTER_IN_PARENT);
            }
            break;
          case LAYOUT_GRAVITY:
            {
              switch (dynProp.type) {
                case INTEGER:
                  {
                    if (params instanceof LinearLayout.LayoutParams)
                      ((LinearLayout.LayoutParams) params).gravity = dynProp.getValueInt();
                  }
                  break;
                case STRING:
                  {
                    if (params instanceof LinearLayout.LayoutParams)
                      ((LinearLayout.LayoutParams) params).gravity =
                          (Integer)
                              dynProp.getValueInt(
                                  Gravity.class, dynProp.getValueString().toUpperCase());
                  }
                  break;
              }
            }
            break;
          case LAYOUT_WEIGHT:
            {
              switch (dynProp.type) {
                case FLOAT:
                  {
                    if (params instanceof LinearLayout.LayoutParams)
                      ((LinearLayout.LayoutParams) params).weight = dynProp.getValueFloat();
                  }
                  break;
              }
            }
            break;
        }
      } catch (Exception e) {
      }
    }

    view.setLayoutParams(params);
  }
Пример #30
0
  /** apply generic function in View */
  public static void applyFunction(View view, DynamicProperty property) {

    if (property.type == DynamicProperty.TYPE.JSON) {
      try {
        JSONObject json = property.getValueJSON();

        String functionName = json.getString("function");
        JSONArray args = json.getJSONArray("args");

        Class[] argsClass;
        Object[] argsValue;
        if (args == null) {
          argsClass = new Class[0];
          argsValue = new Object[0];
        } else {
          try {
            List<Class> classList = new ArrayList<>();
            List<Object> valueList = new ArrayList<>();

            int i = 0;
            int count = args.length();
            for (; i < count; i++) {
              JSONObject argJsonObj = args.getJSONObject(i);
              boolean isPrimitive = argJsonObj.has("primitive");
              String className = argJsonObj.getString(isPrimitive ? "primitive" : "class");
              String classFullName = className;
              if (!classFullName.contains(".")) classFullName = "java.lang." + className;
              Class clazz = Class.forName(classFullName);
              if (isPrimitive) {
                Class primitiveType = (Class) clazz.getField("TYPE").get(null);
                classList.add(primitiveType);
              } else {
                classList.add(clazz);
              }

              try {
                valueList.add(getFromJSON(argJsonObj, "value", clazz));
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
            argsClass = classList.toArray(new Class[classList.size()]);
            argsValue = valueList.toArray(new Object[valueList.size()]);
          } catch (Exception e) {
            argsClass = new Class[0];
            argsValue = new Object[0];
          }
        }

        try {
          view.getClass().getMethod(functionName, argsClass).invoke(view, argsValue);
        } catch (SecurityException e) {
        } catch (NoSuchMethodException e) {
          e.printStackTrace();
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }