public VResult[] check(VObject object) {
    XModelObject o = ((VObjectImpl) object).getModelObject();
    String paramName = o.getAttributeValue("param-name");
    if (paramName == null) return null;
    XModelObject parent = o.getParent();
    if (parent == null || !"WebAppServlet".equals(parent.getModelEntity().getName())) {
      return null;
    }
    if (!paramName.equals("config") && !paramName.startsWith("config/")) return null;

    String value = o.getAttributeValue("param-value");
    if (value == null || value.length() == 0) return null;
    XModel model = getXModel(object);
    XModelObject webRoot = model == null ? null : model.getByPath("FileSystems/WEB-ROOT");
    if (webRoot == null) return null;
    StringTokenizer st = new StringTokenizer(value, ",");
    while (st.hasMoreTokens()) {
      String path = st.nextToken().trim();
      if (path.length() == 0) continue;
      XModelObject fc = XModelImpl.getByRelativePath(model, path);
      if (fc == null) {
        return fire(object, "config.exists", "param-value", path);
      }
      String path2 = path.startsWith("/") ? path.substring(1) : path;
      XModelObject fc2 = webRoot.getChildByPath(path2);
      if (fc2 == null) {
        return fire(object, "config.exists", "param-value", path);
      }
      if (!fc2.getModelEntity().getName().startsWith("StrutsConfig")) {
        return fire(object, "config.valid", "param-value", path);
      }
    }
    return null;
  }
 public static XModelObject getJarEntryObject(IProject p, String jarFile, String entry) {
   if (p == null) {
     IFile f = EclipseResourceUtil.getFile(jarFile);
     if (f == null) return null;
     p = f.getProject();
   }
   if (p == null) return null;
   IModelNature n = EclipseResourceUtil.getModelNature(p);
   XModel model = null;
   if (n != null) {
     model = n.getModel();
   } else {
     XModelObject o = EclipseResourceUtil.createObjectForResource(p);
     if (o != null) model = o.getModel();
   }
   if (model == null) return null;
   XModelObject[] fs = FileSystemsHelper.getFileSystems(model).getChildren();
   for (XModelObject s : fs) {
     String loc =
         Paths.expand(s.get(XModelObjectConstants.ATTR_NAME_LOCATION), model.getProperties());
     if (new File(loc).equals(new File(jarFile))) {
       XModelObject result = s.getChildByPath(entry);
       if (result == null && entry != null) {
         int q = entry.indexOf('/');
         int d = entry.indexOf('.');
         if (q > d && d >= 0) {
           String entry1 = entry.substring(0, q).replace('.', '/') + entry.substring(q);
           result = s.getChildByPath(entry1);
         }
       }
       if (result != null) return result;
     }
   }
   return (n == null) ? null : n.getModel().getByPath("/" + entry); // $NON-NLS-1$
 }
 /**
  * Unregisters listener from this cache. The listener is removed from all models to which it has
  * been added.
  */
 public void removeListener(XModelTreeListener listener) {
   listeners.remove(listener);
   Collection<Map<XModel, XFilteredTree>> i1 = map.values();
   for (Map<XModel, XFilteredTree> m : i1) {
     Collection<XFilteredTree> i2 = m.values();
     for (XFilteredTree t : i2) {
       XModel model = t.getRoot().getModel();
       if (model != null) model.removeModelTreeListener(listener);
     }
   }
 }
 public void remove(XModel model) {
   if (model == null) return;
   Collection<Map<XModel, XFilteredTree>> i1 = map.values();
   for (Map<XModel, XFilteredTree> m : i1) {
     m.remove(model);
     for (XModelTreeListener l : listeners) {
       model.removeModelTreeListener(l);
     }
   }
 }
  public Composite fillGeneralOption(Composite generalTabContent) {

    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 3;
    generalTabContent.setLayout(layout);

    XModel model = getXModel();
    if (model == null) model = XModelFactory.getDefaultInstance();
    support.init(model.getRoot(), data);
    Control c = support.createControl(generalTabContent);
    pcl = new PCL();
    support.addPropertyChangeListener(pcl);

    fWizardModel = getSpecificWizard().getWizardModel();
    mpcl = new MPCL();
    fWizardModel.addPropertyChangeListener(mpcl);

    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 3;
    c.setLayoutData(data);

    data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    generalTabContent.setLayoutData(data);

    Label properties = new Label(generalTabContent, SWT.NONE);
    properties.setText(JsfUIMessages.DataTableWizardPage_Properties);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 3;
    properties.setLayoutData(data);

    propertyListEditor.setObject(propertyListObject);
    Control propertiesTable = propertyListEditor.createControl(generalTabContent);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 3;
    propertiesTable.setLayoutData(data);

    return generalTabContent;
  }
 XFilteredTree createTree(String name, XModel model) {
   if (model == null || name == null) return null;
   String classname =
       model.getMetaData().getMapping("FilteredTrees").getValue(name); // $NON-NLS-1$
   XFilteredTree result = null;
   try {
     result = (XFilteredTree) ModelFeatureFactory.getInstance().createFeatureInstance(classname);
   } catch (ClassCastException e) {
     ModelUIPlugin.getPluginLog().logError(e);
     return null;
   }
   result.setModel(model);
   if (result.getRoot() == null) {
     result = null;
     IProject p = EclipseResourceUtil.getProject(model.getRoot());
     IModelNature nature = EclipseResourceUtil.getModelNature(p);
     if (nature != null) {
       ModelUIPlugin.getPluginLog()
           .logInfo(
               "Red Hat Project " + p.getName() + " is corrupted."); // $NON-NLS-1$ //$NON-NLS-2$
     }
   }
   return result;
 }
Ejemplo n.º 7
0
 void doAttributeTest(XModel model, String testName) {
   IFile f = project.getFile(new Path("/testCases.xml"));
   ArrayList<TestDescription> tests = new TestDescriptionFactory(f).getTestDescriptions(testName);
   System.out.println(testName + " " + (tests == null ? -1 : tests.size()));
   StringBuilder sb = new StringBuilder();
   int errorCount = 0;
   if (tests != null)
     for (int i = 0; i < tests.size(); i++) {
       TestDescription t = tests.get(i);
       String path = t.getProperty("path");
       XModelObject o = model.getByPath(path);
       if (o == null) {
         sb.append("Cannot find object at " + path).append("\n");
         errorCount++;
         continue;
       }
       String attribute = t.getProperty("attributeName");
       if (attribute == null) {
         sb.append("Attribute name is required for this test " + path).append("\n");
         errorCount++;
         continue;
       }
       if (o.getModelEntity().getAttribute(attribute) == null) {
         sb.append("Attribute " + attribute + " is not found in object " + path).append("\n");
         errorCount++;
         continue;
       }
       String testValue = t.getProperty("attributeValue");
       String realValue = o.getAttributeValue(attribute);
       if (realValue == null || !realValue.equals(testValue)) {
         sb.append(
                 "Attribute "
                     + attribute
                     + " in object "
                     + path
                     + " has unexpected value '"
                     + realValue
                     + "'")
             .append("\n");
         errorCount++;
         continue;
       }
     }
   assertTrue(sb.toString(), errorCount == 0);
 }
 /**
  * Registers listener with this cache. Using this cache by stateless content providers makes it
  * necessary to register listener with it, rather than just add it to model. Then, by
  * unregistering the listener while disposing content provider, we can be sure that the listener
  * is removed from all models to which it has been added.
  *
  * @param listener
  * @param model
  */
 public void addListener(XModelTreeListener listener, XModel model) {
   listeners.add(listener);
   model.addModelTreeListener(listener);
 }