001/* 002 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.ui.web.seamremoting; 021 022import java.util.ArrayList; 023import java.util.List; 024 025import org.jboss.seam.ScopeType; 026import org.jboss.seam.annotations.Factory; 027import org.jboss.seam.annotations.Name; 028import org.jboss.seam.annotations.Scope; 029import org.nuxeo.runtime.model.ComponentInstance; 030import org.nuxeo.runtime.model.DefaultComponent; 031 032@Name("SeamRemotingJSBuilderService") 033@Scope(ScopeType.STATELESS) 034public class SeamRemotingJSBuilderComponent extends DefaultComponent implements SeamRemotingJSBuilderService { 035 036 public static final String EP_REMOTABLE_SEAMBEANS = "remotableSeamBeans"; 037 038 protected static final List<String> beanNames = new ArrayList<String>(); 039 040 @Override 041 public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 042 043 if (extensionPoint.equals(EP_REMOTABLE_SEAMBEANS)) { 044 RemotableSeamBeansDescriptor descriptor = (RemotableSeamBeansDescriptor) contribution; 045 beanNames.addAll(descriptor.getBeanNames()); 046 } 047 } 048 049 @Override 050 public List<String> getRemotableBeanNames() { 051 return beanNames; 052 } 053 054 @Override 055 @Factory(value = "SeamRemotingBeanNames", scope = ScopeType.APPLICATION) 056 public String getSeamRemotingJavaScriptURLParameters() { 057 058 StringBuilder sb = new StringBuilder(); 059 060 int idx = 0; 061 for (String beanName : beanNames) { 062 sb.append(beanName); 063 idx++; 064 if (idx < beanNames.size()) { 065 sb.append('&'); 066 } 067 } 068 return sb.toString(); 069 } 070 071}