You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/04/10 16:16:16 UTC
[54/59] [abbrv] [KARAF-2852] Merge region/core and region/command
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/commands/AddRegionCommand.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/commands/AddRegionCommand.java b/region/src/main/java/org/apache/karaf/region/commands/AddRegionCommand.java
new file mode 100644
index 0000000..22c817b
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/commands/AddRegionCommand.java
@@ -0,0 +1,38 @@
+/*
+ * 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.karaf.region.commands;
+
+import java.util.List;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.eclipse.equinox.region.RegionDigraph;
+
+@Command(scope = "region", name = "region-add", description = "Adds a list of regions to the region digraph service.")
+@Service
+public class AddRegionCommand extends RegionCommandSupport {
+
+ @Argument(index = 0, name = "name", description = "Regions to add to the region digraph service separated by whitespaces.", required = true, multiValued = true)
+ List<String> regions;
+
+ protected void doExecute(RegionDigraph regionDigraph) throws Exception {
+ for (String region : regions) {
+ regionDigraph.createRegion(region);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/commands/InfoCommand.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/commands/InfoCommand.java b/region/src/main/java/org/apache/karaf/region/commands/InfoCommand.java
new file mode 100644
index 0000000..7c71e36
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/commands/InfoCommand.java
@@ -0,0 +1,117 @@
+/*
+ * 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.karaf.region.commands;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.eclipse.equinox.region.RegionFilter;
+import org.osgi.framework.Bundle;
+
+@Command(scope = "region", name = "info", description = "Prints information about region digraph.")
+@Service
+public class InfoCommand extends RegionCommandSupport {
+
+ @Option(name = "-v", aliases = "--verbose", required = false, description = "Show all info.")
+ boolean verbose;
+
+ @Option(name = "-b", aliases = "--bundles", required = false, description = "Show bundles in each region.")
+ boolean bundles;
+
+ @Option(name = "-f", aliases = "--filters", required = false, description = "Show filters.")
+ boolean filters;
+
+ @Option(name = "-n", aliases = "--namespaces", required = false, description = "Show namespaces in each filter.")
+ boolean namespaces;
+
+ @Argument(index = 0, name = "regions", description = "Regions to provide detailed info for.", required = false, multiValued = true)
+ List<String> regions;
+
+ protected void doExecute(RegionDigraph regionDigraph) throws Exception {
+ System.out.println("Regions");
+ if (regions == null) {
+ for (Region region : regionDigraph.getRegions()) {
+ showRegion(region);
+ }
+ } else {
+ bundles = true;
+ filters = true;
+ namespaces = true;
+ for (String regionName : regions) {
+ Region region = regionDigraph.getRegion(regionName);
+ if (region == null) {
+ System.out.println("No region " + regionName);
+ } else {
+ showRegion(region);
+ }
+ }
+ }
+ }
+
+ private void showRegion(Region region) {
+ System.out.println(region.getName());
+ if (verbose || bundles) {
+ for (Long id : region.getBundleIds()) {
+ Bundle b = bundleContext.getBundle(id);
+ System.out.println(" " + id + " " + getStateString(b) + b);
+ }
+ }
+ if (verbose || filters || namespaces) {
+ for (RegionDigraph.FilteredRegion f : region.getEdges()) {
+ System.out.println(" filter to " + f.getRegion().getName());
+ if (verbose || namespaces) {
+ RegionFilter rf = f.getFilter();
+ for (Map.Entry<String, Collection<String>> policy : rf.getSharingPolicy().entrySet()) {
+ String namespace = policy.getKey();
+ System.out.println(" namespace: " + namespace);
+ for (String e : policy.getValue()) {
+ System.out.println(" " + e);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public String getStateString(Bundle bundle) {
+ if (bundle == null) {
+ return "Bundle null";
+ }
+ int state = bundle.getState();
+ if (state == Bundle.ACTIVE) {
+ return "Active ";
+ } else if (state == Bundle.INSTALLED) {
+ return "Installed ";
+ } else if (state == Bundle.RESOLVED) {
+ return "Resolved ";
+ } else if (state == Bundle.STARTING) {
+ return "Starting ";
+ } else if (state == Bundle.STOPPING) {
+ return "Stopping ";
+ } else {
+ return "Unknown ";
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/commands/RegionCommandSupport.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/commands/RegionCommandSupport.java b/region/src/main/java/org/apache/karaf/region/commands/RegionCommandSupport.java
new file mode 100644
index 0000000..bcdfb6c
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/commands/RegionCommandSupport.java
@@ -0,0 +1,79 @@
+/*
+ * 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.karaf.region.commands;
+
+import java.io.PrintStream;
+
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+
+public abstract class RegionCommandSupport implements Action {
+
+ protected static final char VERSION_DELIM = ',';
+
+ @Reference
+ BundleContext bundleContext;
+
+ @Override
+ public Object execute() throws Exception {
+ // Get repository instance service.
+ ServiceReference ref = bundleContext.getServiceReference(RegionDigraph.class.getName());
+ if (ref == null) {
+ System.out.println("RegionDigraph service is unavailable.");
+ return null;
+ }
+ try {
+ RegionDigraph admin = (RegionDigraph) bundleContext.getService(ref);
+ if (admin == null) {
+ System.out.println("RegionDigraph service is unavailable.");
+ return null;
+ }
+
+ doExecute(admin);
+ }
+ finally {
+ bundleContext.ungetService(ref);
+ }
+ return null;
+ }
+
+ abstract void doExecute(RegionDigraph admin) throws Exception;
+
+ protected void printUnderline(PrintStream out, int length)
+ {
+ for (int i = 0; i < length; i++)
+ {
+ out.print('-');
+ }
+ out.println("");
+ }
+
+
+ protected Region getRegion(RegionDigraph regionDigraph, String region) throws BundleException {
+ Region r = regionDigraph.getRegion(region);
+ if (r == null) {
+ System.out.println("No region: " + region + ", creating it");
+ r = regionDigraph.createRegion(region);
+ }
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/commands/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/commands/util/FileUtil.java b/region/src/main/java/org/apache/karaf/region/commands/util/FileUtil.java
new file mode 100644
index 0000000..07c39e9
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/commands/util/FileUtil.java
@@ -0,0 +1,177 @@
+/*
+ * 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.karaf.region.commands.util;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+public class FileUtil
+{
+ public static void downloadSource(
+ PrintStream out, PrintStream err,
+ URL srcURL, String dirStr, boolean extract)
+ {
+ // Get the file name from the URL.
+ String fileName = (srcURL.getFile().lastIndexOf('/') > 0)
+ ? srcURL.getFile().substring(srcURL.getFile().lastIndexOf('/') + 1)
+ : srcURL.getFile();
+
+ try
+ {
+ out.println("Connecting...");
+
+ File dir = new File(dirStr);
+ if (!dir.exists())
+ {
+ err.println("Destination directory does not exist.");
+ }
+ File file = new File(dir, fileName);
+
+ OutputStream os = new FileOutputStream(file);
+ URLConnection conn = srcURL.openConnection();
+ int total = conn.getContentLength();
+ InputStream is = conn.getInputStream();
+
+ if (total > 0)
+ {
+ out.println("Downloading " + fileName
+ + " ( " + total + " bytes ).");
+ }
+ else
+ {
+ out.println("Downloading " + fileName + ".");
+ }
+ byte[] buffer = new byte[4096];
+ int count = 0;
+ for (int len = is.read(buffer); len > 0; len = is.read(buffer))
+ {
+ count += len;
+ os.write(buffer, 0, len);
+ }
+
+ os.close();
+ is.close();
+
+ if (extract)
+ {
+ is = new FileInputStream(file);
+ JarInputStream jis = new JarInputStream(is);
+ out.println("Extracting...");
+ unjar(jis, dir);
+ jis.close();
+ file.delete();
+ }
+ }
+ catch (Exception ex)
+ {
+ err.println(ex);
+ }
+ }
+
+ public static void unjar(JarInputStream jis, File dir)
+ throws IOException
+ {
+ // Reusable buffer.
+ byte[] buffer = new byte[4096];
+
+ // Loop through JAR entries.
+ for (JarEntry je = jis.getNextJarEntry();
+ je != null;
+ je = jis.getNextJarEntry())
+ {
+ if (je.getName().startsWith("/"))
+ {
+ throw new IOException("JAR resource cannot contain absolute paths.");
+ }
+
+ File target = new File(dir, je.getName());
+
+ // Check to see if the JAR entry is a directory.
+ if (je.isDirectory())
+ {
+ if (!target.exists())
+ {
+ if (!target.mkdirs())
+ {
+ throw new IOException("Unable to create target directory: "
+ + target);
+ }
+ }
+ // Just continue since directories do not have content to copy.
+ continue;
+ }
+
+ int lastIndex = je.getName().lastIndexOf('/');
+ String name = (lastIndex >= 0) ?
+ je.getName().substring(lastIndex + 1) : je.getName();
+ String destination = (lastIndex >= 0) ?
+ je.getName().substring(0, lastIndex) : "";
+
+ // JAR files use '/', so convert it to platform separator.
+ destination = destination.replace('/', File.separatorChar);
+ copy(jis, dir, name, destination, buffer);
+ }
+ }
+
+ public static void copy(
+ InputStream is, File dir, String destName, String destDir, byte[] buffer)
+ throws IOException
+ {
+ if (destDir == null)
+ {
+ destDir = "";
+ }
+
+ // Make sure the target directory exists and
+ // that is actually a directory.
+ File targetDir = new File(dir, destDir);
+ if (!targetDir.exists())
+ {
+ if (!targetDir.mkdirs())
+ {
+ throw new IOException("Unable to create target directory: "
+ + targetDir);
+ }
+ }
+ else if (!targetDir.isDirectory())
+ {
+ throw new IOException("Target is not a directory: "
+ + targetDir);
+ }
+
+ BufferedOutputStream bos = new BufferedOutputStream(
+ new FileOutputStream(new File(targetDir, destName)));
+ int count = 0;
+ while ((count = is.read(buffer)) > 0)
+ {
+ bos.write(buffer, 0, count);
+ }
+ bos.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/Activator.java b/region/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
new file mode 100644
index 0000000..aa7215f
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/Activator.java
@@ -0,0 +1,91 @@
+/*
+ * 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.karaf.region.persist.internal;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.karaf.features.RegionsPersistence;
+import org.apache.karaf.util.tracker.SingleServiceTracker;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator {
+
+ private static final Logger log = LoggerFactory.getLogger(Activator.class);
+
+ private SingleServiceTracker<RegionDigraph> tracker;
+ private final AtomicReference<RegionsPersistenceImpl> persistence = new AtomicReference<RegionsPersistenceImpl>();
+ private final AtomicReference<RegionsBundleTracker> bundleTracker = new AtomicReference<RegionsBundleTracker>();
+ private ServiceRegistration<RegionsPersistence> reg;
+
+ @Override
+ public void start(final BundleContext bundleContext) throws Exception {
+ tracker = new SingleServiceTracker<RegionDigraph>(bundleContext, RegionDigraph.class, new SingleServiceTracker.SingleServiceListener() {
+ public void serviceFound() {
+ log.debug("Found RegionDigraph service, initializing");
+ RegionDigraph regionDigraph = tracker.getService();
+ Bundle framework = bundleContext.getBundle(0);
+ RegionsPersistenceImpl persistence = null;
+ try {
+ persistence = new RegionsPersistenceImpl(regionDigraph, framework);
+ reg = bundleContext.registerService(RegionsPersistence.class, persistence, null);
+
+ RegionsBundleTracker bundleTracker = new RegionsBundleTracker();
+ bundleTracker.start(bundleContext, persistence);
+ Activator.this.bundleTracker.set(bundleTracker);
+ } catch (Exception e) {
+ log.info("Could not create RegionsPersistenceImpl", e);
+ }
+ Activator.this.persistence.set(persistence);
+ }
+
+ public void serviceLost() {
+ if (reg != null) {
+ reg.unregister();
+ reg = null;
+ }
+ Activator.this.persistence.set(null);
+ Activator.this.bundleTracker.set(null);
+ }
+
+ public void serviceReplaced() {
+ //??
+ }
+ });
+ tracker.open();
+ }
+
+ @Override
+ public void stop(BundleContext bundleContext) throws Exception {
+ tracker.close();
+ persistence.set(null);
+ RegionsBundleTracker tracker = bundleTracker.getAndSet(null);
+ if (tracker != null) {
+ tracker.stop();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java b/region/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java
new file mode 100644
index 0000000..7035303
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/RegionsBundleTracker.java
@@ -0,0 +1,77 @@
+/*
+ * 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.karaf.region.persist.internal;
+
+import org.apache.karaf.features.RegionsPersistence;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleException;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RegionsBundleTracker {
+ private static final Logger log = LoggerFactory.getLogger(RegionsBundleTracker.class);
+
+ private BundleTracker bundleTracker;
+ private RegionsPersistence regionsPersistence;
+
+ void start(BundleContext bundleContext, RegionsPersistence regionsPersistence) {
+ this.regionsPersistence = regionsPersistence;
+ int stateMask = Bundle.INSTALLED;
+ bundleTracker = new BundleTracker<Bundle>(bundleContext, stateMask, new BundleTrackerCustomizer<Bundle>() {
+ @Override
+ public Bundle addingBundle(Bundle bundle, BundleEvent bundleEvent) {
+ return RegionsBundleTracker.this.addingBundle(bundle);
+ }
+
+ @Override
+ public void modifiedBundle(Bundle bundle, BundleEvent bundleEvent, Bundle o) {
+ }
+
+ @Override
+ public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Bundle o) {
+ }
+ });
+ bundleTracker.open();
+ }
+
+ private Bundle addingBundle(Bundle bundle) {
+ String region = bundle.getHeaders().get("Region");
+ if (region != null) {
+ try {
+ regionsPersistence.install(bundle, region);
+ log.debug("Installed bundle " + bundle + " in region " + region);
+ return bundle;
+ } catch (BundleException e) {
+ log.info("Could not install bundle " + bundle + " in region " + region, e);
+ }
+ }
+ return null;
+ }
+
+ void stop() {
+ bundleTracker.close();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java b/region/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java
new file mode 100644
index 0000000..dcf5d26
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/RegionsPersistenceImpl.java
@@ -0,0 +1,203 @@
+/*
+ * 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.karaf.region.persist.internal;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.karaf.features.RegionsPersistence;
+import org.apache.karaf.region.persist.internal.model.FilterAttributeType;
+import org.apache.karaf.region.persist.internal.model.FilterBundleType;
+import org.apache.karaf.region.persist.internal.model.FilterNamespaceType;
+import org.apache.karaf.region.persist.internal.model.FilterPackageType;
+import org.apache.karaf.region.persist.internal.model.FilterType;
+import org.apache.karaf.region.persist.internal.model.RegionBundleType;
+import org.apache.karaf.region.persist.internal.model.RegionType;
+import org.apache.karaf.region.persist.internal.model.RegionsType;
+import org.apache.karaf.region.persist.internal.util.ManifestHeaderProcessor;
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.eclipse.equinox.region.RegionFilterBuilder;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RegionsPersistenceImpl implements RegionsPersistence {
+
+ private static final Logger log = LoggerFactory.getLogger(RegionsPersistenceImpl.class);
+
+ private JAXBContext jaxbContext;
+ private RegionDigraph regionDigraph;
+ private Region kernel;
+ private Bundle framework;
+
+ public RegionsPersistenceImpl(RegionDigraph regionDigraph, Bundle framework) throws JAXBException, BundleException, IOException, InvalidSyntaxException {
+ log.info("Loading region digraph persistence");
+ this.framework = framework;
+ this.regionDigraph = regionDigraph;
+ kernel = regionDigraph.getRegion(0);
+ jaxbContext = JAXBContext.newInstance(RegionsType.class);
+ load();
+ }
+
+ @Override
+ public void install(Bundle b, String regionName) throws BundleException {
+ Region region = regionDigraph.getRegion(regionName);
+ if (region == null) {
+ region = regionDigraph.createRegion(regionName);
+ }
+ kernel.removeBundle(b);
+ region.addBundle(b);
+ }
+
+ void save(RegionsType regionsType, Writer out) throws JAXBException {
+ Marshaller marshaller = jaxbContext.createMarshaller();
+ marshaller.marshal(regionsType, out);
+ }
+
+ void load() throws IOException, BundleException, JAXBException, InvalidSyntaxException {
+ if (this.regionDigraph.getRegions().size() <= 1) {
+ File etc = new File(System.getProperty("karaf.etc"));
+ File regionsConfig = new File(etc, "regions-config.xml");
+ if (regionsConfig.exists()) {
+ log.info("initializing region digraph from etc/regions-config.xml");
+ Reader in = new FileReader(regionsConfig);
+ try {
+ load(this.regionDigraph, in);
+ } finally {
+ in.close();
+ }
+ } else {
+ log.info("no regions config file");
+ }
+ }
+
+ }
+
+ void load(RegionDigraph regionDigraph, Reader in) throws JAXBException, BundleException, InvalidSyntaxException {
+ RegionsType regionsType = load(in);
+ load(regionsType, regionDigraph);
+ }
+
+ RegionsType load(Reader in) throws JAXBException {
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+ return (RegionsType) unmarshaller.unmarshal(in);
+ }
+
+ void load(RegionsType regionsType, RegionDigraph regionDigraph) throws BundleException, InvalidSyntaxException {
+ BundleContext frameworkContext = framework.getBundleContext();
+ for (RegionType regionType: regionsType.getRegion()) {
+ String name = regionType.getName();
+ log.debug("Creating region: " + name);
+ Region region = regionDigraph.createRegion(name);
+ for (RegionBundleType bundleType: regionType.getBundle()) {
+ if (bundleType.getId() != null) {
+ region.addBundle(bundleType.getId());
+ } else {
+ Bundle b = frameworkContext.getBundle(bundleType.getLocation());
+ region.addBundle(b);
+ }
+ }
+ }
+ for (FilterType filterType: regionsType.getFilter()) {
+ Region from = regionDigraph.getRegion(filterType.getFrom());
+ Region to = regionDigraph.getRegion(filterType.getTo());
+ log.debug("Creating filter between " + from.getName() + " to " + to.getName());
+ RegionFilterBuilder builder = regionDigraph.createRegionFilterBuilder();
+ for (FilterBundleType bundleType: filterType.getBundle()) {
+ String symbolicName = bundleType.getSymbolicName();
+ String version = bundleType.getVersion();
+ if (bundleType.getId() != null) {
+ Bundle b = frameworkContext.getBundle(bundleType.getId());
+ symbolicName = b.getSymbolicName();
+ version = b.getVersion().toString();
+ }
+ String namespace = BundleRevision.BUNDLE_NAMESPACE;
+ List<FilterAttributeType> attributeTypes = bundleType.getAttribute();
+ buildFilter(symbolicName, version, namespace, attributeTypes, builder);
+ }
+ for (FilterPackageType packageType: filterType.getPackage()) {
+ String packageName = packageType.getName();
+ String version = packageType.getVersion();
+ String namespace = BundleRevision.PACKAGE_NAMESPACE;
+ List<FilterAttributeType> attributeTypes = packageType.getAttribute();
+ buildFilter(packageName, version, namespace, attributeTypes, builder);
+ }
+ if (to == kernel) {
+ //add framework exports
+ BundleRevision rev = framework.adapt(BundleRevision.class);
+ List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
+ for (BundleCapability cap : caps) {
+ String filter = ManifestHeaderProcessor.generateFilter(filter(cap.getAttributes()));
+ builder.allow(BundleRevision.PACKAGE_NAMESPACE, filter);
+ }
+ }
+ //TODO explicit services?
+ for (FilterNamespaceType namespaceType: filterType.getNamespace()) {
+ String namespace = namespaceType.getName();
+ HashMap<String, Object> attributes = new HashMap<String, Object>();
+ for (FilterAttributeType attributeType: namespaceType.getAttribute()) {
+ attributes.put(attributeType.getName(), attributeType.getValue());
+ }
+ String filter = ManifestHeaderProcessor.generateFilter(attributes);
+ builder.allow(namespace, filter);
+ }
+ regionDigraph.connect(from, builder.build(), to);
+ }
+ }
+
+ private Map<String, Object> filter(Map<String, Object> attributes) {
+ Map<String, Object> result = new HashMap<String, Object>(attributes);
+ result.remove("bundle-version");
+ result.remove("bundle-symbolic-name");
+ return result;
+ }
+
+ private void buildFilter(String packageName, String version, String namespace, List<FilterAttributeType> attributeTypes, RegionFilterBuilder builder) throws InvalidSyntaxException {
+ HashMap<String, Object> attributes = new HashMap<String, Object>();
+ if (namespace != null) {
+ attributes.put(namespace, packageName);
+ }
+ if (version != null) {
+ attributes.put("version", version);
+ }
+ for (FilterAttributeType attributeType: attributeTypes) {
+ attributes.put(attributeType.getName(), attributeType.getValue());
+ }
+ String filter = ManifestHeaderProcessor.generateFilter(attributes);
+ builder.allow(namespace, filter);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterAttributeType.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterAttributeType.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterAttributeType.java
new file mode 100644
index 0000000..857c2b3
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterAttributeType.java
@@ -0,0 +1,94 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for filterAttributeType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="filterAttributeType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * </sequence>
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="value" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "filterAttributeType")
+public class FilterAttributeType {
+
+ @XmlAttribute(required = true)
+ protected String name;
+ @XmlAttribute(required = true)
+ protected String value;
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+ /**
+ * Gets the value of the value property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value of the value property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterBundleType.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterBundleType.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterBundleType.java
new file mode 100644
index 0000000..a9a9fbb
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterBundleType.java
@@ -0,0 +1,156 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for filterBundleType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="filterBundleType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="attribute" type="{http://karaf.apache.org/xmlns/region/v1.0.0}filterAttributeType" maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}long" />
+ * <attribute name="symbolic-name" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="version" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "filterBundleType", propOrder = {
+ "attribute"
+})
+public class FilterBundleType {
+
+ protected List<FilterAttributeType> attribute;
+ @XmlAttribute
+ protected Long id;
+ @XmlAttribute(name = "symbolic-name")
+ protected String symbolicName;
+ @XmlAttribute
+ protected String version;
+
+ /**
+ * Gets the value of the attribute property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the attribute property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getAttribute().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link FilterAttributeType }
+ *
+ *
+ */
+ public List<FilterAttributeType> getAttribute() {
+ if (attribute == null) {
+ attribute = new ArrayList<FilterAttributeType>();
+ }
+ return this.attribute;
+ }
+
+ /**
+ * Gets the value of the id property.
+ *
+ * @return
+ * possible object is
+ * {@link Long }
+ *
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * Sets the value of the id property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Long }
+ *
+ */
+ public void setId(Long value) {
+ this.id = value;
+ }
+
+ /**
+ * Gets the value of the symbolicName property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getSymbolicName() {
+ return symbolicName;
+ }
+
+ /**
+ * Sets the value of the symbolicName property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setSymbolicName(String value) {
+ this.symbolicName = value;
+ }
+
+ /**
+ * Gets the value of the version property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Sets the value of the version property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setVersion(String value) {
+ this.version = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterNamespaceType.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterNamespaceType.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterNamespaceType.java
new file mode 100644
index 0000000..52b937a
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterNamespaceType.java
@@ -0,0 +1,102 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for filterNamespaceType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="filterNamespaceType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="attribute" type="{http://karaf.apache.org/xmlns/region/v1.0.0}filterAttributeType" maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "filterNamespaceType", propOrder = {
+ "attribute"
+})
+public class FilterNamespaceType {
+
+ protected List<FilterAttributeType> attribute;
+ @XmlAttribute(required = true)
+ protected String name;
+
+ /**
+ * Gets the value of the attribute property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the attribute property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getAttribute().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link FilterAttributeType }
+ *
+ *
+ */
+ public List<FilterAttributeType> getAttribute() {
+ if (attribute == null) {
+ attribute = new ArrayList<FilterAttributeType>();
+ }
+ return this.attribute;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterPackageType.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterPackageType.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterPackageType.java
new file mode 100644
index 0000000..b4216ee
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterPackageType.java
@@ -0,0 +1,129 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for filterPackageType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="filterPackageType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="attribute" type="{http://karaf.apache.org/xmlns/region/v1.0.0}filterAttributeType" maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="version" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "filterPackageType", propOrder = {
+ "attribute"
+})
+public class FilterPackageType {
+
+ protected List<FilterAttributeType> attribute;
+ @XmlAttribute
+ protected String name;
+ @XmlAttribute
+ protected String version;
+
+ /**
+ * Gets the value of the attribute property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the attribute property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getAttribute().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link FilterAttributeType }
+ *
+ *
+ */
+ public List<FilterAttributeType> getAttribute() {
+ if (attribute == null) {
+ attribute = new ArrayList<FilterAttributeType>();
+ }
+ return this.attribute;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+ /**
+ * Gets the value of the version property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Sets the value of the version property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setVersion(String value) {
+ this.version = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterType.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterType.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterType.java
new file mode 100644
index 0000000..f4d1352
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/FilterType.java
@@ -0,0 +1,195 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for filterType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="filterType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="bundle" type="{http://karaf.apache.org/xmlns/region/v1.0.0}filterBundleType" maxOccurs="unbounded" minOccurs="0"/>
+ * <element name="package" type="{http://karaf.apache.org/xmlns/region/v1.0.0}filterPackageType" maxOccurs="unbounded" minOccurs="0"/>
+ * <element name="namespace" type="{http://karaf.apache.org/xmlns/region/v1.0.0}filterNamespaceType" maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * <attribute name="from" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="to" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "filterType", propOrder = {
+ "bundle",
+ "_package",
+ "namespace"
+})
+public class FilterType {
+
+ protected List<FilterBundleType> bundle;
+ @XmlElement(name = "package")
+ protected List<FilterPackageType> _package;
+ protected List<FilterNamespaceType> namespace;
+ @XmlAttribute(required = true)
+ protected String from;
+ @XmlAttribute(required = true)
+ protected String to;
+
+ /**
+ * Gets the value of the bundle property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the bundle property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getBundle().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link FilterBundleType }
+ *
+ *
+ */
+ public List<FilterBundleType> getBundle() {
+ if (bundle == null) {
+ bundle = new ArrayList<FilterBundleType>();
+ }
+ return this.bundle;
+ }
+
+ /**
+ * Gets the value of the package property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the package property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getPackage().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link FilterPackageType }
+ *
+ *
+ */
+ public List<FilterPackageType> getPackage() {
+ if (_package == null) {
+ _package = new ArrayList<FilterPackageType>();
+ }
+ return this._package;
+ }
+
+ /**
+ * Gets the value of the namespace property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the namespace property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getNamespace().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link FilterNamespaceType }
+ *
+ *
+ */
+ public List<FilterNamespaceType> getNamespace() {
+ if (namespace == null) {
+ namespace = new ArrayList<FilterNamespaceType>();
+ }
+ return this.namespace;
+ }
+
+ /**
+ * Gets the value of the from property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getFrom() {
+ return from;
+ }
+
+ /**
+ * Sets the value of the from property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setFrom(String value) {
+ this.from = value;
+ }
+
+ /**
+ * Gets the value of the to property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getTo() {
+ return to;
+ }
+
+ /**
+ * Sets the value of the to property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setTo(String value) {
+ this.to = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/ObjectFactory.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/ObjectFactory.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/ObjectFactory.java
new file mode 100644
index 0000000..54f5f3c
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/ObjectFactory.java
@@ -0,0 +1,116 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.annotation.XmlElementDecl;
+import javax.xml.bind.annotation.XmlRegistry;
+import javax.xml.namespace.QName;
+
+
+/**
+ * This object contains factory methods for each
+ * Java content interface and Java element interface
+ * generated in the org.apache.karaf.region.persist.internal.model package.
+ * <p>An ObjectFactory allows you to programatically
+ * construct new instances of the Java representation
+ * for XML content. The Java representation of XML
+ * content can consist of schema derived interfaces
+ * and classes representing the binding of schema
+ * type definitions, element declarations and model
+ * groups. Factory methods for each of these are
+ * provided in this class.
+ *
+ */
+@XmlRegistry
+public class ObjectFactory {
+
+ private final static QName _Regions_QNAME = new QName("http://karaf.apache.org/xmlns/region/v1.0.0", "regions");
+
+ /**
+ * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.apache.karaf.region.persist.internal.model
+ *
+ */
+ public ObjectFactory() {
+ }
+
+ /**
+ * Create an instance of {@link FilterNamespaceType }
+ *
+ */
+ public FilterNamespaceType createFilterNamespaceType() {
+ return new FilterNamespaceType();
+ }
+
+ /**
+ * Create an instance of {@link FilterType }
+ *
+ */
+ public FilterType createFilterType() {
+ return new FilterType();
+ }
+
+ /**
+ * Create an instance of {@link RegionBundleType }
+ *
+ */
+ public RegionBundleType createRegionBundleType() {
+ return new RegionBundleType();
+ }
+
+ /**
+ * Create an instance of {@link FilterBundleType }
+ *
+ */
+ public FilterBundleType createFilterBundleType() {
+ return new FilterBundleType();
+ }
+
+ /**
+ * Create an instance of {@link FilterPackageType }
+ *
+ */
+ public FilterPackageType createFilterPackageType() {
+ return new FilterPackageType();
+ }
+
+ /**
+ * Create an instance of {@link FilterAttributeType }
+ *
+ */
+ public FilterAttributeType createFilterAttributeType() {
+ return new FilterAttributeType();
+ }
+
+ /**
+ * Create an instance of {@link RegionType }
+ *
+ */
+ public RegionType createRegionType() {
+ return new RegionType();
+ }
+
+ /**
+ * Create an instance of {@link RegionsType }
+ *
+ */
+ public RegionsType createRegionsType() {
+ return new RegionsType();
+ }
+
+ /**
+ * Create an instance of {@link JAXBElement }{@code <}{@link RegionsType }{@code >}}
+ *
+ */
+ @XmlElementDecl(namespace = "http://karaf.apache.org/xmlns/region/v1.0.0", name = "regions")
+ public JAXBElement<RegionsType> createRegions(RegionsType value) {
+ return new JAXBElement<RegionsType>(_Regions_QNAME, RegionsType.class, null, value);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionBundleType.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionBundleType.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionBundleType.java
new file mode 100644
index 0000000..7ba3585
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionBundleType.java
@@ -0,0 +1,94 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for regionBundleType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="regionBundleType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * </sequence>
+ * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}long" />
+ * <attribute name="location" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "regionBundleType")
+public class RegionBundleType {
+
+ @XmlAttribute
+ protected Long id;
+ @XmlAttribute
+ protected String location;
+
+ /**
+ * Gets the value of the id property.
+ *
+ * @return
+ * possible object is
+ * {@link Long }
+ *
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * Sets the value of the id property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Long }
+ *
+ */
+ public void setId(Long value) {
+ this.id = value;
+ }
+
+ /**
+ * Gets the value of the location property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getLocation() {
+ return location;
+ }
+
+ /**
+ * Sets the value of the location property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setLocation(String value) {
+ this.location = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionType.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionType.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionType.java
new file mode 100644
index 0000000..f7a810d
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionType.java
@@ -0,0 +1,106 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ *
+ * Regions element
+ *
+ *
+ * <p>Java class for regionType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="regionType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="bundle" type="{http://karaf.apache.org/xmlns/region/v1.0.0}regionBundleType" maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "regionType", propOrder = {
+ "bundle"
+})
+public class RegionType {
+
+ protected List<RegionBundleType> bundle;
+ @XmlAttribute(required = true)
+ protected String name;
+
+ /**
+ * Gets the value of the bundle property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the bundle property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getBundle().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link RegionBundleType }
+ *
+ *
+ */
+ public List<RegionBundleType> getBundle() {
+ if (bundle == null) {
+ bundle = new ArrayList<RegionBundleType>();
+ }
+ return this.bundle;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionsType.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionsType.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionsType.java
new file mode 100644
index 0000000..be172e4
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/RegionsType.java
@@ -0,0 +1,112 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+
+package org.apache.karaf.region.persist.internal.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ *
+ * Regions element
+ *
+ *
+ * <p>Java class for regionsType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="regionsType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="region" type="{http://karaf.apache.org/xmlns/region/v1.0.0}regionType" maxOccurs="unbounded" minOccurs="0"/>
+ * <element name="filter" type="{http://karaf.apache.org/xmlns/region/v1.0.0}filterType" maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlRootElement(name = "regions")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "regionsType", propOrder = {
+ "region",
+ "filter"
+})
+public class RegionsType {
+
+ protected List<RegionType> region;
+ protected List<FilterType> filter;
+
+ /**
+ * Gets the value of the region property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the region property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getRegion().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link RegionType }
+ *
+ *
+ */
+ public List<RegionType> getRegion() {
+ if (region == null) {
+ region = new ArrayList<RegionType>();
+ }
+ return this.region;
+ }
+
+ /**
+ * Gets the value of the filter property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the filter property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getFilter().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link FilterType }
+ *
+ *
+ */
+ public List<FilterType> getFilter() {
+ if (filter == null) {
+ filter = new ArrayList<FilterType>();
+ }
+ return this.filter;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1bcdb173/region/src/main/java/org/apache/karaf/region/persist/internal/model/package-info.java
----------------------------------------------------------------------
diff --git a/region/src/main/java/org/apache/karaf/region/persist/internal/model/package-info.java b/region/src/main/java/org/apache/karaf/region/persist/internal/model/package-info.java
new file mode 100644
index 0000000..cae062c
--- /dev/null
+++ b/region/src/main/java/org/apache/karaf/region/persist/internal/model/package-info.java
@@ -0,0 +1,9 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2011.10.28 at 03:20:55 PM PDT
+//
+
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://karaf.apache.org/xmlns/region/v1.0.0", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package org.apache.karaf.region.persist.internal.model;