001package Torello.Browser.JsonAST;
002
003/**
004 * This method is used to convert a CDP "domain" (which essentially the same as a Java "Package"),
005 * that is represented as a {@code String}, and convert it into a reference to one of the 
006 * {@link Domain} object references.  Just as a reminder, inside of a Web Browser, a "domain" seems
007 * to be extremely similar to the concept of a Java "Package".  CDP calls them "domains" instead of
008 * packages, and they just group together methods, classes & event classes which are related.
009 * 
010 * <BR /><BR />
011 * Essentially this performs:
012 * 
013 * <DIV CLASS=EXAMPLE>{@code
014 * // The following code would print the string representation of the CDP Domain whose 
015 * // ==> domain.name.equals("Target");
016 * 
017 * final Domain d = Helper$FindDomain.find("Target");
018 * System.out.println(d.toString());
019 * }</DIV>
020 */
021@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="LINKER_JDHBI")
022public class Helper$FindDomain
023{
024    private Helper$FindDomain() { }
025
026    private static API browser, js;
027
028    static void initialize(final API browser, final API js)
029    {
030        Helper$FindDomain.browser   = browser;
031        Helper$FindDomain.js        = js;
032    }
033
034
035    // And here it all is!  In all its glory and its majesty.
036    // You give me a "Domain Name" (as a String),
037    // I convert that into a Pointer / Reference to an actual AST Node from the Tree whose name
038    // actually is "domainName" - the String you just gave me
039    // 
040    // Remember, search both the JavaScript API, and the Browser API
041    // Pretend they are basically part of the same thing (the two, together, comprise the CDP API)
042
043    static Domain find(final String domainName)
044    {
045        Domain ret = Helper$FindDomain.js.findDomain(domainName);
046        if (ret != null) return ret;
047
048        ret = Helper$FindDomain.browser.findDomain(domainName);
049        if (ret != null) return ret;
050
051        throw new LinkingStateError("Cannot find the domain: " + domainName);
052    }
053}