Author: dennyxu
Date: 2009-07-20 03:06:28 -0400 (Mon, 20 Jul 2009)
New Revision: 16669
Added:
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/ClasspathFunctionRegistryLoader.java
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/FunctionLibrary.java
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/FunctionRegistry.java
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/IFunctionRegistryLoader.java
Log:
Added:
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/ClasspathFunctionRegistryLoader.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/ClasspathFunctionRegistryLoader.java
(rev 0)
+++
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/ClasspathFunctionRegistryLoader.java 2009-07-20
07:06:28 UTC (rev 16669)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Oracle Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.bpel.fnmeta;
+
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.eclipse.bpel.common.BPELResourceSet;
+import org.eclipse.bpel.fnmeta.model.Registry;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+/**
+ * @author Michal Chmielewski (michal.chmielewski(a)oracle.com)
+ * @date Aug 4, 2008
+ *
+ */
+public class ClasspathFunctionRegistryLoader implements IFunctionRegistryLoader {
+
+ ClassLoader fLoader = null;
+ ResourceSet fResourceSet = null;
+
+ /**
+ * @param obj
+ */
+ public ClasspathFunctionRegistryLoader (ResourceSet obj) {
+ fLoader = obj.getClass().getClassLoader();
+ fResourceSet = obj;
+ }
+
+ /** (non-Javadoc)
+ * @see
org.eclipse.bpel.fnmeta.IFunctionRegistryLoader#load(org.eclipse.bpel.fnmeta.FunctionRegistry)
+ */
+
+ @SuppressWarnings("nls")
+ public void load (FunctionRegistry registry) {
+
+ Enumeration<URL> list = null;
+
+ try {
+ list = fLoader.getResources("fn.fnmeta");
+ while (list.hasMoreElements()) {
+
+ URL url = list.nextElement();
+ URI uri = URI.createURI( url.toExternalForm() ) ;
+
+ Resource resource = fResourceSet.getResource(uri, true);
+
+ if (resource.getContents().size() > 0) {
+ Registry r = (Registry) resource.getContents().get(0);
+ registry.add( r.getFunctions() );
+ }
+ }
+
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ }
+
+ }
+
+}
Added:
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/FunctionLibrary.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/FunctionLibrary.java
(rev 0)
+++
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/FunctionLibrary.java 2009-07-20
07:06:28 UTC (rev 16669)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Oracle Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.bpel.fnmeta;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Function Library collects all the function registries for the given
+ * language in the BPEL context.
+ *
+ * Imagine scripting language "foobar". There may be several registries
contributing functions
+ * to the language "foobar" library. The library is the single lookup point for
scripting language
+ * and the registry encompasses all the functions for the given language.
+ *
+ * @author Michal Chmielewski (michal.chmielewski(a)oracle.com)
+ * @date Aug 4, 2008
+ *
+ */
+
+public class FunctionLibrary {
+
+ /**
+ *
+ */
+ static public FunctionLibrary INSTANCE = new FunctionLibrary();
+
+ /**
+ * Index of all registries, by scripting language namespace name.
+ */
+ Map<String,FunctionRegistry> fRegistries = new
HashMap<String,FunctionRegistry>();
+
+ /**
+ * List of registered loaders for the function library. This way we can do late loading
+ * of registry information, basically delaying it until needed.
+ */
+ List<IFunctionRegistryLoader> fLoaders = new
ArrayList<IFunctionRegistryLoader>();
+
+
+ /**
+ *
+ * @param language the language.
+ * @return the function registry for the given language.
+ */
+
+ public FunctionRegistry getRegistryForLanguage ( String language ) {
+
+ FunctionRegistry registry = fRegistries.get(language);
+ if (registry != null) {
+ return registry;
+ }
+
+ synchronized (fRegistries) {
+ registry = fRegistries.get(language);
+ if (registry != null) {
+ return registry;
+ }
+
+ registry = new FunctionRegistry(language);
+
+ for(IFunctionRegistryLoader loader : fLoaders) {
+ loader.load( registry );
+ }
+
+ fRegistries.put(language, registry);
+ }
+ return registry;
+ }
+
+
+ /**
+ * @param registry
+ */
+
+ public void add (FunctionRegistry registry) {
+ fRegistries.put(registry.getLanguageNS(), registry);
+ }
+
+ /**
+ * @param loader
+ */
+
+ public void registerLoader ( IFunctionRegistryLoader loader ) {
+ if (fLoaders.contains(loader)) {
+ return ;
+ }
+ fLoaders.add ( loader );
+ }
+
+
+ /**
+ * @param loader
+ *
+ */
+ public void unregisterLoader( IFunctionRegistryLoader loader ) {
+ fLoaders.remove(loader);
+ }
+
+
+}
Added:
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/FunctionRegistry.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/FunctionRegistry.java
(rev 0)
+++
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/FunctionRegistry.java 2009-07-20
07:06:28 UTC (rev 16669)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Oracle Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.bpel.fnmeta;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.bpel.fnmeta.model.Function;
+
+/**
+ * @author Michal Chmielewski (michal.chmielewski(a)oracle.com)
+ * @date Aug 3, 2007
+ */
+
+@SuppressWarnings("nls")
+public class FunctionRegistry {
+
+ Map<String,Function> fRegistryIndex = new HashMap<String,Function>();
+
+ String fLanguageNamespace ;
+
+ /**
+ * @param languageNamespace
+ */
+
+ public FunctionRegistry ( String languageNamespace ) {
+ fLanguageNamespace = languageNamespace;
+ }
+
+ /**
+ *
+ * @return the registry for our scripting language
+ */
+
+ public Collection<Function> getRegistry () {
+ return Collections.unmodifiableCollection( fRegistryIndex.values() );
+ }
+
+
+
+
+ /**
+ *
+ * @param ns
+ * @param name
+ * @return the function for the given namespace and name
+ *
+ */
+
+ public Function lookupFunction (String ns, String name) {
+ return fRegistryIndex.get( key(ns,name) );
+ }
+
+
+ /**
+ * @param list
+ */
+
+ public void add (List<Function> list) {
+
+ for ( Function fn : list ) {
+ add(fn);
+ }
+ }
+
+ /**
+ * @param fn
+ */
+
+ public void add (Function fn ) {
+ String aKey = key(fn);
+ Function previous = fRegistryIndex.get( aKey );
+ if (previous != null) {
+ // overwrite ? nope.
+ return ;
+ }
+ fRegistryIndex.put(aKey , fn);
+ }
+
+
+ String key (Function fn) {
+ return key(fn.getNamespace(), fn.getName());
+ }
+
+ String key (String ns, String name) {
+ StringBuilder sb = new StringBuilder();
+ return sb.append(ns).append(";").append(name).toString() ;
+ }
+
+
+ /**
+ * @return the language namespace for this function registry
+ */
+ public String getLanguageNS () {
+ return fLanguageNamespace;
+ }
+
+}
Added:
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/IFunctionRegistryLoader.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/IFunctionRegistryLoader.java
(rev 0)
+++
trunk/bpel/plugins/org.eclipse.bpel.common.model/src/org/eclipse/bpel/fnmeta/IFunctionRegistryLoader.java 2009-07-20
07:06:28 UTC (rev 16669)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Oracle Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.bpel.fnmeta;
+
+/**
+ * @author Michal Chmielewski (michal.chmielewski(a)oracle.com)
+ * @date Aug 4, 2008
+ *
+ */
+public interface IFunctionRegistryLoader {
+
+ /**
+ * @param registry
+ */
+
+ void load ( FunctionRegistry registry );
+
+}