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.processor;
 
 import java.net.URI;
 import java.net.URL;
 
Implementation of an extensible URL artifact processor. Takes a URLArtifactProcessorExtensionPoint and delegates to the proper URLArtifactProcessor by either fileName or fileExtention

Version:
$Rev: 825773 $ $Date: 2009-10-16 06:42:26 +0100 (Fri, 16 Oct 2009) $
 
 
Constructs a new ExtensibleURLArtifactProcessor.

Parameters:
processors
 
         this. = processors;
     }

    
Report a error.

Parameters:
problems
message
model
 
     private void error(Monitor monitorString messageObject modelObject... messageParameters) {
         if (monitor != null) {
             Problem problem =
                 monitor.createProblem(this.getClass().getName(),
                                       "contribution-validation-messages",
                                       .,
                                       model,
                                       message,
                                       (Object[])messageParameters);
             monitor.problem(problem);
         }
     }
 
     @SuppressWarnings("unchecked")
     public Object read(URL contributionURLURI sourceURIURL sourceURLProcessorContext contextthrows ContributionReadException {
         URLArtifactProcessor<Objectprocessor = null;
         if (sourceURI != null) {
             //try to retrieve a processor for the specific URI
             String uri = sourceURI.toString();
             if (!uri.startsWith("/")) {
                 uri = "/" + uri;
             }
             // Register the URI as the artifact type starts with /
             processor = (URLArtifactProcessor<Object>).getProcessor(uri);
         }
         
         /*
         if (processor == null) {
             // Delegate to the processor associated with file extension
             String fileName = getFileName(sourceURL);
 
             //try to retrieve a processor for the specific filename
             processor = (URLArtifactProcessor<Object>)processors.getProcessor(fileName);
         }
 
         if (processor == null) {
             //try to find my file type (extension)
             String extension = sourceURL.getPath();
 
             int extensionStart = extension.lastIndexOf('.');
             //handle files without extension (e.g NOTICE)
             if (extensionStart > 0) {
                 // File extensions are registered as .<extension>
                extension = extension.substring(extensionStart);
                processor = (URLArtifactProcessor<Object>)processors.getProcessor(extension);
            }
        }
        */
        if (processor == null) {
            return null;
        }
        return processor.read(contributionURLsourceURIsourceURLcontext);
    }
    @SuppressWarnings("unchecked")
    public void resolve(Object modelModelResolver resolverProcessorContext contextthrows ContributionResolveException {
        // Delegate to the processor associated with the model type
        if (model != null) {
            URLArtifactProcessor processor = .getProcessor(model.getClass());
            if (processor != null) {
                processor.resolve(modelresolvercontext);
            }
        }
    }
    public <M> M read(URL contributionURLURI artifactURIURL artifactUrlProcessorContext contextClass<M> type)
        throws ContributionReadException {
        Object mo = read(contributionURLartifactURIartifactUrlcontext);
        if (type.isInstance(mo)) {
            return type.cast(mo);
        } else {
            UnrecognizedElementException e = new UnrecognizedElementException(null);
            e.setResourceURI(artifactURI.toString());
            error(context.getMonitor(), "UnrecognizedElementException"artifactURI.toString());
            throw e;
        }
    }
    public String getArtifactType() {
        return "";
    }
    public Class<ObjectgetModelType() {
        return Object.class;
    }
New to GrepCode? Check out our FAQ X