Package org.apache.tuscany.sca.contribution.java

Examples of org.apache.tuscany.sca.contribution.java.JavaImport


     */
    private boolean matchesImport(String name, Import import_, boolean matchJavaClass) {
      
        if (matchJavaClass) {
            if (import_ instanceof JavaImport && name != null && name.lastIndexOf('.') > 0) {
                JavaImport javaImport = (JavaImport) import_;
                String packageName = name.substring(0, name.lastIndexOf('.'));
                if (javaImport.getPackage() == null)
                    return false;
                else
                    return packageName.equals(javaImport.getPackage());
            }
           
        } else {
            if (name == null || name.lastIndexOf('/') <= 0)
                return false;
            else if (import_ instanceof JavaImport) {
                JavaImport javaImport = (JavaImport) import_;
                String packageName = name.substring(0, name.lastIndexOf('/'));
                if (javaImport.getPackage() == null)
                    return false;
                else
                    return packageName.equals(javaImport.getPackage().replaceAll("\\.", "/"));
            } else if (import_ instanceof NamespaceImport) {
                NamespaceImport namespaceImport = (NamespaceImport) import_;
                String namespace = name.substring(0, name.lastIndexOf('/'));
                if (namespaceImport.getNamespace() == null)
                    return false;
View Full Code Here


        Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
        ArrayList<Contribution> exportContribList = new ArrayList<Contribution>();
        exportContribList.add(contribA);
        exportContribList.add(contribC);
       
        JavaImport import_ = javaImportExportFactory.createJavaImport();
        import_.setPackage(this.getClass().getPackage().getName());
        import_.setExportContributions(exportContribList);
        contribB.getImports().add(import_);
        import_ = javaImportExportFactory.createJavaImport();
        import_.setPackage("calculator");
        import_.setExportContributions(exportContribList);
        contribB.getImports().add(import_);
       
        JavaExport export = javaImportExportFactory.createJavaExport();
        export.setPackage(this.getClass().getPackage().getName());
        contribA.getExports().add(export);
View Full Code Here

       
        ArrayList<Contribution> exportContribList = new ArrayList<Contribution>();
        exportContribList.add(contribA);
        exportContribList.add(contribC);
       
        JavaImport import_ = javaImportExportFactory.createJavaImport();
        import_.setPackage(this.getClass().getPackage().getName());
        import_.setExportContributions(exportContribList);
        contribB.getImports().add(import_);
        NamespaceImport import1_ = namespaceImportExportFactory.createNamespaceImport();
        import1_.setNamespace("calculator");
        import1_.setExportContributions(exportContribList);
        contribB.getImports().add(import1_);
View Full Code Here

    /**
     * Process <import.java package="" location=""/>
     */
    public JavaImport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
        JavaImport javaImport = this.factory.createJavaImport();
        QName element = null;
       
        try {
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        element = reader.getName();
   
                        // Read <import.java>
                        if (IMPORT_JAVA.equals(element)) {
                            String packageName = reader.getAttributeValue(null, PACKAGE);
                            if (packageName == null) {
                              error(context.getMonitor(), "AttributePackageMissing", reader);
                                //throw new ContributionReadException("Attribute 'package' is missing");
                            } else
                              javaImport.setPackage(packageName);
                           
                            String location = getURIString(reader, LOCATION);                       
                            javaImport.setLocation(location);
                        }
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                        if (IMPORT_JAVA.equals(reader.getName())) {
                            return javaImport;
View Full Code Here

        this.contribution = new WeakReference<Contribution>(contribution);
        // Index Java import resolvers by package name
        Map<String, List<ModelResolver>> resolverMap = new HashMap<String, List<ModelResolver>>();
        for (Import import_: this.contribution.get().getImports()) {
            if (import_ instanceof JavaImport) {
                JavaImport javaImport = (JavaImport)import_;
                List<ModelResolver> resolvers = resolverMap.get(javaImport.getPackage());
                if (resolvers == null) {
                    resolvers = new ArrayList<ModelResolver>();
                    resolverMap.put(javaImport.getPackage(), resolvers);
                }
                resolvers.add(javaImport.getModelResolver());
            }
        }

        // Create a delegating model resolver for each imported package
        for (Map.Entry<String, List<ModelResolver>> entry: resolverMap.entrySet()) {
View Full Code Here

        // Initialize the contribution imports
        for (Import import_: contribution.getImports()) {
            boolean initialized = false;
           
            if(import_ instanceof JavaImport) {
                JavaImport javaImport = (JavaImport) import_;
               
                //Find a matching contribution
                if(javaImport.getLocation() != null) {
                    Contribution targetContribution = repository.getContribution(javaImport.getLocation());
                    if (targetContribution != null) {
                   
                        // Find a matching contribution export
                        for (Export export: targetContribution.getExports()) {
                            if (export instanceof JavaExport) {
                                JavaExport javaExport = (JavaExport)export;
                                if (javaImport.getPackage().equals(javaExport.getPackage())) {
                                    javaImport.setModelResolver(javaExport.getModelResolver());
                                   
                                    List<Contribution> exportingContributions = new ArrayList<Contribution>();
                                    exportingContributions.add(export.getContribution());
                                    import_.setExportContributions(exportingContributions);
                                   
View Full Code Here

    /**
     * Process <import.java package="" location=""/>
     */
    public JavaImport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
        JavaImport javaImport = this.factory.createJavaImport();
        QName element = null;
       
        try {
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        element = reader.getName();
   
                        // Read <import.java>
                        if (IMPORT_JAVA.equals(element)) {
                            String packageName = reader.getAttributeValue(null, PACKAGE);
                            if (packageName == null) {
                              error(context.getMonitor(), "AttributePackageMissing", reader);
                                //throw new ContributionReadException("Attribute 'package' is missing");
                            } else
                              javaImport.setPackage(packageName);
                           
                            String location = getURIString(reader, LOCATION);                       
                            javaImport.setLocation(location);
                        }
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                        if (IMPORT_JAVA.equals(reader.getName())) {
                            return javaImport;
View Full Code Here

     * @return true if this is a matching import
     */
    private boolean classNameMatchesImport(String name, Import import_) {
       
        if (import_ instanceof JavaImport && name != null && name.lastIndexOf('.') > 0) {
            JavaImport javaImport = (JavaImport) import_;
               
            String packageName = name.substring(0, name.lastIndexOf('.'));
            if (javaImport.getPackage().endsWith(".*")) {
                String prefix = javaImport.getPackage().substring(0, javaImport.getPackage().length() -1);
                 if (packageName.startsWith(prefix)) {
                    return true;
                }
            } else {
                return packageName.equals(javaImport.getPackage());
            }
        }
       
        return false;
    }
View Full Code Here

       
      
        if (name == null || name.lastIndexOf('/') <= 0)
            return false;
        else if (import_ instanceof JavaImport) {
            JavaImport javaImport = (JavaImport) import_;
           
            if (javaImport.getPackage().endsWith(".*")) {
                String packageName = name.substring(0, name.lastIndexOf('/')).replace('/', '.');
                String prefix = javaImport.getPackage().substring(0, javaImport.getPackage().length() -1);
                if (packageName.startsWith(prefix)) {
                    return true;
                }
            } else {
                // 'name' is a resource : contains "/" as separators
                // Get package name from resource name
                String packageName = name.substring(0, name.lastIndexOf('/'));
                 return packageName.equals(javaImport.getPackage().replaceAll("\\.", "/"));
            }
        }
        return false;
    }
View Full Code Here

        this.contribution = new WeakReference<Contribution>(contribution);
        // Index Java import resolvers by package name
        Map<String, List<ModelResolver>> resolverMap = new HashMap<String, List<ModelResolver>>();
        for (Import import_: this.contribution.get().getImports()) {
            if (import_ instanceof JavaImport) {
                JavaImport javaImport = (JavaImport)import_;
                List<ModelResolver> resolvers = resolverMap.get(javaImport.getPackage());
                if (resolvers == null) {
                    resolvers = new ArrayList<ModelResolver>();
                    resolverMap.put(javaImport.getPackage(), resolvers);
                }
                resolvers.add(javaImport.getModelResolver());
            }
        }

        // Create a delegating model resolver for each imported package
        for (Map.Entry<String, List<ModelResolver>> entry: resolverMap.entrySet()) {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.contribution.java.JavaImport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.