org.eclipse.pde.ds.core_1.0.100.v20100601

16:47:25.731 INFO  jd.cli.Main - Decompiling org.eclipse.pde.ds.core_1.0.100.v20100601.jar
package org.eclipse.pde.internal.ds.core;

import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;

public class Activator
  extends Plugin
{
  public static final String PLUGIN_ID = "org.eclipse.pde.ds.core";
  public static final String CONTENT_TYPE_ID = "org.eclipse.pde.ds.core.content-type";
  private static Activator plugin;
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
    super.stop(context);
  }
  
  public static Activator getDefault()
  {
    return plugin;
  }
  
  public static void log(IStatus status)
  {
    if (status != null) {
      ResourcesPlugin.getPlugin().getLog().log(status);
    }
  }
  
  public static void log(Throwable e)
  {
    if ((e instanceof InvocationTargetException)) {
      e = ((InvocationTargetException)e).getTargetException();
    }
    IStatus status = null;
    if ((e instanceof CoreException)) {
      status = ((CoreException)e).getStatus();
    } else if (e.getMessage() != null) {
      status = new Status(4, "org.eclipse.pde.ds.core", 0, e
        .getMessage(), e);
    }
    log(status);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.Activator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSComponent
  extends IDSObject
{
  public abstract void setAttributeName(String paramString);
  
  public abstract String getAttributeName();
  
  public abstract void setEnabled(boolean paramBoolean);
  
  public abstract boolean getEnabled();
  
  public abstract void setFactory(String paramString);
  
  public abstract String getFactory();
  
  public abstract void setConfigurationPolicy(String paramString);
  
  public abstract String getConfigurationPolicy();
  
  public abstract void setActivateMethod(String paramString);
  
  public abstract String getActivateMethod();
  
  public abstract void setDeactivateMethod(String paramString);
  
  public abstract String getDeactivateMethod();
  
  public abstract void setModifiedeMethod(String paramString);
  
  public abstract String getModifiedMethod();
  
  public abstract void setImmediate(boolean paramBoolean);
  
  public abstract boolean getImmediate();
  
  public abstract IDSImplementation getImplementation();
  
  public abstract IDSProperty[] getPropertyElements();
  
  public abstract IDSProperties[] getPropertiesElements();
  
  public abstract IDSService getService();
  
  public abstract IDSReference[] getReferences();
  
  public abstract void setImplementation(IDSImplementation paramIDSImplementation);
  
  public abstract void setService(IDSService paramIDSService);
  
  public abstract void addPropertyElement(IDSProperty paramIDSProperty);
  
  public abstract void addPropertiesElement(IDSProperties paramIDSProperties);
  
  public abstract void addReference(IDSReference paramIDSReference);
  
  public abstract void removePropertyElement(IDSProperty paramIDSProperty);
  
  public abstract void removePropertiesElement(IDSProperties paramIDSProperties);
  
  public abstract void removeReference(IDSReference paramIDSReference);
  
  public abstract void removeService(IDSService paramIDSService);
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSComponent
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSConstants
{
  public static final String NAMESPACE = "http://www.osgi.org/xmlns/scr/v1.1.0";
  public static final String ELEMENT_COMPONENT = "component";
  public static final String ELEMENT_IMPLEMENTATION = "implementation";
  public static final String ELEMENT_PROPERTIES = "properties";
  public static final String ELEMENT_PROPERTY = "property";
  public static final String ELEMENT_SERVICE = "service";
  public static final String ELEMENT_PROVIDE = "provide";
  public static final String ELEMENT_REFERENCE = "reference";
  public static final String ATTRIBUTE_COMPONENT_NAME = "name";
  public static final String ATTRIBUTE_COMPONENT_ENABLED = "enabled";
  public static final String ATTRIBUTE_COMPONENT_FACTORY = "factory";
  public static final String ATTRIBUTE_COMPONENT_IMMEDIATE = "immediate";
  public static final String ATTRIBUTE_COMPONENT_CONFIGURATION_POLICY = "configuration-policy";
  public static final String ATTRIBUTE_COMPONENT_ACTIVATE = "activate";
  public static final String ATTRIBUTE_COMPONENT_DEACTIVATE = "deactivate";
  public static final String ATTRIBUTE_COMPONENT_MODIFIED = "modified";
  public static final String ATTRIBUTE_IMPLEMENTATION_CLASS = "class";
  public static final String ATTRIBUTE_PROPERTY_NAME = "name";
  public static final String ATTRIBUTE_PROPERTY_VALUE = "value";
  public static final String ATTRIBUTE_PROPERTY_TYPE = "type";
  public static final String ATTRIBUTE_PROPERTIES_ENTRY = "entry";
  public static final String ATTRIBUTE_SERVICE_FACTORY = "servicefactory";
  public static final String ATTRIBUTE_PROVIDE_INTERFACE = "interface";
  public static final String ATTRIBUTE_REFERENCE_NAME = "name";
  public static final String ATTRIBUTE_REFERENCE_INTERFACE = "interface";
  public static final String ATTRIBUTE_REFERENCE_CARDINALITY = "cardinality";
  public static final String ATTRIBUTE_REFERENCE_POLICY = "policy";
  public static final String ATTRIBUTE_REFERENCE_TARGET = "target";
  public static final String ATTRIBUTE_REFERENCE_BIND = "bind";
  public static final String ATTRIBUTE_REFERENCE_UNBIND = "unbind";
  public static final int TYPE_COMPONENT = 0;
  public static final int TYPE_IMPLEMENTATION = 1;
  public static final int TYPE_PROPERTIES = 2;
  public static final int TYPE_PROPERTY = 3;
  public static final int TYPE_SERVICE = 4;
  public static final int TYPE_PROVIDE = 5;
  public static final int TYPE_REFERENCE = 6;
  public static final String VALUE_PROPERTY_TYPE_STRING = "String";
  public static final String VALUE_PROPERTY_TYPE_LONG = "Long";
  public static final String VALUE_PROPERTY_TYPE_FLOAT = "Float";
  public static final String VALUE_PROPERTY_TYPE_DOUBLE = "Double";
  public static final String VALUE_PROPERTY_TYPE_INTEGER = "Integer";
  public static final String VALUE_PROPERTY_TYPE_BYTE = "Byte";
  public static final String VALUE_PROPERTY_TYPE_CHAR = "Character";
  public static final String VALUE_PROPERTY_TYPE_BOOLEAN = "Boolean";
  public static final String VALUE_PROPERTY_TYPE_SHORT = "Short";
  public static final String VALUE_REFERENCE_POLICY_STATIC = "static";
  public static final String VALUE_REFERENCE_POLICY_DYNAMIC = "dynamic";
  public static final String VALUE_REFERENCE_CARDINALITY_ZERO_ONE = "0..1";
  public static final String VALUE_REFERENCE_CARDINALITY_ZERO_N = "0..n";
  public static final String VALUE_REFERENCE_CARDINALITY_ONE_ONE = "1..1";
  public static final String VALUE_REFERENCE_CARDINALITY_ONE_N = "1..n";
  public static final String VALUE_TRUE = "true";
  public static final String VALUE_FALSE = "false";
  public static final String VALUE_DEFAULT_TARGET = "(name=value)";
  public static final String VALUE_CONFIGURATION_POLICY_IGNORE = "ignore";
  public static final String VALUE_CONFIGURATION_POLICY_OPTIONAL = "optional";
  public static final String VALUE_CONFIGURATION_POLICY_REQUIRE = "require";
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSConstants
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSDocumentFactory
{
  public abstract IDSProvide createProvide();
  
  public abstract IDSProperty createProperty();
  
  public abstract IDSReference createReference();
  
  public abstract IDSService createService();
  
  public abstract IDSProperties createProperties();
  
  public abstract IDSImplementation createImplementation();
  
  public abstract IDSComponent createComponent();
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSDocumentFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSImplementation
  extends IDSObject
{
  public abstract void setClassName(String paramString);
  
  public abstract String getClassName();
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSImplementation
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

import org.eclipse.core.resources.IResource;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.core.IModelChangeProvider;

public abstract interface IDSModel
  extends IModelChangeProvider, IModel
{
  public abstract IDSDocumentFactory getFactory();
  
  public abstract IDSComponent getDSComponent();
  
  public abstract void setUnderlyingResource(IResource paramIResource);
  
  public abstract void save();
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSModel
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

import org.eclipse.pde.internal.core.text.IDocumentObject;

public abstract interface IDSObject
  extends IDocumentObject
{
  public abstract IDSModel getModel();
  
  public abstract IDSComponent getComponent();
  
  public abstract String getName();
  
  public abstract int getType();
  
  public abstract boolean canBeParent();
  
  public abstract String[] getAttributesNames();
  
  public abstract String getXMLTagName();
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSObject
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSProperties
  extends IDSObject
{
  public abstract void setEntry(String paramString);
  
  public abstract String getEntry();
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSProperties
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSProperty
  extends IDSObject
{
  public abstract String getPropertyName();
  
  public abstract void setPropertyName(String paramString);
  
  public abstract String getPropertyValue();
  
  public abstract void setPropertyValue(String paramString);
  
  public abstract void setPropertyType(String paramString);
  
  public abstract String getPropertyType();
  
  public abstract void setPropertyElemBody(String paramString);
  
  public abstract String getPropertyElemBody();
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSProperty
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSProvide
  extends IDSObject
{
  public abstract void setInterface(String paramString);
  
  public abstract String getInterface();
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSProvide
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSReference
  extends IDSObject
{
  public abstract void setReferenceName(String paramString);
  
  public abstract String getReferenceName();
  
  public abstract void setReferenceInterface(String paramString);
  
  public abstract String getReferenceInterface();
  
  public abstract void setReferenceCardinality(String paramString);
  
  public abstract String getReferenceCardinality();
  
  public abstract void setReferencePolicy(String paramString);
  
  public abstract String getReferencePolicy();
  
  public abstract void setReferenceTarget(String paramString);
  
  public abstract String getReferenceTarget();
  
  public abstract void setReferenceBind(String paramString);
  
  public abstract String getReferenceBind();
  
  public abstract void setReferenceUnbind(String paramString);
  
  public abstract String getReferenceUnbind();
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSReference
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

public abstract interface IDSService
  extends IDSObject
{
  public abstract void setServiceFactory(boolean paramBoolean);
  
  public abstract boolean getServiceFactory();
  
  public abstract IDSProvide[] getProvidedServices();
  
  public abstract void addProvidedService(IDSProvide paramIDSProvide);
  
  public abstract void removeProvidedService(IDSProvide paramIDSProvide);
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.IDSService
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.pde.internal.ds.core.messages";
  public static String DSErrorReporter_cannotFindJavaType;
  public static String DSErrorReporter_requiredElement;
  public static String DSErrorReporter_requiredAttribute;
  public static String DSErrorReporter_attrValue;
  public static String DSErrorReporter_emptyAttrValue;
  public static String DSErrorReporter_duplicateReferenceName;
  public static String DSErrorReporter_requiredDefaultConstructor;
  public static String DSErrorReporter_invalidTarget;
  public static String DSErrorReporter_unimplementedProvidedInterface;
  public static String DSErrorReporter_singleAndMultipleAttrValue;
  public static String DSErrorReporter_emptyPropertyValue;
  public static String DSErrorReporter_invalidImmediateValue;
  public static String DSErrorReporter_invalidConfigurationPolicyValue;
  public static String DSErrorReporter_invalidImmediateValueFactory;
  public static String DSErrorReporter_duplicatedInterface;
  public static String DSErrorReporter_cannotFindProperties;
  public static String DSErrorReporter_invalidCardinalityValue;
  public static String DSErrorReporter_invalidPolicyValue;
  public static String DSErrorReporter_propertyTypeCastException;
  public static String DSErrorReporter_illegalServiceFactory;
  public static String DSErrorReporter_illegalServiceFactory_Immediate;
  public static String DSErrorReporter_illegalEmptyService;
  public static String DSBuilder_verifying;
  public static String DSBuilder_updating;
  
  static
  {
    NLS.initializeMessages("org.eclipse.pde.internal.ds.core.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.Messages
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core.builders;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

class DSBuilder$DeltaVisitor
  implements IResourceDeltaVisitor
{
  private IProgressMonitor monitor;
  final DSBuilder this$0;
  
  public DSBuilder$DeltaVisitor(DSBuilder paramDSBuilder, IProgressMonitor monitor)
  {
    this$0 = paramDSBuilder;
    this.monitor = monitor;
  }
  
  public boolean visit(IResourceDelta delta)
  {
    IResource resource = delta.getResource();
    if ((resource instanceof IProject))
    {
      IProject project = (IProject)resource;
      try
      {
        return project.hasNature(DSBuilder.access$0());
      }
      catch (CoreException localCoreException)
      {
        return false;
      }
    }
    if ((resource instanceof IFile))
    {
      IFile candidate = (IFile)resource;
      if (DSBuilder.access$1(this$0, candidate)) {
        if (delta.getKind() != 2)
        {
          DSBuilder.access$2(this$0, candidate, monitor);
          return true;
        }
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.builders.DSBuilder.DeltaVisitor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core.builders;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

class DSBuilder$ResourceVisitor
  implements IResourceVisitor
{
  private IProgressMonitor monitor;
  final DSBuilder this$0;
  
  public DSBuilder$ResourceVisitor(DSBuilder paramDSBuilder, IProgressMonitor monitor)
  {
    this$0 = paramDSBuilder;
    this.monitor = monitor;
  }
  
  public boolean visit(IResource resource)
  {
    if ((resource instanceof IProject))
    {
      IProject project = (IProject)resource;
      try
      {
        return project.hasNature(DSBuilder.access$0());
      }
      catch (CoreException localCoreException)
      {
        return false;
      }
    }
    if ((resource instanceof IFile))
    {
      IFile candidate = (IFile)resource;
      if (DSBuilder.access$1(this$0, candidate))
      {
        DSBuilder.access$2(this$0, candidate, monitor);
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.builders.DSBuilder.ResourceVisitor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core.builders;

import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.ds.core.Messages;

public class DSBuilder
  extends IncrementalProjectBuilder
{
  private static String PDE_NATURE = "org.eclipse.pde.PluginNature";
  private static IProject[] EMPTY_LIST = new IProject[0];
  
  class ResourceVisitor
    implements IResourceVisitor
  {
    private IProgressMonitor monitor;
    
    public ResourceVisitor(IProgressMonitor monitor)
    {
      this.monitor = monitor;
    }
    
    public boolean visit(IResource resource)
    {
      if ((resource instanceof IProject))
      {
        IProject project = (IProject)resource;
        try
        {
          return project.hasNature(DSBuilder.PDE_NATURE);
        }
        catch (CoreException localCoreException)
        {
          return false;
        }
      }
      if ((resource instanceof IFile))
      {
        IFile candidate = (IFile)resource;
        if (DSBuilder.this.isDSFile(candidate))
        {
          DSBuilder.this.checkFile(candidate, monitor);
          return true;
        }
      }
      return false;
    }
  }
  
  class DeltaVisitor
    implements IResourceDeltaVisitor
  {
    private IProgressMonitor monitor;
    
    public DeltaVisitor(IProgressMonitor monitor)
    {
      this.monitor = monitor;
    }
    
    public boolean visit(IResourceDelta delta)
    {
      IResource resource = delta.getResource();
      if ((resource instanceof IProject))
      {
        IProject project = (IProject)resource;
        try
        {
          return project.hasNature(DSBuilder.PDE_NATURE);
        }
        catch (CoreException localCoreException)
        {
          return false;
        }
      }
      if ((resource instanceof IFile))
      {
        IFile candidate = (IFile)resource;
        if (DSBuilder.this.isDSFile(candidate)) {
          if (delta.getKind() != 2)
          {
            DSBuilder.this.checkFile(candidate, monitor);
            return true;
          }
        }
      }
      return true;
    }
  }
  
  protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
    throws CoreException
  {
    IResourceDelta delta = null;
    if (kind != 6) {
      delta = getDelta(getProject());
    }
    if ((delta == null) || (kind == 6))
    {
      IProject project = getProject();
      project.accept(new ResourceVisitor(monitor));
    }
    else
    {
      delta.accept(new DeltaVisitor(monitor));
    }
    return EMPTY_LIST;
  }
  
  private boolean isDSFile(IFile candidate)
  {
    try
    {
      IContentDescription description = candidate.getContentDescription();
      if (description == null) {
        return false;
      }
      IContentType type = description.getContentType();
      return "org.eclipse.pde.ds.core.content-type".equals(type.getId());
    }
    catch (CoreException localCoreException) {}
    return false;
  }
  
  private void checkFile(IFile file, IProgressMonitor monitor)
  {
    if (monitor.isCanceled()) {
      return;
    }
    String message = NLS.bind(Messages.DSBuilder_verifying, file
      .getFullPath().toString());
    monitor.subTask(message);
    
    DSErrorReporter reporter = new DSErrorReporter(file);
    DefaultSAXParser.parse(file, reporter);
    reporter.validateContent(monitor);
    monitor.subTask(Messages.DSBuilder_updating);
    monitor.done();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.core.builders.DSBuilder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.core.builders;

import java.lang.reflect.Constructor;
import java.util.Hashtable;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.text.Document;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
import org.eclipse.pde.internal.core.util.CoreUtility;
import org.eclipse.pde.internal.ds.core.Activator;
import org.eclipse.pde.internal.ds.core.IDSComponent;
import org.eclipse.pde.internal.ds.core.IDSImplementation;
import org.eclipse.pde.internal.ds.core.IDSModel;
import org.eclipse.pde.internal.ds.core.IDSProperties;
import org.eclipse.pde.internal.ds.core.IDSProperty;
import org.eclipse.pde.internal.ds.core.IDSProvide;
import org.eclipse.pde.internal.ds.core.IDSReference;
import org.eclipse.pde.internal.ds.core.IDSService;
import org.eclipse.pde.internal.ds.core.Messages;
import org.eclipse.pde.internal.ds.core.text.DSModel;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class DSErrorReporter
  extends XMLErrorReporter
{
  public static final int ERROR = 0;
  public static final int WARNING = 1;
  public static final int IGNORE = 2;
  
  public DSErrorReporter(IFile file)
  {
    super(file);
  }
  
  public void validateContent(IProgressMonitor monitor)
  {
    try
    {
      Document textDocument = CoreUtility.getTextDocument(fFile
        .getContents());
      IDSModel model = new DSModel(textDocument, false);
      
      model.load();
      
      IDSComponent component = model.getDSComponent();
      
      validateComponentElement(component);
      validateImplementationElement(component.getImplementation());
      validateServiceElement(component.getService());
      validatePropertyElements(component.getPropertyElements());
      validatePropertiesElements(component.getPropertiesElements());
      validateReferenceElements(component.getReferences());
    }
    catch (CoreException e)
    {
      Activator.log(e);
    }
  }
  
  private void validateBoolean(Element element, Attr attr)
  {
    if (attr != null)
    {
      String value = attr.getValue();
      if ((!value.equalsIgnoreCase("true")) && (!value.equalsIgnoreCase("false"))) {
        reportIllegalAttributeValue(element, attr);
      }
    }
  }
  
  private void reportIllegalAttributeValue(Element element, Attr attr)
  {
    if ((attr == null) || (attr.getValue() == null) || (attr.getName() == null)) {
      return;
    }
    String message = NLS.bind(Messages.DSErrorReporter_attrValue, attr
      .getValue(), attr.getName());
    report(message, getLine(element, attr.getName()), 0, 
      "");
  }
  
  private void validateReferenceElements(IDSReference[] references)
  {
    Hashtable referencedNames = new Hashtable();
    for (int i = 0; i < references.length; i++)
    {
      IDSReference reference = references[i];
      Element element = (Element)getElements(reference).item(i);
      if (reference.getReferenceInterface() == null) {
        reportMissingRequiredAttribute(element, 
          "interface", 0);
      } else {
        validateJavaElement(reference.getReferenceInterface(), 
          "reference", 
          "interface", i);
      }
      validateReferenceCardinality(element);
      
      validateReferencePolicy(element);
      
      validateReferenceElementNames(referencedNames, element);
      
      validateTargetAttribute(element);
    }
  }
  
  private void validateTargetAttribute(Element element)
  {
    Attr attr = element
      .getAttributeNode("target");
    if (attr != null)
    {
      String value = attr.getValue();
      try
      {
        Activator.getDefault().getBundle().getBundleContext().createFilter(value);
      }
      catch (InvalidSyntaxException localInvalidSyntaxException)
      {
        reportInvalidTarget(element, value);
      }
    }
  }
  
  private void reportInvalidTarget(Element element, String target)
  {
    String name = element
      .getAttribute("name");
    String message = NLS.bind(Messages.DSErrorReporter_invalidTarget, name, 
      target);
    report(message, getLine(element), 0, "");
  }
  
  private void validateReferenceElementNames(Hashtable referencedNames, Element element)
  {
    String name = element
      .getAttribute("name");
    if ((name != null) && (referencedNames.containsKey(name))) {
      reportDuplicateReferenceElementName(element, name);
    } else {
      referencedNames.put(name, name);
    }
  }
  
  private void reportDuplicateReferenceElementName(Element element, String name)
  {
    Attr attr = element
      .getAttributeNode("name");
    if ((attr == null) || (attr.getValue() == null) || (attr.getName() == null)) {
      return;
    }
    String message = NLS.bind(
      Messages.DSErrorReporter_duplicateReferenceName, name);
    report(message, 
      getLine(element, "name"), 0, 
      "");
  }
  
  private void validateReferencePolicy(Element element)
  {
    String attribute = element
      .getAttribute("policy");
    String[] allowedValues = {
      "dynamic", 
      "static" };
    if ((attribute != null) && (attribute.length() > 0))
    {
      for (int i = 0; i < allowedValues.length; i++) {
        if (allowedValues[i].equalsIgnoreCase(attribute)) {
          return;
        }
      }
      reportIllegalPolicy(element, attribute);
    }
  }
  
  private void reportIllegalPolicy(Element element, String policy)
  {
    String name = element
      .getAttribute("name");
    if (name == null) {
      name = 
        element.getAttribute("interface");
    }
    String message = NLS.bind(Messages.DSErrorReporter_invalidPolicyValue, 
      name, policy);
    Attr attr = element
      .getAttributeNode("policy");
    report(message, getLine(element, attr.getName()), 0, 
      "");
  }
  
  private void validateReferenceCardinality(Element element)
  {
    String cardinality = element
      .getAttribute("cardinality");
    String[] allowedValues = {
      "1..n", 
      "1..1", 
      "0..n", 
      "0..1" };
    if (cardinality != null)
    {
      for (int i = 0; i < allowedValues.length; i++) {
        if (allowedValues[i].equalsIgnoreCase(cardinality)) {
          return;
        }
      }
      reportIllegalCardinality(element, cardinality);
    }
  }
  
  private void reportIllegalCardinality(Element element, String cardinality)
  {
    String name = element
      .getAttribute("name");
    if (name == null) {
      name = 
        element.getAttribute("interface");
    }
    String message = NLS.bind(
      Messages.DSErrorReporter_invalidCardinalityValue, name, 
      cardinality);
    Attr attr = element
      .getAttributeNode("cardinality");
    if ((attr == null) || (attr.getValue() == null) || (attr.getName() == null)) {
      return;
    }
    report(message, getLine(element, attr.getName()), 0, 
      "");
  }
  
  private void validatePropertiesElements(IDSProperties[] propertiesElements)
  {
    for (int i = 0; i < propertiesElements.length; i++)
    {
      IDSProperties properties = propertiesElements[i];
      Element element = (Element)getElements(properties).item(i);
      if ((properties.getEntry() == null) || 
        (properties.getEntry().length() == 0)) {
        reportMissingRequiredAttribute(element, 
          "entry", 0);
      } else if (!fProject.exists(new Path(properties.getEntry()))) {
        report(
          NLS.bind(
          Messages.DSErrorReporter_cannotFindProperties, 
          properties.getEntry()), getLine(element), 1, 
          "");
      }
    }
  }
  
  private void validatePropertyElements(IDSProperty[] propertyElements)
  {
    for (int i = 0; i < propertyElements.length; i++)
    {
      IDSProperty property = propertyElements[i];
      Element element = (Element)getElements(property).item(i);
      
      String name = property.getName();
      if ((name == null) || (name.length() == 0)) {
        reportMissingRequiredAttribute(element, 
          "name", 0);
      }
      validatePropertyTypes(element);
      
      validatePropertyAttrValueAndBody(element, property);
      
      validatePropertyTypesValues(element, property);
    }
  }
  
  private void validatePropertyTypesValues(Element element, IDSProperty property)
  {
    String type = property.getPropertyType();
    String value = property.getPropertyValue();
    String body = property.getPropertyElemBody();
    if ((value != null) && (value.length() > 0)) {
      validatePropertySpecificTypeValue(type, value, element);
    } else if ((body != null) && (body.length() > 0)) {
      validatePropertySpecificTypeBody(type, body, element);
    }
  }
  
  private void validatePropertySpecificTypeBody(String type, String body, Element element)
  {
    StringTokenizer st = new StringTokenizer(body, "\n");
    while (st.hasMoreTokens())
    {
      String token = st.nextToken();
      token = token.trim();
      if (token.length() > 0) {
        validatePropertySpecificTypeValue(type, token, element);
      }
    }
  }
  
  private void validatePropertySpecificTypeValue(String type, String value, Element element)
  {
    if (type == null) {
      type = "String";
    }
    if ((!type.equals("Character")) && 
      (!type.equals("Boolean"))) {
      try
      {
        Class forName = Class.forName("java.lang." + type);
        Constructor[] constructors = forName.getConstructors();
        for (int i = 0; i < constructors.length; i++)
        {
          Constructor constructor = constructors[i];
          Class[] parameterTypes = constructor.getParameterTypes();
          if ((parameterTypes.length == 1) && 
            (parameterTypes[0].equals(
            Class.forName("java.lang.String")))) {
            constructor.newInstance(new Object[] { value });
          }
        }
      }
      catch (Exception localException)
      {
        reportPropertyTypeCastException(element, value, type);
      }
    } else if (type.equals("Boolean"))
    {
      if ((!value.equals("false")) && 
        (!value.equals("true"))) {
        reportPropertyTypeCastException(element, value, type);
      }
    }
    else if ((type.equals("Character")) && 
      (value.length() > 1)) {
      reportPropertyTypeCastException(element, value, type);
    }
  }
  
  private void reportPropertyTypeCastException(Element element, String value, String type)
  {
    String message = NLS.bind(
      Messages.DSErrorReporter_propertyTypeCastException, 
      new String[] { value, type });
    report(message, getLine(element), 1, "");
  }
  
  private void validatePropertyAttrValueAndBody(Element element, IDSProperty property)
  {
    if (property.getPropertyValue() != null)
    {
      if ((property.getPropertyElemBody() != null) && 
        (!property.getPropertyElemBody().equals("")))
      {
        String propertyName = property.getPropertyName();
        reportSingleAndMultiplePropertyValues(element, propertyName, 
          property.getPropertyValue());
      }
      String propertyType = property.getPropertyType();
      if ((propertyType == null) || 
      
        (propertyType.equals("String"))) {
        return;
      }
      if (property.getPropertyValue().equals(""))
      {
        String propertyName = property.getPropertyName();
        reportEmptyPropertyValue(element, propertyName);
      }
    }
    else if ((property.getPropertyElemBody() == null) || 
      (property.getPropertyElemBody().equals("")))
    {
      String propertyName = property.getPropertyName();
      reportEmptyPropertyValue(element, propertyName);
    }
  }
  
  private void reportEmptyPropertyValue(Element element, String propertyName)
  {
    String message = NLS.bind(Messages.DSErrorReporter_emptyPropertyValue, 
      propertyName);
    report(message, getLine(element), 1, "");
  }
  
  private void reportSingleAndMultiplePropertyValues(Element element, String propertyName, String value)
  {
    String message = NLS.bind(
      Messages.DSErrorReporter_singleAndMultipleAttrValue, 
      propertyName, value);
    report(message, getLine(element), 1, "");
  }
  
  private void validatePropertyTypes(Element element)
  {
    String attribute = element
      .getAttribute("type");
    String[] allowedValues = {
      "Boolean", 
      "Byte", 
      "Character", 
      "Double", 
      "Float", 
      "Integer", 
      "Long", 
      "Short", 
      "String" };
    if (attribute != null)
    {
      for (int i = 0; i < allowedValues.length; i++) {
        if (allowedValues[i].equalsIgnoreCase(attribute)) {
          return;
        }
      }
      reportIllegalAttributeValue(element, element
        .getAttributeNode("type"));
    }
  }
  
  private void validateImplementationElement(IDSImplementation implementation)
  {
    if (implementation != null)
    {
      String className = implementation.getClassName();
      Element element = (Element)getElements(implementation).item(0);
      if (className == null) {
        reportMissingRequiredAttribute(element, 
          "class", 0);
      } else {
        validateJavaElement(className, 
          "implementation", 
          "class", 0);
      }
    }
  }
  
  private void validateJavaElement(String fullyQualifiedName, String elementName, String attrName, int index)
  {
    try
    {
      if (fProject.hasNature("org.eclipse.jdt.core.javanature"))
      {
        IJavaProject jp = JavaCore.create(fProject);
        if (!DSJavaHelper.isOnClasspath(fullyQualifiedName, jp)) {
          reportJavaTypeNotFound(elementName, attrName, 
            fullyQualifiedName, index);
        }
      }
    }
    catch (CoreException localCoreException) {}
  }
  
  private void reportMissingRequiredAttribute(Element element, String attName, int severity)
  {
    String message = NLS.bind(Messages.DSErrorReporter_requiredAttribute, 
      attName, element.getNodeName());
    report(message, getLine(element), severity, "");
  }
  
  private void reportJavaTypeNotFound(String elementConstant, String attributeConstant, String resource, int index)
  {
    Element documentRoot = getDocumentRoot();
    NodeList elementsByTagName = documentRoot
      .getElementsByTagName(elementConstant);
    Element element = (Element)elementsByTagName.item(index);
    report(NLS.bind(Messages.DSErrorReporter_cannotFindJavaType, resource, 
      attributeConstant), getLine(element), 1, 
      "");
  }
  
  private void validateComponentElement(IDSComponent component)
  {
    if (component != null)
    {
      Element element = getDocumentRoot();
      if (component.getImplementation() == null) {
        report(NLS.bind(Messages.DSErrorReporter_requiredElement, 
          "implementation"), 
          getLine(getDocumentRoot()), 0, 
          "");
      }
      validateBoolean(
        element, 
        element
        .getAttributeNode("immediate"));
      validateBoolean(element, element
        .getAttributeNode("enabled"));
      
      validateEmpty(element, element
        .getAttributeNode("factory"));
      
      validateEmpty(element, element
        .getAttributeNode("name"));
      
      validateImmediateAttribute(element, component);
      
      validateConfigurationPolicyAttribute(element, component);
    }
  }
  
  private void validateConfigurationPolicyAttribute(Element element, IDSComponent component)
  {
    String modified = component.getModifiedMethod();
    String policy = component.getConfigurationPolicy();
    if ((policy != null) && (policy.length() > 0)) {
      if ((policy.equalsIgnoreCase("ignore")) && 
        (modified != null) && (modified.length() > 0)) {
        report(
          Messages.DSErrorReporter_invalidConfigurationPolicyValue, 
          getLine(element), 1, 
          "");
      }
    }
  }
  
  private void validateImmediateAttribute(Element element, IDSComponent component)
  {
    boolean isService = false;
    boolean isFactory = component.getFactory() != null;
    boolean isImmediate = component.getImmediate();
    if (component.getService() != null)
    {
      IDSProvide[] providedServices = component.getService()
        .getProvidedServices();
      if ((providedServices != null) && (providedServices.length > 0)) {
        isService = true;
      }
    }
    if ((!isService) && (!isFactory) && (!isImmediate) && 
      (component
      .getXMLAttributeValue("immediate") != null)) {
      reportInvalidImmediate(element);
    }
    if ((isFactory) && (isImmediate)) {
      reportInvalidImmediateFactory(element);
    }
  }
  
  private void reportInvalidImmediateFactory(Element element)
  {
    report(Messages.DSErrorReporter_invalidImmediateValueFactory, 
      getLine(element), 1, "");
  }
  
  private void reportInvalidImmediate(Element element)
  {
    report(Messages.DSErrorReporter_invalidImmediateValue, 
      getLine(element), 1, "");
  }
  
  private void validateEmpty(Element element, Attr attr)
  {
    if (attr != null)
    {
      String value = attr.getValue();
      if (value.equalsIgnoreCase("")) {
        reportIllegalEmptyAttributeValue(element, attr);
      }
    }
  }
  
  private void reportIllegalEmptyAttributeValue(Element element, Attr attr)
  {
    if ((attr == null) || (attr.getValue() == null) || (attr.getName() == null)) {
      return;
    }
    String message = NLS.bind(Messages.DSErrorReporter_emptyAttrValue, attr
      .getName());
    report(message, getLine(element, attr.getName()), 0, 
      "");
  }
  
  private voi
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd