コード例 #1
1
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
  /**
   * If the outbound level is BINARY, convert the string field to binary, then pad to the left with
   * the appropriate number of zero bits to reach a number of bits specified by the bitLength
   * attribute of the TDT definition file.
   */
  private void binaryPadding(Map<String, String> extraparams, Field tdtfield) {
    String fieldname = tdtfield.getName();
    int reqbitlength = tdtfield.getBitLength();
    String value;

    String binaryValue = fieldToBinary(tdtfield, extraparams);
    if (binaryValue.length() < reqbitlength) {
      int extraBitLength = reqbitlength - binaryValue.length();

      StringBuilder zeroPaddedBinaryValue = new StringBuilder("");
      for (int i = 0; i < extraBitLength; i++) {
        zeroPaddedBinaryValue.append("0");
      }
      zeroPaddedBinaryValue.append(binaryValue);
      value = zeroPaddedBinaryValue.toString();
    } else {
      if (binaryValue.length() > reqbitlength)
        throw new TDTException(
            "Binary value ["
                + binaryValue
                + "] for field "
                + fieldname
                + " exceeds maximum allowed "
                + reqbitlength
                + " bits.  Decimal value was "
                + extraparams.get(fieldname));

      value = binaryValue;
    }
    extraparams.put(fieldname, value);
  }
コード例 #2
0
ファイル: Library.java プロジェクト: pwansch/iTradeTunes
  private AlbumBean addOrUpdateAlbum(
      Map<Integer, AlbumBean> map, SongBean song, boolean albumOnly) {
    // Add an album bean
    if (song != null && song.getAlbum() != null) {
      int hashCode = (song.getAlbum() + (albumOnly ? "" : '\uFFFF' + song.getArtist())).hashCode();

      // Check if the album beam already exists
      AlbumBean album = map.get(hashCode);
      if (album == null) {
        album = new AlbumBean();
        album.setAlbum(song.getAlbum());
        map.put(hashCode, album);
      }

      // Update the album properties
      try {
        // Add the track id to the album bean
        album.addSong(song);
        album.incTracks();
        album.setArtist(song.getArtist());
        album.setGenre(song.getGenre());
        album.setDisc_Count(song.getDisc_Count());
      } catch (LibraryException le) {
        // There was an error adding the song to this album, remove it
        map.remove(hashCode);

        // Add to warning message
        warningList.add(song.getName() + " " + le);
      }

      return album;
    }

    return null;
  }
コード例 #3
0
 public static final Map parseFrame(Node node) {
   NodeList bones = node.getChildNodes();
   Map bone_infos = new HashMap();
   for (int i = 0; i < bones.getLength(); i++) {
     Node bone = bones.item(i);
     if (bone.getNodeName().equals("transform")) {
       String name = bone.getAttributes().getNamedItem("name").getNodeValue();
       float[] matrix = new float[16];
       matrix[0 * 4 + 0] = getAttrFloat(bone, "m00");
       matrix[0 * 4 + 1] = getAttrFloat(bone, "m01");
       matrix[0 * 4 + 2] = getAttrFloat(bone, "m02");
       matrix[0 * 4 + 3] = getAttrFloat(bone, "m03");
       matrix[1 * 4 + 0] = getAttrFloat(bone, "m10");
       matrix[1 * 4 + 1] = getAttrFloat(bone, "m11");
       matrix[1 * 4 + 2] = getAttrFloat(bone, "m12");
       matrix[1 * 4 + 3] = getAttrFloat(bone, "m13");
       matrix[2 * 4 + 0] = getAttrFloat(bone, "m20");
       matrix[2 * 4 + 1] = getAttrFloat(bone, "m21");
       matrix[2 * 4 + 2] = getAttrFloat(bone, "m22");
       matrix[2 * 4 + 3] = getAttrFloat(bone, "m23");
       matrix[3 * 4 + 0] = getAttrFloat(bone, "m30");
       matrix[3 * 4 + 1] = getAttrFloat(bone, "m31");
       matrix[3 * 4 + 2] = getAttrFloat(bone, "m32");
       matrix[3 * 4 + 3] = getAttrFloat(bone, "m33");
       bone_infos.put(name, matrix);
     }
   }
   return bone_infos;
 }
コード例 #4
0
 private void addTagToMethod(
     Map<String, MethodInfo> methods, String tagText, MethodTagType tagType) {
   MethodInfo mi = methods.get(methodName);
   if (mi == null) {
     mi = new MethodInfo();
     methods.put(methodName, mi);
   }
   if (tagType == MethodTagType.OMIT_FROM_UI) {
     mi.omitFromUI = true;
     return;
   }
   String[] tagParts =
       Iterables.toArray(
           Splitter.on(WHITESPACE_PATTERN)
               .trimResults()
               .omitEmptyStrings()
               .limit(2)
               .split(tagText),
           String.class);
   if (tagParts.length == 2) {
     if (tagType == MethodTagType.DESCRIPTION) {
       mi.descriptions.put(tagParts[0], tagParts[1]);
     } else {
       mi.useSchemas.put(tagParts[0], tagParts[1]);
     }
   }
 }
コード例 #5
0
ファイル: MetatypeTest.java プロジェクト: vikchilu/bnd
 public static void testConfigurableForNonPrimitives() {
   Map<String, String> p = new HashMap<String, String>();
   C config = Configurable.createConfigurable(C.class, p);
   assertNull(config.port());
   p.put("port", "10");
   config = Configurable.createConfigurable(C.class, p);
   assertEquals(Integer.valueOf(10), config.port()); // property port is
   // not set
 }
コード例 #6
0
ファイル: Parser.java プロジェクト: vadeq/repotest
 private void addDefaultValues(Map attributes, Map mappings) {
   if (mappings == null) return;
   Iterator i = mappings.entrySet().iterator();
   while (i.hasNext()) {
     Map.Entry e = (Map.Entry) i.next();
     TagMap.AttributeMapping m = (TagMap.AttributeMapping) e.getValue();
     if (null != m && null != m.getDefaultValue() && null == attributes.get(m.getPropertyName()))
       attributes.put(m.getPropertyName(), m.getDefaultValue());
   }
 }
コード例 #7
0
 /*
  * XXX I hope this methos is not needed in this form
  */
 public Map getKnownProjectsAndVersions(ICVSRepositoryLocation location) {
   Map knownTags = new HashMap();
   RepositoryRoot root = getRepositoryRootFor(location);
   String[] paths = root.getKnownRemotePaths();
   for (int i = 0; i < paths.length; i++) {
     String path = paths[i];
     Set result = new HashSet();
     result.addAll(Arrays.asList(root.getAllKnownTags(path)));
     knownTags.put(path, result);
   }
   return knownTags;
 }
コード例 #8
0
ファイル: XMLUtils.java プロジェクト: ghys/orbeon-forms
  /**
   * Get a SAXParserFactory to build combinations of validating and XInclude-aware SAXParser.
   *
   * @param parserConfiguration parser configuration
   * @return the SAXParserFactory
   */
  public static synchronized SAXParserFactory getSAXParserFactory(
      XMLUtils.ParserConfiguration parserConfiguration) {

    final String key = parserConfiguration.getKey();

    final SAXParserFactory existingFactory = parserFactories.get(key);
    if (existingFactory != null) return existingFactory;

    final SAXParserFactory newFactory = createSAXParserFactory(parserConfiguration);
    parserFactories.put(key, newFactory);
    return newFactory;
  }
コード例 #9
0
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
  /**
   * The convert method translates a String input to a specified outbound level of the same coding
   * scheme. For example, the input string value may be a tag-encoding URI and the outbound level
   * specified by string outboundlevel may be BINARY, in which case the return value is a binary
   * representation expressed as a string.
   *
   * @param input the identifier to be converted.
   * @param inputParameters additional parameters which need to be provided because they cannot
   *     always be determined from the input value alone. Examples include the taglength,
   *     companyprefixlength and filter values.
   * @param outputLevel the outbound level required for the ouput. Permitted values include BINARY,
   *     TAG_ENCODING, PURE_IDENTITY, LEGACY and ONS_HOSTNAME.
   * @return the identifier converted to the output level.
   */
  public String convert(
      String input, Map<String, String> inputParameters, LevelTypeList outputLevel) {

    TagLengthList tagLength = null;
    if (inputParameters.containsKey("taglength")) {
      // in principle, the user should provide a
      // TagLengthList object in the parameter list.
      String s = inputParameters.get("taglength");
      tagLength = TagLengthList.valueOf(s);
    }

    PrefixMatch match = findPrefixMatch(input, tagLength);

    return convertLevel(match.getScheme(), match.getLevel(), input, inputParameters, outputLevel);
  }
コード例 #10
0
 private void broadcastRepositoryChange(RepositoryRoot root) {
   if (notificationLevel == 0) {
     broadcastRepositoriesChanged(new ICVSRepositoryLocation[] {root.getRoot()});
   } else {
     changedRepositories.put(root.getRoot().getLocation(false), root.getRoot());
   }
 }
コード例 #11
0
  public Set<String> getOperatorClasses(String parent, String searchTerm)
      throws ClassNotFoundException {
    if (CollectionUtils.isEmpty(operatorClassNames)) {
      loadOperatorClass();
    }
    if (parent == null) {
      parent = Operator.class.getName();
    } else {
      if (!typeGraph.isAncestor(Operator.class.getName(), parent)) {
        throw new IllegalArgumentException("Argument must be a subclass of Operator class");
      }
    }

    Set<String> filteredClass =
        Sets.filter(
            operatorClassNames,
            new Predicate<String>() {
              @Override
              public boolean apply(String className) {
                OperatorClassInfo oci = classInfo.get(className);
                return oci == null || !oci.tags.containsKey("@omitFromUI");
              }
            });

    if (searchTerm == null && parent.equals(Operator.class.getName())) {
      return filteredClass;
    }

    if (searchTerm != null) {
      searchTerm = searchTerm.toLowerCase();
    }

    Set<String> result = new HashSet<String>();
    for (String clazz : filteredClass) {
      if (parent.equals(Operator.class.getName()) || typeGraph.isAncestor(parent, clazz)) {
        if (searchTerm == null) {
          result.add(clazz);
        } else {
          if (clazz.toLowerCase().contains(searchTerm)) {
            result.add(clazz);
          } else {
            OperatorClassInfo oci = classInfo.get(clazz);
            if (oci != null) {
              if (oci.comment != null && oci.comment.toLowerCase().contains(searchTerm)) {
                result.add(clazz);
              } else {
                for (Map.Entry<String, String> entry : oci.tags.entrySet()) {
                  if (entry.getValue().toLowerCase().contains(searchTerm)) {
                    result.add(clazz);
                    break;
                  }
                }
              }
            }
          }
        }
      }
    }
    return result;
  }
コード例 #12
0
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
 /**
  * Returns the value of a specified fieldname from the specified hashmap and returns an integer
  * value or throws an exception if the value is not an integer
  */
 private int getIntValue(String fieldname, Map<String, String> extraparams) {
   Matcher checkint = Pattern.compile("^\\d+$").matcher(fieldname);
   int rv;
   if (checkint.matches()) {
     rv = Integer.parseInt(fieldname);
   } else {
     if (extraparams.containsKey(fieldname)) {
       rv = Integer.parseInt(extraparams.get(fieldname));
     } else {
       rv = -1;
       throw new TDTException(
           "No integer value for " + fieldname + " can be found - check extraparams");
     }
   }
   return rv;
 }
コード例 #13
0
 public RepositoryRoot getRepositoryRootFor(ICVSRepositoryLocation location) {
   RepositoryRoot root = (RepositoryRoot) repositoryRoots.get(location.getLocation(false));
   if (root == null) {
     root = new RepositoryRoot(location);
     add(root);
   }
   return root;
 }
コード例 #14
0
ファイル: Parser.java プロジェクト: vadeq/repotest
 private void checkForRequiredAttributes(String tagName, Map attributes, Map mappings)
     throws ParserException {
   if (mappings == null) return;
   Iterator i = mappings.entrySet().iterator();
   while (i.hasNext()) {
     Map.Entry e = (Map.Entry) i.next();
     TagMap.AttributeMapping m = (TagMap.AttributeMapping) e.getValue();
     if (null != m && m.getRequired())
       if (null == mappings || null == attributes.get(m.getPropertyName()))
         throw new ParserException(
             "An attribute that maps to property name: "
                 + m.getPropertyName()
                 + " is required and was not specified for tag:"
                 + tagName
                 + "!");
   }
 }
コード例 #15
0
 private static final Bone buildBone(
     byte index, Map bone_children_map, String bone_name, Map name_to_bone_map) {
   List children_list = (List) bone_children_map.get(bone_name);
   Bone[] children_array;
   if (children_list != null) {
     children_array = new Bone[children_list.size()];
     for (int i = 0; i < children_array.length; i++) {
       String child_name = (String) children_list.get(i);
       Bone child_bone = buildBone(index, bone_children_map, child_name, name_to_bone_map);
       children_array[i] = child_bone;
       index = (byte) (child_bone.getIndex() + 1);
     }
   } else children_array = new Bone[0];
   Bone bone = new Bone(bone_name, index, children_array);
   name_to_bone_map.put(bone_name, bone);
   return bone;
 }
コード例 #16
0
ファイル: Parser.java プロジェクト: vadeq/repotest
 private Map attributeMap(String tagName, Attributes atts) throws ParserException {
   if (null == tagName || null == atts) return null;
   Map mapping = null;
   try {
     mapping = (Map) attributeMaps.get(tagName);
   } catch (Exception e) {
     throw new ParserException(
         "Typecast error, unknown element found in attribute list mappings! " + e.getMessage());
   }
   if (null == mapping) return null;
   Map resultMapping = new HashMap();
   for (int i = 0; i < atts.getLength(); i++) {
     String xmlName = atts.getQName(i);
     String value = atts.getValue(i);
     TagMap.AttributeMapping aMap = null;
     try {
       aMap = (TagMap.AttributeMapping) mapping.get(xmlName);
     } catch (Exception e) {
       throw new ParserException(
           "Typecast error, unknown element found in property mapping! " + e.getMessage());
     }
     if (null == aMap)
       throw new ParserException(
           "No attribute mapping specified for attribute: " + xmlName + " in tag: " + tagName);
     String propertyName = aMap.getPropertyName();
     try {
       resultMapping.put(propertyName, aMap.convertValue(value));
     } catch (Exception e) {
       throw new ParserException(
           "Can not convert given value: \""
               + value
               + "\" to specified type: "
               + aMap.getType()
               + " for attribute: "
               + xmlName
               + " in tag: "
               + tagName
               + "! "
               + e.getMessage());
     }
   }
   checkForRequiredAttributes(tagName, resultMapping, mapping);
   addDefaultValues(resultMapping, mapping);
   return resultMapping;
 }
コード例 #17
0
 /**
  * Run the given runnable, waiting until the end to perform a refresh
  *
  * @param runnable
  * @param monitor
  */
 public void run(IRunnableWithProgress runnable, IProgressMonitor monitor)
     throws InvocationTargetException, InterruptedException {
   try {
     notificationLevel++;
     runnable.run(monitor);
   } finally {
     notificationLevel = Math.max(0, notificationLevel - 1);
     if (notificationLevel == 0) {
       try {
         Collection roots = changedRepositories.values();
         broadcastRepositoriesChanged(
             (ICVSRepositoryLocation[]) roots.toArray(new ICVSRepositoryLocation[roots.size()]));
       } finally {
         changedRepositories.clear();
       }
     }
   }
 }
コード例 #18
0
ファイル: XMLUtils.java プロジェクト: ghys/orbeon-forms
 /**
  * Associated one DocumentBuilder per thread. This is so we avoid synchronizing (parse() for
  * example may take a lot of time on a DocumentBuilder) or creating DocumentBuilder instances all
  * the time. Since typically in an app server we work with a thread pool, not too many instances
  * of DocumentBuilder should be created.
  */
 private static DocumentBuilder getThreadDocumentBuilder() {
   Thread thread = Thread.currentThread();
   DocumentBuilder documentBuilder =
       (documentBuilders == null) ? null : documentBuilders.get(thread);
   // Try a first test outside the synchronized block
   if (documentBuilder == null) {
     synchronized (documentBuilderFactory) {
       // Redo the test within the synchronized block
       documentBuilder = (documentBuilders == null) ? null : documentBuilders.get(thread);
       if (documentBuilder == null) {
         if (documentBuilders == null) documentBuilders = new HashMap<Thread, DocumentBuilder>();
         documentBuilder = newDocumentBuilder();
         documentBuilders.put(thread, documentBuilder);
       }
     }
   }
   return documentBuilder;
 }
コード例 #19
0
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
  /** pad a value according the field definition. */
  private void padField(Map<String, String> extraparams, Field field) {
    String name = field.getName();
    String value = extraparams.get(name);
    PadDirectionList padDir = field.getPadDir();
    int requiredLength = field.getLength();

    // assert value != null;
    if (value == null) return;

    String padCharString = field.getPadChar();
    // if no pad char specified, don't attempt padding
    if (padCharString == null) return;
    assert padCharString.length() > 0;
    char padChar = padCharString.charAt(0);

    StringBuilder buf = new StringBuilder(requiredLength);
    if (padDir == PadDirectionList.LEFT) {
      for (int i = 0; i < requiredLength - value.length(); i++) buf.append(padChar);
      buf.append(value);
    } else if (padDir == PadDirectionList.RIGHT) {
      buf.append(value);
      for (int i = 0; i < requiredLength - value.length(); i++) buf.append(padChar);
    }
    assert buf.length() == requiredLength;
    if (requiredLength != value.length()) {
      // System.out.println("    updated " + name + " to '" + buf + "'");
      extraparams.put(name, buf.toString());
    }
    /*
    else {
        StringBuilder mybuf = new StringBuilder();
        for (int i = 0; i < value.length(); i++) {
    	if (i > 0)
    	    mybuf.append(',');
    	mybuf.append('\'');
    	mybuf.append(value.charAt(i));
    	mybuf.append('\'');
        }


        System.out.println("    field " + name + " not padded as " + mybuf.toString() + " is already " + requiredLength + " characters long");
    }
    */
  }
コード例 #20
0
ファイル: readDocument.java プロジェクト: kmizu/spnuts
 protected Object exec(Object[] args, Context context) {
   int nargs = args.length;
   Object schema = null;
   Map properties = null;
   Object errorHandler;
   Object input;
   switch (nargs) {
     case 4:
       schema = args[3];
     case 3:
       properties = (Map) args[2];
     case 2:
       errorHandler = args[1];
       break;
     case 1:
       errorHandler = Util.getDefaultErrorHandler(context);
       break;
     default:
       undefined(args, context);
       return null;
   }
   input = args[0];
   if (properties == null) {
     properties = new LinkedHashMap();
   }
   if (schema != null) {
     properties.put(Util.KEY_SCHEMA, schema);
   }
   DocumentBuilder builder = Util.getDocumentBuilder(properties, context);
   if (errorHandler != null) {
     builder.setErrorHandler((ErrorHandler) Util.contentHandler(errorHandler, context));
   }
   try {
     return builder.parse(Util.inputSource(input, context));
   } catch (IOException e1) {
     throw new PnutsException(e1, context);
   } catch (SAXException e2) {
     throw new PnutsException(e2, context);
   }
 }
コード例 #21
0
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
  /**
   * Returns a string built using a particular grammar. Single-quotes strings are counted as literal
   * strings, whereas all other strings appearing in the grammar require substitution with the
   * corresponding value from the extraparams hashmap.
   */
  private String buildGrammar(String grammar, Map<String, String> extraparams) {
    StringBuilder outboundstring = new StringBuilder();
    String[] fields = Pattern.compile("\\s+").split(grammar);
    for (int i = 0; i < fields.length; i++) {
      if (fields[i].substring(0, 1).equals("'")) {
        outboundstring.append(fields[i].substring(1, fields[i].length() - 1));
      } else {
        outboundstring.append(extraparams.get(fields[i]));
      }
    }

    return outboundstring.toString();
  }
コード例 #22
0
 private static final Map[] parseAnimation(Node node) {
   NodeList frames = node.getChildNodes();
   Map anim_infos_map = new HashMap();
   for (int i = 0; i < frames.getLength(); i++) {
     Node frame = frames.item(i);
     if (frame.getNodeName().equals("frame")) {
       int frame_index = getAttrInt(frame, "index");
       assert frame_index >= 0;
       anim_infos_map.put(new Integer(frame_index), parseFrame(frame));
     }
   }
   Map[] anim_infos = new Map[anim_infos_map.size()];
   Iterator it = anim_infos_map.keySet().iterator();
   while (it.hasNext()) {
     Integer frame_index_obj = (Integer) it.next();
     Map frame = (Map) anim_infos_map.get(frame_index_obj);
     int index = frame_index_obj.intValue();
     assert anim_infos[index] == null;
     anim_infos[index] = frame;
   }
   return anim_infos;
 }
コード例 #23
0
 private static final Skeleton parseSkeleton(Node skel_node) {
   Map name_to_bone_map = new HashMap();
   Map initial_pose =
       AnimationLoader.parseFrame(ConvertToBinary.getNodeByName("init_pose", skel_node));
   NodeList bone_list = ConvertToBinary.getNodeByName("bones", skel_node).getChildNodes();
   Map bone_parent_map = new HashMap();
   for (int i = 0; i < bone_list.getLength(); i++) {
     Node bone_node = bone_list.item(i);
     if (bone_node.getNodeName().equals("bone")) {
       String bone_name = bone_node.getAttributes().getNamedItem("name").getNodeValue();
       String bone_parent_name = bone_node.getAttributes().getNamedItem("parent").getNodeValue();
       // System.out.println("bone name = " + bone_name + " parent name = " + bone_parent_name);
       bone_parent_map.put(bone_name, bone_parent_name);
     }
   }
   Map bone_children_map = new HashMap();
   Iterator it = bone_parent_map.keySet().iterator();
   String root = null;
   while (it.hasNext()) {
     String name = (String) it.next();
     String parent = (String) bone_parent_map.get(name);
     if (bone_parent_map.get(parent) == null) {
       if (root != null) {
         System.out.println(
             "WARNING: Multiple roots in skeleton, root = "
                 + root
                 + ", additional root = "
                 + name);
         parent = root;
         bone_parent_map.put(name, parent);
       } else root = name;
     }
     List parent_children = (List) bone_children_map.get(parent);
     if (parent_children == null) {
       parent_children = new ArrayList();
       bone_children_map.put(parent, parent_children);
     }
     parent_children.add(name);
   }
   Bone bone_root = buildBone((byte) 0, bone_children_map, root, name_to_bone_map);
   return new Skeleton(bone_root, initial_pose, name_to_bone_map);
 }
コード例 #24
0
  private void putFieldDescription(CompactFieldNode field, JSONObject port, TypeGraphVertex tgv)
      throws JSONException {
    OperatorClassInfo oci = classInfo.get(tgv.typeName);
    if (oci != null) {
      String fieldDesc = oci.fields.get(field.getName());
      if (fieldDesc != null) {
        port.put("description", fieldDesc);
        return;
      }
    }

    for (TypeGraphVertex ancestor : tgv.getAncestors()) {
      putFieldDescription(field, port, ancestor);
    }
  }
コード例 #25
0
  private OperatorClassInfo getOperatorClassWithGetterSetter(
      TypeGraphVertex tgv, String setterName, String getterName) {
    OperatorClassInfo oci = classInfo.get(tgv.typeName);
    if (oci != null
        && (oci.getMethods.containsKey(getterName) || oci.setMethods.containsKey(setterName))) {
      return oci;
    } else {
      if (tgv.getAncestors() != null) {
        for (TypeGraphVertex ancestor : tgv.getAncestors()) {
          return getOperatorClassWithGetterSetter(ancestor, setterName, getterName);
        }
      }
    }

    return null;
  }
コード例 #26
0
 /** Get the list of known version tags for a given project. */
 public CVSTag[] getKnownTags(ICVSRepositoryLocation location, int tagType) {
   Set result = new HashSet();
   RepositoryRoot root = (RepositoryRoot) repositoryRoots.get(location.getLocation(false));
   if (root != null) {
     String[] paths = root.getKnownRemotePaths();
     for (int i = 0; i < paths.length; i++) {
       String path = paths[i];
       CVSTag[] tags = root.getAllKnownTags(path);
       for (int j = 0; j < tags.length; j++) {
         CVSTag tag = tags[j];
         if (tag.getType() == tagType) result.add(tag);
       }
     }
   }
   return (CVSTag[]) result.toArray(new CVSTag[0]);
 }
コード例 #27
0
ファイル: TDTEngine.java プロジェクト: max90727/fosstrak
  /**
   * Converts the value of a specified fieldname from the extraparams map into binary, either
   * handling it as a large integer or taking into account the compaction of each ASCII byte that is
   * specified in the TDT definition file for that particular field
   */
  private String fieldToBinary(Field field, Map<String, String> extraparams) {
    // really need an index to find field number given fieldname;

    String fieldname = field.getName();
    String value = extraparams.get(fieldname);
    CompactionMethodList compaction = field.getCompaction();

    if (compaction == null) {
      value = dec2bin(value);
    } else {
      if (compaction == CompactionMethodList.VALUE_5) {
        value = uppercasefive2bin(value);
      } else if (compaction == CompactionMethodList.VALUE_4) {
        value = alphanumsix2bin(value);
      } else if (compaction == CompactionMethodList.VALUE_3) {
        value = asciiseven2bin(value);
      } else if (compaction == CompactionMethodList.VALUE_2) {
        value = bytestring2bin(value);
      } else throw new Error("Unsupported compaction " + compaction);
    }

    return value;
  }
コード例 #28
0
  private JSONArray getClassProperties(Class<?> clazz, int level) throws IntrospectionException {
    JSONArray arr = new JSONArray();
    TypeDiscoverer td = new TypeDiscoverer();
    try {
      for (PropertyDescriptor pd : Introspector.getBeanInfo(clazz).getPropertyDescriptors()) {
        Method readMethod = pd.getReadMethod();
        if (readMethod != null) {
          if (readMethod.getDeclaringClass() == java.lang.Enum.class) {
            // skip getDeclaringClass
            continue;
          } else if ("class".equals(pd.getName())) {
            // skip getClass
            continue;
          }
        } else {
          // yields com.datatorrent.api.Context on JDK6 and
          // com.datatorrent.api.Context.OperatorContext with JDK7
          if ("up".equals(pd.getName())
              && com.datatorrent.api.Context.class.isAssignableFrom(pd.getPropertyType())) {
            continue;
          }
        }
        // LOG.info("name: " + pd.getName() + " type: " + pd.getPropertyType());

        Class<?> propertyType = pd.getPropertyType();
        if (propertyType != null) {
          JSONObject propertyObj = new JSONObject();
          propertyObj.put("name", pd.getName());
          propertyObj.put("canGet", readMethod != null);
          propertyObj.put("canSet", pd.getWriteMethod() != null);
          if (readMethod != null) {
            for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
              OperatorClassInfo oci = classInfo.get(c.getName());
              if (oci != null) {
                MethodInfo getMethodInfo = oci.getMethods.get(readMethod.getName());
                if (getMethodInfo != null) {
                  addTagsToProperties(getMethodInfo, propertyObj);
                  break;
                }
              }
            }
            // type can be a type symbol or parameterized type
            td.setTypeArguments(clazz, readMethod.getGenericReturnType(), propertyObj);
          } else {
            if (pd.getWriteMethod() != null) {
              td.setTypeArguments(
                  clazz, pd.getWriteMethod().getGenericParameterTypes()[0], propertyObj);
            }
          }
          // if (!propertyType.isPrimitive() && !propertyType.isEnum() && !propertyType.isArray() &&
          // !propertyType.getName().startsWith("java.lang") && level < MAX_PROPERTY_LEVELS) {
          //  propertyObj.put("properties", getClassProperties(propertyType, level + 1));
          // }
          arr.put(propertyObj);
        }
      }
    } catch (JSONException ex) {
      throw new RuntimeException(ex);
    }
    return arr;
  }
コード例 #29
0
ファイル: ConfigEditor.java プロジェクト: kaine-shaman/jcfg
  private void processTxt(Node operation) {
    List<Node> targets = getChildNodes(operation, "target");
    List<Node> optionNodes = getChildNodes(operation, "opt");
    List<Node> separatorNode = getChildNodes(operation, "separator");
    if (targets.isEmpty() || optionNodes.isEmpty()) {
      return;
    }
    String defaultSeparator = "=";
    String globalSeparator = defaultSeparator;
    if (!separatorNode.isEmpty()) {
      globalSeparator = separatorNode.get(0).getTextContent();
      if (globalSeparator.length() != 1) {
        globalSeparator = defaultSeparator;
      }
    }
    Map<String, String> options = new HashMap<String, String>();
    Map<String, String> processedOptions = new HashMap<String, String>();
    for (int i = 0; i < optionNodes.size(); i++) {
      Node option = optionNodes.get(i);
      String name = option.getAttributes().getNamedItem("name").getNodeValue();
      String value = option.getTextContent();
      if (options.containsKey(name)) {
        options.remove(name);
      }
      options.put(name, value);
    }
    for (int t = 0; t < targets.size(); t++) {
      File target = new File(absolutePath(targets.get(t).getTextContent()));
      File tmpFile = new File(Utils.timestamp());
      BufferedWriter bw = null;
      BufferedReader br = null;
      try {
        Node separatorAttr = targets.get(t).getAttributes().getNamedItem("separator");
        String separator = (separatorAttr == null) ? globalSeparator : separatorAttr.getNodeValue();
        if (separator.length() != 1) {
          separator = globalSeparator;
        }
        bw = new BufferedWriter(new FileWriter(tmpFile));
        if (target.exists()) {
          br = new BufferedReader(new FileReader(target));
          for (String line; (line = br.readLine()) != null; ) {
            String[] parts = line.split(separator);
            if (parts.length < 2) {
              bw.write(line);
              bw.newLine();
              continue;
            }

            String optName = parts[0].trim();
            if (options.containsKey(optName)) {
              String optValue = options.get(optName);
              bw.write(optName + " " + separator + " " + optValue);
              bw.newLine();
              processedOptions.put(optName, optValue);
              options.remove(optName);
            } else if (processedOptions.containsKey(optName)) {
              bw.write(optName + " " + separator + " " + processedOptions.get(optName));
              bw.newLine();
            } else {
              bw.write(line);
              bw.newLine();
            }
          }
          br.close();
        }
        for (Map.Entry<String, String> entry : options.entrySet()) {
          bw.write(entry.getKey() + " " + separator + " " + entry.getValue());
          bw.newLine();
        }
        bw.close();
        FileUtils.copyFile(tmpFile, target);
        FileUtils.forceDelete(tmpFile);
      } catch (IOException ex) {
        Utils.onError(new Error.WriteTxtConfig(target.getPath()));
      }
    }
  }
コード例 #30
0
  public JSONObject describeOperator(String clazz) throws Exception {
    TypeGraphVertex tgv = typeGraph.getTypeGraphVertex(clazz);
    if (tgv.isInstantiable()) {
      JSONObject response = new JSONObject();
      JSONArray inputPorts = new JSONArray();
      JSONArray outputPorts = new JSONArray();
      // Get properties from ASM

      JSONObject operatorDescriptor = describeClassByASM(clazz);
      JSONArray properties = operatorDescriptor.getJSONArray("properties");

      properties = enrichProperties(clazz, properties);

      JSONArray portTypeInfo = operatorDescriptor.getJSONArray("portTypeInfo");

      List<CompactFieldNode> inputPortfields = typeGraph.getAllInputPorts(clazz);
      List<CompactFieldNode> outputPortfields = typeGraph.getAllOutputPorts(clazz);

      try {
        for (CompactFieldNode field : inputPortfields) {
          JSONObject inputPort = setFieldAttributes(clazz, field);
          if (!inputPort.has("optional")) {
            inputPort.put(
                "optional",
                false); // input port that is not annotated is default to be not optional
          }
          if (!inputPort.has(SCHEMA_REQUIRED_KEY)) {
            inputPort.put(SCHEMA_REQUIRED_KEY, false);
          }
          inputPorts.put(inputPort);
        }

        for (CompactFieldNode field : outputPortfields) {
          JSONObject outputPort = setFieldAttributes(clazz, field);

          if (!outputPort.has("optional")) {
            outputPort.put(
                "optional", true); // output port that is not annotated is default to be optional
          }
          if (!outputPort.has("error")) {
            outputPort.put("error", false);
          }
          if (!outputPort.has(SCHEMA_REQUIRED_KEY)) {
            outputPort.put(SCHEMA_REQUIRED_KEY, false);
          }
          outputPorts.put(outputPort);
        }

        response.put("name", clazz);
        response.put("properties", properties);
        response.put(PORT_TYPE_INFO_KEY, portTypeInfo);
        response.put("inputPorts", inputPorts);
        response.put("outputPorts", outputPorts);

        OperatorClassInfo oci = classInfo.get(clazz);

        if (oci != null) {
          if (oci.comment != null) {
            String[] descriptions;
            // first look for a <p> tag
            String keptPrefix = "<p>";
            descriptions = oci.comment.split("<p>", 2);
            if (descriptions.length == 0) {
              keptPrefix = "";
              // if no <p> tag, then look for a blank line
              descriptions = oci.comment.split("\n\n", 2);
            }
            if (descriptions.length > 0) {
              response.put("shortDesc", descriptions[0]);
            }
            if (descriptions.length > 1) {
              response.put("longDesc", keptPrefix + descriptions[1]);
            }
          }
          response.put("category", oci.tags.get("@category"));
          String displayName = oci.tags.get("@displayName");
          if (displayName == null) {
            displayName = decamelizeClassName(ClassUtils.getShortClassName(clazz));
          }
          response.put("displayName", displayName);
          String tags = oci.tags.get("@tags");
          if (tags != null) {
            JSONArray tagArray = new JSONArray();
            for (String tag : StringUtils.split(tags, ',')) {
              tagArray.put(tag.trim().toLowerCase());
            }
            response.put("tags", tagArray);
          }
          String doclink = oci.tags.get("@doclink");
          if (doclink != null) {
            response.put("doclink", doclink + "?" + getDocName(clazz));
          } else if (clazz.startsWith("com.datatorrent.lib.")
              || clazz.startsWith("com.datatorrent.contrib.")) {
            response.put("doclink", DT_OPERATOR_DOCLINK_PREFIX + "?" + getDocName(clazz));
          }
        }
      } catch (JSONException ex) {
        throw new RuntimeException(ex);
      }
      return response;
    } else {
      throw new UnsupportedOperationException();
    }
  }