Exemplo n.º 1
0
  /**
   * Given a IOR string this will decode it and output a corbaloc::... string.
   *
   * <p>Split off into a separate function from main so its easier to be called programmatically.
   */
  public static String printCorbalocIOR(org.omg.CORBA.ORB orb, String iorString) {
    if (!(orb instanceof org.jacorb.orb.ORB)) {
      throw new RuntimeException("ORB must be a JacORB ORB.");
    }
    final ParsedIOR pior = new ParsedIOR((org.jacorb.orb.ORB) orb, iorString);

    StringBuffer result = new StringBuffer();

    result.append("corbaloc:iiop:");

    ProfileBase profile = (ProfileBase) pior.getEffectiveProfile();
    if (profile instanceof IIOPProfile) {
      result.append(((IIOPAddress) ((IIOPProfile) profile).getAddress()).getOriginalHost());
      result.append(':');
      result.append(((IIOPAddress) ((IIOPProfile) profile).getAddress()).getPort());
      result.append('/');
      result.append(CorbaLoc.parseKey(pior.get_object_key()));
    } else {
      throw new RuntimeException("Sorry, only print corbaloc strings for IIOP profiles.");
    }
    return result.toString();
  }
Exemplo n.º 2
0
  /** entry point from the command line */
  public static void main(String args[]) throws Exception {
    final org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
    final org.jacorb.orb.ORB jorb = (org.jacorb.orb.ORB) orb;
    final Logger logger = jorb.getConfiguration().getLogger("jacorb.print_ior");

    boolean urlForm = false;
    boolean corbalocForm = false;
    String iorString = null;
    String file = null;

    if (args.length < 2 || args.length > 3) {
      usage();
    }

    for (int i = 0; i < args.length; i++) {
      if ("-u".equals(args[i])) {
        urlForm = true;
      } else if ("-c".equals(args[i])) {
        corbalocForm = true;
      } else if ("-i".equals(args[i])) {
        iorString = args[i + 1];
        ++i;
      } else if ("-f".equals(args[i])) {
        file = args[i + 1];
        ++i;
      } else {
        usage();
      }
    }

    if (logger.isDebugEnabled()) {
      logger.debug(
          "Under "
              + System.getProperty("os.name")
              + " the encoding name is "
              + System.getProperty("file.encoding")
              + " and the canonical encoding name is "
              + (new java.io.OutputStreamWriter(new ByteArrayOutputStream())).getEncoding());
    }

    PrintWriter out = new PrintWriter(System.out, true);

    try {
      if (file != null) {
        final LineNumberReader in = new LineNumberReader(new BufferedReader(new FileReader(file)));
        try {
          String line = null;
          while ((line = in.readLine()) != null) {
            iorString = line;
          }
        } finally {
          in.close();
        }
      }

      if (iorString.startsWith("IOR:")) {
        final ParsedIOR pior = new ParsedIOR(jorb, iorString);
        if (urlForm) {
          out.println(CorbaLoc.parseKey(pior.get_object_key()));
        } else if (corbalocForm) {
          out.println(printCorbalocIOR(orb, iorString));
        } else {
          printIOR(jorb, pior, out);
        }
      } else {
        out.println("Sorry, we only unparse IORs in the standard IOR URL scheme");
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      out.flush();
    }

    orb.shutdown(true);
  }
Exemplo n.º 3
0
  /** top-level */
  public static void printIOR(ORB orb, ParsedIOR pior, PrintWriter out) {
    org.omg.IOP.IOR ior = pior.getIOR();

    out.println("------IOR components-----");
    out.println("TypeId\t:\t" + ior.type_id);

    List profiles = pior.getProfiles();

    out.println("TAG_INTERNET_IOP Profiles:");
    for (int i = 0; i < profiles.size(); i++) {
      out.println("\tProfile Id:\t\t" + i);

      ProfileBase profile = (ProfileBase) profiles.get(i);
      out.println(
          "\tIIOP Version:\t\t"
              + (int) profile.version().major
              + "."
              + (int) profile.version().minor);
      if (profile instanceof IIOPProfile) {
        out.println(
            "\tHost:\t\t\t"
                + ((IIOPAddress) ((IIOPProfile) profile).getAddress()).getOriginalHost());
        int port = ((IIOPAddress) ((IIOPProfile) profile).getAddress()).getPort();
        if (port < 0) {
          port += 65536;
        }

        out.println("\tPort:\t\t\t" + port);
      } else if (profile instanceof MIOPProfile) {
        out.println("MIOPProfile:\t" + ((MIOPProfile) profile).toString());
      }
      out.println("\tObject key (URL):\t" + CorbaLoc.parseKey(profile.get_object_key()));
      out.print("\tObject key (hex):\t0x");
      dumpHex(profile.get_object_key(), out);
      out.println();

      if (profile.version().minor >= (char) 1) {
        if (profile.getComponents().size() > 0) {
          out.println("\t-- Found " + profile.getComponents().size() + " Tagged Components--");
        }

        printTaggedComponents(orb, profile.getComponents().asArray(), out);
      }
      out.print("\n");
    }

    TaggedComponentList multiple_components = pior.getMultipleComponents();

    if (multiple_components.size() > 0) {
      out.println("Components in MULTIPLE_COMPONENTS profile: " + multiple_components.size());

      printTaggedComponents(orb, multiple_components.asArray(), out);
    }

    // Print any unknown tags. This block is a simplified version of the private
    // ParsedIOR::decode function.
    for (int i = 0; i < ior.profiles.length; i++) {
      int tag = ior.profiles[i].tag;
      boolean found = false;

      // See if JacORB managed to parse this tag before into the ParsedIOR
      for (int j = 0; j < profiles.size(); j++) {
        final IIOPProfile profile = (IIOPProfile) profiles.get(j);

        if (profile.tag() == tag) {
          found = true;
        }

        if (tag == TAG_MULTIPLE_COMPONENTS.value) {
          found = true;
        }
      }
      // This is an unknown tag that wasn't dealt with before.
      if (!found) {
        out.println("Unknown profile found with tag " + tag);
      }
    }
  }
Exemplo n.º 4
0
 /** extracts the type id and the object key from an IOR string. */
 public static String toID(String iorString) {
   ParsedIOR pior = new ParsedIOR(iorString);
   org.omg.IOP.IOR ior = pior.getIOR();
   return ior.type_id; //	dumpHex( pior.get_object_key() );
 }