001/*
002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.platform.ui.web.seamremoting;
023
024import java.util.ArrayList;
025import java.util.List;
026
027import org.jboss.seam.ScopeType;
028import org.jboss.seam.annotations.Factory;
029import org.jboss.seam.annotations.Name;
030import org.jboss.seam.annotations.Scope;
031import org.nuxeo.runtime.model.ComponentInstance;
032import org.nuxeo.runtime.model.DefaultComponent;
033
034@Name("SeamRemotingJSBuilderService")
035@Scope(ScopeType.STATELESS)
036public class SeamRemotingJSBuilderComponent extends DefaultComponent implements SeamRemotingJSBuilderService {
037
038    public static final String EP_REMOTABLE_SEAMBEANS = "remotableSeamBeans";
039
040    protected static final List<String> beanNames = new ArrayList<String>();
041
042    @Override
043    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
044
045        if (extensionPoint.equals(EP_REMOTABLE_SEAMBEANS)) {
046            RemotableSeamBeansDescriptor descriptor = (RemotableSeamBeansDescriptor) contribution;
047            beanNames.addAll(descriptor.getBeanNames());
048        }
049    }
050
051    @Override
052    public List<String> getRemotableBeanNames() {
053        return beanNames;
054    }
055
056    @Override
057    @Factory(value = "SeamRemotingBeanNames", scope = ScopeType.APPLICATION)
058    public String getSeamRemotingJavaScriptURLParameters() {
059
060        StringBuilder sb = new StringBuilder();
061
062        int idx = 0;
063        for (String beanName : beanNames) {
064            sb.append(beanName);
065            idx++;
066            if (idx < beanNames.size()) {
067                sb.append('&');
068            }
069        }
070        return sb.toString();
071    }
072
073}