Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 package org.apache.tuscany.sca.contribution.scanner;
 
 import java.util.List;
 import java.util.Map;
 
Default implementation of a contribution scanner extension point.

Version:
$Rev: 891986 $ $Date: 2009-12-18 01:28:45 +0200 (Fri, 18 Dec 2009) $
 
 
     private boolean loaded;
     private ExtensionPointRegistry registry;
 
         this. = registry;
     }
 
     public void addContributionScanner(ContributionScanner scanner) {
         .put(scanner.getContributionType(), scanner);
     }
 
     public void removeContributionScanner(ContributionScanner scanner) {
         .remove(scanner.getContributionType());
     }
 
     public ContributionScanner getContributionScanner(String contentType) {
         loadScanners();
         return .get(contentType);
     }
 
     private synchronized void loadScanners() {
         if ()
             return;
 
         // Get the scanner service declarations
         Collection<ServiceDeclarationscannerDeclarations;
         try {
             scannerDeclarations = .getServiceDiscovery().getServiceDeclarations(ContributionScanner.class.getName());
         } catch (IOException e) {
             throw new IllegalStateException(e);
         }
 
         for (ServiceDeclaration scannerDeclarationscannerDeclarations) {
             Map<StringStringattributes = scannerDeclaration.getAttributes();
 
             // Load a URL artifact scanner
             String contributionType = attributes.get("type");
 
             // Create a scanner wrapper and register it
             ContributionScanner scanner = new LazyContributionScanner(contributionTypescannerDeclaration);
             addContributionScanner(scanner);
         }
 
          = true;
     }

    
A facade for contribution scanners.
 
     private static class LazyContributionScanner implements ContributionScanner {
         private ExtensionPointRegistry registry;
         private ServiceDeclaration scannerDeclaration;
         private String contributionType;
         private ContributionScanner scanner;
         private ContributionFactory contributionFactory;
        private LazyContributionScanner(ExtensionPointRegistry registryString contributionTypeServiceDeclaration scannerDeclaration) {
            this. = registry;
            this. = scannerDeclaration;
            this. = contributionType;
            
            FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
            this. = factories.getFactory(ContributionFactory.class);
        }
        public List<Artifactscan(Contribution contributionSourceURLthrows ContributionReadException {
            return getScanner().scan(contributionSourceURL);
        }
        public String getContributionType() {
            return ;
        }
        private ContributionScanner getScanner() {
            if ( == null) {
                try {
                    Class<ContributionScannerscannerClass = (Class<ContributionScanner>).loadClass();
                    Constructor<ContributionScannerconstructor = scannerClass.getConstructor(ContributionFactory.class);
                     = constructor.newInstance();
                } catch (Exception e) {
                    throw new IllegalStateException(e);
                }
            }
            return ;
        }
    }
New to GrepCode? Check out our FAQ X