Ejemplo n.º 1
0
 /** Creates a new instance that has a property for each available property type. */
 public MetaClass() {
   try {
     List<PropertyClassProvider> providers =
         Utils.getContextComponentManager().getInstanceList(PropertyClassProvider.class);
     for (PropertyClassProvider provider : providers) {
       PropertyInterface property = provider.getDefinition();
       safeput(property.getName(), property);
     }
   } catch (ComponentLookupException e) {
     LOGGER.error("Failed to initialize the meta class.", e);
   }
 }
Ejemplo n.º 2
0
  public void fromXML(Element cel) throws XWikiException {
    try {
      int j = 1;
      setName(cel.element("name").getText());
      Element cclel = cel.element("customClass");
      if (cclel != null) {
        setCustomClass(cclel.getText());
        j++;
      }
      Element cmapel = cel.element("customMapping");
      if (cmapel != null) {
        setCustomMapping(cmapel.getText());
        j++;
      }
      Element cdvsel = cel.element("defaultViewSheet");
      if (cdvsel != null) {
        setDefaultViewSheet(cdvsel.getText());
        j++;
      }
      Element cdesel = cel.element("defaultEditSheet");
      if (cdesel != null) {
        setDefaultViewSheet(cdesel.getText());
        j++;
      }
      Element cdwel = cel.element("defaultWeb");
      if (cdwel != null) {
        setDefaultWeb(cdwel.getText());
        j++;
      }
      Element cnfel = cel.element("nameField");
      if (cnfel != null) {
        setNameField(cnfel.getText());
        j++;
      }

      Element valel = cel.element("validationScript");
      if (valel != null) {
        setValidationScript(valel.getText());
        j++;
      }

      @SuppressWarnings("unchecked")
      List<Element> list = cel.elements();
      for (int i = j; i < list.size(); i++) {
        Element pcel = list.get(i);
        String name = pcel.getName();
        String classType = pcel.element("classType").getText();
        PropertyClassProvider provider = null;
        try {
          // First try to use the specified class type as hint.
          provider = Utils.getComponent(PropertyClassProvider.class, classType);
        } catch (Exception e) {
          // In previous versions the class type was the full Java class name of the property class
          // implementation. Extract the hint by removing the Java package prefix and the Class
          // suffix.
          classType =
              StringUtils.removeEnd(StringUtils.substringAfterLast(classType, "."), "Class");
          provider = Utils.getComponent(PropertyClassProvider.class, classType);
        }
        // We should use PropertyClassInterface (instead of PropertyClass, its default
        // implementation) but it
        // doesn't have the fromXML method and adding it breaks the backwards compatibility. We make
        // the
        // assumption that all property classes extend PropertyClass.
        PropertyClass property = (PropertyClass) provider.getInstance();
        property.setName(name);
        property.setObject(this);
        property.fromXML(pcel);
        safeput(name, property);
      }
    } catch (Exception e) {
      throw new XWikiException(
          XWikiException.MODULE_XWIKI_CLASSES,
          XWikiException.ERROR_XWIKI_CLASSES_PROPERTY_CLASS_INSTANCIATION,
          "Error instanciating property class",
          e,
          null);
    }
  }