1 19 20 package org.netbeans.core.registry; 21 22 import org.netbeans.core.registry.ContextImpl; 23 import org.netbeans.core.registry.ObjectBinding; 24 import org.netbeans.spi.registry.BasicContext; 25 import org.netbeans.spi.registry.SpiUtils; 26 import org.openide.filesystems.FileObject; 27 28 import java.io.IOException ; 29 30 34 final class ShadowBinding { 35 private static final String SHADOW_EXTENSION = "shadow"; static final ObjectBinding.Reader READER = new ObjectBinding.Reader() { 37 boolean canRead(FileObject fo) { 38 return fo.getExt().equalsIgnoreCase(SHADOW_EXTENSION); 39 } 40 41 String getFileExtension() { 42 return SHADOW_EXTENSION; 43 } 44 45 ObjectBinding getObjectBinding(BasicContext ctx, FileObject fo) { 46 return new ObjectBindingImpl((ContextImpl) ctx, fo); 47 } 48 }; 49 50 private ShadowBinding() { 51 } 52 53 private static class ObjectBindingImpl extends ObjectBinding { 54 private ContextImpl context; 55 56 protected ObjectBindingImpl(ContextImpl context, FileObject fo) { 57 super(fo); 58 this.context = context; 59 } 60 61 public Object createInstance() throws IOException { 62 FileObject fo = getFile(); 64 String originalFile = (String ) fo.getAttribute("originalFile"); int i = originalFile.lastIndexOf('/'); String contextName = "/" + originalFile.substring(0, i); String bindingName = originalFile.substring(i + 1); 69 i = bindingName.lastIndexOf('.'); 70 if (i > 0) { 71 bindingName = bindingName.substring(0, i); 72 } 73 return SpiUtils.createObjectRef(context.getRootContextImpl(), contextName, bindingName); 74 } 75 76 public boolean isEnabled() { 77 return (getFile() != null && getFile().isValid()); 78 } 79 } 80 81 } 82 83 | Popular Tags |