[jboss-cvs] JBossAS SVN: r62256 - in projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi: spi/metadata and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 11 11:08:55 EDT 2007
Author: alesj
Date: 2007-04-11 11:08:55 -0400 (Wed, 11 Apr 2007)
New Revision: 62256
Added:
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractAttributeAware.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractPackageAttribute.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractParameter.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractParameterizedAttribute.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/BooleanValueCreator.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/OSGiParameters.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/VersionRangeValueCreator.java
Modified:
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractValueCreator.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractVersionRange.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/HeaderValue.jj
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/PackageAttributeListValueCreator.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ParameterizedAttributeListValueCreator.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ParameterizedAttributeValueCreator.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/StringListValueCreator.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ValueCreatorUtil.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/Parameter.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/ParameterizedAttribute.java
Log:
OSGi headers parsing; javacc + data holders.
Missing tests --> todo.
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractAttributeAware.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractAttributeAware.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractAttributeAware.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -0,0 +1,60 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.metadata;
+
+import java.io.Serializable;
+
+import org.jboss.osgi.spi.metadata.AttributeAware;
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Attribute holder.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractAttributeAware extends JBossObject implements AttributeAware, Serializable
+{
+ private static final long serialVersionUID = 1l;
+
+ protected String attribute;
+
+ protected AbstractAttributeAware(String attribute)
+ {
+ this.attribute = attribute;
+ }
+
+ public String getAttribute()
+ {
+ return attribute;
+ }
+
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ buffer.append("attribute=" + attribute);
+ }
+
+ protected void toString(JBossStringBuilder buffer)
+ {
+ buffer.append("attribute=" + attribute);
+ }
+}
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractPackageAttribute.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractPackageAttribute.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractPackageAttribute.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.metadata;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.jboss.osgi.spi.metadata.PackageAttribute;
+import org.jboss.osgi.spi.metadata.Parameter;
+import org.jboss.osgi.spi.metadata.VersionRange;
+import org.jboss.reflect.plugins.PackageInfoImpl;
+import org.jboss.reflect.spi.PackageInfo;
+import org.osgi.framework.Constants;
+
+/**
+ * Package attribute impl.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractPackageAttribute extends AbstractParameterizedAttribute implements PackageAttribute, Serializable
+{
+ private static final long serialVersionUID = 1l;
+
+ protected PackageInfo packageInfo;
+ protected VersionRange versionRange;
+
+ public AbstractPackageAttribute(String attribute, Map<String, Parameter> parameters)
+ {
+ super(attribute, parameters);
+ packageInfo = new PackageInfoImpl(attribute);
+ }
+
+ public PackageInfo getPackageInfo()
+ {
+ return packageInfo;
+ }
+
+ public VersionRange getVersion()
+ {
+ if (versionRange == null)
+ {
+ Parameter parameter = getParameter(Constants.VERSION_ATTRIBUTE);
+ if (parameter != null)
+ {
+ if (parameter.isCollection())
+ throw new IllegalArgumentException("Duplicate version parameter.");
+ Object value = parameter.getValue();
+ if (value != null)
+ {
+ versionRange = AbstractVersionRange.parseRangeSpec(value.toString());
+ }
+ }
+ }
+ return versionRange;
+ }
+}
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractParameter.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractParameter.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractParameter.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.metadata;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.jboss.osgi.spi.metadata.Parameter;
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Parameter impl.
+ * It uses [Hash]Set to hold the values.
+ * So duplicate values (by hash) will be ignored.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class AbstractParameter extends JBossObject implements Parameter, Serializable
+{
+ protected Collection<String> values = new HashSet<String>();
+
+ public void addValue(String value)
+ {
+ values.add(value);
+ }
+
+ public Object getValue()
+ {
+ if (values.isEmpty())
+ return null;
+ else if (values.size() == 1)
+ return values.iterator().next();
+ else
+ return values;
+ }
+
+ public boolean isCollection()
+ {
+ return values.size() > 1;
+ }
+
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ buffer.append("value=" + getValue());
+ }
+
+ protected void toString(JBossStringBuilder buffer)
+ {
+ buffer.append("value=" + getValue());
+ }
+}
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractParameterizedAttribute.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractParameterizedAttribute.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractParameterizedAttribute.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -0,0 +1,62 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.metadata;
+
+import java.util.Map;
+
+import org.jboss.osgi.spi.metadata.Parameter;
+import org.jboss.osgi.spi.metadata.ParameterizedAttribute;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Parameter attribute impl.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractParameterizedAttribute extends AbstractAttributeAware implements ParameterizedAttribute
+{
+ private static final long serialVersionUID = 1l;
+
+ protected Map<String, Parameter> parameters;
+
+ public AbstractParameterizedAttribute(String attribute, Map<String, Parameter> parameters)
+ {
+ super(attribute);
+ this.parameters = parameters;
+ }
+
+ public Map<String, Parameter> getParameters()
+ {
+ return parameters;
+ }
+
+ public Parameter getParameter(String name)
+ {
+ return parameters.get(name);
+ }
+
+ protected void toString(JBossStringBuilder buffer)
+ {
+ super.toString(buffer);
+ buffer.append(" parameters=" + parameters);
+ }
+}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractValueCreator.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractValueCreator.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractValueCreator.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -21,6 +21,8 @@
*/
package org.jboss.osgi.plugins.metadata;
+import org.jboss.logging.Logger;
+
/**
* Abstract value creator.
* Extend this one for safe string usage.
@@ -29,6 +31,7 @@
*/
abstract class AbstractValueCreator<T> implements ValueCreator<T>
{
+ protected Logger log = Logger.getLogger(getClass());
private boolean trim;
protected AbstractValueCreator()
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractVersionRange.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractVersionRange.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/AbstractVersionRange.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -71,6 +71,7 @@
StringTokenizer st = new StringTokenizer(rangeSpec, ",[]()", true);
Boolean floorIsGreaterThan = null;
Boolean ceilingIsLessThan = null;
+ boolean mid = false;
while (st.hasMoreTokens())
{
String token = st.nextToken();
@@ -82,7 +83,9 @@
ceilingIsLessThan = false;
else if (token.equals(")"))
ceilingIsLessThan = true;
- else if (token.equals(",") == false)
+ else if (token.equals(","))
+ mid = true;
+ else
{
// A version token
if (floor == null)
@@ -93,7 +96,7 @@
}
// check for parenthesis
- if (floorIsGreaterThan == null || ceilingIsLessThan == null)
+ if (mid && (floorIsGreaterThan == null || ceilingIsLessThan == null))
throw new IllegalArgumentException("Missing parenthesis: " + rangeSpec);
return new AbstractVersionRange(rangeSpec, floor, ceiling, floorIsGreaterThan, ceilingIsLessThan);
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/BooleanValueCreator.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/BooleanValueCreator.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/BooleanValueCreator.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.metadata;
+
+/**
+ * Parse boolean from string.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+*/
+class BooleanValueCreator extends AbstractValueCreator<Boolean>
+{
+ public BooleanValueCreator()
+ {
+ super();
+ }
+
+ public BooleanValueCreator(boolean trim)
+ {
+ super(trim);
+ }
+
+ public Boolean useString(String attribute)
+ {
+ return Boolean.valueOf(attribute);
+ }
+}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/HeaderValue.jj
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/HeaderValue.jj 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/HeaderValue.jj 2007-04-11 15:08:55 UTC (rev 62256)
@@ -1,26 +1,5 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
options {
- LOOKAHEAD=1;
+ LOOKAHEAD=2;
DEBUG_PARSER=true;
DEBUG_LOOKAHEAD=true;
DEBUG_TOKEN_MANAGER=false;
@@ -36,26 +15,16 @@
import java.util.List;
import java.util.Map;
+import org.jboss.osgi.spi.metadata.*;
+
/**
* A JavaCC 3.2 grammar for the OSGi R4 bundle headers
-
- * @see https://javacc.dev.java.net/
- * eclipse plugin: http://sourceforge.net/projects/eclipse-javacc
*
* @author Scott.Stark at jboss.org
* @author Ales.Justin at jboss.org
*/
public class HeaderValue
{
- /**
- * Package name and param holder.
- */
- public static class PkgInfo
- {
- List<String> pkgNames = new ArrayList<String>();
- Map<String, String> paramMap = new HashMap<String, String>();
- }
-
public HeaderValue()
{
this(new StringReader(""));
@@ -66,30 +35,58 @@
this(new StringReader(value));
}
- public PkgInfo parseImportPackage(StringReader header, boolean trace)
- throws ParseException
+ private void applyTracing(boolean trace)
{
- ReInit(header);
-
- // This will have no effect unless the debugging options are true
if (trace)
{
- this.enable_tracing();
+ enable_tracing();
}
else
{
- this.disable_tracing();
+ disable_tracing();
}
+ }
- return this.ImportPackage();
+ private void addParameter(Map<String, Parameter> parameters, String key, String value)
+ {
+ Parameter parameter = parameters.get(key);
+ if (parameter == null)
+ {
+ parameter = new AbstractParameter();
+ parameters.put(key, parameter);
+ }
+ parameter.addValue(value);
}
-
- public static PkgInfo parseImportPackage(String header, boolean trace)
+
+ public void parsePackages(List<PackageAttribute> list, boolean trace)
throws ParseException
{
- HeaderValue parser = new HeaderValue();
- return parser.parseImportPackage(new StringReader(header), trace);
+ // This will have no effect unless the debugging options are true
+ applyTracing(trace);
+ parsePackages(list);
}
+
+ public void parseParameters(List<ParameterizedAttribute> list, boolean trace)
+ throws ParseException
+ {
+ // This will have no effect unless the debugging options are true
+ applyTracing(trace);
+ parseParameters(list);
+ }
+
+ public static void parsePackages(String header, List<PackageAttribute> list, boolean trace)
+ throws ParseException
+ {
+ HeaderValue parser = new HeaderValue(header);
+ parser.parsePackages(list, trace);
+ }
+
+ public static void parseParameters(String header, List<ParameterizedAttribute> list, boolean trace)
+ throws ParseException
+ {
+ HeaderValue parser = new HeaderValue(header);
+ parser.parseParameters(list, trace);
+ }
}
PARSER_END(HeaderValue)
@@ -110,145 +107,126 @@
|
<#DIGIT: ["0" - "9"] >
|
- <#ALPHANUM: <ALPHA>|<DIGIT> >
+ <NUMBER: (<DIGIT>)+ >
|
- <#TOKN: (<ALPHANUM>|"_"|"-")+ >
+ <DECIMAL_NUMBER: <NUMBER> ( "." <NUMBER> )? >
|
- <NUMBER: (<DIGIT>)+ >
+ <#ALPHANUM: <ALPHA>|<DECIMAL_NUMBER> >
|
- <QNAME: <JLETTER> (<JLETTER>|<DIGIT>)* ("." <JLETTER> (<JLETTER>|<DIGIT>)*)* >
+ <VERSION_VALUE: (<NUMBER> ("." <NUMBER> ("." <NUMBER> ("." <ALPHANUM>)? )? )?) >
|
+ <#TOKN: (<ALPHANUM>|<VERSION_VALUE>|"_"|"-")+ >
+|
<#JLETTER: [ "_", "a"-"z", "A"-"Z" ] >
|
<#JLETTER_OR_DIGIT: <JLETTER> | <DIGIT> >
|
- <IDENTIFIER: <JLETTER> (<JLETTER> | <JLETTER_OR_DIGIT>)* >
+ <QNAME: <JLETTER> (<JLETTER_OR_DIGIT>)* ("." <JLETTER> (<JLETTER_OR_DIGIT>)*)* >
|
<QUOTED_STRING: "\"" ( ~["\"", "\\", "\r", "\n", "\u0000"] | "\\\"")* "\"" >
|
- <ARGUMENT: <TOKN>|<QUOTED_STRING> >
+ <#ARGUMENT: <TOKN>|<QUOTED_STRING> >
|
- <DIRECTIVE: <TOKN> ":=" <ARGUMENT> >
-|
<ATTRIBUTE: <TOKN> "=" <ARGUMENT> >
|
- <PARAMETER: <DIRECTIVE>|<ATTRIBUTE> >
-|
- <UNIQUE_NAME: <IDENTIFIER> ("." <IDENTIFIER>)* >
-|
- <SYMBOLIC_NAME: <TOKN> ("." <TOKN>)* >
-|
- <PACKAGE_NAME: <UNIQUE_NAME> >
-|
- <PATH: <PATH_UNQUOTED> | "\"" <PATH_UNQUOTED> "\"" >
-|
- <PATH_UNQUOTED: <PATH_SEP> | (<PATH_SEP>)? <PATH_ELEMENT> (<PATH_SEP> <PATH_ELEMENT>)* >
-|
- <PATH_ELEMENT: (~["/", "\"", "\n", "\r", "\u0000"])+ >
-|
- <PATH_SEP: "/" >
+ <DIRECTIVE: <TOKN> ":=" <ARGUMENT> >
}
-/* Directives */
-TOKEN [IGNORE_CASE]:
-{
- <EXCLUDE_DIRECTIVE: "exclude">
-|
- <EXTENSION_DIRECTIVE: "extension">
-|
- <FRAGMENT_ATTACHMENT_DIRECTIVE: "fragment-attachment">
-|
- <INCLUDE_DIRECTIVE: "include">
-|
- <MANDATORY_DIRECTIVE: "mandatory">
-|
- <RESOLUTION_DIRECTIVE: "resolution">
-|
- <RESOLUTION_DIRECTIVE_VALUE: "mandatory"|"optional">
-|
- <SINGLETON_DIRECTIVE: "singleton">
-|
- <USES_DIRECTIVE: "uses">
-|
- <VISIBILITY_DIRECTIVE: "visibility">
-}
-
-/* Attributes */
-TOKEN [IGNORE_CASE]:
-{
- <BUNDLE_SYMBOLICNAME_ATTRIBUTE: "bundle-symbolic-name">
-|
- <BUNDLE_VERSION_ATTRIBUTE: "bundle-version">
-|
- <SELECTION_FILTER_ATTRIBUTE: "selection-filter">
-|
- <VERSION_ATTRIBUTE: "version">
-|
- <VERSION_VALUE: (<NUMBER> ("." <NUMBER> ("." <NUMBER> ("." <ALPHANUM>)? )? )?) >
-}
-
/** Start of the grammar */
+/** Entry point for the Import-Package header value parsing. */
-void headers() :
+void parsePackages(List<PackageAttribute> list) :
{
}
{
- header() <EOF>
+ packageInfo(list) ( "," packageInfo(list) )*
+ {
+ }
}
-void header() :
+
+void parseParameters(List<ParameterizedAttribute> list) :
{
}
{
- (BundleManifestVersion())?
- | (ImportPackage())?
+ parameterInfo(list) ( "," parameterInfo(list) )*
+ {
+ }
}
-void BundleManifestVersion() :
+void packageInfo(List<PackageAttribute> list) :
{
+ List<String> packages = new ArrayList<String>();
+ Map<String, Parameter> parameters = new HashMap<String, Parameter>();
}
{
- <NUMBER>
+ packageNames(packages) ( ";" parsePackageParameters(parameters) )*
+ {
+ for(String pckg : packages)
+ {
+ list.add(new AbstractPackageAttribute(pckg, parameters));
+ }
+ }
}
-/**
-Entry point for the Import-Package header value parsing.
-*/
-PkgInfo ImportPackage() :
+void parameterInfo(List<ParameterizedAttribute> list) :
{
- PkgInfo info = new PkgInfo();
+ Token t;
+ Map<String, Parameter> parameters = new HashMap<String, Parameter>();
}
{
- Import(info) ( "," Import(info) )*
- {
- return info;
- }
+ t = <QNAME> ( ";" parseAttributeParameters(parameters) )*
+ {
+ list.add(new AbstractParameterizedAttribute(t.toString(), parameters));
+ }
}
-void Import(PkgInfo info) :
+void packageNames(List<String> packages) :
{
+ Token t;
}
{
- PackageNames(info) ( ";" <PARAMETER> )*
+ t=<QNAME> {packages.add(t.image);} ( ";" packageNames(packages))*
}
-void PackageNames(PkgInfo info) :
+void parsePackageParameters(Map<String, Parameter> parameters) :
{
- Token t = null;
+ Token t;
}
{
- t=<PACKAGE_NAME> {info.pkgNames.add(t.image);} ( ";" t=<PACKAGE_NAME> {info.pkgNames.add(t.image);})*
+ t = <DIRECTIVE>
+ {
+ String ts = t.toString();
+ String[] params = ts.split(":=");
+ addParameter(parameters, params[0], params[1]);
+ }
+|
+ t = <ATTRIBUTE>
+ {
+ String ts = t.toString();
+ String[] params = ts.split("=");
+ addParameter(parameters, params[0], params[1]);
+ }
+ ( ";" parsePackageParameters(parameters))*
}
-void ImportParameters(PkgInfo info) :
+
+void parseAttributeParameters(Map<String, Parameter> parameters) :
{
- Token t = null;
+ Token t;
}
{
- <RESOLUTION_DIRECTIVE> <DIRECTIVE> t=<RESOLUTION_DIRECTIVE_VALUE>
- {
- info.paramMap.put("resolution", t.image);
- }
- | <VERSION_ATTRIBUTE> <ATTRIBUTE> t=<VERSION_VALUE>
- {
- info.paramMap.put("version", t.image);
- }
+ t = <DIRECTIVE>
+ {
+ String ts = t.toString();
+ String[] params = ts.split(":=");
+ addParameter(parameters, params[0], params[1]);
+ }
+|
+ t = <ATTRIBUTE>
+ {
+ String ts = t.toString();
+ String[] params = ts.split("=");
+ addParameter(parameters, params[0], params[1]);
+ }
+ ( ";" parseAttributeParameters(parameters))*
}
+
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/OSGiParameters.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/OSGiParameters.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/OSGiParameters.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -0,0 +1,107 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.metadata;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.osgi.spi.metadata.Parameter;
+import org.jboss.osgi.spi.metadata.VersionRange;
+import static org.osgi.framework.Constants.*;
+
+/**
+ * OSGi parameter values.
+ * Util for transforming parameter info to actual useful values.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OSGiParameters
+{
+ protected Map<String, Parameter> parameters;
+ protected Map<String, Object> cachedAttributes;
+
+ public OSGiParameters(Map<String, Parameter> parameters)
+ {
+ this.parameters = parameters;
+ this.cachedAttributes = new HashMap<String, Object>();
+ }
+
+ public VersionRange getVersion()
+ {
+ return get(VERSION_ATTRIBUTE, ValueCreatorUtil.VERSION_RANGE_VC);
+ }
+
+ public String getBundleSymbolicName()
+ {
+ return get(BUNDLE_SYMBOLICNAME_ATTRIBUTE, ValueCreatorUtil.STRING_VC);
+ }
+
+ public VersionRange getBundleVersion()
+ {
+ return get(BUNDLE_VERSION_ATTRIBUTE, ValueCreatorUtil.VERSION_RANGE_VC);
+ }
+
+ public String getVisibility()
+ {
+ return get(VISIBILITY_DIRECTIVE, ValueCreatorUtil.STRING_VC, VISIBILITY_PRIVATE);
+ }
+
+ public String getResolution()
+ {
+ return get(RESOLUTION_DIRECTIVE, ValueCreatorUtil.STRING_VC, RESOLUTION_MANDATORY);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T> T get(String key, ValueCreator<T> creator)
+ {
+ return get(key, creator, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T> T get(String key, ValueCreator<T> creator, T defaultValue)
+ {
+ T value = (T)cachedAttributes.get(key);
+ if (value == null)
+ {
+ Parameter parameter = parameters.get(key);
+ if (parameter != null)
+ {
+ Object paramValue = parameter.getValue();
+ if(parameter.isCollection())
+ {
+ // todo
+ }
+ else
+ {
+ value = creator.createValue(paramValue.toString());
+ }
+ cachedAttributes.put(key, value);
+ }
+ else if (defaultValue != null)
+ {
+ value = defaultValue;
+ cachedAttributes.put(key, value);
+ }
+ }
+ return value;
+ }
+}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/PackageAttributeListValueCreator.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/PackageAttributeListValueCreator.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/PackageAttributeListValueCreator.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -21,6 +21,7 @@
*/
package org.jboss.osgi.plugins.metadata;
+import java.util.ArrayList;
import java.util.List;
import org.jboss.osgi.spi.metadata.PackageAttribute;
@@ -34,6 +35,15 @@
{
public List<PackageAttribute> useString(String attibute)
{
- return null; // todo
+ List<PackageAttribute> list = new ArrayList<PackageAttribute>();
+ try
+ {
+ HeaderValue.parsePackages(attibute, list, log.isTraceEnabled());
+ }
+ catch (ParseException e)
+ {
+ log.error("Exception parsing package headers.", e);
+ }
+ return list;
}
}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ParameterizedAttributeListValueCreator.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ParameterizedAttributeListValueCreator.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ParameterizedAttributeListValueCreator.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -21,6 +21,7 @@
*/
package org.jboss.osgi.plugins.metadata;
+import java.util.ArrayList;
import java.util.List;
import org.jboss.osgi.spi.metadata.ParameterizedAttribute;
@@ -34,6 +35,15 @@
{
public List<ParameterizedAttribute> useString(String attribute)
{
- return null; //Todo
+ List<ParameterizedAttribute> list = new ArrayList<ParameterizedAttribute>();
+ try
+ {
+ HeaderValue.parseParameters(attribute, list, log.isTraceEnabled());
+ }
+ catch (ParseException e)
+ {
+ log.error("Exception parsing parameters.", e);
+ }
+ return list;
}
}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ParameterizedAttributeValueCreator.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ParameterizedAttributeValueCreator.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ParameterizedAttributeValueCreator.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -21,6 +21,8 @@
*/
package org.jboss.osgi.plugins.metadata;
+import java.util.List;
+
import org.jboss.osgi.spi.metadata.ParameterizedAttribute;
/**
@@ -32,6 +34,8 @@
{
public ParameterizedAttribute useString(String attribute)
{
- return null; //todo
+ ParameterizedAttributeListValueCreator palvc = new ParameterizedAttributeListValueCreator();
+ List<ParameterizedAttribute> list = palvc.useString(attribute);
+ return list.size() > 0 ? list.get(0) : null;
}
}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/StringListValueCreator.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/StringListValueCreator.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/StringListValueCreator.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -31,8 +31,32 @@
*/
class StringListValueCreator extends ListValueCreator<String>
{
+ protected String delimiter = ",";
+
+ public StringListValueCreator()
+ {
+ super();
+ }
+
+ public StringListValueCreator(boolean trim)
+ {
+ super(trim);
+ }
+
+ public StringListValueCreator(String delimiter)
+ {
+ this();
+ this.delimiter = delimiter;
+ }
+
+ public StringListValueCreator(String delimiter, boolean trim)
+ {
+ this(trim);
+ this.delimiter = delimiter;
+ }
+
public List<String> useString(String attribute)
{
- return Arrays.asList(attribute.split(","));
+ return Arrays.asList(attribute.split(delimiter));
}
}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ValueCreatorUtil.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ValueCreatorUtil.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ValueCreatorUtil.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -30,10 +30,12 @@
{
static StringValueCreator STRING_VC = new StringValueCreator();
static IntegerValueCreator INTEGER_VC = new IntegerValueCreator();
+ static BooleanValueCreator BOOLEAN_VC = new BooleanValueCreator();
static VersionValueCreator VERSION_VC = new VersionValueCreator();
+ static VersionRangeValueCreator VERSION_RANGE_VC = new VersionRangeValueCreator();
static URLValueCreator URL_VC = new URLValueCreator();
- static ParameterizedAttributeValueCreator PARAM_ATTRIB_VC = new ParameterizedAttributeValueCreator();
static StringListValueCreator STRING_LIST_VC = new StringListValueCreator();
- static ParameterizedAttributeListValueCreator PARAM_ATTRIB_LIST_VC = new ParameterizedAttributeListValueCreator();
- static PackageAttributeListValueCreator PACKAGE_LIST_VC = new PackageAttributeListValueCreator();
+ public static ParameterizedAttributeValueCreator PARAM_ATTRIB_VC = new ParameterizedAttributeValueCreator();
+ public static ParameterizedAttributeListValueCreator PARAM_ATTRIB_LIST_VC = new ParameterizedAttributeListValueCreator();
+ public static PackageAttributeListValueCreator PACKAGE_LIST_VC = new PackageAttributeListValueCreator();
}
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/VersionRangeValueCreator.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/VersionRangeValueCreator.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/VersionRangeValueCreator.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.plugins.metadata;
+
+import org.jboss.osgi.spi.metadata.VersionRange;
+
+/**
+ * Parse VersionRange from string.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+*/
+class VersionRangeValueCreator extends AbstractValueCreator<VersionRange>
+{
+ public VersionRangeValueCreator()
+ {
+ super();
+ }
+
+ public VersionRangeValueCreator(boolean trim)
+ {
+ super(trim);
+ }
+
+ public VersionRange useString(String attribute)
+ {
+ return AbstractVersionRange.parseRangeSpec(attribute);
+ }
+}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/Parameter.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/Parameter.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/Parameter.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -30,13 +30,20 @@
{
/**
* Get value.
- * Simple value or collection.
+ * Simple string value or collection of string values.
*
* @return value
*/
Object getValue();
/**
+ * Add value.
+ *
+ * @param value string to add
+ */
+ void addValue(String value);
+
+ /**
* Has multiple values.
* Used when same name is used for multiple parameter values.
* Value _can_ be casted into Collection.
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/ParameterizedAttribute.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/ParameterizedAttribute.java 2007-04-11 14:40:10 UTC (rev 62255)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/spi/metadata/ParameterizedAttribute.java 2007-04-11 15:08:55 UTC (rev 62256)
@@ -24,6 +24,8 @@
import java.util.Map;
/**
+ * Attribute with parameters.
+ *
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
public interface ParameterizedAttribute extends AttributeAware
More information about the jboss-cvs-commits
mailing list