modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java [57:180]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class DefaultSCADomain extends SCADomain {

    private String uri;
    private String[] composites;
    // private Composite domainComposite;
    // private List<Contribution> contributions;
    private Map<String, Component> components;
    private ComponentManager componentManager;
    // private ClassLoader runtimeClassLoader;
    private ClassLoader applicationClassLoader;
    private String domainURI;
    private List<String> contributionURLs;

    private CompositeActivator compositeActivator;
    private SCANode node;
    private SCAClient client;

    /**
     * Constructs a new domain facade.
     * 
     * @param domainURI
     * @param contributionLocation
     * @param composites
     */
    public DefaultSCADomain(ClassLoader runtimeClassLoader,
                            ClassLoader applicationClassLoader,
                            String domainURI,
                            String contributionLocation,
                            String... composites) {
        this.uri = domainURI;
        this.composites = composites;
        // this.runtimeClassLoader = runtimeClassLoader;
        this.applicationClassLoader = applicationClassLoader;
        this.domainURI = domainURI;
        this.contributionURLs = new ArrayList<String>();
        if (contributionLocation != null && !"/".equals(contributionLocation)) {
            this.contributionURLs.add(contributionLocation);
        }
        this.composites = composites;

        init();

        this.componentManager = new DefaultSCADomainComponentManager(this);

    }

    /**
     * A hack to create an aggregated composite
     * @param classLoader
     * @param composites
     * @return
     */
    private String createDeploymentComposite(ClassLoader classLoader, String composites[]) {
        try {
            StringBuffer xml =
                new StringBuffer("<sca:composite xmlns:sca=\"http://www.osoa.org/xmlns/sca/1.0\"")
                    .append(" targetNamespace=\"http://tuscany.apache.org/xmlns/sca/1.0\" name=\"aggregated\">\n");
            XMLInputFactory factory = XMLInputFactory.newInstance();
            for (int i = 0; i < composites.length; i++) {
                URL url = classLoader.getResource(composites[i]);
                if (url == null) {
                    continue;
                }
                String location = NodeImpl.getContributionURL(url, composites[i]).toString();
                if (!contributionURLs.contains(location)) {
                    contributionURLs.add(location);
                }
                URLConnection connection = url.openConnection();
                connection.setUseCaches(false);
                XMLStreamReader reader = factory.createXMLStreamReader(connection.getInputStream());
                reader.nextTag();

                assert Constants.COMPOSITE_QNAME.equals(reader.getName());
                String ns = reader.getAttributeValue(null, "targetNamespace");
                if (ns == null) {
                    ns = XMLConstants.NULL_NS_URI;
                }
                String name = reader.getAttributeValue(null, "name");
                reader.close();
                if (XMLConstants.NULL_NS_URI.equals(ns)) {
                    xml.append("<sca:include name=\"").append(name).append("\"/>\n");
                } else {
                    xml.append("<sca:include xmlns:ns").append(i).append("=\"").append(ns).append("\"");
                    xml.append(" name=\"").append("ns").append(i).append(":").append(name).append("\"/>\n");
                }
            }
            xml.append("</sca:composite>");
            // System.out.println(xml.toString());
            return xml.toString();
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }

    public void init() {
        SCANodeFactory factory = SCANodeFactory.newInstance();

        List<SCAContribution> contributions = new ArrayList<SCAContribution>();

        if (composites != null && composites.length > 1) {
            // Create an aggregated composite that includes all the composites as Node API only takes one composite
            String content = createDeploymentComposite(applicationClassLoader, composites);
            // Create SCA contributions
            for (String location : contributionURLs) {
                contributions.add(new SCAContribution(location, location));
            }
            node =
                factory.createSCANode("http://tuscany.apache.org/xmlns/sca/1.0/aggregated", content, contributions
                    .toArray(new SCAContribution[contributions.size()]));
        } else {
            for (String location : contributionURLs) {
                contributions.add(new SCAContribution(location, location));
            }
            String composite = (composites != null && composites.length >= 1) ? composites[0] : null;
            if (!contributions.isEmpty()) {
                node =
                    factory.createSCANode(composite, contributions.toArray(new SCAContribution[contributions.size()]));
            } else {
                node = factory.createSCANodeFromClassLoader(composite, applicationClassLoader);
            }
        }
        client = (SCAClient)node;
        compositeActivator = ((NodeImpl)node).getCompositeActivator();
        components = new HashMap<String, Component>();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java [60:183]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class DefaultSCADomain extends SCADomain {

    private String uri;
    private String[] composites;
    // private Composite domainComposite;
    // private List<Contribution> contributions;
    private Map<String, Component> components;
    private ComponentManager componentManager;
    // private ClassLoader runtimeClassLoader;
    private ClassLoader applicationClassLoader;
    private String domainURI;
    private List<String> contributionURLs;

    private CompositeActivator compositeActivator;
    private SCANode node;
    private SCAClient client;

    /**
     * Constructs a new domain facade.
     * 
     * @param domainURI
     * @param contributionLocation
     * @param composites
     */
    public DefaultSCADomain(ClassLoader runtimeClassLoader,
                            ClassLoader applicationClassLoader,
                            String domainURI,
                            String contributionLocation,
                            String... composites) {
        this.uri = domainURI;
        this.composites = composites;
        // this.runtimeClassLoader = runtimeClassLoader;
        this.applicationClassLoader = applicationClassLoader;
        this.domainURI = domainURI;
        this.contributionURLs = new ArrayList<String>();
        if (contributionLocation != null && !"/".equals(contributionLocation)) {
            this.contributionURLs.add(contributionLocation);
        }
        this.composites = composites;

        init();

        this.componentManager = new DefaultSCADomainComponentManager(this);

    }

    /**
     * A hack to create an aggregated composite
     * @param classLoader
     * @param composites
     * @return
     */
    private String createDeploymentComposite(ClassLoader classLoader, String composites[]) {
        try {
            StringBuffer xml =
                new StringBuffer("<sca:composite xmlns:sca=\"http://www.osoa.org/xmlns/sca/1.0\"")
                    .append(" targetNamespace=\"http://tuscany.apache.org/xmlns/sca/1.0\" name=\"aggregated\">\n");
            XMLInputFactory factory = XMLInputFactory.newInstance();
            for (int i = 0; i < composites.length; i++) {
                URL url = classLoader.getResource(composites[i]);
                if (url == null) {
                    continue;
                }
                String location = NodeImpl.getContributionURL(url, composites[i]).toString();
                if (!contributionURLs.contains(location)) {
                    contributionURLs.add(location);
                }
                URLConnection connection = url.openConnection();
                connection.setUseCaches(false);
                XMLStreamReader reader = factory.createXMLStreamReader(connection.getInputStream());
                reader.nextTag();

                assert Constants.COMPOSITE_QNAME.equals(reader.getName());
                String ns = reader.getAttributeValue(null, "targetNamespace");
                if (ns == null) {
                    ns = XMLConstants.NULL_NS_URI;
                }
                String name = reader.getAttributeValue(null, "name");
                reader.close();
                if (XMLConstants.NULL_NS_URI.equals(ns)) {
                    xml.append("<sca:include name=\"").append(name).append("\"/>\n");
                } else {
                    xml.append("<sca:include xmlns:ns").append(i).append("=\"").append(ns).append("\"");
                    xml.append(" name=\"").append("ns").append(i).append(":").append(name).append("\"/>\n");
                }
            }
            xml.append("</sca:composite>");
            // System.out.println(xml.toString());
            return xml.toString();
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }

    public void init() {
        SCANodeFactory factory = SCANodeFactory.newInstance();

        List<SCAContribution> contributions = new ArrayList<SCAContribution>();

        if (composites != null && composites.length > 1) {
            // Create an aggregated composite that includes all the composites as Node API only takes one composite
            String content = createDeploymentComposite(applicationClassLoader, composites);
            // Create SCA contributions
            for (String location : contributionURLs) {
                contributions.add(new SCAContribution(location, location));
            }
            node =
                factory.createSCANode("http://tuscany.apache.org/xmlns/sca/1.0/aggregated", content, contributions
                    .toArray(new SCAContribution[contributions.size()]));
        } else {
            for (String location : contributionURLs) {
                contributions.add(new SCAContribution(location, location));
            }
            String composite = (composites != null && composites.length >= 1) ? composites[0] : null;
            if (!contributions.isEmpty()) {
                node =
                    factory.createSCANode(composite, contributions.toArray(new SCAContribution[contributions.size()]));
            } else {
                node = factory.createSCANodeFromClassLoader(composite, applicationClassLoader);
            }
        }
        client = (SCAClient)node;
        compositeActivator = ((NodeImpl)node).getCompositeActivator();
        components = new HashMap<String, Component>();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



