Example usage for org.apache.commons.lang StringUtils substringBetween

List of usage examples for org.apache.commons.lang StringUtils substringBetween

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringBetween.

Prototype

public static String substringBetween(String str, String open, String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:org.eclipse.wb.internal.core.model.util.TemplateUtils.java

/**
 * Evaluates source {@link String}, with <code>"${variable}"</code> variables and
 * <code>"${expression}"</code> expressions.
 * <p>/*from  w w w .  j  ava2s. c  o m*/
 * Typical expression is <code>"${parent.firstChild[java.awt.LayoutManager].expression}"</code>.
 * 
 * @param source
 *          the source {@link String} to evaluate.
 * @param javaInfo
 *          the starting {@link JavaInfo}, relative to which expressions should be evaluated.
 * @param templateVariables
 *          the {@link Map} to variable names into values, may be <code>null</code>.
 * 
 * @return the source with replaced template variables/expressions.
 */
public static String evaluate(String source, JavaInfo javaInfo, Map<String, String> templateVariables)
        throws Exception {
    // replace template variables
    if (templateVariables != null) {
        source = StrSubstitutor.replace(source, templateVariables);
    }
    // replace template expressions
    while (true) {
        // extract single template expression
        String expression = StringUtils.substringBetween(source, "${", "}");
        if (expression == null) {
            break;
        }
        // replace template expression
        try {
            String result = evaluateExpression(expression, javaInfo);
            source = StringUtils.replace(source, "${" + expression + "}", result);
        } catch (Throwable e) {
            String message = String.format("Exception during evaluation |%s|.", source);
            throw new IllegalArgumentException(message, e);
        }
    }
    return source;
}

From source file:org.eclipse.wb.internal.rcp.databinding.emf.model.bindables.EObjectBindableInfo.java

@Override
public EPropertyBindableInfo resolvePropertyReference(String reference) throws Exception {
    if (reference.startsWith("org.eclipse.emf.databinding.FeaturePath.fromList(")) {
        reference = StringUtils.substringBetween(reference, "(", ")");
        String[] references = StringUtils.split(reference, ", ");
        ////from w  w w  .  jav  a2 s. c o m
        for (EPropertyBindableInfo property : m_properties) {
            if (references[0].equals(property.getReference())) {
                return property.resolvePropertyReference(references, 1);
            }
        }
    } else {
        for (EPropertyBindableInfo property : m_properties) {
            if (reference.equals(property.getReference())) {
                return property;
            }
        }
    }
    return null;
}

From source file:org.eclipse.wb.internal.rcp.databinding.emf.model.observables.DetailEmfObservableInfo.java

@Override
public void setDetailPropertyReference(Class<?> detailBeanClass, String detailPropertyReference)
        throws Exception {
    m_detailPropertyReference = detailPropertyReference;
    ////from   www .  j a v a2s  .  com
    if (detailBeanClass == null) {
        if (detailPropertyReference.startsWith("org.eclipse.emf.databinding.FeaturePath.fromList(")) {
            detailPropertyReference = StringUtils.substringBetween(detailPropertyReference, "(", ")");
            String[] references = StringUtils.split(detailPropertyReference, ", ");
            detailPropertyReference = references[references.length - 1];
        }
    } else {
        m_detailBeanClass = detailBeanClass;
    }
    // prepare EMF class info
    Object[] result = m_propertiesSupport.getClassInfoForProperty(detailPropertyReference);
    Assert.isNotNull(result);
    // prepare detail class
    if (detailBeanClass == null) {
        ClassInfo classInfo = (ClassInfo) result[0];
        m_detailBeanClass = classInfo.thisClass;
    }
    // prepare EMF property
    PropertyInfo emfPropertyInfo = (PropertyInfo) result[1];
    Assert.isNotNull(emfPropertyInfo.type);
    m_detailPropertyType = emfPropertyInfo.type;
    //
    m_detailEMFPropertyName = "\"" + emfPropertyInfo.name + "\"";
}

From source file:org.eclipse.wb.internal.rcp.databinding.model.ControllerSupport.java

public static String automaticWizardPerformSubstitutions(AutomaticDatabindingFirstPage firstWizardPage,
        String code, ImportsManager imports, IJavaProject javaProject, ClassLoader classLoader,
        Class<?> beanClass, List<PropertyAdapter> properties,
        Map<PropertyAdapter, AbstractDescriptor[]> propertyToEditor) throws Exception {
    InputStream controllerStream = Activator.getFile("templates/Controller.jvt");
    String controllerCode = IOUtils.toString(controllerStream);
    IOUtils.closeQuietly(controllerStream);
    ///*from   ww w.  j av  a2 s.  c  o  m*/
    String hostClassName = ClassUtils.getShortClassName(firstWizardPage.getTypeName());
    String hostVariable = StringUtils.uncapitalize(hostClassName);
    String hostField = "m_" + hostVariable;
    //
    controllerCode = StringUtils.replace(controllerCode, "%HostClass%", hostClassName);
    controllerCode = StringUtils.replace(controllerCode, "%HostVariable%", hostVariable);
    controllerCode = StringUtils.replace(controllerCode, "%HostField%", hostField);
    //
    String begin = "";
    String end = "\t\t";
    String widgetStart = "";
    boolean blockMode = SwtDatabindingProvider.useBlockMode();
    if (blockMode) {
        begin = "\t\t{\r\n";
        end = "\t\t}";
        widgetStart = "\t";
    }
    // prepare imports
    Collection<String> hostImportList = Sets.newHashSet();
    hostImportList.add(SWT.class.getName());
    hostImportList.add("org.eclipse.swt.widgets.Label");
    hostImportList.add("org.eclipse.swt.layout.GridLayout");
    hostImportList.add("org.eclipse.swt.layout.GridData");
    //
    Collection<String> controllerImportList = Sets.newHashSet();
    controllerImportList.add(SWT.class.getName());
    controllerImportList.add("org.eclipse.jface.databinding.swt.SWTObservables");
    controllerImportList.add("org.eclipse.core.databinding.observable.value.IObservableValue");
    controllerImportList.add("org.eclipse.core.databinding.UpdateValueStrategy");
    //
    DataBindingsCodeUtils.ensureDBLibraries(javaProject);
    //
    IAutomaticWizardStub automaticWizardStub = GlobalFactoryHelper.automaticWizardCreateStub(javaProject,
            classLoader, beanClass);
    //
    String observeMethod = null;
    if (automaticWizardStub == null) {
        if (ObservableInfo.isPojoBean(beanClass)) {
            String pojoClassName = DataBindingsCodeUtils.getPojoObservablesClass();
            observeMethod = "ObserveValue = " + ClassUtils.getShortClassName(pojoClassName) + ".observeValue(";
            controllerImportList.add(pojoClassName);
        } else {
            observeMethod = "ObserveValue = BeansObservables.observeValue(";
            controllerImportList.add("org.eclipse.core.databinding.beans.BeansObservables");
        }
    } else {
        automaticWizardStub.addImports(controllerImportList);
    }
    // prepare bean
    String beanClassName = CoreUtils.getClassName(beanClass);
    String beanClassShortName = ClassUtils.getShortClassName(beanClassName);
    String fieldPrefix = JavaCore.getOption(JavaCore.CODEASSIST_FIELD_PREFIXES);
    String fieldName = fieldPrefix + StringUtils.uncapitalize(beanClassShortName);
    controllerCode = StringUtils.replace(controllerCode, "%BeanClass%", beanClassName);
    //
    if (ReflectionUtils.getConstructorBySignature(beanClass, "<init>()") == null) {
        controllerCode = StringUtils.replace(controllerCode, "%BeanField%", fieldName);
    } else {
        controllerCode = StringUtils.replace(controllerCode, "%BeanField%",
                fieldName + " = new " + beanClassName + "()");
    }
    //
    IPreferenceStore preferences = ToolkitProvider.DESCRIPTION.getPreferences();
    String accessPrefix = preferences.getBoolean(FieldUniqueVariableSupport.P_PREFIX_THIS) ? "this." : "";
    controllerCode = StringUtils.replace(controllerCode, "%BeanFieldAccess%", accessPrefix + fieldName);
    //
    controllerCode = StringUtils.replace(controllerCode, "%BeanName%",
            StringUtils.capitalize(beanClassShortName));
    // prepare code
    StringBuffer widgetFields = new StringBuffer();
    StringBuffer widgets = new StringBuffer();
    String swtContainer = StringUtils.substringBetween(code, "%Widgets%", "%");
    String swtContainerWithDot = "this".equals(swtContainer) ? "" : swtContainer + ".";
    //
    StringBuffer observables = new StringBuffer();
    StringBuffer bindings = new StringBuffer();
    StringBuffer widgetGetters = new StringBuffer();
    //
    hostImportList.add(GridLayout.class.getName());
    widgets.append("\t\t" + swtContainerWithDot + "setLayout(new GridLayout(2, false));\r\n");
    if (!blockMode) {
        widgets.append("\t\t\r\n");
    }
    //
    for (Iterator<PropertyAdapter> I = properties.iterator(); I.hasNext();) {
        PropertyAdapter property = I.next();
        Object[] editorData = propertyToEditor.get(property);
        SwtWidgetDescriptor widgetDescriptor = (SwtWidgetDescriptor) editorData[0];
        JFaceBindingStrategyDescriptor strategyDescriptor = (JFaceBindingStrategyDescriptor) editorData[1];
        //
        String propertyName = property.getName();
        String widgetClassName = widgetDescriptor.getClassName();
        String widgetFieldName = fieldPrefix + propertyName + widgetClassName;
        String widgetFieldAccess = accessPrefix + widgetFieldName;
        String widgetAccessor = "get" + StringUtils.capitalize(propertyName) + widgetClassName + "()";
        String widgetControllerAccessor = hostField + "." + widgetAccessor;
        // getter
        widgetGetters.append("method\n\tpublic " + widgetClassName + " " + widgetAccessor + " {\n\t\treturn "
                + widgetFieldName + ";\n\t}\n\n");
        // field
        widgetFields.append("\r\nfield\r\n\tprivate " + widgetClassName + " " + widgetFieldName + ";");
        // widget
        widgets.append(begin);
        widgets.append(widgetStart + "\t\tnew Label(" + swtContainer + ", SWT.NONE).setText(\""
                + StringUtils.capitalize(propertyName) + ":\");\r\n");
        widgets.append(end + "\r\n");
        //
        widgets.append(begin);
        widgets.append(
                "\t\t" + widgetFieldAccess + " = " + widgetDescriptor.getCreateCode(swtContainer) + ";\r\n");
        widgets.append(widgetStart + "\t\t" + widgetFieldAccess
                + ".setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r\n");
        widgets.append(end);
        // observables
        observables.append("\t\tIObservableValue " + propertyName + "ObserveWidget = "
                + widgetDescriptor.getBindingCode(widgetControllerAccessor) + ";\r\n");
        if (automaticWizardStub == null) {
            observables.append("\t\tIObservableValue " + propertyName + observeMethod + fieldName + ", \""
                    + propertyName + "\");");
        } else {
            observables.append(automaticWizardStub.createSourceCode(fieldName, propertyName));
        }
        // bindings
        bindings.append("\t\tbindingContext.bindValue(" + propertyName + "ObserveWidget, " + propertyName
                + "ObserveValue, " + strategyDescriptor.getTargetStrategyCode() + ", "
                + strategyDescriptor.getModelStrategyCode() + ");");
        //
        if (I.hasNext()) {
            widgetFields.append("\r\n");
            widgets.append("\r\n");
            observables.append("\r\n");
            bindings.append("\r\n");
        }
        //
        hostImportList.add(widgetDescriptor.getFullClassName());
    }
    // replace template patterns
    String controllerClass = hostClassName + "Controller";
    code = StringUtils.replace(code, "%ControllerClass%", controllerClass);
    code = StringUtils.replace(code, "%WidgetFields%", widgetFields.toString());
    code = StringUtils.replace(code, "%Widgets%" + swtContainer + "%", widgets.toString());
    code = StringUtils.replace(code, "%WidgetGetters%", widgetGetters.toString());
    //
    controllerCode = StringUtils.replace(controllerCode, "%Observables%", observables.toString());
    controllerCode = StringUtils.replace(controllerCode, "%Bindings%", bindings.toString());
    // add imports
    for (String qualifiedTypeName : hostImportList) {
        imports.addImport(qualifiedTypeName);
    }
    StringBuffer controllerImportString = new StringBuffer();
    for (String controllerImport : controllerImportList) {
        controllerImportString.append("import " + controllerImport + ";\n");
    }
    controllerCode = StringUtils.replace(controllerCode, "%imports%", controllerImportString.toString());
    //
    IPackageFragment packageFragment = firstWizardPage.getPackageFragment();
    //
    String packageString = packageFragment.getElementName();
    if (packageString.length() > 0) {
        packageString = "package " + packageString + ";";
    }
    controllerCode = StringUtils.replace(controllerCode, "%package%", packageString);
    //
    IPath packagePath = packageFragment.getPath().removeFirstSegments(1);
    IFile controllerFile = javaProject.getProject().getFile(packagePath.append(controllerClass + ".java"));
    IOUtils2.setFileContents(controllerFile, controllerCode);
    //
    return code;
}

From source file:org.eclipse.wb.internal.rcp.databinding.model.widgets.input.CellEditorValuePropertyCodeSupport.java

public void setParsePropertyReference(String parsePropertyReference) {
    if (getParsePropertyReference().equals(parsePropertyReference)) {
        return;/*from   ww  w . j  a v  a2s.  com*/
    }
    if (parsePropertyReference.startsWith("\"control.")) {
        if (m_master == null) {
            m_master = new CellEditorControlPropertyCodeSupport();
        }
        String propertyReference = getParsePropertyReference(
                StringUtils.substringBetween(parsePropertyReference, ".", "\""));
        m_detail = createDetail(propertyReference);
    } else {
        m_master = null;
        String propertyReference = getParsePropertyReference(
                StringUtils.substringBetween(parsePropertyReference, "\"", "\""));
        m_detail = createDetail(propertyReference);
    }
}

From source file:org.eclipse.wb.internal.rcp.databinding.parser.BindingContextClassLoaderInitializer.java

/**
 * Inject to all public static methods contains parameters {@code Object} bean and {@code String}
 * property://from   w  w  w  .  ja  va 2s . c o  m
 * 
 * <pre>
  * public static %ReturnType% %method%(..., Object bean, ..., String property, ....) {
  *     if (bean == null) {
  *         bean = DefaultBean.INSTANCE;
  *         property = "foo"; // "fooList"; // "fooSet";
  *     }
  *     %FOO_BODY_PART%
  * }
  * </pre>
 */
private static byte[] transformBindings(byte[] bytes) {
    ClassReader classReader = new ClassReader(bytes);
    ToBytesClassAdapter codeRewriter = new ToBytesClassAdapter(ClassWriter.COMPUTE_MAXS) {
        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
            if ((access & ACC_PUBLIC) != 0 && (access & ACC_STATIC) != 0) {
                // find indexes for bean object argument and bean property argument
                final int[] indexes = { -1, -1 };
                String[] parameters = StringUtils.split(StringUtils.substringBetween(desc, "(", ")"), ";");
                for (int i = 0; i < parameters.length; i++) {
                    String parameter = parameters[i];
                    if (indexes[0] == -1 && parameter.equals("Ljava/lang/Object")) {
                        indexes[0] = i;
                    } else if (indexes[0] != -1 && indexes[1] == -1 && parameter.equals("Ljava/lang/String")) {
                        indexes[1] = i;
                    }
                }
                if (indexes[0] != -1 && indexes[1] != -1) {
                    // prepare bean property name
                    final String[] property = { "foo" };
                    if (name.endsWith("List")) {
                        property[0] = "fooList";
                    } else if (name.endsWith("Set")) {
                        property[0] = "fooSet";
                    }
                    return new MethodAdapter(mv) {
                        @Override
                        public void visitCode() {
                            visitVarInsn(ALOAD, indexes[0]);
                            Label label = new Label();
                            visitJumpInsn(IFNONNULL, label);
                            visitFieldInsn(GETSTATIC,
                                    "org/eclipse/wb/internal/rcp/databinding/parser/DefaultBean", "INSTANCE",
                                    "Lorg/eclipse/wb/internal/rcp/databinding/parser/DefaultBean;");
                            visitVarInsn(ASTORE, indexes[0]);
                            visitLdcInsn(property[0]);
                            visitVarInsn(ASTORE, indexes[1]);
                            visitLabel(label);
                            super.visitCode();
                        }
                    };
                }
            }
            return mv;
        }
    };
    classReader.accept(codeRewriter, 0);
    return codeRewriter.toByteArray();
}

From source file:org.eclipse.wb.internal.rcp.databinding.wizards.autobindings.SwtDatabindingProvider.java

public String performSubstitutions(String code, ImportsManager imports) throws Exception {
    // prepare properties
    final List<PropertyAdapter> properties = Lists.newArrayList();
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            CollectionUtils.addAll(properties, m_propertiesViewer.getCheckedElements());
        }/*from  w  w  w  .j av a 2 s .c o  m*/
    });
    //
    if (m_firstPage.isCreateControlClass()) {
        return ControllerSupport.automaticWizardPerformSubstitutions(m_firstPage, code, imports, m_javaProject,
                m_classLoader, m_beanClass, properties, m_propertyToEditor);
    }
    //
    String begin = "";
    String end = "\t\t";
    String widgetStart = "";
    boolean blockMode = useBlockMode();
    if (blockMode) {
        begin = "\t\t{\r\n";
        end = "\t\t}";
        widgetStart = "\t";
    }
    // prepare imports
    Collection<String> importList = Sets.newHashSet();
    importList.add(SWT.class.getName());
    importList.add("org.eclipse.jface.databinding.swt.SWTObservables");
    importList.add("org.eclipse.core.databinding.observable.value.IObservableValue");
    importList.add("org.eclipse.core.databinding.UpdateValueStrategy");
    importList.add("org.eclipse.swt.widgets.Label");
    importList.add("org.eclipse.swt.layout.GridLayout");
    importList.add("org.eclipse.swt.layout.GridData");
    //
    DataBindingsCodeUtils.ensureDBLibraries(m_javaProject);
    //
    IAutomaticWizardStub automaticWizardStub = GlobalFactoryHelper.automaticWizardCreateStub(m_javaProject,
            m_classLoader, m_beanClass);
    //
    String observeMethod = null;
    if (automaticWizardStub == null) {
        if (ObservableInfo.isPojoBean(m_beanClass)) {
            String pojoClass = DataBindingsCodeUtils.getPojoObservablesClass();
            observeMethod = "ObserveValue = " + ClassUtils.getShortClassName(pojoClass) + ".observeValue(";
            importList.add(pojoClass);
        } else {
            observeMethod = "ObserveValue = BeansObservables.observeValue(";
            importList.add("org.eclipse.core.databinding.beans.BeansObservables");
        }
    } else {
        automaticWizardStub.addImports(importList);
    }
    // prepare bean
    String beanClassName = CoreUtils.getClassName(m_beanClass);
    String beanClassShortName = ClassUtils.getShortClassName(beanClassName);
    String fieldPrefix = JavaCore.getOption(JavaCore.CODEASSIST_FIELD_PREFIXES);
    String fieldName = fieldPrefix + StringUtils.uncapitalize(beanClassShortName);
    code = StringUtils.replace(code, "%BeanClass%", beanClassName);
    //
    if (ReflectionUtils.getConstructorBySignature(m_beanClass, "<init>()") == null) {
        code = StringUtils.replace(code, "%BeanField%", fieldName);
    } else {
        code = StringUtils.replace(code, "%BeanField%", fieldName + " = new " + beanClassName + "()");
    }
    //
    IPreferenceStore preferences = ToolkitProvider.DESCRIPTION.getPreferences();
    String accessPrefix = preferences.getBoolean(FieldUniqueVariableSupport.P_PREFIX_THIS) ? "this." : "";
    code = StringUtils.replace(code, "%BeanFieldAccess%", accessPrefix + fieldName);
    //
    code = StringUtils.replace(code, "%BeanName%", StringUtils.capitalize(beanClassShortName));
    // prepare code
    StringBuffer widgetFields = new StringBuffer();
    StringBuffer widgets = new StringBuffer();
    String swtContainer = StringUtils.substringBetween(code, "%Widgets%", "%");
    String swtContainerWithDot = "this".equals(swtContainer) ? "" : swtContainer + ".";
    //
    StringBuffer observables = new StringBuffer();
    StringBuffer bindings = new StringBuffer();
    //
    importList.add(GridLayout.class.getName());
    widgets.append("\t\t" + swtContainerWithDot + "setLayout(new GridLayout(2, false));\r\n");
    if (!blockMode) {
        widgets.append("\t\t\r\n");
    }
    //
    for (Iterator<PropertyAdapter> I = properties.iterator(); I.hasNext();) {
        PropertyAdapter property = I.next();
        Object[] editorData = m_propertyToEditor.get(property);
        SwtWidgetDescriptor widgetDescriptor = (SwtWidgetDescriptor) editorData[0];
        JFaceBindingStrategyDescriptor strategyDescriptor = (JFaceBindingStrategyDescriptor) editorData[1];
        //
        String propertyName = property.getName();
        String widgetClassName = widgetDescriptor.getClassName();
        String widgetFieldName = fieldPrefix + propertyName + widgetClassName;
        String widgetFieldAccess = accessPrefix + widgetFieldName;
        // field
        widgetFields.append("\r\nfield\r\n\tprivate " + widgetClassName + " " + widgetFieldName + ";");
        // widget
        widgets.append(begin);
        widgets.append(widgetStart + "\t\tnew Label(" + swtContainer + ", SWT.NONE).setText(\""
                + StringUtils.capitalize(propertyName) + ":\");\r\n");
        widgets.append(end + "\r\n");
        //
        widgets.append(begin);
        widgets.append(
                "\t\t" + widgetFieldAccess + " = " + widgetDescriptor.getCreateCode(swtContainer) + ";\r\n");
        widgets.append(widgetStart + "\t\t" + widgetFieldAccess
                + ".setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r\n");
        widgets.append(end);
        // observables
        observables.append("\t\tIObservableValue " + propertyName + "ObserveWidget = "
                + widgetDescriptor.getBindingCode(widgetFieldName) + ";\r\n");
        if (automaticWizardStub == null) {
            observables.append("\t\tIObservableValue " + propertyName + observeMethod + fieldName + ", \""
                    + propertyName + "\");");
        } else {
            observables.append(automaticWizardStub.createSourceCode(fieldName, propertyName));
        }
        // bindings
        bindings.append("\t\tbindingContext.bindValue(" + propertyName + "ObserveWidget, " + propertyName
                + "ObserveValue, " + getStrategyValue(strategyDescriptor.getTargetStrategyCode()) + ", "
                + getStrategyValue(strategyDescriptor.getModelStrategyCode()) + ");");
        //
        if (I.hasNext()) {
            widgetFields.append("\r\n");
            widgets.append("\r\n");
            observables.append("\r\n");
            bindings.append("\r\n");
        }
        //
        importList.add(widgetDescriptor.getFullClassName());
    }
    // replace template patterns
    code = StringUtils.replace(code, "%WidgetFields%", widgetFields.toString());
    code = StringUtils.replace(code, "%Widgets%" + swtContainer + "%", widgets.toString());
    //
    code = StringUtils.replace(code, "%Observables%", observables.toString());
    code = StringUtils.replace(code, "%Bindings%", bindings.toString());
    // add imports
    for (String qualifiedTypeName : importList) {
        imports.addImport(qualifiedTypeName);
    }
    //
    return code;
}

From source file:org.eclipse.wb.internal.rcp.databinding.xwt.model.beans.BeansObserveTypeContainer.java

@Override
public void createObservables(XmlObjectInfo xmlObjectRoot) throws Exception {
    m_observables = Lists.newArrayList();
    m_xmlObjectRoot = xmlObjectRoot;//from  ww w  . j  ava2  s.  c  om
    // handle XML elements
    final ClassLoader classLoader = m_xmlObjectRoot.getContext().getClassLoader();
    final BeanSupport beanSupport = new BeanSupport(classLoader, null);
    final Class<?> BindingContextClass = classLoader.loadClass("org.eclipse.e4.xwt.databinding.BindingContext");
    //
    DocumentElement rootElement = m_xmlObjectRoot.getElement();
    //
    final Map<String, String> namespaceToPackage = Maps.newHashMap();
    final String[] xKey = new String[1];
    final String[] dataContextReference = new String[1];
    //
    for (DocumentAttribute attribute : rootElement.getDocumentAttributes()) {
        String name = attribute.getName();
        String value = attribute.getValue();
        if (name.startsWith(NAMESPACE_KEY)) {
            if (value.startsWith(NAMESPACE_VALUE)) {
                namespaceToPackage.put(name.substring(NAMESPACE_KEY.length()),
                        value.substring(NAMESPACE_VALUE.length()));
            } else if (value.equals("http://www.eclipse.org/xwt")) {
                xKey[0] = name.substring(NAMESPACE_KEY.length()) + ":Key";
            }
        } else if (name.equalsIgnoreCase("DataContext")) {
            dataContextReference[0] = StringUtils.substringBetween(value, "{StaticResource", "}").trim();
        }
    }
    //
    rootElement.accept(new DocumentModelVisitor() {
        @Override
        public boolean visit(DocumentElement element) {
            if (element.getTag().endsWith(".Resources")) {
                for (DocumentElement child : element.getChildren()) {
                    try {
                        String elementName = child.getTag();
                        Class<?> beanClass = null;
                        //
                        if (elementName.equalsIgnoreCase("BindingContext")) {
                            beanClass = BindingContextClass;
                        } else {
                            int index = elementName.indexOf(':');
                            String beanClassName = namespaceToPackage.get(elementName.substring(0, index)) + "."
                                    + elementName.substring(index + 1);
                            beanClass = CoreUtils.load(classLoader, beanClassName);
                        }
                        //
                        IReferenceProvider referenceProvider = new StringReferenceProvider(
                                child.getAttribute(xKey[0]));
                        boolean dataContext = referenceProvider.getReference().equals(dataContextReference[0]);
                        //
                        XmlElementBeanBindableInfo bindable = new XmlElementBeanBindableInfo(beanSupport,
                                beanClass, referenceProvider, null, dataContext);
                        m_observables.add(bindable);
                        if (dataContext) {
                            m_dataContext = bindable;
                        }
                    } catch (ClassNotFoundException e) {
                        m_xmlObjectRoot.getContext().addWarning(
                                new EditorWarning("ClassNotFoundException: " + element, new Throwable()));
                    } catch (Throwable e) {
                        throw ReflectionUtils.propagate(e);
                    }
                }
                return false;
            }
            return true;
        }
    });
}

From source file:org.eclipse.wb.internal.rcp.databinding.xwt.model.ConverterInfo.java

public void parse(DatabindingsProvider provider, DocumentElement root, String attribute) throws Exception {
    m_staticResurce = attribute != null && attribute.startsWith("{StaticResource");
    ////from   ww  w  .jav a 2  s. c  o  m
    if (m_staticResurce) {
        m_resourceReference = StringUtils.substringBetween(attribute, "{StaticResource", "}").trim();
        //
        BeansObserveTypeContainer beanContainer = (BeansObserveTypeContainer) provider
                .getContainer(ObserveType.BEANS);
        if (beanContainer.resolve(m_resourceReference) == null) {
            m_staticResurce = false;
            m_resourceReference = null;
            provider.addWarning(MessageFormat.format(Messages.ConverterInfo_converterNotFound, attribute),
                    new Throwable());
        }
    } else {
        parseClass(provider, root, attribute);
    }
}

From source file:org.eclipse.wb.internal.rcp.databinding.xwt.model.ValidationInfo.java

public void parse(DatabindingsProvider provider, DocumentElement root, String validationRules,
        String validationRule) throws Exception {
    if (validationRules != null) {
        parseNamespaces(root);/*ww w  . j a  v a  2s  .  c  o m*/
        String[] rules = StringUtils.split(StringUtils.substringBetween(validationRules, "{", "}"), ',');
        //
        for (String rule : rules) {
            parseClass(provider, rule.trim());
        }
    } else if (validationRule != null) {
        parseNamespaces(root);
        parseClass(provider, validationRule);
    } else {
        parseNamespaces(root);
    }
    m_namespaceToPackage = null;
}