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.policy.xml;
 
 import java.util.List;
 
 
Processor for handling XML models of ExtensionType meta data definitions

Version:
$Rev: 825773 $ $Date: 2009-10-16 08:42:26 +0300 (Fri, 16 Oct 2009) $
 
 abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implements
 
     private PolicyFactory policyFactory;
     
 
     protected abstract ExtensionType resolveExtensionType(ExtensionType extnTypeModelResolver resolverProcessorContext context)
         throws ContributionResolveException;
 
     public ExtensionTypeProcessor(PolicyFactory policyFactory,
                                   StAXArtifactProcessor<ObjectextensionProcessor) {
         this. = policyFactory;
     }

    
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(),
                                       .,
                                       .,
                                       model,
                                       message,
                                       (Object[])messageParameters);
             monitor.problem(problem);
         }
     }
 
         QName extType = getArtifactType();
         QName type = getQName(reader"type");
 
         if (type != null) {
             ExtensionType extensionType = null;
             if (.equals(extType)) {
                 extensionType = .createBindingType();
             } else if (.equals(extType)) {
                 extensionType = .createImplementationType();
             } else {
                 error(context.getMonitor(), "UnrecognizedExtensionType"readertype);
                 return null;
                 //throw new ContributionReadException("Unrecognized ExtensionType - " + type);
            }
            extensionType.setType(type);
            extensionType.setUnresolved(true);
            readAlwaysProvidedIntents(extensionTypereader);
            readMayProvideIntents(extensionTypereader);
            return extensionType;
        } else {
            error(context.getMonitor(), "RequiredAttributeMissing"readerextType);
            //throw new ContributionReadException("Required attribute '" + TYPE + 
            //"' missing from BindingType Definition");
        }
        return null;
    }
    private void readAlwaysProvidedIntents(ExtensionType extnTypeXMLStreamReader reader) {
        String value = reader.getAttributeValue(null);
        if (value != null) {
            List<IntentalwaysProvided = extnType.getAlwaysProvidedIntents();
            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
                QName qname = getQNameValue(readertokens.nextToken());
                Intent intent = .createIntent();
                intent.setName(qname);
                alwaysProvided.add(intent);
            }
        }
    }
    private void readMayProvideIntents(ExtensionType extnTypeXMLStreamReader reader) {
        String value = reader.getAttributeValue(null);
        if (value != null) {
            List<IntentmayProvide = extnType.getMayProvidedIntents();
            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
                QName qname = getQNameValue(readertokens.nextToken());
                Intent intent = .createIntent();
                intent.setName(qname);
                mayProvide.add(intent);
            }
        }
    }
    public void write(ExtensionType extnTypeXMLStreamWriter writerProcessorContext contextthrows ContributionWriteException,
        XMLStreamException {
        // Write an <sca:bindingType or sca:implementationType>
        if (extnType instanceof BindingType) {
            writer.writeStartElement();
        } else if (extnType instanceof ImplementationType) {
            writer.writeStartElement();
        }
        writeAlwaysProvidesIntentsAttribute(extnTypewriter);
        writeMayProvideIntentsAttribute(extnTypewriter);
        writer.writeEndElement();
    }
    private void writeMayProvideIntentsAttribute(ExtensionType extnTypeXMLStreamWriter writer)
        throws XMLStreamException {
        StringBuffer sb = new StringBuffer();
        for (Intent intent : extnType.getMayProvidedIntents()) {
            writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI());
            sb.append(intent.getName().getPrefix() +  + intent.getName().getLocalPart());
            sb.append();
        }
        if (sb.length() > 0) {
            writer.writeAttribute(sb.toString());
        }
    }
    private void writeAlwaysProvidesIntentsAttribute(ExtensionType extnTypeXMLStreamWriter writer)
        throws XMLStreamException {
        StringBuffer sb = new StringBuffer();
        for (Intent intent : extnType.getAlwaysProvidedIntents()) {
            writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI());
            sb.append(intent.getName().getPrefix() +  + intent.getName().getLocalPart());
            sb.append();
        }
        if (sb.length() > 0) {
            writer.writeAttribute(sb.toString());
        }
    }
    public void resolve(ExtensionType extnTypeModelResolver resolverProcessorContext contextthrows ContributionResolveException {
        if (extnType != null && extnType.isUnresolved()) {
            resolveAlwaysProvidedIntents(extnTyperesolvercontext);
            resolveMayProvideIntents(extnTyperesolvercontext);
            extnType.setUnresolved(false);
            //resolveExtensionType(extnType, resolver);
        }
    }
    private void resolveAlwaysProvidedIntents(ExtensionType extensionTypeModelResolver resolverProcessorContext context)
        throws ContributionResolveException {
        if (extensionType != null) {
            // resolve all provided intents
            List<IntentalwaysProvided = new ArrayList<Intent>();
            for (Intent providedIntent : extensionType.getAlwaysProvidedIntents()) {
                if (providedIntent.isUnresolved()) {
                    providedIntent = resolver.resolveModel(Intent.classprovidedIntentcontext);
                    if (!providedIntent.isUnresolved()) {
                        alwaysProvided.add(providedIntent);
                    } else {
                        error(context.getMonitor(), "AlwaysProvidedIntentNotFound"resolverprovidedIntentextensionType);
                        //throw new ContributionResolveException("Always Provided Intent - " + providedIntent
                        //+ " not found for ExtensionType "
                        //+ extensionType);
                    }
                } else {
                    alwaysProvided.add(providedIntent);
                }
            }
            extensionType.getAlwaysProvidedIntents().clear();
            extensionType.getAlwaysProvidedIntents().addAll(alwaysProvided);
        }
    }
    private void resolveMayProvideIntents(ExtensionType extensionTypeModelResolver resolverProcessorContext context)
        throws ContributionResolveException {
        if (extensionType != null) {
            // resolve all provided intents
            List<IntentmayProvide = new ArrayList<Intent>();
            for (Intent providedIntent : extensionType.getMayProvidedIntents()) {
                if (providedIntent.isUnresolved()) {
                    providedIntent = resolver.resolveModel(Intent.classprovidedIntentcontext);
                    if (!providedIntent.isUnresolved()) {
                        mayProvide.add(providedIntent);
                    } else {
                        error(context.getMonitor(), "MayProvideIntentNotFound"resolverprovidedIntentextensionType);
                        //throw new ContributionResolveException("May Provide Intent - " + providedIntent
                        //+ " not found for ExtensionType "
                        //+ extensionType);
                    }
                } else {
                    mayProvide.add(providedIntent);
                }
            }
            extensionType.getMayProvidedIntents().clear();
            extensionType.getMayProvidedIntents().addAll(mayProvide);
        }
    }
    public Class<ExtensionTypegetModelType() {
        return ExtensionType.class;
    }
New to GrepCode? Check out our FAQ X