001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.cfx.customtag; 020 021import java.util.Map; 022import java.util.Set; 023 024import lucee.commons.collection.MapFactory; 025import lucee.runtime.cfx.CFXTagException; 026import lucee.runtime.cfx.CFXTagPool; 027import lucee.runtime.config.Config; 028import lucee.runtime.type.util.ListUtil; 029 030import com.allaire.cfx.CustomTag; 031 032 033/** 034 * 035 */ 036public final class CFXTagPoolImpl implements CFXTagPool { 037 038 Config config; 039 Map<String,CFXTagClass> classes; 040 Map<String,CFXTagClass> objects=MapFactory.<String,CFXTagClass>getConcurrentMap(); 041 042 /** 043 * constructor of the class 044 * @param classes 045 */ 046 public CFXTagPoolImpl(Map<String,CFXTagClass> classes) { 047 this.classes=classes; 048 } 049 050 @Override 051 public Map<String,CFXTagClass> getClasses() {// FUTURE add generic type to interface 052 return classes; 053 } 054 055 @Override 056 public synchronized CustomTag getCustomTag(String name) throws CFXTagException { 057 name=name.toLowerCase(); 058 059 Object o=classes.get(name); 060 if(o==null) { 061 Set<String> set = classes.keySet(); 062 String names = ListUtil.arrayToList(set.toArray(new String[set.size()]),","); 063 064 throw new CFXTagException("there is no Custom Tag (CFX) with name ["+name+"], available Custom Tags are ["+names+"]"); 065 } 066 CFXTagClass ctc=(CFXTagClass) o; 067 CustomTag ct = ctc.newInstance(); 068 //if(!(o instanceof CustomTag))throw new CFXTagException("["+name+"] is not of type ["+CustomTag.class.getName()+"]"); 069 return ct; 070 } 071 072 @Override 073 public synchronized CFXTagClass getCFXTagClass(String name) throws CFXTagException { 074 name=name.toLowerCase(); 075 CFXTagClass ctc = classes.get(name); 076 if(ctc==null) throw new CFXTagException("there is not Custom Tag (CFX) with name ["+name+"]"); 077 return ctc; 078 } 079 080 @Override 081 public synchronized void releaseCustomTag(CustomTag ct) { 082 //table.put(ct.getClass().toString(),ct); 083 } 084 public synchronized void releaseTag(Object tag) { 085 //table.put(ct.getClass().toString(),ct); 086 } 087}