You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by do...@apache.org on 2007/12/06 15:07:30 UTC
svn commit: r601738 [1/3] - in /felix/sandbox/donsez/sosoc: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/felix/ src/main/java/org/apache/felix/sandbox/
src/main/java/org/apache/felix/sandbox/sos...
Author: donsez
Date: Thu Dec 6 06:07:25 2007
New Revision: 601738
URL: http://svn.apache.org/viewvc?rev=601738&view=rev
Log:
creation of the sosoc bundle
SOSOC is a Script-oriented and Service-Oriented Component (SOSOC) Model.
SOSOC enables to develop service-oriented components with scripting languages such as JavaScript, Jython, PHP, ...
Added:
felix/sandbox/donsez/sosoc/
felix/sandbox/donsez/sosoc/pom.xml (with props)
felix/sandbox/donsez/sosoc/src/
felix/sandbox/donsez/sosoc/src/main/
felix/sandbox/donsez/sosoc/src/main/java/
felix/sandbox/donsez/sosoc/src/main/java/org/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/ComponentChangeEvent.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/BasicComponent.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Component.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/DescriptorParser.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/ExtendedProperty.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Implementation.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Instance.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Properties.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Property.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Provide.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Reference.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Service.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceEvent.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceListener.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/Constants.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/InstanceChangeEvent.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ReferenceChangeEvent.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/ComponentManager.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/InstanceReference.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/Logger.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/LoggerImpl.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/ReferenceManager.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/java/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/java/JavaComponentManager.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/java/JavaComponentReferenceManager.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/javascript/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/javascript/JavaScriptComponentManager.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/javascript/JavaScriptComponentReferenceManager.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/manager/javascript/JavaScriptContainer.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/rule/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/rule/Rule.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/rule/RuleConstants.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/rule/RuleManager.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/rule/RuleSet.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/rule/RuleSetManager.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/util/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/util/load/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/util/load/LoadUtils.java (with props)
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/util/rhino/
felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/util/rhino/RhinoUtils.java (with props)
felix/sandbox/donsez/sosoc/src/site/
felix/sandbox/donsez/sosoc/src/site/component.benchcmd.xml (with props)
felix/sandbox/donsez/sosoc/src/site/component.echocmd.withembeddedscript.xml (with props)
felix/sandbox/donsez/sosoc/src/site/component.echocmd.xml (with props)
felix/sandbox/donsez/sosoc/src/site/component.loglistener.xml (with props)
felix/sandbox/donsez/sosoc/src/site/component.prototype.xml (with props)
felix/sandbox/donsez/sosoc/src/site/component.ruleset.xml (with props)
felix/sandbox/donsez/sosoc/src/site/component.runnable.xml (with props)
felix/sandbox/donsez/sosoc/src/site/component.servlet.xml (with props)
felix/sandbox/donsez/sosoc/src/site/component.thread.xml (with props)
felix/sandbox/donsez/sosoc/src/site/echocmd.js (with props)
felix/sandbox/donsez/sosoc/src/site/index.html (with props)
felix/sandbox/donsez/sosoc/src/site/proposition.for.SCR.R4.extensions.html (with props)
felix/sandbox/donsez/sosoc/src/site/script.txt (with props)
felix/sandbox/donsez/sosoc/src/site/template.standalonecomponent.xml (with props)
felix/sandbox/donsez/sosoc/src/site/thread.js (with props)
Added: felix/sandbox/donsez/sosoc/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/pom.xml?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/pom.xml (added)
+++ felix/sandbox/donsez/sosoc/pom.xml Thu Dec 6 06:07:25 2007
@@ -0,0 +1,115 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+
+ <properties>
+ <repositoryLocation>http://people.apache.org/~donsez/dev/felix/sandbox/</repositoryLocation>
+ <description>provides a script-oriented and service-oriented component model (SOSOC).</description>
+ </properties>
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>SOSOC</name>
+ <artifactId>org.apache.felix.sandbox.sosoc</artifactId>
+ <groupId>org.apache.felix.sandbox</groupId>
+ <version>0.1.0</version>
+ <description>${description}</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.bundlerepository</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ <version>1.6R7</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
+ <!-- docs in http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html and http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html -->
+
+ <Import-Package>
+ org.osgi.framework,org.osgi.service.cm,org.osgi.service.component,org.osgi.service.event,
+ !javax.xml.parsers,!org.xml.sax,*
+ </Import-Package>
+
+ <Export-Package>${pom.artifactId}</Export-Package>
+
+ <Private-Package>
+ ${pom.artifactId}.*,
+ org.apache.felix.sandbox.util.*,
+ org.kxml2.io,org.xmlpull.*,org.apache.felix.bundlerepository.metadataparser.*,
+ org.mozilla.javascript.xml, org.mozilla.classfile,!org.mozilla.javascript.tools.*,!org.mozilla.javascript.xml.*,!org.mozilla.javascript.xmlimpl,org.mozilla.javascript.*
+ </Private-Package>
+
+
+ <!--<Bundle-Activator>${pom.artifactId}.SOSOCActivator</Bundle-Activator>-->
+
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Description>${description}</Bundle-Description>
+
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+<!--
+ <repositories>
+ <repository>
+ <id>apache.m2.incubator</id>
+ <name>Apache M2 Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>apache.m2.incubator</id>
+ <name>Apache M2 Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ </pluginRepository>
+ </pluginRepositories>
+ -->
+</project>
Propchange: felix/sandbox/donsez/sosoc/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/ComponentChangeEvent.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/ComponentChangeEvent.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/ComponentChangeEvent.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/ComponentChangeEvent.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sandbox.sosoc;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ComponentChangeEvent {
+
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/ComponentChangeEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,431 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sandbox.sosoc;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.apache.felix.sandbox.sosoc.descriptor.xml.Component;
+import org.apache.felix.sandbox.sosoc.descriptor.xml.DescriptorParser;
+import org.apache.felix.sandbox.sosoc.descriptor.xml.Reference;
+import org.apache.felix.sandbox.sosoc.descriptor.xml.Service;
+import org.apache.felix.sandbox.sosoc.event.Constants;
+import org.apache.felix.sandbox.sosoc.event.InstanceChangeEvent;
+import org.apache.felix.sandbox.sosoc.event.ReferenceChangeEvent;
+import org.apache.felix.sandbox.sosoc.manager.ComponentManager;
+import org.apache.felix.sandbox.sosoc.manager.LoggerImpl;
+import org.apache.felix.sandbox.sosoc.manager.java.JavaComponentManager;
+import org.apache.felix.sandbox.sosoc.manager.javascript.JavaScriptComponentManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentConstants;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * The SOSOCActivator, it will read information from the metadata.xml file and
+ * will create the corresponding instance managers
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+abstract public class SOSOCActivator implements BundleActivator {
+
+ private LoggerImpl m_logger=new LoggerImpl();
+
+ private BundleContext bundleContext = null;
+
+ private Map componentDescriptors = new HashMap();
+
+ private List componentManagers = new ArrayList();
+
+ private InputStream m_inputStream = null;
+
+ private String m_baseUrlStr = null;
+
+ private ClassLoader serviceComponentClassLoader = this.getClass().getClassLoader();
+
+ private ServiceTracker eventAdminServiceTracker;
+
+
+ public SOSOCActivator() {
+ m_logger.initProperties(System.getProperties());
+ }
+
+ public SOSOCActivator(InputStream inputStream, Properties initProperties, String baseUrlStr) {
+ m_logger.initProperties(initProperties);
+ m_baseUrlStr=baseUrlStr;
+ m_inputStream = inputStream;
+ }
+
+ public SOSOCActivator(InputStream[] inputStream, Properties initProperties, String baseUrlStr) {
+ m_logger.initProperties(initProperties);
+ m_baseUrlStr=baseUrlStr;
+ throw new IllegalArgumentException("Not implemented");
+ }
+
+ public void reinitProperties(Properties initProperties){
+ m_logger.initProperties(initProperties);
+ }
+
+ /**
+ * Called upon starting of the bundle. This method invokes initialize()
+ * which parses the meta data and creates the instance managers
+ *
+ * @param context
+ * The bundle context passed by the framework
+ * @exception Exception
+ * any exception thrown from initialize
+ */
+ public void start(BundleContext context) throws Exception {
+ eventAdminServiceTracker=new ServiceTracker(context,EventAdmin.class.getName(),null);
+ eventAdminServiceTracker.open();
+
+ try {
+ bundleContext = context;
+
+ if (serviceComponentClassLoader == null) {
+ throw new IllegalStateException(getClass().getName()+": in bundle ["
+ + context.getBundle().getBundleId()
+ + "] : service component classloader is not set");
+ }
+
+ try {
+ initialize();
+ } catch (Exception e) {
+ m_logger.error(getClass().getName()+": in bundle ["
+ + context.getBundle().getBundleId() + "] : " + e);
+ e.printStackTrace();
+ throw e;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ /**
+ * Gets the descriptor location, parses the meta data and requests the processing of binder instances
+ *
+ * @throws java.io.FileNotFoundException
+ * if the metadata file is not found
+ * @throws javax.xml.parsers.ParserConfigurationException
+ * @throws org.xml.sax.SAXException
+ * @throws java.io.IOException
+ * @throws java.lang.ClassNotFoundException
+ * it the instance class is not found
+ * @throws java.lang.NoSuchMethodException
+ * if binder methods are not found
+ * @throws org.osgi.framework.InvalidSyntaxException
+ * if the filter has an incorrect syntax
+ * @throws Exception
+ * if any exception is thrown during the validation of the
+ * InstanceManagers
+ */
+ private void initialize() throws Exception {
+ if (m_inputStream == null) {
+ // Get the Service-Component value from the manifest
+
+ String descriptorLocations = null;
+ // Dictionary dict = bundleContext.getBundle().getHeaders();
+
+ descriptorLocations = (String) bundleContext.getBundle()
+ .getHeaders().get(ComponentConstants.SERVICE_COMPONENT);
+
+ if (descriptorLocations == null) {
+ throw new java.io.FileNotFoundException(
+ ComponentConstants.SERVICE_COMPONENT
+ + " entry not found in the manifest");
+ }
+
+ StringTokenizer st = new StringTokenizer(descriptorLocations, ", ");
+
+ while (st.hasMoreTokens()) {
+ String descriptorLocation = st.nextToken();
+ /*
+ * if (descriptorLocation.startsWith("/") == false) {
+ * descriptorLocation = "/" + descriptorLocation; }
+ */
+ m_inputStream = serviceComponentClassLoader
+ .getResourceAsStream(descriptorLocation);
+
+ if (m_inputStream == null) {
+ throw new java.io.FileNotFoundException(
+ "Component descriptor entry '" + descriptorLocation
+ + "' not found");
+ }
+
+ DescriptorParser descriptorParser = new DescriptorParser();
+ descriptorParser.setTrace(m_logger.getParserTraceFlag());
+ Component component = descriptorParser.getComponent(serviceComponentClassLoader, descriptorLocation);
+ componentDescriptors.put(component.getName(),component);
+ }
+ } else {
+ // Create the parser
+ DescriptorParser descriptorParser = new DescriptorParser();
+ Component component = descriptorParser.getComponent(
+ serviceComponentClassLoader, m_inputStream);
+ componentDescriptors.put(component.getName(),component);
+ }
+ if (componentDescriptors != null) {
+ Iterator iterator = componentDescriptors.values().iterator();
+ StringBuffer sb = new StringBuffer();
+ sb.append(getClass().getName()+": Bundle [").append(
+ bundleContext.getBundle().getBundleId()).append(
+ "] will manage ").append(componentDescriptors.size())
+ .append(" components : ");
+ while (iterator.hasNext()) {
+ sb.append(" ");
+ sb.append(((Component) iterator.next()).getName());
+ }
+ m_logger.trace(sb.toString());
+
+ Iterator i = componentDescriptors.values().iterator();
+ while (i.hasNext()) {
+ Component descriptor = (Component) i.next();
+
+ if (descriptor.isFactory()) {
+ // NOT YET SUPPORTED IN THIS VERSION
+ throw new IllegalArgumentException(
+ "SOSOCActivator : Bundle ["
+ + bundleContext.getBundle().getBundleId()
+ + "] this version can not manage the factory "
+ + descriptor.getFactory()
+ + " for component " + descriptor.getName());
+ } else // deployment instance
+ {
+ enableComponent(descriptor);
+ }
+ }
+ }
+ }
+
+ private void enableComponent(Component descriptor) throws Exception {
+ ComponentManager componentManager;
+ String language = descriptor.getImplementation().getLanguage();
+ if (language == null || language.toLowerCase().equals("java")) {
+ // create the instance manager for Java component
+ componentManager = new JavaComponentManager(this, descriptor,m_logger);
+ } else if(language.toLowerCase().startsWith("javascript") || language.toLowerCase().startsWith("jscript")) {
+ // create the instance manager for JavaScript component
+ componentManager = new JavaScriptComponentManager(this, descriptor,m_logger,m_baseUrlStr);
+ } else {
+// componentManager = new JSR223ComponentManager(this,descriptor,m_logger);
+ throw new IllegalArgumentException(language+ " components are not supported in this version");
+ }
+
+ if (componentManager != null) {
+ // start managing lifecycle
+ componentManager.validate();
+ }
+ }
+
+ /**
+ * Stop method that destroys all the instance managers
+ *
+ * @param context
+ * The Bundle Context passed by the framework
+ * @exception Exception
+ * any exception thrown during destruction of the instance
+ * managers
+ */
+ public void stop(BundleContext context) throws java.lang.Exception {
+ m_logger.trace(getClass().getName()+": Bundle ["
+ + context.getBundle().getBundleId() + "] will destroy "
+ + componentManagers.size() + " instances");
+
+ while (componentManagers.size() != 0) {
+ ComponentManager current = (ComponentManager) componentManagers
+ .get(0);
+ try {
+ current.destroy();
+ } catch (Exception e) {
+ m_logger.error(getClass().getName()+": Exception during invalidate : " + e);
+ e.printStackTrace();
+ // stop the next manager
+ }
+ }
+
+ bundleContext = null;
+
+ eventAdminServiceTracker.close();
+
+
+ m_logger.trace(getClass().getName()+": Bundle ["
+ + context.getBundle().getBundleId() + "] STOPPED");
+ }
+
+ /**
+ * Returns the list of instance references currently associated to this
+ * activator
+ *
+ * @return the list of instance references
+ */
+ protected List getInstanceReferences() {
+ return componentManagers;
+ }
+
+ /**
+ * Returns the BundleContext
+ *
+ * @return the BundleContext
+ */
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+
+ /**
+ * Method called before an object implementing services is registered in the
+ * OSGi framework. This method is provided so that subclasses of the generic
+ * activator may proxy the object. The default implementation returns the
+ * passed in object.
+ *
+ * @param obj
+ * the instance object
+ * @param descriptor
+ * the instance descriptor that provides information relevant to
+ * the instance object
+ */
+ public Object proxyProvidedServiceObject(Object obj, Service descriptor) {
+ return obj;
+ }
+
+ /**
+ * Method called before the binding of the service object occurs. This
+ * method is provided so that subclasses of the generic activator may proxy
+ * the object. The default implementation returns the passed in object.
+ *
+ * @param obj the instance object
+ * @param serviceReference
+ * @param descriptor
+ * the dependency descriptor that provides information relevant
+ * to the service object
+ */
+ public Object proxyRequiredServiceObject(Object obj, ServiceReference serviceReference, Reference referenceDescriptor) {
+ return obj;
+ }
+
+ public void addComponentManagers(ComponentManager componentManager) {
+ componentManagers.add(componentManager);
+ }
+
+ public void removeComponentManagers(ComponentManager componentManager) {
+ componentManagers.remove(componentManager);
+ }
+
+ // TODO should synchronized !!!
+ public void disableComponent(String name) {
+ // just for checking
+ Component component=(Component) componentDescriptors.get(name);
+ if(component==null) {
+ m_logger.trace(getClass().getName()+": component "+name+" not found");
+ return;
+ }
+
+ Iterator iterator=componentManagers.iterator();
+ while (iterator.hasNext()) {
+ ComponentManager current = (ComponentManager) iterator.next();
+ if(!current.getComponent().getName().equals(name)) continue;
+ try {
+ current.destroy();
+ } catch (Exception e) {
+ m_logger.error(getClass().getName()+": Exception during disable component : " + e);
+ e.printStackTrace();
+ // stop the next manager
+ }
+ break;
+ }
+ }
+
+ public void enableComponent(String name) {
+ Iterator iterator=componentManagers.iterator();
+ while (iterator.hasNext()) {
+ ComponentManager current = (ComponentManager) iterator.next();
+ if(current.getComponent().getName().equals(name)) {
+ m_logger.trace(getClass().getName()+": the component "+name+" is already enabled");
+ return;
+ }
+ }
+
+ Component component=(Component) componentDescriptors.get(name);
+ if(component==null) {
+ m_logger.trace(getClass().getName()+": component "+name+" not found");
+ return;
+ }
+
+ try {
+ enableComponent(component);
+ } catch (Exception e) {
+ m_logger.error(getClass().getName()+": Exception during enableComponent : " + e);
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Fires an event when an instance has changed
+ * @evt The InstanceChangeEvent
+ */
+ public void fireInstanceChangeEvent(InstanceChangeEvent evt) {
+ EventAdmin eventAdmin=(EventAdmin) eventAdminServiceTracker.getService();
+ if(eventAdmin!=null){
+ Component component=evt.getComponent();
+ ComponentManager componentManager=evt.getComponentManager();
+ Dictionary properties=new Hashtable();
+ properties.put(ComponentConstants.COMPONENT_NAME, component.getName());
+ if(component.getFactory()!=null) properties.put(ComponentConstants.COMPONENT_FACTORY, component.getFactory());
+ // properties.put(ComponentConstants.COMPONENT_ID, componentManager.);
+ properties.put("component.description", component);
+ //properties.put("bundle.id", bundleId);
+ StringBuffer sb=new StringBuffer();
+ sb.append(Constants.TOPIC_INSTANCE).append('/').append(ComponentManager.statesString[evt.getCurrentState()]);
+ Event event=new Event(sb.toString(),properties);
+ eventAdmin.sendEvent(event);
+ }
+ }
+
+ /**
+ * Fires an event when an component has changed
+ * @evt The ComponentChangeEvent
+ */
+ public void fireComponentChangeEvent(ComponentChangeEvent evt) {
+ // TODO
+ }
+
+
+ /**
+ * Fires an event when a reference has changed
+ *
+ * @evt The ReferenceChangeEvent
+ */
+ void fireDependencyChangeEvent(ReferenceChangeEvent evt) {
+ // TODO
+ }
+
+
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/SOSOCActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/BasicComponent.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/BasicComponent.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/BasicComponent.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/BasicComponent.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.felix.sandbox.sosoc.SOSOCActivator;
+import org.apache.felix.sandbox.sosoc.rule.RuleSet;
+import org.osgi.service.component.ComponentConstants;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class BasicComponent {
+
+ private Implementation implementation;
+
+ private Set property;
+
+ private Set properties;
+
+ private Service service;
+
+ private List references;
+
+ private boolean enabled = true;
+
+ private String name;
+
+ private String factory;
+
+ private String session = "supports"; // notsupported, supports, never,
+ // required, newrequired, mandatory
+
+ private boolean immediate = true;
+
+ // -----
+
+ private Dictionary registrationProperties = null;
+
+ // -----
+
+ private SOSOCActivator sosocActivator;
+
+ private RuleSet ruleSet;
+
+
+ public void setContext(Map map) {
+
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public String getFactory() {
+ return factory;
+ }
+
+ public void setFactory(String factory) {
+ this.factory = factory;
+ }
+
+ public boolean isImmediate() {
+ return immediate;
+ }
+
+ public void setImmediate(boolean immediate) {
+ this.immediate = immediate;
+ }
+
+ public Implementation getImplementation() {
+ return implementation;
+ }
+
+ public void setImplementation(Implementation implementation) {
+ this.implementation = implementation;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getProperties() {
+ return properties;
+ }
+
+ public void addProperties(Properties p) {
+ if (properties == null)
+ properties = new HashSet();
+ properties.add(p);
+ }
+
+ public Set getProperty() {
+ return property;
+ }
+
+ public void addProperty(Property p) {
+ if (property == null)
+ property = new HashSet();
+ property.add(p);
+ }
+
+ public List getReferences() {
+ return references;
+ }
+
+ public void addReference(Reference r) {
+ if (references == null)
+ references = new ArrayList();
+ references.add(r);
+ }
+
+ public Service getService() {
+ return service;
+ }
+
+ public void setService(Service service) {
+ this.service = service;
+ }
+
+ public RuleSet getRuleSet() {
+ return this.ruleSet;
+ }
+
+ public void setRuleSet(RuleSet ruleSet) {
+ this.ruleSet=ruleSet;
+ }
+
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("[Project:");
+ if (name != null)
+ sb.append("name=").append(name).append(';');
+ if (factory != null)
+ sb.append("factory=").append(factory).append(';');
+ sb.append("immediate=").append(immediate).append(';');
+ sb.append("enabled=").append(enabled).append(';');
+ if (implementation != null)
+ sb.append("implementation=").append(implementation).append(';');
+ if (property != null)
+ sb.append("property=").append(property).append(';');
+ // if(properties!=null)
+ // sb.append("properties=").append(properties).append(';');
+ if (service != null)
+ sb.append("service=").append(service).append(';');
+ if (references != null)
+ sb.append("references=").append(references);
+ sb.append(']');
+ return sb.toString();
+ }
+
+ public void process() throws Throwable {
+ if (name == null)
+ throw new IllegalArgumentException("attribute name is missing");
+ if (service != null && service.getProvide() != null
+ && service.getProvide().size() == 0)
+ throw new IllegalArgumentException(
+ "service element must contain one");
+ setRegistrationProperties();
+ }
+
+ public boolean isFactory() {
+ return (factory != null);
+ }
+
+ public String[] getServiceInterfaces() {
+ if (service == null)
+ return null;
+ List p = service.getProvide();
+ String[] serviceInterfaces = new String[p.size()];
+ Iterator iterator = p.iterator();
+ for (int i = 0; iterator.hasNext(); i++)
+ serviceInterfaces[i] = ((Provide) iterator.next()).getInterface();
+ return serviceInterfaces;
+ }
+
+ public Dictionary getRegistrationProperties() {
+ return registrationProperties;
+ }
+
+ private void setRegistrationProperties() throws IOException {
+ if (property != null) {
+ if(registrationProperties==null) registrationProperties = new Hashtable();
+
+ Iterator iterator;
+ iterator = property.iterator();
+ for (int i = 0; iterator.hasNext(); i++) {
+ Property p = (Property) iterator.next();
+ Object value = null;
+ try {
+ value = p.getObjectValue(null);
+ } catch (Exception e) {
+ // never thrown
+ }
+ registrationProperties.put(p.getName(), value);
+ }
+ }
+ if (properties != null) {
+ if(registrationProperties==null) registrationProperties = new Hashtable();
+
+ Iterator iterator;
+ iterator = properties.iterator();
+ ClassLoader classLoader = getSOSOCActivator().getClass()
+ .getClassLoader();
+ while (iterator.hasNext()) {
+ Properties properties = (Properties) iterator.next();
+ java.util.Properties props = new java.util.Properties();
+ InputStream inputStream = classLoader
+ .getResourceAsStream(properties.getEntry());
+ props.load(inputStream);
+ // TODO SHOULD close te inputstream ?
+ Iterator iterator2 = props.entrySet().iterator();
+ while (iterator2.hasNext()) {
+ Map.Entry mapentry = (Map.Entry) iterator2.next();
+ registrationProperties.put(mapentry.getKey(), mapentry.getValue());
+ }
+ }
+ }
+ if (name != null) {
+ if(registrationProperties==null) registrationProperties = new Hashtable();
+ registrationProperties.put(ComponentConstants.COMPONENT_NAME, name);
+ }
+ if (factory != null) {
+ if(registrationProperties==null) registrationProperties = new Hashtable();
+ registrationProperties.put(ComponentConstants.COMPONENT_FACTORY, factory);
+ }
+ }
+
+ public String getSession() {
+ return session;
+ }
+
+ public void setSession(String session) {
+ this.session = session;
+ }
+
+ public SOSOCActivator getSOSOCActivator() {
+ return sosocActivator;
+ }
+
+ public void setSOSOCActivator(SOSOCActivator sosocActivator) {
+ this.sosocActivator = sosocActivator;
+ }
+
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/BasicComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Component.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Component.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Component.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Component.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.felix.sandbox.sosoc.SOSOCActivator;
+import org.apache.felix.sandbox.sosoc.rule.RuleSet;
+import org.osgi.service.component.ComponentConstants;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Component {
+
+ private Implementation implementation;
+
+ private Set/*<Property>*/ property;
+
+ private Set/*<Properties>*/ properties;
+
+ private Service service;
+
+ private List/*<Reference>*/ references;
+
+ private boolean enabled = true;
+
+ private String name;
+
+ private String factory;
+
+ private String session = "supports"; // notsupported, supports, never,
+ // required, newrequired, mandatory
+
+ private boolean immediate = true;
+
+ // -----
+
+ private Dictionary registrationProperties = null;
+
+ // -----
+
+ private SOSOCActivator sosocActivator;
+
+ private RuleSet ruleSet;
+
+
+ public void setContext(Map map) {
+
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public String getFactory() {
+ return factory;
+ }
+
+ public void setFactory(String factory) {
+ this.factory = factory;
+ }
+
+ public boolean isImmediate() {
+ return immediate;
+ }
+
+ public void setImmediate(boolean immediate) {
+ this.immediate = immediate;
+ }
+
+ public Implementation getImplementation() {
+ return implementation;
+ }
+
+ public void setImplementation(Implementation implementation) {
+ this.implementation = implementation;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getProperties() {
+ return properties;
+ }
+
+ public void addProperties(Properties p) {
+ if (properties == null)
+ properties = new HashSet();
+ properties.add(p);
+ }
+
+ public Set getProperty() {
+ return property;
+ }
+
+ public void addProperty(Property p) {
+ if (property == null)
+ property = new HashSet();
+ property.add(p);
+ }
+
+ public List getReferences() {
+ return references;
+ }
+
+ public void addReference(Reference r) {
+ if (references == null)
+ references = new ArrayList();
+ references.add(r);
+ }
+
+ public Service getService() {
+ return service;
+ }
+
+ public void setService(Service service) {
+ this.service = service;
+ }
+
+ public RuleSet getRuleSet() {
+ return this.ruleSet;
+ }
+
+ public void setRuleSet(RuleSet ruleSet) {
+ this.ruleSet=ruleSet;
+ }
+
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("[Project:");
+ if (name != null)
+ sb.append("name=").append(name).append(';');
+ if (factory != null)
+ sb.append("factory=").append(factory).append(';');
+ sb.append("immediate=").append(immediate).append(';');
+ sb.append("enabled=").append(enabled).append(';');
+ if (implementation != null)
+ sb.append("implementation=").append(implementation).append(';');
+ if (property != null)
+ sb.append("property=").append(property).append(';');
+ // if(properties!=null)
+ // sb.append("properties=").append(properties).append(';');
+ if (service != null)
+ sb.append("service=").append(service).append(';');
+ if (references != null)
+ sb.append("references=").append(references);
+ sb.append(']');
+ return sb.toString();
+ }
+
+ public void process() throws Throwable {
+ if (name == null)
+ throw new IllegalArgumentException("attribute name is missing");
+ if (service != null && service.getProvide() != null
+ && service.getProvide().size() == 0)
+ throw new IllegalArgumentException(
+ "service element must contain one");
+ setRegistrationProperties();
+ }
+
+ public boolean isFactory() {
+ return (factory != null);
+ }
+
+ public String[] getServiceInterfaces() {
+ if (service == null)
+ return null;
+ List p = service.getProvide();
+ String[] serviceInterfaces = new String[p.size()];
+ Iterator iterator = p.iterator();
+ for (int i = 0; iterator.hasNext(); i++)
+ serviceInterfaces[i] = ((Provide) iterator.next()).getInterface();
+ return serviceInterfaces;
+ }
+
+ public Dictionary getRegistrationProperties() {
+ return registrationProperties;
+ }
+
+ private void setRegistrationProperties() throws IOException {
+ if (property != null) {
+ if(registrationProperties==null) registrationProperties = new Hashtable();
+
+ Iterator iterator;
+ iterator = property.iterator();
+ for (int i = 0; iterator.hasNext(); i++) {
+ Property p = (Property) iterator.next();
+ Object value = null;
+ try {
+ value = p.getObjectValue(null);
+ } catch (Exception e) {
+ // never thrown
+ }
+ registrationProperties.put(p.getName(), value);
+ }
+ }
+ if (properties != null) {
+ if(registrationProperties==null) registrationProperties = new Hashtable();
+
+ Iterator iterator;
+ iterator = properties.iterator();
+ ClassLoader classLoader = getSOSOCActivator().getClass()
+ .getClassLoader();
+ while (iterator.hasNext()) {
+ Properties properties = (Properties) iterator.next();
+ java.util.Properties props = new java.util.Properties();
+ InputStream inputStream = classLoader
+ .getResourceAsStream(properties.getEntry());
+ props.load(inputStream);
+ // TODO SHOULD close te inputstream ?
+ Iterator iterator2 = props.entrySet().iterator();
+ while (iterator2.hasNext()) {
+ Map.Entry mapentry = (Map.Entry) iterator2.next();
+ registrationProperties.put(mapentry.getKey(), mapentry.getValue());
+ }
+ }
+ }
+ if (name != null) {
+ if(registrationProperties==null) registrationProperties = new Hashtable();
+ registrationProperties.put(ComponentConstants.COMPONENT_NAME, name);
+ }
+ if (factory != null) {
+ if(registrationProperties==null) registrationProperties = new Hashtable();
+ registrationProperties.put(ComponentConstants.COMPONENT_FACTORY, factory);
+ }
+ }
+
+ public String getSession() {
+ return session;
+ }
+
+ public void setSession(String session) {
+ this.session = session;
+ }
+
+ public SOSOCActivator getSOSOCActivator() {
+ return sosocActivator;
+ }
+
+ public void setSOSOCActivator(SOSOCActivator sosocActivator) {
+ this.sosocActivator = sosocActivator;
+ }
+
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Component.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/DescriptorParser.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/DescriptorParser.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/DescriptorParser.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/DescriptorParser.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.io.InputStream;
+
+import org.apache.felix.bundlerepository.metadataparser.KXml2MetadataHandler;
+import org.apache.felix.bundlerepository.metadataparser.MetadataHandler;
+import org.apache.felix.sandbox.sosoc.rule.Rule;
+import org.apache.felix.sandbox.sosoc.rule.RuleSet;
+import org.osgi.service.component.ComponentException;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class DescriptorParser
+{
+ public static final String DESCRIPTORS_ENTRY="Service-Component";
+ private boolean flag=false;
+
+ public Component getComponent(ClassLoader classLoader, String entry) throws ComponentException {
+ // metadata file can be a path in the bundle classpath or a remote document over the Web
+ // 1) get the input stream
+
+ InputStream is;
+
+ // metadata may be in the bundle classpath
+ is=classLoader.getResourceAsStream(entry);
+
+ if(is==null)
+ throw new ComponentException("Cannot open entry " +entry);
+
+ return getComponent(classLoader,is);
+ }
+
+
+ public Component getComponent(ClassLoader classLoader, InputStream is) throws ComponentException {
+ // 2) create a metadata handler
+ // * KXml2MetadataHandler for kXML parser (light XML parser)
+ // * XmlMetadataHandler for SAX compliant parser
+ MetadataHandler handler=new KXml2MetadataHandler();
+ // MetadataHandler handler=new XmlMetadataHandler();
+
+ // 3) set the corresponding type for each PI
+ handler.setMissingPIExceptionFlag(false);
+ //handler.addPI("mapping", MappingProcessingInstructionHandler.class);
+
+ try {
+ // 4) set the corresponding type for each element
+ // java.util.ArrayList is used for a element which is a list of sub-elements
+ handler.addType("component", Component.class);
+ // attributes and sub-elements are put in SpecialMultivalueMap. When sub-elements have the same name, the values are stored in a java.util.List.
+ handler.addType("implementation", Implementation.class);
+ // the specified type must have setter or adder methods for each attributes and sub-elements
+ handler.addType("service", Service.class);
+ handler.addType("provide", Provide.class);
+ handler.addType("reference", Reference.class);
+ handler.addType("property", Property.class);
+ // TODO handler.addType("property", ExtendedProperty.class);
+ handler.addType("properties", Properties.class);
+ handler.addType("ruleset", RuleSet.class);
+ handler.addType("rule", Rule.class);
+
+ // 5) set a default type (String, HashMap, ...) for the other elements
+ // if the default type is not set, then the parsing of other elements fails
+ // handler.setDefaultType(String.class);
+ // String is for terminal element (EMPTY with a value attribute or PCDATA)
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ComponentException("Error occur during metadata parsing:"+e.getMessage(),e);
+ }
+
+ // 6) parse the stream
+ handler.setTrace(flag);
+ try {
+ handler.parse(is);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ComponentException("Error occur during metadata parsing:"+e.getMessage(),e);
+ }
+
+ // 7) use the metadata
+ return (Component)handler.getMetadata();
+ }
+
+ public void setTrace(boolean flag){
+ this.flag=flag;
+ }
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/DescriptorParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/ExtendedProperty.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/ExtendedProperty.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/ExtendedProperty.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/ExtendedProperty.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+
+/**
+ * This class represents a extension of implementation element
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ExtendedProperty extends Property {
+ private String factory;
+ private String factorymethod;
+
+ public String toString(){
+ StringBuffer sb=new StringBuffer();
+ sb.append("[Property:");
+ if(getName()!=null) sb.append("name=").append(getName()).append(';');
+ if(getValue()!=null) sb.append("value=").append(getValue()).append(';');
+ if(getText()!=null) sb.append("text=").append(getText()).append(';');
+ if(getType()!=null) sb.append("type=").append(getType()).append(';');
+ if(factory!=null) sb.append("factory=").append(factory).append(';');
+ if(factorymethod!=null) sb.append("factorymethod=").append(factorymethod).append(';');
+ sb.append(']');
+ return sb.toString();
+ }
+
+ public void process() throws Throwable {
+ if(getName()==null) throw new IllegalArgumentException("attribute name is missing");
+ if(getValue()==null && getText()==null) throw new IllegalArgumentException("attribute value is missing");
+ if(getValue()!=null && getText()!=null) throw new IllegalArgumentException("can not have both attribute value and PCDATA");
+ }
+
+ public String getFactory() {
+ return factory;
+ }
+
+ public void setFactory(String factory) {
+ this.factory = factory;
+ }
+
+ public String getFactorymethod() {
+ return factorymethod;
+ }
+
+ public void setFactorymethod(String factorymethod) {
+ this.factorymethod = factorymethod;
+ }
+
+ // TODO array of getType() for getText()
+ public Object getObjectValue(ClassLoader classLoader) throws Exception{
+ if(factorymethod!=null && factory!=null){
+ Class factoryClass=classLoader.loadClass(factory);
+ Method theFactoryMethod=factoryClass.getMethod(factorymethod,new Class[]{String.class});
+ return theFactoryMethod.invoke(null,new Object[]{getValue()==null ? getText() : getValue() }); // static method
+ } else if(getType()!=null){
+ Object res=super.getObjectValue(classLoader);
+ if(res!=null) return res;
+ Class factoryClass=classLoader.loadClass(getType());
+ Constructor constructor=factoryClass.getConstructor(new Class[]{String.class});
+ return constructor.newInstance(new Object[]{getValue()==null ? getText() : getValue() }); // static method
+ } else {
+ return getValue()==null ? getText() : getValue();
+ }
+ }
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/ExtendedProperty.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Implementation.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Implementation.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Implementation.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Implementation.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Implementation {
+ private String clazz;
+
+ /**
+ * the langage of the SOSOC script. by default Java
+ */
+ private String language="java";
+
+ /**
+ * the entry in which the SOSOC script is stored
+ */
+ private String entry;
+
+ /**
+ * the url in which the SOSOC script is stored
+ */
+ private String url;
+
+ /**
+ * the CDATA text of the SOSOC script
+ */
+ private String text;
+
+
+ public String getClassName() {
+ return clazz;
+ }
+
+ public void setClass(String clazz) {
+ this.clazz = clazz;
+ }
+
+ public String toString(){
+ StringBuffer sb=new StringBuffer();
+ sb.append("[Implementation:");
+ if(language!=null) sb.append("language=").append(language).append(';');
+ if(clazz!=null) sb.append("class=").append(clazz).append(';');
+ if(entry!=null) sb.append("entry=").append(entry).append(';');
+ if(url!=null) sb.append("url=").append(url).append(';');
+ if(text!=null) sb.append("text=").append(text).append(';');
+ sb.append(']');
+ return sb.toString();
+ }
+
+ public void process() throws Throwable {
+ if(clazz==null && entry==null && url==null && text==null) throw new IllegalArgumentException("attribute class is missing");
+ if(clazz!=null && entry!=null) throw new IllegalArgumentException("could not have both attributes class and entry");
+ if(url!=null && entry!=null) throw new IllegalArgumentException("could not have both attributes url and entry");
+ if(clazz!=null && url!=null) throw new IllegalArgumentException("could not have both attributes class and url");
+ if(clazz==null && language==null && (entry!=null || url!=null)) throw new IllegalArgumentException("attribute language is missing");
+
+ // check for text : remark text is append to the script located in the url or in the entry
+ }
+
+ public String getEntry() {
+ return entry;
+ }
+
+ public void setEntry(String entry) {
+ this.entry = entry;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void addText(String text) {
+ this.text = text;
+ }
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Implementation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Instance.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Instance.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Instance.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Instance.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface Instance
+{
+ public static final int INSTANCE_CREATED = 0;
+ public static final int INSTANCE_VALID = 1;
+ public static final int INSTANCE_INVALID = 2;
+ public static final int INSTANCE_DESTROYED = 3;
+
+ /**
+ * Get the state of the instance
+ *
+ * @return an integer representing the state of the instance
+ **/
+ public int getState();
+
+ /**
+ * Get the bundle
+ *
+ * @return an integer with the bundle id
+ **/
+ public long getBundleId();
+
+ /**
+ * Get a list of references
+ *
+ * @return a List containing all of the references
+ **/
+ public Reference[] getReferences();
+
+ /**
+ * Get a list of child instances in case this instance is a factory
+ *
+ * @return a List containing all of the child instances
+ **/
+ public Instance[] getChildInstances();
+
+ /**
+ * Get the instance metadata
+ *
+ * @return the isntance metadata
+ **/
+ public Component getComponent();
+}
+
+
+
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Instance.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Properties.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Properties.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Properties.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Properties.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Properties {
+ private Component parent;
+ private String entry;
+
+ public void setContext(Map map){
+
+ }
+
+ public Component getParent() {
+ return parent;
+ }
+
+ public void setParent(Component parent){
+ this.parent=parent;
+ }
+
+ public String getEntry() {
+ return entry;
+ }
+
+ public void setEntry(String entry) {
+ this.entry = entry;
+ }
+
+ public String toString(){
+ StringBuffer sb=new StringBuffer();
+ sb.append("[Properties:");
+ if(entry!=null) sb.append("entry=").append(entry).append(';');
+ sb.append(']');
+ return sb.toString();
+ }
+
+ public void process() throws Throwable {
+ if(entry==null) throw new IllegalArgumentException("attribute entry is missing");
+ }
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Properties.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Property.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Property.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Property.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Property.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Property {
+ private Component parent;
+ private String name;
+ private String value;
+ private String type;
+ private String text;
+
+ public void setContext(Map map){
+
+ }
+
+ public Component getParent() {
+ return parent;
+ }
+
+ public void setParent(Component parent){
+ this.parent=parent;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void addText(String text) {
+ this.text = text;
+ }
+
+ public String toString(){
+ StringBuffer sb=new StringBuffer();
+ sb.append("[Property:");
+ if(name!=null) sb.append("name=").append(name).append(';');
+ if(value!=null) sb.append("value=").append(value).append(';');
+ if(text!=null) sb.append("text=").append(text).append(';');
+ if(type!=null) sb.append("type=").append(type).append(';');
+ sb.append(']');
+ return sb.toString();
+ }
+
+ public void process() throws Throwable {
+ if(name==null) throw new IllegalArgumentException("attribute name is missing");
+ if(value==null) throw new IllegalArgumentException("attribute name is missing");
+ }
+
+ // TODO the Object[] from the getText()
+ public Object getObjectValue(ClassLoader classLoader) throws Exception{
+ Object res;
+ if(type==null || type.equals("String")){
+ res=value;
+ } else if(type.equals("Boolean")){
+ res=new Boolean(value);
+ } else if(type.equals("Byte")){
+ res=new Byte(value);
+ } else if(type.equals("Short")){
+ res=new Short(value);
+ } else if(type.equals("Int")){
+ res=new Integer(value);
+ } else if(type.equals("Long")){
+ res=new Long(value);
+ } else if(type.equals("Float")){
+ res=new Float(value);
+ } else if(type.equals("Double")){
+ res=new Double(value);
+ } else {
+ res=null;
+ }
+ return res;
+ }
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Property.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Provide.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Provide.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Provide.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Provide.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Provide {
+ private Service parent;
+ private String interfaze;
+
+ public void setContext(Map map){
+
+ }
+
+ public Service getParent() {
+ return parent;
+ }
+
+ public void setParent(Service parent){
+ this.parent=parent;
+ }
+
+ public String getInterface() {
+ return interfaze;
+ }
+
+ public void setInterface(String interfaze) {
+ this.interfaze = interfaze;
+ }
+
+ public String toString(){
+ StringBuffer sb=new StringBuffer();
+ sb.append("[Provide:");
+ if(interfaze!=null) sb.append("interface=").append(interfaze).append(';');
+ sb.append(']');
+ return sb.toString();
+ }
+
+ public void process() throws Throwable {
+ if(interfaze==null) throw new IllegalArgumentException("attribute interface is missing");
+ }
+
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Provide.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Reference.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Reference.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Reference.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Reference.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Reference {
+
+ public final static String CARDINALITY_01="0..1";
+ public final static String CARDINALITY_11="1..1";
+ public final static String CARDINALITY_0N="0..n";
+ public final static String CARDINALITY_1N="1..n";
+
+ public final static String POLICY_STATIC="static";
+ public final static String POLICY_DYNAMIC="dynamic";
+
+ public final static String ONDEMAND_NONE="none";
+ public final static String ONDEMAND_LAZYACTIVATION="lazyactivation";
+ public final static String ONDEMAND_LAZYINSTALLION="lazyinstallation";
+
+ private Component parent;
+ private String name;
+ private String interfaze;
+ private String cardinality=CARDINALITY_11;
+ private String policy=POLICY_STATIC;
+ private String target;
+ private String bind;
+ private String unbind;
+ private String ondemand=ONDEMAND_NONE;
+
+ public void setContext(Map map){
+
+ }
+
+ public Component getParent() {
+ return parent;
+ }
+
+ public void setParent(Component parent){
+ this.parent=parent;
+ }
+
+ public String getBind() {
+ return bind;
+ }
+
+ public void setBind(String bind) {
+ this.bind = bind;
+ }
+
+ public String getCardinality() {
+ return cardinality;
+ }
+
+ public void setCardinality(String cardinality) {
+ this.cardinality = cardinality;
+ }
+
+ public String getInterface() {
+ return interfaze;
+ }
+
+ public void setInterface(String interfaze) {
+ this.interfaze = interfaze;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPolicy() {
+ return policy;
+ }
+
+ public void setPolicy(String policy) {
+ this.policy = policy;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ public String getUnbind() {
+ return unbind;
+ }
+
+ public void setUnbind(String unbind) {
+ this.unbind = unbind;
+ }
+
+
+ public String toString(){
+ StringBuffer sb=new StringBuffer();
+ sb.append("[Reference:");
+ if(name!=null) sb.append("name=").append(name).append(';');
+ if(interfaze!=null) sb.append("interface=").append(interfaze).append(';');
+ if(target!=null) sb.append("target=").append(target).append(';');
+ if(cardinality!=null) sb.append("cardinality=").append(cardinality).append(';');
+ if(policy!=null) sb.append("policy=").append(policy).append(';');
+ if(bind!=null) sb.append("bind=").append(bind).append(';');
+ if(unbind!=null) sb.append("unbind=").append(unbind).append(';');
+ sb.append(']');
+ return sb.toString();
+ }
+
+ public void process() throws Throwable {
+ if(interfaze==null) throw new IllegalArgumentException("attribute interface is missing");
+ if(name==null) throw new IllegalArgumentException("attribute name is missing");
+ if(!(policy.equals(POLICY_DYNAMIC)
+ || policy.equals(POLICY_STATIC)
+ )) throw new IllegalArgumentException("attribute policy is not correct");
+ if(!(cardinality.equals(CARDINALITY_01)
+ || cardinality.equals(CARDINALITY_11)
+ || cardinality.equals(CARDINALITY_0N)
+ || cardinality.equals(CARDINALITY_1N)
+ )) throw new IllegalArgumentException("attribute cardinality is not correct");
+ }
+
+ public boolean isOptional() {
+ return (cardinality.equals(CARDINALITY_01)
+ || cardinality.equals(CARDINALITY_0N)
+ );
+ }
+
+ public boolean isMultiple() {
+ return (cardinality.equals(CARDINALITY_0N)
+ || cardinality.equals(CARDINALITY_1N)
+ );
+ }
+
+ public boolean isStatic() {
+ return policy.equals(POLICY_STATIC);
+ }
+
+ public String getOndemand() {
+ return ondemand;
+ }
+
+ public void setOndemand(String ondemand) {
+ this.ondemand = ondemand;
+ }
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Reference.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Service.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Service.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Service.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Service.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.descriptor.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Service {
+ private List provide;
+ private boolean servicefactory=false;
+
+ public List getProvide() {
+ return provide;
+ }
+ public void addProvide(Provide p) {
+ if(provide==null) provide=new ArrayList();
+ this.provide.add(p);
+ }
+ public boolean isServicefactory() {
+ return servicefactory;
+ }
+ public void setServicefactory(boolean servicefactory) {
+ this.servicefactory = servicefactory;
+ }
+
+ private Component parent;
+
+ public void setContext(Map map){
+
+ }
+
+ public Component getParent() {
+ return parent;
+ }
+
+ public void setParent(Component parent){
+ this.parent=parent;
+ }
+
+ public String toString(){
+ StringBuffer sb=new StringBuffer();
+ sb.append("[Service:");
+ if(provide!=null) sb.append("provide=").append(provide).append(';');
+ sb.append(']');
+ return sb.toString();
+ }
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/descriptor/xml/Service.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceEvent.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceEvent.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceEvent.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceEvent.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.event;
+
+import org.apache.felix.sandbox.sosoc.manager.InstanceReference;
+
+/**
+ * This class is the event generated when the availability of the
+ * underlying object associated with an <tt>InstanceReference</tt>
+ * changes. Use the <tt>ComponentReferenceListener</tt> interface
+ * to listen for this event. The <tt>getSource()</tt> method
+ * returns the <tt>InstanceReference</tt> that generated the event.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ComponentReferenceEvent extends java.util.EventObject
+{
+ /**
+ * Construct an event with the specified source instance reference.
+ * @param ir the instance reference that generated the event.
+ **/
+ public ComponentReferenceEvent(InstanceReference ir)
+ {
+ super(ir);
+ }
+
+
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceListener.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceListener.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceListener.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceListener.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.sosoc.event;
+
+/**
+ * This is an event listener for listening to changes in
+ * the availability of the underlying object associated
+ * with an <tt>InstanceReference</tt>. For the precise
+ * details of when this event is fired, refer to the
+ * methods below.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface ComponentReferenceListener extends java.util.EventListener
+{
+ /**
+ * This method is called when an <tt>InstanceReference</tt>'s
+ * underlying object becomes valid, i.e., the instance is
+ * available for use. This event is fired during the following
+ * sequence of steps:
+ * <p>
+ * <ol>
+ * <li>Instance created.</li>
+ * <li>Dependencies bound, if any.</li>
+ * <li>Services registered, if any.</li>
+ * <li><tt>Lifecycle.activate()</tt> is called, if the instance
+ * implements the <tt>Lifecycle</tt> interface.</li>
+ * <li>Fire <tt>ComponentReferenceListener.validated()</tt>.
+ * </ol>
+ * @param event the associated instance reference event.
+ **/
+ public void validated(ComponentReferenceEvent event);
+
+ /**
+ * This method is called when an <tt>InstanceReference</tt>'s
+ * underlying object is going to be invalidated. This event
+ * is fired during the following sequence of steps:
+ * <p>
+ * <ol>
+ * <li>Fire <tt>ComponentReferenceListener.invalidating()</tt>.
+ * <li>Call <tt>Lifecycle.deactivate()</tt>, if the instance
+ * implements the <tt>Lifecycle</tt> interface.</li>
+ * <li>Unregister services, if any.</li>
+ * <li>Unbind dependencies, if any.</li>
+ * <li>Dispose instance.</li>
+ * </ol>
+ * <p>
+ * Note: Care must be taken during this callback, because the
+ * underlying object associated with the instance reference may
+ * not be fully functioning. For example, this event might be
+ * fired in direct response to a dependent service shutting down,
+ * which then instigates the invalidation of the underlying object
+ * instance.
+ * @param event the associated instance reference event.
+ **/
+ public void invalidating(ComponentReferenceEvent event);
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/ComponentReferenceListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/Constants.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/Constants.java?rev=601738&view=auto
==============================================================================
--- felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/Constants.java (added)
+++ felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/Constants.java Thu Dec 6 06:07:25 2007
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sandbox.sosoc.event;
+
+/**
+ * Constants for SOSOC related topics for the Event Admin
+ * (component and instance lifecycles, factory, ...)
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface Constants {
+
+ // Topics
+ public final static String TOPIC_PREFIX="org/osgi/service/component";
+ public final static String TOPIC_COMPONENT="org/osgi/service/component/ComponentEvent";
+ public final static String TOPIC_INSTANCE="org/osgi/service/component/InstanceEvent";
+ public final static String TOPIC_FACTORY="org/osgi/service/component/FactoryEvent";
+
+ public final static String TOPIC_COMPONENT_ENABLED="org/osgi/service/component/ComponentEvent/ENABLED";
+ public final static String TOPIC_COMPONENT_DISABLED="org/osgi/service/component/ComponentEvent/DISABLED";
+
+ // Event properties
+ // ...
+}
Propchange: felix/sandbox/donsez/sosoc/src/main/java/org/apache/felix/sandbox/sosoc/event/Constants.java
------------------------------------------------------------------------------
svn:eol-style = native